KickJava   Java API By Example, From Geeks To Geeks.

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


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

5 package xdoclet.modules.web;
6
7 import java.util.ArrayList JavaDoc;
8
9 import xdoclet.XDocletException;
10 import xdoclet.XDocletMessages;
11 import xdoclet.XmlSubTask;
12 import xdoclet.util.Translator;
13
14 /**
15  * Generates web.xml deployment descriptor.
16  *
17  * @author Ara Abrahamian (ara_e@email.com)
18  * @created June 19, 2001
19  * @ant.element display-name="web.xml" name="deploymentdescriptor" parent="xdoclet.modules.web.WebDocletTask"
20  * @version $Revision: 1.15 $
21  * @xdoclet.merge-file file="web-settings.xml" relates-to="web.xml" description="An XML unparsed entity containing
22  * (icon?, display-name?, description?, distributable?, context-param*) elements, to be used instead of generating
23  * them from config parameters."
24  * @xdoclet.merge-file file="filters.xml" relates-to="web.xml" description="An XML unparsed entity containing the
25  * filter elements for any additional filters not processed by XDoclet."
26  * @xdoclet.merge-file file="filter-mappings.xml" relates-to="web.xml" description="An XML unparsed entity containing
27  * the filter-mapping elements for any additional filters not processed by XDoclet."
28  * @xdoclet.merge-file file="listeners.xml" relates-to="web.xml" description="An XML unparsed entity containing the
29  * listener elements for any additional listeners not processed by XDoclet."
30  * @xdoclet.merge-file file="servlets.xml" relates-to="web.xml" description="An XML unparsed entity containing the
31  * servlet elements for any additional servlets not processed by XDoclet."
32  * @xdoclet.merge-file file="servlet-mappings.xml" relates-to="web.xml" description="An XML unparsed entity containing
33  * the servlet-mapping elements for any additional servlets not processed by XDoclet."
34  * @xdoclet.merge-file file="web-sec-rolerefs-{0}.xml" relates-to="web.xml" description="An XML unparsed entity
35  * containing any security-role-ref elements for a servlet, to use instead of generating from web.security-role-ref
36  * tags."
37  * @xdoclet.merge-file file="mime-mappings.xml" relates-to="web.xml" description="An XML unparsed entity containing
38  * the mime-mapping elements for the web application."
39  * @xdoclet.merge-file file="welcomefiles.xml" relates-to="web.xml" description="XML document containing a
40  * welcome-file-list element, used instead of welcomeFiles config parameters."
41  * @xdoclet.merge-file file="error-pages.xml" relates-to="web.xml" description="An XML unparsed entity containing the
42  * error-page elements for the web application."
43  * @xdoclet.merge-file file="taglibs.xml" relates-to="web.xml" description="An XML unparsed entity containing taglib
44  * elements, for tag libraries not defined in tagLibs config parameters."
45  * @xdoclet.merge-file file="web-resource-env-refs.xml" relates-to="web.xml" description="An XML unparsed entity
46  * containing resource-env-ref elements for any resources not specified by web.resource-env-ref tags."
47  * @xdoclet.merge-file file="ejb-resourcerefs.xml" relates-to="web.xml" description="An XML unparsed entity containing
48  * resource-ref entities for any resources not specified in web.resource-ref tags."
49  * @xdoclet.merge-file file="ejb-resourcerefs-{0}.xml" relates-to="web.xml" description="An XML unparsed entity
50  * containing resource-ref entities for any resources for a class not specified in web.resource-ref tags."
51  * @xdoclet.merge-file file="web-security.xml" relates-to="web.xml" description="An XML unparsed entity containing the
52  * (security-constraint*, login-config?) elements for the web application."
53  * @xdoclet.merge-file file="web-sec-roles.xml" relates-to="web.xml" description="An XML unparsed entity containing
54  * security-role entities for any roles not specified in web.security-role tags."
55  * @xdoclet.merge-file file="web-env-entries.xml" relates-to="web.xml" description="An XML unparsed entity containing
56  * env-entry entities for any entries not specified in web.env-entry tags."
57  * @xdoclet.merge-file file="web-env-entries-{0}.xml" relates-to="web.xml" description="An XML unparsed entity
58  * containing env-entry entities for any entries for a class not specified in web.env-entry tags."
59  * @xdoclet.merge-file file="web-ejbrefs.xml" relates-to="web.xml" description="An XML unparsed entity containing
60  * ejb-ref entities for any EJB references not specified in web.ejb-ref tags."
61  * @xdoclet.merge-file file="web-ejbrefs-{0}.xml" relates-to="web.xml" description="An XML unparsed entity containing
62  * ejb-ref entities for any EJB references for a class not specified in web.ejb-ref tags."
63  * @xdoclet.merge-file file="web-ejbrefs-local.xml" relates-to="web.xml" description="An XML unparsed entity
64  * containing ejb-local-ref entities for any EJB local references not specified in web.ejb-local-ref tags."
65  * @xdoclet.merge-file file="web-ejbrefs-local-{0}.xml" relates-to="web.xml" description="An XML unparsed entity
66  * containing ejb-local-ref entities for any EJB local references for a class not specified in web.ejb-local-ref
67  * tags."
68  * @xdoclet.merge-file file="taglib-functions.ent" relates-to="taglib_tld.xml" description="An XML unparsed entity
69  * containing describe functions in JSP 2.0 taglibs."
70  */

