KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > JRHyperlinkHelper


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;
29
30 import java.util.HashMap JavaDoc;
31 import java.util.Map JavaDoc;
32
33
34 /**
35  * Utility class that manages built-in hyperlink types.
36  *
37  * @author Lucian Chirita (lucianc@users.sourceforge.net)
38  * @version $Id: JRHyperlinkHelper.java 1355 2006-08-04 17:31:54 +0300 (Fri, 04 Aug 2006) lucianc $
39  */

40 public class JRHyperlinkHelper
41 {
42     /**
43      * "None" link type, equivalent to {@link JRHyperlink#HYPERLINK_TYPE_NONE JRHyperlink.HYPERLINK_TYPE_NONE}.
44      */

45     public static final String JavaDoc HYPERLINK_TYPE_NONE = "None";
46     
47     /**
48      * "Reference" link type, equivalent to {@link JRHyperlink#HYPERLINK_TYPE_REFERENCE JRHyperlink.HYPERLINK_TYPE_REFERENCE}.
49      */

50     public static final String JavaDoc HYPERLINK_TYPE_REFERENCE = "Reference";
51     
52     /**
53      * "LocalAnchor" link type, equivalent to {@link JRHyperlink#HYPERLINK_TYPE_LOCAL_ANCHOR JRHyperlink.HYPERLINK_LOCAL_ANCHOR}.
54      */

55     public static final String JavaDoc HYPERLINK_TYPE_LOCAL_ANCHOR = "LocalAnchor";
56     
57     /**
58      * "LocalPage" link type, equivalent to {@link JRHyperlink#HYPERLINK_TYPE_LOCAL_PAGE JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE}.
59      */

60     public static final String JavaDoc HYPERLINK_TYPE_LOCAL_PAGE = "LocalPage";
61     
62     /**
63      * "RemoteAnchor" link type, equivalent to {@link JRHyperlink#HYPERLINK_TYPE_REMOTE_ANCHOR JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR}.
64      */

65     public static final String JavaDoc HYPERLINK_TYPE_REMOTE_ANCHOR = "RemoteAnchor";
66     
67     /**
68      * "RemotePage" link type, equivalent to {@link JRHyperlink#HYPERLINK_TYPE_REMOTE_PAGE JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE}.
69      */

70     public static final String JavaDoc HYPERLINK_TYPE_REMOTE_PAGE = "RemotePage";
71     
72     private static final Map JavaDoc builtinTypes;
73     
74     static
75     {
76         builtinTypes = createBuiltinTypes();
77     }
78
79     private static Map JavaDoc createBuiltinTypes()
80     {
81         Map JavaDoc types = new HashMap JavaDoc();
82         types.put(HYPERLINK_TYPE_NONE, new Byte JavaDoc(JRHyperlink.HYPERLINK_TYPE_NONE));
83         types.put(HYPERLINK_TYPE_REFERENCE, new Byte JavaDoc(JRHyperlink.HYPERLINK_TYPE_REFERENCE));
84         types.put(HYPERLINK_TYPE_LOCAL_ANCHOR, new Byte JavaDoc(JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR));
85         types.put(HYPERLINK_TYPE_LOCAL_PAGE, new Byte JavaDoc(JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE));
86         types.put(HYPERLINK_TYPE_REMOTE_ANCHOR, new Byte JavaDoc(JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR));
87         types.put(HYPERLINK_TYPE_REMOTE_PAGE, new Byte JavaDoc(JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE));
88         return types;
89     }
90     
91     
92     /**
93      * Returns the built-in hyperlink type, or {@link JRHyperlink#HYPERLINK_TYPE_CUSTOM JRHyperlink.HYPERLINK_TYPE_CUSTOM}
94      * if the type is not a built-in type.
95      *
96      * @param hyperlink the hyperlink object
97      * @return the hyperlink type
98      */

99     public static byte getHyperlinkType(JRHyperlink hyperlink)
100     {
101         return getHyperlinkType(hyperlink.getLinkType());
102     }
103     
104
105     /**
106      * Returns the built-in hyperlink type, or {@link JRHyperlink#HYPERLINK_TYPE_CUSTOM JRHyperlink.HYPERLINK_TYPE_CUSTOM}
107      * if the type is not a built-in type.
108      *
109      * @param linkType the link type
110      * @return the hyperlink type
111      */

112     public static byte getHyperlinkType(String JavaDoc linkType)
113     {
114         byte type;
115         if (linkType == null)
116         {
117             type = JRHyperlink.HYPERLINK_TYPE_NONE;
118         }
119         else
120         {
121             Byte JavaDoc builtinType = (Byte JavaDoc) builtinTypes.get(linkType);
122             if (builtinType == null)
123             {
124                 type = JRHyperlink.HYPERLINK_TYPE_CUSTOM;
125             }
126             else
127             {
128                 type = builtinType.byteValue();
129             }
130         }
131         return type;
132     }
133     
134     
135     /**
136      * Returns the link type associated with a built-in type.
137      *
138      * @param hyperlinkType the built-in type
139      * @return the String link type
140      */

141     public static String JavaDoc getLinkType(byte hyperlinkType)
142     {
143         String JavaDoc type;
144         switch (hyperlinkType)
145         {
146             case JRHyperlink.HYPERLINK_TYPE_NULL:
147             case JRHyperlink.HYPERLINK_TYPE_NONE:
148                 type = null;
149                 break;
150             case JRHyperlink.HYPERLINK_TYPE_REFERENCE:
151                 type = HYPERLINK_TYPE_REFERENCE;
152                 break;
153             case JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR:
154                 type = HYPERLINK_TYPE_LOCAL_ANCHOR;
155                 break;
156             case JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE:
157                 type = HYPERLINK_TYPE_LOCAL_PAGE;
158                 break;
159             case JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR:
160                 type = HYPERLINK_TYPE_REMOTE_ANCHOR;
161                 break;
162             case JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE:
163                 type = HYPERLINK_TYPE_REMOTE_PAGE;
164                 break;
165             case JRHyperlink.HYPERLINK_TYPE_CUSTOM:
166                 throw new JRRuntimeException("Custom hyperlink types cannot be specified using the byte constant");
167             default:
168                 throw new JRRuntimeException("Unknown hyperlink type " + hyperlinkType);
169         }
170         return type;
171     }
172
173 }
174
Popular Tags