001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * 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,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.engine.fill;
029:
030: import net.sf.jasperreports.engine.JRException;
031: import net.sf.jasperreports.engine.JRExpression;
032: import net.sf.jasperreports.engine.JRHyperlink;
033: import net.sf.jasperreports.engine.JRHyperlinkParameter;
034: import net.sf.jasperreports.engine.JRPrintHyperlink;
035: import net.sf.jasperreports.engine.JRPrintHyperlinkParameter;
036: import net.sf.jasperreports.engine.JRPrintHyperlinkParameters;
037: import net.sf.jasperreports.engine.base.JRBasePrintHyperlink;
038:
039: /**
040: * Utility class used to evaluate custom hyperlink parameters.
041: *
042: * @author Lucian Chirita (lucianc@users.sourceforge.net)
043: * @version $Id: JRFillHyperlinkHelper.java 1364 2006-08-31 15:13:20Z lucianc $
044: */
045: public class JRFillHyperlinkHelper {
046:
047: /**
048: * Evaluates a list of hyperlink parameters and produces a hyperlink paramters set
049: * that can be associated with a print element.
050: *
051: * @param hyperlink the hyperlink instance
052: * @param expressionEvaluator the expression evaluator to use for evaluation parameter value
053: * @param evaluationType the evaluation type
054: * @return a print hyperlink paramters set
055: * @throws JRException
056: */
057: public static JRPrintHyperlinkParameters evaluateHyperlinkParameters(
058: JRHyperlink hyperlink,
059: JRFillExpressionEvaluator expressionEvaluator,
060: byte evaluationType) throws JRException {
061: JRHyperlinkParameter[] hyperlinkParameters = hyperlink
062: .getHyperlinkParameters();
063: JRPrintHyperlinkParameters printParameters;
064: if (hyperlinkParameters == null) {
065: printParameters = null;
066: } else {
067: printParameters = new JRPrintHyperlinkParameters();
068: for (int i = 0; i < hyperlinkParameters.length; i++) {
069: JRHyperlinkParameter hyperlinkParameter = hyperlinkParameters[i];
070: JRExpression valueExpression = hyperlinkParameter
071: .getValueExpression();
072: Class valueClass;
073: Object value;
074: if (valueExpression == null) {
075: value = null;
076: valueClass = Object.class;
077: } else {
078: value = expressionEvaluator.evaluate(
079: valueExpression, evaluationType);
080: valueClass = valueExpression.getValueClass();
081: }
082:
083: JRPrintHyperlinkParameter printParam = new JRPrintHyperlinkParameter(
084: hyperlinkParameter.getName(), valueClass
085: .getName(), value);
086: printParameters.addParameter(printParam);
087: }
088: }
089: return printParameters;
090: }
091:
092: /**
093: * Evaluate a hyperlink specification.
094: *
095: * @param hyperlink the hyperlink specification
096: * @param expressionEvaluator the expression evaluator to use for evaluation the hyperlink expressions
097: * @param evaluationType the evaluation type, as in {@link JRFillExpressionEvaluator#evaluate(JRExpression, byte) JRFillExpressionEvaluator.evaluate(JRExpression, byte)}
098: * @return a {@link JRPrintHyperlink print hyperlink} resulted from the expression evaluations.
099: * @throws JRException
100: */
101: public static JRPrintHyperlink evaluateHyperlink(
102: JRHyperlink hyperlink,
103: JRFillExpressionEvaluator expressionEvaluator,
104: byte evaluationType) throws JRException {
105: JRBasePrintHyperlink printHyperlink = new JRBasePrintHyperlink();
106: printHyperlink.setLinkType(hyperlink.getLinkType());
107: printHyperlink.setHyperlinkTarget(hyperlink
108: .getHyperlinkTarget());
109: printHyperlink
110: .setHyperlinkReference((String) expressionEvaluator
111: .evaluate(hyperlink
112: .getHyperlinkReferenceExpression(),
113: evaluationType));
114: printHyperlink.setHyperlinkAnchor((String) expressionEvaluator
115: .evaluate(hyperlink.getHyperlinkAnchorExpression(),
116: evaluationType));
117: printHyperlink.setHyperlinkPage((Integer) expressionEvaluator
118: .evaluate(hyperlink.getHyperlinkPageExpression(),
119: evaluationType));
120: printHyperlink.setHyperlinkTooltip((String) expressionEvaluator
121: .evaluate(hyperlink.getHyperlinkTooltipExpression(),
122: evaluationType));
123: printHyperlink
124: .setHyperlinkParameters(evaluateHyperlinkParameters(
125: hyperlink, expressionEvaluator, evaluationType));
126: return printHyperlink;
127: }
128: }
|