KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > jsf > FacesConfigXmlSubTask


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

5 package xdoclet.modules.jsf;
6
7 import java.util.*;
8
9 import xdoclet.*;
10 import xdoclet.template.*;
11 import xdoclet.util.*;
12
13 /**
14  * Generate the faces.config.xml for Java Server Faces
15  *
16  * @author <a HREF="mailto:markus.plattner at plattners.de">Markus Plattner</a> Date: 03.06.2004 Time:
17  * 14:15:27
18  * @created 27. Juni 2004
19  * @version $Revision: 1.2 $
20  * @ant.element display-name="Java Server Faces" name="facesconfigxml"
21  * parent="xdoclet.modules.web.WebDocletTask"
22  * @ant.attribute name="destDir" description="the target directory for the faces-config.xml file" required="true"
23  * @xdoclet.merge-file file="jsf-beans.xml" relates-to="faces-config.xml" description="An XML document containing the
24  * optional backing beans."
25  * @xdoclet.merge-file file="jsf-navigations.xml" relates-to="faces-config.xml" description="An XML document
26  * containing the additional navigation rules."
27  * @xdoclet.merge-file file="jsf-validators.xml" relates-to="faces-config.xml" description="An XML document containing
28  * additional validator configurations."
29  * @xdoclet.merge-file file="jsf-application.xml" relates-to="faces-config.xml" description="An XML document
30  * containing application level settings (language resources)."
31  * @xdoclet.merge-file file="jsf-converters.xml" relates-to="faces-config.xml" description="An XML document containing
32  * additional converters."
33  */

34 public class FacesConfigXmlSubTask extends XmlSubTask
35 {
36
37     private final static String JavaDoc V_10 = "1.0";
38     private final static String JavaDoc V_11 = "1.1";
39
40     //private enum FacesVersion {V_10,V_11};
41

42     private final static String JavaDoc FACES_PUBLICID_10 = "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN";
43     private final static String JavaDoc FACES_SYSTEMID_10 = "http://java.sun.com/dtd/web-facesconfig_1_0.dtd";
44
45     private final static String JavaDoc FACES_PUBLICID_11 = "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN";
46     private final static String JavaDoc FACES_SYSTEMID_11 = "http://java.sun.com/dtd/web-facesconfig_1_1.dtd";
47
48     private static String JavaDoc DEFAULT_TEMPLATE_FILE = "resources/faces_config_xml.xdt";
49     private static String JavaDoc GENERATED_FILE_NAME = "faces-config.xml";
50
51     private String JavaDoc version = V_10;
52     private String JavaDoc messageBundle = null;
53     private String JavaDoc defaultLocale = null;
54     private String JavaDoc supportedLocales = null;
55     private String JavaDoc currentSupportedLocale = null;
56
57     public FacesConfigXmlSubTask()
58     {
59         setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE));
60         setDestinationFile(GENERATED_FILE_NAME);
61     }
62
63     public String JavaDoc getVersion()
64     {
65         return this.version;
66     }
67
68     public String JavaDoc getDefaultLocale()
69     {
70         return this.defaultLocale;
71     }
72
73     public String JavaDoc getMessageBundle()
74     {
75         return this.messageBundle;
76     }
77
78     public String JavaDoc getSupportedLocales()
79     {
80         return this.supportedLocales;
81     }
82
83     /**
84      * @return
85      * @doc.tag type="content"
86      */

87     public String JavaDoc getSupportedLocale()
88     {
89         return this.currentSupportedLocale;
90     }
91
92     /**
93      * @param v
94      * @ant.not-required No. Default is "1.0".
95      */

96     public void setVersion(String JavaDoc v)
97     {
98         this.version = v;
99     }
100
101     /**
102      * @param loc
103      * @ant.not-required No. If not specified, no bundle is used
104      */

105     public void setDefaultLocale(String JavaDoc loc)
106     {
107         this.defaultLocale = loc;
108     }
109
110     /**
111      * @param bundle
112      * @ant.not-required No. If not specified, no bundle is used
113      */

114     public void setMessageBundle(String JavaDoc bundle)
115     {
116         this.messageBundle = bundle;
117     }
118
119     /**
120      * @param listOfLocales
121      * @ant.not-required No. If not specified, no bundle supported locales are used
122      */

123     public void setSupportedLocales(String JavaDoc listOfLocales)
124     {
125         this.supportedLocales = listOfLocales;
126     }
127
128     /**
129      * @param template
130      * @throws XDocletException
131      * @doc.tag type="block"
132      */

133     public void forAllSupportedLocales(String JavaDoc template) throws XDocletException
134     {
135         try {
136             if (this.supportedLocales != null) {
137                 for (Iterator it = Arrays.asList(DocletUtil.tokenizeDelimitedToArray(this.supportedLocales, ",")).iterator(); it.hasNext(); ) {
138                     //for (String it : Arrays.asList(DocletUtil.tokenizeDelimitedToArray(this.supportedLocales, ","))) {
139
currentSupportedLocale = (String JavaDoc) it.next();
140                     getEngine().generate(template);
141                 }
142             }
143         }
144         catch (TemplateException e) {
145             if (e instanceof XDocletException) {
146                 throw (XDocletException) e;
147             }
148             else {
149                 throw new XDocletException(e, Translator.getString(XDocletMessages.class, XDocletMessages.RUNNING_FAILED) + ": " + e.toString());
150             }
151         }
152     }
153
154     public void execute() throws XDocletException
155     {
156
157         if (getVersion().equals(V_10)) {
158             setPublicId(FACES_PUBLICID_10);
159             setSystemId(FACES_SYSTEMID_10);
160         }
161         else {
162             setPublicId(FACES_PUBLICID_11);
163             setSystemId(FACES_SYSTEMID_11);
164         }
165         super.startProcess();
166     }
167
168 }
169
Popular Tags