KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > fill > JRFillHyperlinkHelper


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.engine.fill;
29
30 import net.sf.jasperreports.engine.JRException;
31 import net.sf.jasperreports.engine.JRExpression;
32 import net.sf.jasperreports.engine.JRHyperlink;
33 import net.sf.jasperreports.engine.JRHyperlinkParameter;
34 import net.sf.jasperreports.engine.JRPrintHyperlink;
35 import net.sf.jasperreports.engine.JRPrintHyperlinkParameter;
36 import net.sf.jasperreports.engine.JRPrintHyperlinkParameters;
37 import net.sf.jasperreports.engine.base.JRBasePrintHyperlink;
38
39
40 /**
41  * Utility class used to evaluate custom hyperlink parameters.
42  *
43  * @author Lucian Chirita (lucianc@users.sourceforge.net)
44  * @version $Id: JRFillHyperlinkHelper.java 1364 2006-08-31 18:13:20 +0300 (Thu, 31 Aug 2006) lucianc $
45  */

46 public class JRFillHyperlinkHelper
47 {
48
49     /**
50      * Evaluates a list of hyperlink parameters and produces a hyperlink paramters set
51      * that can be associated with a print element.
52      *
53      * @param hyperlink the hyperlink instance
54      * @param expressionEvaluator the expression evaluator to use for evaluation parameter value
55      * @param evaluationType the evaluation type
56      * @return a print hyperlink paramters set
57      * @throws JRException
58      */

59     public static JRPrintHyperlinkParameters evaluateHyperlinkParameters(
60             JRHyperlink hyperlink,
61             JRFillExpressionEvaluator expressionEvaluator,
62             byte evaluationType) throws JRException
63     {
64         JRHyperlinkParameter[] hyperlinkParameters = hyperlink.getHyperlinkParameters();
65         JRPrintHyperlinkParameters printParameters;
66         if (hyperlinkParameters == null)
67         {
68             printParameters = null;
69         }
70         else
71         {
72             printParameters = new JRPrintHyperlinkParameters();
73             for (int i = 0; i < hyperlinkParameters.length; i++)
74             {
75                 JRHyperlinkParameter hyperlinkParameter = hyperlinkParameters[i];
76                 JRExpression valueExpression = hyperlinkParameter.getValueExpression();
77                 Class JavaDoc valueClass;
78                 Object JavaDoc value;
79                 if (valueExpression == null)
80                 {
81                     value = null;
82                     valueClass = Object JavaDoc.class;
83                 }
84                 else
85                 {
86                     value = expressionEvaluator.evaluate(valueExpression, evaluationType);
87                     valueClass = valueExpression.getValueClass();
88                 }
89                 
90                 JRPrintHyperlinkParameter printParam = new JRPrintHyperlinkParameter(hyperlinkParameter.getName(), valueClass.getName(), value);
91                 printParameters.addParameter(printParam);
92             }
93         }
94         return printParameters;
95     }
96     
97     
98     /**
99      * Evaluate a hyperlink specification.
100      *
101      * @param hyperlink the hyperlink specification
102      * @param expressionEvaluator the expression evaluator to use for evaluation the hyperlink expressions
103      * @param evaluationType the evaluation type, as in {@link JRFillExpressionEvaluator#evaluate(JRExpression, byte) JRFillExpressionEvaluator.evaluate(JRExpression, byte)}
104      * @return a {@link JRPrintHyperlink print hyperlink} resulted from the expression evaluations.
105      * @throws JRException
106      */

107     public static JRPrintHyperlink evaluateHyperlink(JRHyperlink hyperlink,
108             JRFillExpressionEvaluator expressionEvaluator,
109             byte evaluationType) throws JRException
110     {
111         JRBasePrintHyperlink printHyperlink = new JRBasePrintHyperlink();
112         printHyperlink.setLinkType(hyperlink.getLinkType());
113         printHyperlink.setHyperlinkTarget(hyperlink.getHyperlinkTarget());
114         printHyperlink.setHyperlinkReference((String JavaDoc) expressionEvaluator.evaluate(hyperlink.getHyperlinkReferenceExpression(), evaluationType));
115         printHyperlink.setHyperlinkAnchor((String JavaDoc) expressionEvaluator.evaluate(hyperlink.getHyperlinkAnchorExpression(), evaluationType));
116         printHyperlink.setHyperlinkPage((Integer JavaDoc) expressionEvaluator.evaluate(hyperlink.getHyperlinkPageExpression(), evaluationType));
117         printHyperlink.setHyperlinkTooltip((String JavaDoc) expressionEvaluator.evaluate(hyperlink.getHyperlinkTooltipExpression(), evaluationType));
118         printHyperlink.setHyperlinkParameters(evaluateHyperlinkParameters(hyperlink, expressionEvaluator, evaluationType));
119         return printHyperlink;
120     }
121 }
122
Popular Tags