KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > ibm > websphere > web > WebSphereWebXmlSubTask


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

5 package xdoclet.modules.ibm.websphere.web;
6
7 import xdoclet.XDocletException;
8
9 import xdoclet.XmlSubTask;
10 import xdoclet.util.Translator;
11
12 /**
13  * Generates WebSphere specific deployment descriptors for Web modules. The following files are generated:
14  * ibm-web-bnd.xmi and ibm-web-ext.xmi. <p>
15  *
16  * NOTE: Since the WebSphere specific deployment descriptors depend on that id's are set in the web.xml file you must
17  * genererate it with useIds set to true, e.g. <code>&lt;deploymentdescriptor useIds="true"/&gt;</code>. </p> <p>
18  *
19  * This Ant task defines the following attributes (the rest of the attributes in the list below comes from its
20  * baseclass):
21  * <ul>
22  * <li> virtualHostName</li>
23  * <li> reloadInterval</li>
24  * <li> reloadingEnabled</li>
25  * <li> defaultErrorPage</li>
26  * <li> additionalClassPath</li>
27  * <li> fileServingEnabled</li>
28  * <li> directoryBrowsingEnabled</li>
29  * <li> serveServletsByClassnameEnabled</li>
30  * <li> preCompileJSPs</li>
31  * <li> autoRequestEncoding</li>
32  * <li> autoResponseEncoding</li>
33  * <li> autoLoadFilters</li>
34  * </ul>
35  * </p> NOTE: All attributes except "virtualHostName" are IBM specific WebSphere extensions to the web.xml file and are
36  * the same as the attributes that can be found in the IBM WSAD wizard (v5.1.2) for Web Deployment Descriptors (see tab
37  * "Extensions" and section "General")
38  *
39  * @author <a HREF="mailto:ed@whatsa.co.uk">Ed Ward</a>
40  * @author <a HREF="mailto:ml at callista.se">Magnus Larsson</a>
41  * @created 22 August 2002
42  * @version $Revision: 1.8 $
43  * @ant.element display-name="WebSphere" name="webspherewebxml" parent="xdoclet.modules.web.WebDocletTask"
44  */