71 public class WebXmlSubTask extends XmlSubTask
72 {
73     private final static String JavaDoc DEFAULT_TEMPLATE_FILE = "resources/web_xml.xdt";
74
75     private final static String JavaDoc GENERATED_FILE_NAME = "web.xml";
76
77     private final static String JavaDoc WEBXML_PUBLICID_2_4 = "http://java.sun.com/xml/ns/j2ee";
78     // xmlns attribute
79

80     private final static String JavaDoc WEBXML_PUBLICID_2_3 = "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN";
81
82     private final static String JavaDoc WEBXML_PUBLICID_2_2 = "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN";
83
84     private final static String JavaDoc WEBXML_SYSTEMID_2_4 = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";
85     // xsi:schemaLocation
86

87     private final static String JavaDoc WEBXML_SYSTEMID_2_3 = "http://java.sun.com/dtd/web-app_2_3.dtd";
88
89     private final static String JavaDoc WEBXML_SYSTEMID_2_2 = "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd";
90
91     private final static String JavaDoc WEBXML_XSD_FILE_NAME_2_4 = "resources/web-app_2_4.xsd";
92
93     private final static String JavaDoc WEBXML_DTD_FILE_NAME_2_3 = "resources/web-jar-23.dtd";
94
95     private final static String JavaDoc WEBXML_DTD_FILE_NAME_2_2 = "resources/web-jar-22.dtd";
96
97     private final static String JavaDoc XSD_LOCATION_24 = "http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";
98
99     protected String JavaDoc servletSpec = ServletVersionTypes.VERSION_2_3;
100
101     protected String JavaDoc smallIcon = "";
102
103     protected String JavaDoc largeIcon = "";
104
105     protected String JavaDoc displayName = "";
106
107     protected String JavaDoc description = "";
108
109     protected boolean distributable = true;
110
111     protected ArrayList JavaDoc contextParams = new ArrayList JavaDoc();
112
113     protected Integer JavaDoc sessionTimeout = null;
114
115     // container default
116

117     protected ArrayList JavaDoc welcomeFiles = new ArrayList JavaDoc();
118
119     protected ArrayList JavaDoc tagLibs = new ArrayList JavaDoc();
120
121     /**
122      * Describe what the WebXmlSubTask constructor does
123      */

124     public WebXmlSubTask()
125     {
126         setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE));
127         setDestinationFile(GENERATED_FILE_NAME);
128     }
129
130     /**
131      * Gets the Servletspec attribute of the WebXmlSubTask object
132      *
133      * @return The Servletspec value
134      */

