KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > data > templates > Templates_Xml


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12
//
13
//
14
// Templates_Xml
15
//
16
// NK 29.01.2001
17
//
18
//
19

20 package org.jahia.data.templates;
21
22
23 import java.util.Vector JavaDoc;
24
25 import org.jahia.data.xml.JahiaXmlDocument;
26 import org.jahia.exceptions.JahiaException;
27 import org.jahia.utils.xml.XMLParser;
28 import org.w3c.dom.Element JavaDoc;
29 import org.w3c.dom.Node JavaDoc;
30
31
32 /**
33  * Holds Informations about a template deployment descriptor file
34  * templates.xml
35  *
36  * <tpml>
37  * <parameter name="package-name">DigitalCortexDHTML</parameter>
38  * <parameter name="root-folder">DigitalCortexDHTML</parameter>
39  * <parameter name="classes-file">digicorp.jar</parameter>
40  * <parameter name="provider">www.jahia.org</parameter>
41  * <template id="1" visible="1">
42  * <parameter name="name">DigitalCortexDHTML</parameter>
43  * <parameter name="filename">digicorp.jsp</parameter>
44  * <parameter name="display-name">Digital Cortex DHTML</parameter>
45  * </template>
46  * </tpml>
47  *
48  * @author Khue ng
49  * @version 1.0
50  */

