KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > web > JspTaglibSubTask


1 /*
2  * Copyright (c) 2001, 2002 The XDoclet team
3  * All rights reserved.
4  */

5 package xdoclet.modules.web;
6
7 import xdoclet.XDocletException;
8 import xdoclet.XDocletMessages;
9
10 import xdoclet.XmlSubTask;
11 import xdoclet.util.Translator;
12
13 /**
14  * Generates taglib.tld deployment descriptor for JSP taglibs.
15  *
16  * @author Ara Abrahamian (ara_e@email.com)
17  * @created July 12, 2001
18  * @ant.element display-name="JSP Taglib" name="jsptaglib" parent="xdoclet.modules.web.WebDocletTask"
19  * @version $Revision: 1.15 $
20  * @xdoclet.merge-file file="taglib-settings.xml" relates-to="taglib.tld" description="Unparsed XML entity containing
21  * (tlib-version, jsp-version, short-name, uri?, display-name?, small-icon?, large-icon?, description?) elements."
22  * @xdoclet.merge-file file="taglib-validator.xml" relates-to="taglib.tld" description="XML document containing the
23  * validator element, used to include a validator which isn't processed by XDoclet."
24  * @xdoclet.merge-file file="taglib-listener.xml" relates-to="taglib.tld" description="Unparsed XML entity containing
25  * additional listener elements, for including listeners not processed by XDoclet."
26  * @xdoclet.merge-file file="taglib-tag.xml" relates-to="taglib.tld" description="Unparsed XML entity containing
27  * additional tag elements, for including tags not processed by XDoclet."
28  */

29 public class JspTaglibSubTask extends XmlSubTask
30 {
31     private static String JavaDoc DEFAULT_TEMPLATE_FILE = "resources/taglib_tld.xdt";
32
33     private static String JavaDoc TLD_PUBLICID_2_0 = "http://java.sun.com/xml/ns/j2ee";
34     // xmlns attribute
35

36     private static String JavaDoc TLD_PUBLICID_1_2 = "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN";
37
38     private static String JavaDoc TLD_PUBLICID_1_1 = "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN";
39
40     private static String JavaDoc TLD_SYSTEMID_2_0 = "http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd";
41
42     private static String JavaDoc TLD_SYSTEMID_1_2 = "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd";
43
44     private static String JavaDoc TLD_SYSTEMID_1_1 = "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd";
45
46     private static String JavaDoc TLD_XSD_FILE_NAME_2_0 = "resources/web-jsptaglibrary_2_0.xsd";
47
48     private static String JavaDoc TLD_DTD_FILE_NAME_1_2 = "resources/web-jsptaglibrary_1_2.dtd";
49
50     private static String JavaDoc TLD_DTD_FILE_NAME_1_1 = "resources/web-jsptaglibrary_1_1.dtd";
51
52     protected String JavaDoc taglibversion = "1.0";
53
54     protected String JavaDoc jspversion = JspVersionTypes.VERSION_1_2;
55
56     protected String JavaDoc shortname = "";
57
58     protected String JavaDoc uri = "";
59
60     protected String JavaDoc displayname = "";
61
62     protected String JavaDoc smallicon = "";
63
64     protected String JavaDoc largeicon = "";
65
66     protected String JavaDoc description = "";
67
68     protected String JavaDoc filename = "taglib.tld";
69
70     /**
71      * Describe what the JspTaglibSubTask constructor does
72      */

73     public JspTaglibSubTask()
74     {
75         setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE));
76         setDestinationFile(filename);
77     }
78
79     /**
80      * Gets the Jspversion attribute of the JspTaglibSubTask object
81      *
82      * @return The Jspversion value
83      */

84     public String JavaDoc getJspversion()
85     {
86         return jspversion;
87     }
88
89     /**
90      * Gets the Taglibversion attribute of the JspTaglibSubTask object
91      *
92      * @return The Taglibversion value
93      */

94     public String JavaDoc getTaglibversion()
95     {
96         return taglibversion;
97     }
98
99     /**
100      * Gets the Shortname attribute of the JspTaglibSubTask object
101      *
102      * @return The Shortname value
103      */

104     public String JavaDoc getShortname()
105     {
106         return shortname;
107     }
108
109     /**
110      * Gets the Uri attribute of the JspTaglibSubTask object
111      *
112      * @return The Uri value
113      */

114     public String JavaDoc getUri()
115     {
116         return uri;
117     }
118
119     /**
120      * Gets the Displayname attribute of the JspTaglibSubTask object
121      *
122      * @return The Displayname value
123      */

124     public String JavaDoc getDisplayname()
125     {
126         return displayname;
127     }
128
129     /**
130      * Gets the Smallicon attribute of the JspTaglibSubTask object
131      *
132      * @return The Smallicon value
133      */

134     public String JavaDoc getSmallicon()
135     {
136         return smallicon;
137     }
138
139     /**
140      * Gets the Largeicon attribute of the JspTaglibSubTask object
141      *
142      * @return The Largeicon value
143      */

144     public String JavaDoc getLargeicon()
145     {
146         return largeicon;
147     }
148
149     /**
150      * Gets the Description attribute of the JspTaglibSubTask object
151      *
152      * @return The Description value
153      */

