001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * CreateHyperLinksFunction.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.function;
030:
031: import org.jfree.report.Band;
032: import org.jfree.report.Element;
033: import org.jfree.report.style.ElementStyleKeys;
034:
035: /**
036: * Adds hyperlinks to all elements with the name specified in 'element'. The link target is read from a specified field.
037: * The column referenced by this field should contain URLs or Strings.
038: *
039: * @author Thomas Morgner
040: * @deprecated add style expressions to the 'href-target' and 'href-window' instead. It is much easier and less
041: * confusing.
042: */
043: public class CreateHyperLinksFunction extends
044: AbstractElementFormatFunction {
045: /**
046: * The field name from where to read the hyper-link target.
047: */
048: private String field;
049: /**
050: * The field from where to read the link target-window specifier.
051: */
052: private String windowField;
053: /**
054: * The constant target window. This property is used if no window field was set.
055: */
056: private String target;
057:
058: /**
059: * Default Constructor.
060: */
061: public CreateHyperLinksFunction() {
062: }
063:
064: /**
065: * Returns the field name from where to read the hyper-link target.
066: *
067: * @return the name of the field.
068: */
069: public String getField() {
070: return field;
071: }
072:
073: /**
074: * Defines the field name from where to read the hyper-link target.
075: *
076: * @param field a field name.
077: */
078: public void setField(final String field) {
079: this .field = field;
080: }
081:
082: /**
083: * Returns the target window. This property is used if no window field was set. This is only meaningful for HTML
084: * exports.
085: *
086: * @return the target window string.
087: */
088: public String getTarget() {
089: return target;
090: }
091:
092: /**
093: * Defines the target window. This property is used if no window field was set. This is only meaningful for HTML
094: * exports.
095: *
096: * @param target the target window string.
097: */
098: public void setTarget(final String target) {
099: this .target = target;
100: }
101:
102: /**
103: * Returns the datarow-field from where to read the target window. This is only meaningful for HTML
104: * exports.
105: *
106: * @return the fieldname from where to read the target window string.
107: */
108: public String getWindowField() {
109: return windowField;
110: }
111:
112: /**
113: * Defines the datarow-field from where to read the target window. This is only meaningful for HTML
114: * exports.
115: *
116: * @param windowField the fieldname from where to read the target window string.
117: */
118: public void setWindowField(final String windowField) {
119: this .windowField = windowField;
120: }
121:
122: /**
123: * Updates the root band and adds a hyperlink to all elements that have the specified name.
124: * @param b the root band.
125: */
126: protected void processRootBand(final Band b) {
127: String hrefLinkTarget = null;
128: final Object targetRaw = getDataRow().get(getField());
129: if (targetRaw != null) {
130: hrefLinkTarget = String.valueOf(targetRaw);
131: }
132:
133: if (hrefLinkTarget == null) {
134: return;
135: }
136:
137: final String windowField = getWindowField();
138: final String window;
139: if (windowField != null) {
140: final Object windowRaw = getDataRow().get(windowField);
141: if (windowRaw != null) {
142: window = String.valueOf(windowRaw);
143: } else {
144: window = null;
145: }
146: } else {
147: window = getTarget();
148: }
149:
150: final Element[] elements = FunctionUtilities.findAllElements(b,
151: getElement());
152: for (int i = 0; i < elements.length; i++) {
153: elements[i].setHRefTarget(hrefLinkTarget);
154: if (window != null) {
155: elements[i].getStyle().setStyleProperty(
156: ElementStyleKeys.HREF_WINDOW, window);
157: }
158: }
159: }
160: }
|