KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > apache > struts > StrutsConfigXmlSubTask


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

5 package xdoclet.modules.apache.struts;
6
7 import xdoclet.XDocletException;
8
9 import xdoclet.XmlSubTask;
10 import xdoclet.modules.apache.struts.ejb.XDocletModulesApacheStrutsEjbMessages;
11 import xdoclet.util.Translator;
12
13 /**
14  * Generates struts-config.xml deployment descriptor.
15  *
16  * @author <a HREF="mailto:dim at bigpond.net.au">Dmitri Colebatch</a>
17  * @author <a HREF="mailto:nick at systemmobile.com">Nick Heudecker</a>
18  * @created September 2, 2001
19  * @ant.element display-name="struts-config.xml" name="strutsconfigxml"
20  * parent="xdoclet.modules.web.WebDocletTask"
21  * @ant.task ignore="true"
22  * @version $Revision: 1.12 $
23  * @xdoclet.merge-file file="struts-data-sources.xml" relates-to="struts-config.xml" description="An XML document
24  * containing the optional data-sources element."
25  * @xdoclet.merge-file file="struts-forms.xml" relates-to="struts-config.xml" description="An XML unparsed entity
26  * containing form-bean elements, for additional non-XDoclet forms."
27  * @xdoclet.merge-file file="global-exceptions.xml" relates-to="struts-config.xml" description="An XML document
28  * containing the optional global-exceptions element."
29  * @xdoclet.merge-file file="global-forwards.xml" relates-to="struts-config.xml" description="An XML document
30  * containing the optional global-forwards element."
31  * @xdoclet.merge-file file="struts-actions.xml" relates-to="struts-config.xml" description="An XML unparsed entity
32  * containing action elements, for additional non-XDoclet actions."
33  * @xdoclet.merge-file file="actions.xml" relates-to="struts-config.xml" description="Deprecated (renamed to
34  * struts-actions.xml). Still used, but only for backwards compatibility."
35  * @xdoclet.merge-file file="struts-controller.xml" relates-to="struts-config.xml" description="An XML document
36  * containing the optional controller element."
37  * @xdoclet.merge-file file="struts-message-resources.xml" relates-to="struts-config.xml" description="An XML unparsed
38  * entity containing any message-resources elements."
39  * @xdoclet.merge-file file="struts-plugins.xml" relates-to="struts-config.xml" description="An XML unparsed entity
40  * containing any plug-in elements."
41  */

42 public class StrutsConfigXmlSubTask extends XmlSubTask
43 {
44     private final static String JavaDoc STRUTS_PUBLICID_10 = "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN";
45
46     private final static String JavaDoc STRUTS_SYSTEMID_10 = "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd";
47
48     private final static String JavaDoc DTD_FILE_NAME_10 = "resources/struts-config_1_0.dtd";
49
50     private final static String JavaDoc STRUTS_PUBLICID_11 = "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN";
51
52     private final static String JavaDoc STRUTS_SYSTEMID_11 = "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd";
53
54     private final static String JavaDoc DTD_FILE_NAME_11 = "resources/struts-config_1_1.dtd";
55
56     private final static String JavaDoc STRUTS_PUBLICID_12 = "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN";
57
58     private final static String JavaDoc STRUTS_SYSTEMID_12 = "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd";
59
60     private final static String JavaDoc DTD_FILE_NAME_12 = "resources/struts-config_1_2.dtd";
61
62     private static String JavaDoc DEFAULT_TEMPLATE_FILE = "resources/struts_config_xml.xdt";
63
64     private static String JavaDoc GENERATED_FILE_NAME = "struts-config.xml";
65
66     /**
67      * Defaults to Struts 1.0.
68      */

69     private String JavaDoc strutsVersion = StrutsVersion.STRUTS_1_0;
70
71     /**
72      * Sets the controller that the struts application should use. Valid for version 1.1
73      */

74     private String JavaDoc controller = "";
75
76     /**
77      * Describe what the StrutsConfigXmlSubTask constructor does
78      */

79     public StrutsConfigXmlSubTask()
80     {
81         setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE));
82         setDestinationFile(GENERATED_FILE_NAME);
83     }
84
85     public String JavaDoc getController()
86     {
87         return controller;
88     }
89
90     /**
91      * Gets the Version attribute of the StrutsConfigXmlSubTask object
92      *
93      * @return The Version value
94      */

95     public String JavaDoc getVersion()
96     {
97         return strutsVersion;
98     }
99
100     /**
101      * Sets the struts version to use. Legal values are "1.0", "1.1" and "1.2".
102      *
103      * @param version
104      * @ant.not-required No. Default is "1.0".
105      */

106     public void setVersion(StrutsVersion version)
107     {
108         strutsVersion = version.getValue();
109     }
110
111     /**
112      * Sets fully qualified class to use when instantiating ActionMapping objects.
113      *
114      * @param controller
115      */

116     public void setController(String JavaDoc controller)
117     {
118         this.controller = controller;
119     }
120
121     /**
122      * Generate struts-config.xml
123      *
124      * @exception XDocletException
125      */

126     public void execute() throws XDocletException
127     {
128         if (strutsVersion.equals(StrutsVersion.STRUTS_1_0) && (controller.equals("") == false)) {
129             throw new XDocletException(Translator.getString(XDocletModulesApacheStrutsEjbMessages.class, XDocletModulesApacheStrutsEjbMessages.BAD_STRUTS_VERSION, new String JavaDoc[]{controller, "1.1", "controller"}));
130         }
131
132         if (strutsVersion.equals(StrutsVersion.STRUTS_1_0)) {
133             setPublicId(STRUTS_PUBLICID_10);
134             setSystemId(STRUTS_SYSTEMID_10);
135             setDtdURL(getClass().getResource(DTD_FILE_NAME_10));
136         }
137         else if (strutsVersion.equals(StrutsVersion.STRUTS_1_1)) {
138             setPublicId(STRUTS_PUBLICID_11);
139             setSystemId(STRUTS_SYSTEMID_11);
140             setDtdURL(getClass().getResource(DTD_FILE_NAME_11));
141         }
142         else {
143             setPublicId(STRUTS_PUBLICID_12);
144             setSystemId(STRUTS_SYSTEMID_12);
145             setDtdURL(getClass().getResource(DTD_FILE_NAME_12));
146         }
147         startProcess();
148     }
149
150     /**
151      * @created 17. juni 2002
152      */

153     public static class StrutsVersion extends org.apache.tools.ant.types.EnumeratedAttribute
154     {
155         public final static String JavaDoc STRUTS_1_0 = "1.0";
156
157         public final static String JavaDoc STRUTS_1_1 = "1.1";
158
159         public final static String JavaDoc STRUTS_1_2 = "1.2";
160
161         /**
162          * Gets the Values attribute of the StrutsVersion object
163          *
164          * @return The Values value
165          */

166         public java.lang.String JavaDoc[] getValues()
167         {
168             return (new java.lang.String JavaDoc[]{
169                 STRUTS_1_0, STRUTS_1_1, STRUTS_1_2
170                 });
171         }
172     }
173 }
174
Popular Tags