135     public String JavaDoc getServletspec()
136     {
137         return servletSpec;
138     }
139
140     /**
141      * Gets the ContextParams attribute of the WebXmlSubTask object
142      *
143      * @return The ContextParams value
144      */

145     public ArrayList JavaDoc getContextParams()
146     {
147         return contextParams;
148     }
149
150     /**
151      * Gets the Smallicon attribute of the WebXmlSubTask object
152      *
153      * @return The Smallicon value
154      */

155     public String JavaDoc getSmallicon()
156     {
157         return smallIcon;
158     }
159
160     /**
161      * Gets the Largeicon attribute of the WebXmlSubTask object
162      *
163      * @return The Largeicon value
164      */

165     public String JavaDoc getLargeicon()
166     {
167         return largeIcon;
168     }
169
170     /**
171      * Gets the Displayname attribute of the WebXmlSubTask object
172      *
173      * @return The Displayname value
174      */

175     public String JavaDoc getDisplayname()
176     {
177         return displayName;
178     }
179
180     /**
181      * Gets the Description attribute of the WebXmlSubTask object
182      *
183      * @return The Description value
184      */

185     public String JavaDoc getDescription()
186     {
187         return description;
188     }
189
190     /**
191      * Gets the Distributable attribute of the WebXmlSubTask object
192      *
193      * @return The Distributable value
194      */

195     public boolean getDistributable()
196     {
197         return distributable;
198     }
199
200     /**
201      * Gets the Sessiontimeout attribute of the WebXmlSubTask object
202      *
203      * @return The Sessiontimeout value
204      */

205     public Integer JavaDoc getSessiontimeout()
206     {
207         return sessionTimeout;
208     }
209
210     /**
211      * Gets the WelcomeFiles attribute of the WebXmlSubTask object
212      *
213      * @return The WelcomeFiles value
214      */

215     public ArrayList JavaDoc getWelcomeFiles()
216     {
217         return welcomeFiles;
218     }
219
220     /**
221      * Gets the TagLibs attribute of the WebXmlSubTask object
222      *
223      * @return The TagLibs value
224      */

225     public ArrayList JavaDoc getTagLibs()
226     {
227         return tagLibs;
228     }
229
230     /**
231      * The Servlet spec version to which the web application conforms.
232      *
233      * @param servletSpec The new Servletspec value
234      */

235     public void setServletspec(ServletVersionTypes servletSpec)
236     {
237         this.servletSpec = servletSpec.getValue();
238     }
239
240     /**
241      * Optional relative path within the web application's war file of a small (16 x 16) icon image in either JPEG or
242      * GIF format.
243      *
244      * @param smallIcon The new smallIcon value
245      */

246     public void setSmallicon(String JavaDoc smallIcon)
247     {
248         this.smallIcon = smallIcon;
249     }
250
251     /**
252      * Optional relative path within the web application's war file of a large (32 x 32) icon image in either JPEG or
253      * GIF format.
254      *
255      * @param largeIcon The new largeIcon value
256      */

257     public void setLargeicon(String JavaDoc largeIcon)
258     {
259         this.largeIcon = largeIcon;
260     }
261
262     /**
263      * Optional short name for the web application that is intended to be displayed by tools.
264      *
265      * @param displayName The new Displayname value
266      */

267     public void setDisplayname(String JavaDoc displayName)
268     {
269         this.displayName = displayName;
270     }
271
272     /**
273      * Optional description of the web application.
274      *
275      * @param description The new Description value
276      */

277     public void setDescription(String JavaDoc description)
278     {
279         this.description = description;
280     }
281
282     /**
283      * Optional boolean flag indicating whether this web application is programmed appropriately to be deployed into a
284      * distributed servlet container.
285      *
286      * @param distributable The new Distributable value
287      */