154     public String JavaDoc getDescription()
155     {
156         return description;
157     }
158
159     /**
160      * Gets the Filename attribute of the JspTaglibSubTask object
161      *
162      * @return The Filename value
163      */

164     public String JavaDoc getFilename()
165     {
166         return filename;
167     }
168
169     /**
170      * The JSP spec version to which the tag library conforms.
171      *
172      * @param jspversion The new Jspversion value
173      */

174     public void setJspversion(JspVersionTypes jspversion)
175     {
176         this.jspversion = jspversion.getValue();
177     }
178
179     /**
180      * The tag library implementation version.
181      *
182      * @param taglibversion The new Taglibversion value
183      */

184     public void setTaglibversion(String JavaDoc taglibversion)
185     {
186         this.taglibversion = taglibversion;
187     }
188
189     /**
190      * A simple default short name that could be used by a JSP authoring tool to create names with a mnemonic value. For
191      * example, it may be used as the prefered prefix value in taglib directives.
192      *
193      * @param shortname The new Shortname value
194      */

195     public void setShortname(String JavaDoc shortname)
196     {
197         this.shortname = shortname;
198     }
199
200     /**
201      * A URI uniquely identifying this tag library.
202      *
203      * @param uri The new Uri value
204      */

205     public void setUri(String JavaDoc uri)
206     {
207         this.uri = uri;
208     }
209
210     /**
211      * A short name that is intended to be displayed by tools.
212      *
213      * @param new_display_name The new Displayname value
214      */

215     public void setDisplayname(String JavaDoc new_display_name)
216     {
217         displayname = new_display_name;
218     }
219
220     /**
221      * Optional small-icon that can be used by tools.
222      *
223      * @param new_icon The new Smallicon value
224      */

225     public void setSmallicon(String JavaDoc new_icon)
226     {
227         smallicon = new_icon;
228     }
229
230     /**
231      * Optional large-icon that can be used by tools.
232      *
233      * @param new_icon The new Largeicon value
234      */

235     public void setLargeicon(String JavaDoc new_icon)
236     {
237         largeicon = new_icon;
238     }
239
240     /**
241      * A simple string describing the use of this tag library, Should be user discernable.
242      *
243      * @param new_description The new Description value
244      */

245     public void setDescription(String JavaDoc new_description)
246     {
247         description = new_description;
248     }
249
250     /**
251      * Specifies the filename of the generated tag library descriptor.
252      *
253      * @param new_filename The new Filename value
254      */

255     public void setFilename(String JavaDoc new_filename)
256     {
257         filename = new_filename;
258         setDestinationFile(filename);
259     }
260
261     /**
262      * Called to validate configuration parameters.
263      *
264      * @exception XDocletException
265      */

266     public void validateOptions() throws XDocletException
267     {
268         super.validateOptions();
269
270         if (getShortname() == null || getShortname().trim().equals("")) {
271             throw new XDocletException(Translator.getString(XDocletMessages.class, XDocletMessages.PARAMETER_MISSING_OR_EMPTY, new String JavaDoc[]{"shortName"}));
272         }
273     }
274
275     /**
276      * Describe what the method does
277      *
278      * @exception XDocletException
279      */

280     public void execute() throws XDocletException
281     {
282         if (getJspversion().equals(JspVersionTypes.VERSION_2_0)) {
283             setPublicId(TLD_PUBLICID_2_0);
284             // xmlns attribute
285
setSystemId(TLD_SYSTEMID_2_0);
286             // xsi:schemaLocation
287
setSchema(TLD_XSD_FILE_NAME_2_0);
288         }
289         else if (getJspversion().equals(JspVersionTypes.VERSION_1_1)) {
290             setPublicId(TLD_PUBLICID_1_1);
291             setSystemId(TLD_SYSTEMID_1_1);
292             setDtdURL(getClass().getResource(TLD_DTD_FILE_NAME_1_1));
293         }
294         else {
295             setPublicId(TLD_PUBLICID_1_2);
296             setSystemId(TLD_SYSTEMID_1_2);
297             setDtdURL(getClass().getResource(TLD_DTD_FILE_NAME_1_2));
298         }
299
300         startProcess();
301     }
302
303     /**
304      * Describe what the method does
305      *
306      * @exception XDocletException
307      */

308     protected void engineStarted() throws XDocletException
309     {
310         System.out.println(Translator.getString(XDocletMessages.class, XDocletMessages.GENERATING_SOMETHING, new String JavaDoc[]{getDestinationFile().toString()}));
311     }
312
313     /**
314      * Supported JSP spec versions.
315      *
316      * @author Ara Abrahamian (ara_e@email.com)
317      * @created July 19, 2001
318      */

319     public static class JspVersionTypes extends org.apache.tools.ant.types.EnumeratedAttribute
320     {
321         public final static String JavaDoc VERSION_1_1 = "1.1";
322         public final static String JavaDoc VERSION_1_2 = "1.2";
323         public final static String JavaDoc VERSION_2_0 = "2.0";
324
325         // We're getting there!
326

327         /**
328          * Gets the Values attribute of the JspVersionTypes object
329          *
330          * @return The Values value
331          */

332         public String JavaDoc[] getValues()
333         {
334             return (new String JavaDoc[]{VERSION_1_1, VERSION_1_2, VERSION_2_0});
335         }
336     }
337
338 }
339
Popular Tags