KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > data > webapps > Application_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
// Application_Xml
15
//
16
// NK 29.01.2001
17
//
18
//
19

20 package org.jahia.data.webapps;
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 the Application deployment descriptors file
34  * application.xml ( J2EE Standard )
35  *
36  * <application>
37  * <display-name>filemanager.ear</display-name>
38  * <desc>Application desc</desc>
39  * <module>
40  * <web>
41  * <web-uri>war-ic.war</web-uri>
42  * <context-root>filemanager</context-root>
43  * </web>
44  * </module>
45  * </application>
46  *
47  *
48  * @author Khue ng
49  * @version 1.0
50  */

51 public class Application_Xml extends JahiaXmlDocument {
52
53    /** The J2EE Application Display Name **/
54    private String JavaDoc m_DisplayName;
55    /** The J2EE Application desc **/
56    private String JavaDoc m_desc;
57    /** The list of Web Components *
58     * @associates Web_Component*/

59    private Vector JavaDoc m_WebComponents = new Vector JavaDoc();
60
61
62    /**
63     * Constructor
64     *
65     * @param (String) path, the full path to the application.xml file
66     */

67     public Application_Xml (String JavaDoc docPath) throws JahiaException
68     {
69       super(docPath);
70     }
71
72
73     /**
74      * Constructor using a gived parser
75      *
76      * @param (String) path, the full path to a xml file
77      * @param (Parser) parser, the parser to use
78      */

79     public Application_Xml (String JavaDoc docPath, org.xml.sax.helpers.ParserAdapter JavaDoc parser)
80     throws JahiaException {
81         super(docPath,parser);
82     }
83
84
85    /**
86     * Extracts data from the application.xml file. Build the JahiaWebAppsWarPackage object
87     * to store extracted data
88     */

89    public void extractDocumentData() throws JahiaException {
90
91       //JahiaConsole.println("Application_Xml::extractDocumentData","started");
92

93        if (m_XMLDocument == null) {
94
95           throw new JahiaException( "Application_Xml",
96                                     "Parsed application.xml document is null",
97                                        JahiaException.ERROR_SEVERITY,
98                                        JahiaException.SERVICE_ERROR);
99        }
100
101
102        if (!m_XMLDocument.hasChildNodes()) {
103
104           throw new JahiaException( "Application_Xml",
105                                        "Main document node has no children",
106                                         JahiaException.ERROR_SEVERITY,
107                                         JahiaException.SERVICE_ERROR);
108        }
109
110
111       // get application node
112
Element JavaDoc docElNode = (Element JavaDoc) m_XMLDocument.getDocumentElement();
113
114        if (!docElNode.getNodeName().equalsIgnoreCase("application")) {
115
116           throw new JahiaException( "Invalid XML format",
117                                         "application tag is not present as starting tag in file",
118                                         JahiaException.ERROR_SEVERITY,
119                                         JahiaException.SERVICE_ERROR);
120        }
121
122
123       // get module nodes
124
Vector JavaDoc modNodes = XMLParser.getChildNodes(docElNode,"module");
125        Node JavaDoc nodeItem = null;
126        Node JavaDoc webNode = null;
127        Node JavaDoc webURINode = null;
128        Node JavaDoc contextNode = null;
129        Node JavaDoc textNode = null;
130       String JavaDoc webURI = null;
131       String JavaDoc contextRoot = null;
132       int size = modNodes.size();
133
134       for ( int i=0 ; i<size; i++ ){
135
136          nodeItem = (Node JavaDoc)modNodes.get(i);
137
138          webNode = XMLParser.nextChildOfTag(nodeItem,"web");
139          if (webNode != null ){
140             webURINode = XMLParser.nextChildOfTag(webNode,"web-uri");
141             if (webURINode != null ){
142                textNode = webURINode.getFirstChild();
143                if ( textNode != null ){
144                   webURI = textNode.getNodeValue().trim();
145                }
146             }
147
148             contextNode = XMLParser.nextChildOfTag(webNode,"context-root");
149             if (contextNode != null ){
150                textNode = contextNode.getFirstChild();
151                if ( textNode != null){
152                   contextRoot = textNode.getNodeValue().trim();
153                } else {
154                   contextRoot = "";
155                }
156
157             }
158
159             if ( (webURI != null) && (webURI.length()>0) && contextRoot != null) {
160
161                Web_Component webComp = new Web_Component( webURI, contextRoot );
162
163                //JahiaConsole.println(">>"," Web Component Web URI :" + webComp.getWebURI());
164
//JahiaConsole.println(">>"," Context Root :" + webComp.getContextRoot());
165

166                m_WebComponents.add(webComp);
167             }
168          }
169       }
170
171       //JahiaConsole.println("Application_Xml::extractDocumentData","extraction done");
172
}
173
174
175    /**
176     * Return the Display Name
177     *
178     * @return (String) the display name of the Application
179     */

180    public String JavaDoc getDisplayName(){
181
182       return m_DisplayName;
183    }
184
185
186    /**
187     * Set the DisplayName
188     * @param (String) the display name of the webApp
189     */

190    protected void setDisplayName(String JavaDoc name){
191
192       m_DisplayName = name;
193    }
194
195    /**
196     * Return the Web App desc
197     *
198     * @return (String) the desc
199     */

200    public String JavaDoc getdesc(){
201
202       return m_desc;
203    }
204
205
206    /**
207     * Set the desc
208     * @param (String) the desc
209     */

210    protected void setdesc(String JavaDoc descr){
211
212       m_desc = descr;
213    }
214
215
216    /**
217     * Return the list of Web Components
218     *
219     * @return (Vector) list of Web Components
220     */

221    public Vector JavaDoc getWebComponents(){
222
223       return m_WebComponents;
224
225    }
226
227
228
229
230
231
232 } // end Application_Xml
233
Popular Tags