288     public void setDistributable(boolean distributable)
289     {
290         this.distributable = distributable;
291     }
292
293     /**
294      * The default session timeout interval for all sessions created in this web application. The specified timeout must
295      * be expressed in a whole number of minutes. If the timeout is 0 or less, the container ensures the default
296      * behaviour of sessions is never to time out.
297      *
298      * @param session_timeout The new Sessiontimeout value
299      */

300     public void setSessiontimeout(Integer JavaDoc session_timeout)
301     {
302         sessionTimeout = session_timeout;
303     }
304
305     /**
306      * Sets the TagLibs attribute of the WebXmlSubTask object
307      *
308      * @param tagLibs The new TagLibs value
309      * @ant.ignore
310      */

311     public void setTagLibs(ArrayList JavaDoc tagLibs)
312     {
313         this.tagLibs = tagLibs;
314     }
315
316     /**
317      * Sets the WelcomeFiles attribute of the WebXmlSubTask object
318      *
319      * @param welcomeFiles The new WelcomeFiles value
320      * @ant.ignore
321      */

322     public void setWelcomeFiles(ArrayList JavaDoc welcomeFiles)
323     {
324         this.welcomeFiles = welcomeFiles;
325     }
326
327     /**
328      * Sets the ContextParams attribute of the WebXmlSubTask object
329      *
330      * @param contextParams The new ContextParams value
331      * @ant.ignore
332      */

333     public void setContextParams(ArrayList JavaDoc contextParams)
334     {
335         this.contextParams = contextParams;
336     }
337
338     /**
339      * Defines a web application context parameter. May occur multiple times.
340      *
341      * @param cp Describe the method parameter
342      */

343     public void addConfiguredContextparam(ContextParam cp)
344     {
345         contextParams.add(cp);
346     }
347
348     /**
349      * Defines a welcome file for the web application. May occur multiple times.
350      *
351      * @param file Describe the method parameter
352      */

353     public void addConfiguredWelcomefile(WelcomeFile file)
354     {
355         welcomeFiles.add(file);
356     }
357
358     /**
359      * Declares a custom tag library for the web application's JSPs. May occur multiple times.
360      *
361      * @param taglib Describe the method parameter
362      */

363     public void addConfiguredTaglib(TagLib taglib)
364     {
365         tagLibs.add(taglib);
366     }
367
368     /**
369      * Describe what the method does
370      *
371      * @exception XDocletException
372      */

373     public void execute() throws XDocletException
374     {
375         if (getServletspec().equals("2.2")) {
376             setPublicId(WEBXML_PUBLICID_2_2);
377             setSystemId(WEBXML_SYSTEMID_2_2);
378             setDtdURL(getClass().getResource(WEBXML_DTD_FILE_NAME_2_2));
379         }
380         else if (getServletspec().equals("2.4")) {
381             setSchema(XSD_LOCATION_24);
382             setSchemaURL(getClass().getResource(WEBXML_XSD_FILE_NAME_2_4));
383         }
384         else {
385             setPublicId(WEBXML_PUBLICID_2_3);
386             setSystemId(WEBXML_SYSTEMID_2_3);
387             setDtdURL(getClass().getResource(WEBXML_DTD_FILE_NAME_2_3));
388         }
389
390         startProcess();
391     }
392
393     /**
394      * Describe what the method does
395      *
396      * @exception XDocletException
397      */

398     protected void engineStarted() throws XDocletException
399     {
400         System.out.println(Translator.getString(XDocletMessages.class, XDocletMessages.GENERATING_SOMETHING, new String JavaDoc[]{getDestinationFile()}));
401     }
402
403     /**
404      * The declaration of a web application's servlet context initialization parameter.
405      *
406      * @author Aslak Hellesøy
407      * @created July 28, 2001
408      */