45 public class WebSphereWebXmlSubTask extends XmlSubTask
46 {
47     /**
48      * A config paramater value: true
49      */

50     private final static String JavaDoc TRUE = "true";
51
52     /**
53      * A config parameter value: false
54      */

55     private final static String JavaDoc FALSE = "false";
56
57     /**
58      * The template file for the bindings. The template generates a stylesheet, which when styled with a web.xml file
59      * (modified with id attributes) will produce the ibm-web-bnd.xmi bindings deployment descriptor
60      */

61     private final static String JavaDoc
62         BINDINGS_TEMPLATE_FILE = "resources/ibm-web-bnd_xmi.xdt";
63
64     /**
65      * The name of the IBM bindings deployment descriptor - ibm-web-bnd.xmi
66      */

67     private final static String JavaDoc
68         GENERATED_BINDINGS_FILE_NAME = "ibm-web-bnd.xmi";
69
70     /**
71      * The template file for the extensions. The template generates a stylesheet, which when styled with a web.xml file
72      * (modified with id attributes) will produce the ibm-web-ext.xmi extensions deployment descriptor
73      */

74     private final static String JavaDoc
75         EXTENSIONS_TEMPLATE_FILE = "resources/ibm-web-ext_xmi.xdt";
76
77     /**
78      * The name of the IBM bindings deployment descriptor - ibm-web-bnd.xmi
79      */

80     private final static String JavaDoc
81         GENERATED_EXTENSIONS_FILE_NAME = "ibm-web-ext.xmi";
82
83     /**
84      * Flag indicating whether we've styled the web.xml file
85      */

86     private boolean hasTransformedWebXml = false;
87
88     /**
89      * @see #setVirtualHostName(String)
90      */

91     private String JavaDoc virtualHostName = "default_host";
92
93     /**
94      * @see #setReloadInterval(String)
95      */

96     private String JavaDoc reloadInterval = "3";
97
98     /**
99      * @see #setReloadingEnabled(String)
100      */

101     private String JavaDoc reloadingEnabled = "true";
102
103     /**
104      * @see #setDefaultErrorPage(String)
105      */

106     private String JavaDoc defaultErrorPage = "";
107
108     /**
109      * @see #setAdditionalClassPath(String)
110      */

111     private String JavaDoc additionalClassPath = "";
112
113     /**
114      * @see #setFileServingEnabled(String)
115      */

116     private String JavaDoc fileServingEnabled = "true";
117
118     /**
119      * @see #setDirectoryBrowsingEnabled(String)
120      */

121     private String JavaDoc directoryBrowsingEnabled = "true";
122
123     /**
124      * @see #setServeServletsByClassnameEnabled(String)
125      */

126     private String JavaDoc serveServletsByClassnameEnabled = "true";
127
128     /**
129      * @see #setPreCompileJSPs(String)
130      */

131     private String JavaDoc preCompileJSPs = "true";
132
133     /**
134      * @see #setAutoRequestEncoding(String)
135      */

136     private String JavaDoc autoRequestEncoding = "false";
137
138     /**
139      * @see #setAutoResponseEncoding(String)
140      */

141     private String JavaDoc autoResponseEncoding = "false";
142
143     /**
144      * @see #setAutoLoadFilters(String)
145      */

146     private String JavaDoc autoLoadFilters = "false";
147
148     public WebSphereWebXmlSubTask()
149     {
150         setUseIds(true);
151     }
152
153     /**
154      * @return the virtual host name
155      * @see #setVirtualHostName(String)
156      */

157     public String JavaDoc getVirtualHostName()
158     {
159         return virtualHostName;
160     }
161
162     /**
163      * @return the reload interval
164      * @see #setReloadInterval(String)
165      */

166     public String JavaDoc getReloadInterval()
167     {
168         return reloadInterval;
169     }
170
171     /**
172      * @return
173      * @see #setReloadingEnabled(String)
174      */

175     public String JavaDoc getReloadingEnabled()
176     {
177         return reloadingEnabled;
178     }
179
180     /**
181      * @return
182      * @see #setDefaultErrorPage(String)
183      */

184     public String JavaDoc getDefaultErrorPage()
185     {
186         return defaultErrorPage;
187     }
188
189     /**
190      * @return
191      * @see #setAdditionalClassPath(String)
192      */

193     public String JavaDoc getAdditionalClassPath()
194     {
195         return additionalClassPath;
196     }
197
198     /**
199      * @return
200      * @see #setFileServingEnabled(String)
201      */

202     public String JavaDoc getFileServingEnabled()
203     {
204         return fileServingEnabled;
205     }
206
207     /**
208      * @return
209      * @see #setDirectoryBrowsingEnabled(String)
210      */

211     public String JavaDoc getDirectoryBrowsingEnabled()
212     {
213         return directoryBrowsingEnabled;
214     }
215
216     /**
217      * @return
218      * @see #setServeServletsByClassnameEnabled(String)
219      */

220     public String JavaDoc getServeServletsByClassnameEnabled()
221     {
222         return serveServletsByClassnameEnabled;
223     }
224
225     /**
226      * @return
227      * @see #setPreCompileJSPs(String)
228      */

229     public String JavaDoc getPreCompileJSPs()
230     {
231         return preCompileJSPs;
232     }
233
234     /**
235      * @return
236      * @see #setAutoRequestEncoding(String)
237      */

238     public String JavaDoc getAutoRequestEncoding()
239     {
240         return autoRequestEncoding;
241     }
242
243     /**
244      * @return
245      * @see #setAutoResponseEncoding(String)
246      */

247     public String JavaDoc getAutoResponseEncoding()
248     {
249         return autoResponseEncoding;
250     }
251
252     /**
253      * @return
254      * @see #setAutoLoadFilters(String)
255      */

256     public String JavaDoc getAutoLoadFilters()
257     {
258         return autoLoadFilters;
259     }
260
261     /**
262      * The virtual host name. "A virtual host is a configuration enabling a single host machine to resemble multiple
263      * host machines. This property allows you to bind the application to a virtual host in order to enable execution on
264      * that virtual host."
265      *
266      * @param name the virtual host name
267      * @ant.not-required No. Default is "default_host"
268      */

269     public void setVirtualHostName(String JavaDoc name)
270     {
271         virtualHostName = name;
272     }
273
274     /**
275      * A Reload Interval. Every 'reload interval' seconds, the web application's files are checked and reloaded if they
276      * have been modified. Requires that reloadingEnabled is set to true.
277      *
278      * @param reloadInterval
279      * @see #setReloadingEnabled(String)
280      * @ant.not-required No. Default is "3"
281      */

282     public void setReloadInterval(String JavaDoc reloadInterval)
283     {
284         this.reloadInterval = validateIntegerValue(reloadInterval, "reloadInterval");
285     }
286
287     /**
288      * Specifies whether reloading is enabled.
289      *
290      * @param reloadingEnabled
291      * @ant.not-required No. Default is "true"
292      */

293     public void setReloadingEnabled(String JavaDoc reloadingEnabled)
294     {
295         this.reloadingEnabled = reloadingEnabled;
296     }
297
298     /**
299      * Specifies a file name for the default error page. If no other error page is specified in the application, this
300      * error page is used.
301      *
302      * @param defaultErrorPage
303      * @ant.not-required No. Default is ""
304      */

305     public void setDefaultErrorPage(String JavaDoc defaultErrorPage)
306     {
307         this.defaultErrorPage = defaultErrorPage;
308     }
309
310     /**
311      * Specifies an additional class path that will be used to reference resources outside of those specified in the
312      * archive.
313      *
314      * @param additionalClassPath
315      * @ant.not-required No. Default is ""
316      */

317     public void setAdditionalClassPath(String JavaDoc additionalClassPath)
318     {
319         this.additionalClassPath = additionalClassPath;
320     }
321
322     /**
323      * Specifies whether file serving is enabled. File serving allows the application to serve static file types, such
324      * as HTML and GIF. File serving can be disabled if, for example, the application contains only dynamic components.
325      *
326      * @param fileServingEnabled
327      * @ant.not-required No. Default is "true"
328      */

329     public void setFileServingEnabled(String JavaDoc fileServingEnabled)
330     {
331         this.fileServingEnabled = validateBooleanValue(fileServingEnabled, "fileServingEnabled");
332     }
333
334     /**
335      * Specifies whether directory browsing is enabled. Directory browsing allows the application to browse disk
336      * directories. Directory browsing can be disabled if, for example, you want to protect data.
337      *
338      * @param directoryBrowsingEnabled
339      * @ant.not-required No. Default is "true"
340      */

341     public void setDirectoryBrowsingEnabled(String JavaDoc directoryBrowsingEnabled)
342     {
343         this.directoryBrowsingEnabled = validateBooleanValue(directoryBrowsingEnabled, "directoryBrowsingEnabled");
344     }
345
346     /**
347      * Specifies whether a servlet can be served by requesting its class name. Usually, servlets are served only through
348      * a URI reference. The class name is the actual name of the servlet on disk. For example, a file named
349      * SnoopServlet.java compiles into SnoopServlet.class. (This is the class name.) SnoopServlet.class is normally
350      * invoked by specifying snoop in the URI. However, if Serve Servlets by Classname is enabled, the servlet is
351      * invoked by specifying SnoopServlet.
352      *
353      * @param serveServletsByClassnameEnabled
354      * @ant.not-required No. Default is "true"
355      */

356     public void setServeServletsByClassnameEnabled(String JavaDoc serveServletsByClassnameEnabled)
357     {
358         this.serveServletsByClassnameEnabled = validateBooleanValue(serveServletsByClassnameEnabled, "serveServletsByClassnameEnabled");
359     }
360
361     /**
362      * Specifies wheter JSP pages will be precompiled at deploy time or not.
363      *
364      * @param preCompileJSPs
365      * @ant.not-required No. Default is "true"
366      */

367     public void setPreCompileJSPs(String JavaDoc preCompileJSPs)
368     {
369         this.preCompileJSPs = validateBooleanValue(preCompileJSPs, "preCompileJSPs");
370     }
371
372     /**
373      * See IBM WebSphere documentation regarding this attribute.
374      *
375      * @param autoRequestEncoding
376      * @ant.not-required No. Default is "false"
377      */

378     public void setAutoRequestEncoding(String JavaDoc autoRequestEncoding)
379     {
380         this.autoRequestEncoding = validateBooleanValue(autoRequestEncoding, "autoRequestEncoding");
381     }
382
383     /**
384      * See IBM WebSphere documentation regarding this attribute.
385      *
386      * @param autoResponseEncoding
387      * @ant.not-required No. Default is "false"
388      */

389     public void setAutoResponseEncoding(String JavaDoc autoResponseEncoding)
390     {
391         this.autoResponseEncoding = validateBooleanValue(autoResponseEncoding, "autoResponseEncoding");
392     }
393
394     /**
395      * See IBM WebSphere documentation regarding this attribute.
396      *
397      * @param autoLoadFilters
398      * @ant.not-required No. Default is "false"
399      */

400     public void setAutoLoadFilters(String JavaDoc autoLoadFilters)
401     {
402         this.autoLoadFilters = validateBooleanValue(autoLoadFilters, "autoLoadFilters");
403     }
404
405     /**
406      * Called to validate configuration parameters.
407      *
408      * @exception XDocletException Description of Exception
409      */

410     public void validateOptions() throws XDocletException
411     {
412         // Skip the default validation to avoid the following error message:
413
// "webspherewebxml: 'templateFile' parameter missing. Specify both 'destinationFile' and 'templateFile' configuration parameters please."
414
// The WebSphereWebXmlSubTask does not require a template url or a destination file anyhow.
415
// super.validateOptions();
416
}
417
418     /**
419      * Called by xdoclet to execute the subtask.
420      *
421      * @exception XDocletException
422      */

423     public void execute() throws XDocletException
424     {
425         setTemplateURL(getClass().getResource(BINDINGS_TEMPLATE_FILE));
426         setDestinationFile(GENERATED_BINDINGS_FILE_NAME);
427         startProcess();
428
429         setTemplateURL(getClass().getResource(EXTENSIONS_TEMPLATE_FILE));
430         setDestinationFile(GENERATED_EXTENSIONS_FILE_NAME);
431         startProcess();
432     }
433
434     /**
435      * TODO: Describe what the method does
436      *
437      * @exception XDocletException
438      */

439     protected void engineStarted() throws XDocletException
440     {
441     }
442
443     /**
444      * Helper method that validates if a value can be interpreted as an integer
445      *
446      * @param integerValue
447      * @param name
448      * @return the value if it is ok or else throws an runtime exception
449      */

450     private String JavaDoc validateIntegerValue(String JavaDoc integerValue, String JavaDoc name)
451     {
452         try {
453             Integer.parseInt(integerValue);
454         }
455         catch (NumberFormatException JavaDoc e) {
456             throwInvalidConfigValueException(integerValue, name);
457         }
458
459         return integerValue;
460     }
461
462     /**
463      * Helper method that validates if a value can be interpreted as a boolean
464      *
465      * @param booleanValue
466      * @param name
467      * @return the value if it is ok or else throws an runtime exception
468      */

469     private String JavaDoc validateBooleanValue(String JavaDoc booleanValue, String JavaDoc name)
470     {
471         if (booleanValue == null) {
472             booleanValue = "";
473         }
474
475         if (!(TRUE.equals(booleanValue) ||
476             FALSE.equals(booleanValue) ||
477             "".equals(booleanValue))) {
478             throwInvalidConfigValueException(booleanValue, name);
479         }
480
481         return booleanValue;
482     }
483
484     /**
485      * Helper method for throwing an exception indicating that an configuration attribute was set incorect.
486      *
487      * @param value
488      * @param name
489      */

490     private void throwInvalidConfigValueException(String JavaDoc value, String JavaDoc name)
491     {
492         throw new RuntimeException JavaDoc(
493             Translator.getString(
494             XDocletModulesIbmWebsphereWebMessages.class,
495             XDocletModulesIbmWebsphereWebMessages.INVALID_CONFIG_VALUE,
496             new String JavaDoc[]{value, name}));
497     }
498 }
499
Popular Tags