51 public class Templates_Xml extends JahiaXmlDocument {
52
53     /** The Package name **/
54     private String JavaDoc m_Name ="";
55     /** The Root_Folder **/
56     private String JavaDoc m_RootFolder;
57     /** The classes file **/
58     private String JavaDoc m_ClassesFile;
59     /** The provider **/
60     private String JavaDoc m_Provider;
61     /** The thumbnail image file name **/
62     private String JavaDoc m_Thumbnail;
63     /** The list of Templates *
64      * @associates JahiaTemplateDef*/

65     private Vector JavaDoc m_Templates = new Vector JavaDoc();
66     
67     private static final String JavaDoc TPML_TAG = "tpml";
68     private static final String JavaDoc CLASSES_FILE_ENTRY = "jahiatemplates/";
69
70     /**
71      * Constructor
72      *
73      * @param (String) path, the full path to the templates.xml file
74      */

75     public Templates_Xml (String JavaDoc docPath) throws JahiaException
76     {
77       super(docPath);
78     }
79
80
81     /**
82      * Extracts data from the Templates.xml file. Build the JahiaWebAppsWarPackage object
83      * to store extracted data
84      */

85     public void extractDocumentData() throws JahiaException {
86
87         //JahiaConsole.println("Templates_Xml.extractDocumentData","started");
88

89         if (m_XMLDocument == null) {
90
91             throw new JahiaException( "Templates_Xml",
92                                     "Parsed Templates.xml document is null",
93                                        JahiaException.ERROR_SEVERITY,
94                                        JahiaException.SERVICE_ERROR);
95         }
96
97
98         if (!m_XMLDocument.hasChildNodes()) {
99
100             throw new JahiaException( "Templates_Xml",
101                                        "Main document node has no children",
102                                         JahiaException.ERROR_SEVERITY,
103                                         JahiaException.SERVICE_ERROR);
104         }
105
106
107         // get the document node
108
Element JavaDoc docElNode = (Element JavaDoc) m_XMLDocument.getDocumentElement();
109
110         if (!docElNode.getNodeName().equalsIgnoreCase(TPML_TAG)) {
111
112             throw new JahiaException( "Invalid XML format",
113                                         "tpml tag is not present as starting tag in file",
114                                         JahiaException.ERROR_SEVERITY,
115                                         JahiaException.SERVICE_ERROR);
116         }
117
118
119         // get the package name
120
m_Name = XMLParser.getParameterValue(docElNode,"package-name");
121
122         //JahiaConsole.println(">>"," template package name :" + m_Name);
123

124         // get the root folder
125
m_RootFolder = XMLParser.getParameterValue(docElNode,"root-folder");
126
127         //JahiaConsole.println(">>"," template root-folder :" + m_RootFolder);
128

129         // get the class file entry
130
m_ClassesFile = XMLParser.getParameterValue(docElNode,"classes-file");
131
132         //JahiaConsole.println(">>"," template classes-file :" + m_ClassesFile);
133

134         // get the provider info
135
m_Provider = XMLParser.getParameterValue(docElNode,"provider");
136
137         //JahiaConsole.println(">>"," template provider :" + m_Provider);
138

139         // get the thumbnail image file name
140
m_Thumbnail = XMLParser.getParameterValue(docElNode,"thumbnail");
141
142         //JahiaConsole.println(">>"," template provider :" + m_Provider);
143

144         // build the templates list
145
Vector JavaDoc nodesList = XMLParser.getChildNodes(docElNode,"template");
146         int size = nodesList.size();
147         if ( size>0 ){
148
149
150             Node JavaDoc nodeItem = null;
151             String JavaDoc templateName = "";
152             String JavaDoc templateFile = "";
153             String JavaDoc templateDisplayName = "";
154
155             Node JavaDoc currNode = null;
156
157             for ( int i=0 ; i<size ; i++ ){
158                 nodeItem = (Node JavaDoc)nodesList.get(i);
159
160                 templateName = XMLParser.getParameterValue(nodeItem,"name");
161
162                 templateFile = XMLParser.getParameterValue(nodeItem,"filename");
163
164                 templateDisplayName = XMLParser.getParameterValue(nodeItem,"display-name");
165                 if ( templateDisplayName.length()<=0 ){
166                     templateDisplayName = templateName;
167                 }
168
169                 boolean visible = true;
170                 
171                 String JavaDoc val = XMLParser.getAttributeValue(nodeItem,"visible");
172                 if ( val != null ){
173                     visible = ( Integer.parseInt(val) == 1 );
174                 }
175
176                 boolean isHomePage = false;
177                 val = XMLParser.getAttributeValue(nodeItem,"homepage");
178                 if ( val != null ){
179                     isHomePage = ( Integer.parseInt(val) == 1 );
180                 }
181
182                 
183                 if ( (templateName != null) && (templateName.length()>0) &&
184                     (templateFile != null) && (templateFile.length()>0) &&
185                     (templateDisplayName != null) && (templateDisplayName.length()>0) ){
186
187                     JahiaTemplateDef template = new JahiaTemplateDef(
188                                                                         templateName,
189                                                                         templateFile,
190                                                                         templateDisplayName,
191                                                                         visible,
192                                                                         isHomePage
193                                                                       );
194
195                     //JahiaConsole.println(">>"," template name :" + template.getName());
196
//JahiaConsole.println(">>"," display name :" + template.getDisplayName());
197
//JahiaConsole.println(">>"," filename :" + template.getFileName());
198
m_Templates.add(template);
199                 
200                 }
201             }
202         }
203
204       //JahiaConsole.println("Templates_Xml.extractDocumentData","extraction done");
205
}
206
207
208    /**
209     * Return the Package Name
210     *
211     * @return (String) the package name
212     */

213    public String JavaDoc getPackageName(){
214
215       return m_Name;
216    }
217
218
219    /**
220     * Set the package name
221     * @param (String) the package name
222     */

223    public void setPackageName(String JavaDoc name){
224
225       m_Name = name;
226    }
227
228    /**
229     * Return the Root folder
230     *
231     * @return (String) the root folder
232     */

233    public String JavaDoc getRootFolder(){
234
235       return m_RootFolder;
236    }
237
238
239    /**
240     * Set the Root Folder
241     * @param (String) the root folder
242     */

243    public void setRootFolder(String JavaDoc rootFolder){
244
245       m_RootFolder = rootFolder;
246    }
247
248
249    /**
250     * Return the Classes file name
251     *
252     * @return (String) the classes file name
253     */

254    public String JavaDoc getClassesFile(){
255
256       return m_ClassesFile;
257    }
258
259
260    /**
261     * Set the Classes file
262     * @param (String) the file name
263     */

264    public void setClassesFile(String JavaDoc filename){
265
266       m_ClassesFile = filename;
267    }
268
269
270    /**
271     * Return the Provider value
272     *
273     * @return (String) the provider value
274     */

275    public String JavaDoc getProvider(){
276
277       return m_Provider;
278    }
279
280
281    /**
282     * Set the provider attribute
283     * @param (String) the value
284     */

285    public void setProvider(String JavaDoc val){
286
287       m_Provider = val;
288    }
289
290
291    /**
292     * Return the thumbnail file name
293     *
294     * @return (String) the thumbnail file name
295     */

296    public String JavaDoc getThumbnail(){
297
298       return m_Thumbnail;
299    }
300
301
302    /**
303     * Set the thumbnail file name
304     * @param (String) the file name
305     */

306    public void setThumbnail(String JavaDoc val){
307
308       m_Thumbnail = val;
309    }
310
311
312    /**
313     * Return the list of templates
314     *
315     * @return (Vector) list of templates
316     */

317    public Vector JavaDoc getTemplates(){
318
319       return m_Templates;
320
321    }
322
323
324
325
326 } // end Templates_Xml
327
Popular Tags