409     public static class ContextParam implements java.io.Serializable JavaDoc
410     {
411         private String JavaDoc paramName = null;
412
413         private String JavaDoc paramValue = null;
414
415         private String JavaDoc description = "";
416
417         /**
418          * Gets the Name attribute of the ContextParam object
419          *
420          * @return The Name value
421          */

422         public String JavaDoc getName()
423         {
424             return paramName;
425         }
426
427         /**
428          * Gets the Value attribute of the ContextParam object
429          *
430          * @return The Value value
431          */

432         public String JavaDoc getValue()
433         {
434             return paramValue;
435         }
436
437         /**
438          * Gets the Description attribute of the ContextParam object
439          *
440          * @return The Description value
441          */

442         public String JavaDoc getDescription()
443         {
444             return description;
445         }
446
447         /**
448          * The name of the parameter. Each parameter name must be unique in the web application.
449          *
450          * @param name The new Name value
451          */

452         public void setName(String JavaDoc name)
453         {
454             paramName = name;
455         }
456
457         /**
458          * The value of the parameter.
459          *
460          * @param value The new Value value
461          */

462         public void setValue(String JavaDoc value)
463         {
464             paramValue = value;
465         }
466
467         /**
468          * An optional description of the parameter.
469          *
470          * @param desc The new Description value
471          */

472         public void setDescription(String JavaDoc desc)
473         {
474             description = desc;
475         }
476     }
477
478     /**
479      * Describes a JSP tag library.
480      *
481      * @author Aslak Hellesøy
482      * @created July 28, 2001
483      */

484     public static class TagLib implements java.io.Serializable JavaDoc
485     {
486         private String JavaDoc taglibUri = null;
487
488         private String JavaDoc taglibLocation = null;
489
490         /**
491          * Gets the Uri attribute of the TagLib object
492          *
493          * @return The Uri value
494          */

495         public String JavaDoc getUri()
496         {
497             return taglibUri;
498         }
499
500
501         /**
502          * Gets the Location attribute of the TagLib object
503          *
504          * @return The Location value
505          */

506         public String JavaDoc getLocation()
507         {
508             return taglibLocation;
509         }
510
511         /**
512          * A URI, relative to the location of the web.xml document, identifying the tag library used in the web
513          * application.
514          *
515          * @param uri The new Uri value
516          */

517         public void setUri(String JavaDoc uri)
518         {
519             taglibUri = uri;
520         }
521
522         /**
523          * The location (as a resource relative to the root of the web application) where the Tag Libary Description
524          * file for the tag library is found.
525          *
526          * @param location The new Location value
527          */

528         public void setLocation(String JavaDoc location)
529         {
530             taglibLocation = location;
531         }
532     }
533
534     /**
535      * The welcomefile element contains file name to use as a default welcome file, such as index.html.
536      *
537      * @author Aslak Hellesøy
538      * @created Sep 18, 2001
539      */

540     public static class WelcomeFile implements java.io.Serializable JavaDoc
541     {
542         private String JavaDoc file = null;
543
544         /**
545          * Gets the File attribute of the WelcomeFile object
546          *
547          * @return The File value
548          */

549         public String JavaDoc getFile()
550         {
551             return file;
552         }
553
554         /**
555          * The welcomefile element contains file name to use as a default welcome file, such as index.html.
556          *
557          * @param file The new File value
558          */

559         public void setFile(String JavaDoc file)
560         {
561             this.file = file;
562         }
563     }
564
565     /**
566      * Supported Servlet spec versions.
567      *
568      * @author Ara Abrahamian (ara_e@email.com)
569      * @created October 20, 2001
570      */

571     public static class ServletVersionTypes extends org.apache.tools.ant.types.EnumeratedAttribute
572     {
573         public final static String JavaDoc VERSION_2_2 = "2.2";
574         public final static String JavaDoc VERSION_2_3 = "2.3";
575         public final static String JavaDoc VERSION_2_4 = "2.4";
576
577         /**
578          * Gets the Values attribute of the ServletVersionTypes object
579          *
580          * @return The Values value
581          */

582         public String JavaDoc[] getValues()
583         {
584             return (new String JavaDoc[]{VERSION_2_2, VERSION_2_3, VERSION_2_4});
585         }
586     }
587 }
588
Popular Tags