KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > data > webapps > JahiaEarFileHandler


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
// JahiaEarFileHandler
15
//
16
// NK 13.01.2001
17
//
18
//
19

20 package org.jahia.data.webapps;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.Vector JavaDoc;
25
26 import org.jahia.exceptions.JahiaException;
27 import org.jahia.utils.JahiaConsole;
28 import org.jahia.utils.zip.JahiaArchiveFileHandler;
29
30 /**
31  * This class is responsible for loading data from a .Ear File
32  * The Information are loaded from the META-INF/application.xml file :
33  *
34  * -----------------------------------------------------------------
35  * IMPORTANT !!!!! Must call the method closeArchiveFile()
36  * to be able to delete the file later !!!
37  * -----------------------------------------------------------------
38  *
39  * @author Khue ng
40  * @version 1.0
41  *
42  */

43 public class JahiaEarFileHandler {
44
45    /** The web.xml file **/
46    private static final String JavaDoc APPLICATION_XML_FILE = "META-INF/application.xml";
47    /** The Full path to the Ear File **/
48    private String JavaDoc m_FilePath;
49    /** The Archive File **/
50    private JahiaArchiveFileHandler m_ArchFile;
51    /** The List of Web Compomnents Definition **/
52    private Vector JavaDoc m_WebComponents = new Vector JavaDoc();
53    /** The Application_Xml to store data extracted from application.xml file **/
54    private Application_Xml m_AppXmlDoc ;
55
56    /**
57     * Constructor is initialized with the Ear File full path
58     *
59     */

60    public JahiaEarFileHandler (String JavaDoc filePath)
61    throws JahiaException {
62
63       m_FilePath = filePath;
64       File JavaDoc f = new File JavaDoc(filePath);
65       try {
66
67          m_ArchFile = new JahiaArchiveFileHandler( f.getAbsolutePath() );
68
69       } catch (IOException JavaDoc e ) {
70
71          String JavaDoc errMsg = "Failed creating an Archive File Handler " ;
72          JahiaConsole.println("JahiaEarFileHandler::Constructor", errMsg + "\n" + e.toString());
73          throw new JahiaException ("JahiaEarFileHandler", errMsg ,
74                                     JahiaException.SERVICE_ERROR, JahiaException.ERROR_SEVERITY);
75
76       }
77         
78         
79       try {
80          buildWebComponents();
81       } catch ( JahiaException je ) {
82
83          if ( m_ArchFile != null ){
84             m_ArchFile.closeArchiveFile();
85          }
86
87          JahiaConsole.println("JahiaEarFileHandler:: Constructor", "error building the WebApssWarPackage" + je.toString());
88          throw new JahiaException ("JahiaEarFileHandler", "error building the JahiaWebAppsWar Package" ,
89                                     JahiaException.SERVICE_ERROR, JahiaException.ERROR_SEVERITY);
90
91       }
92
93
94    }
95
96
97    /**
98     * Extract data from the application.xml file and build the list
99     * of WebComponents Definition
100     *
101     */

102    protected void buildWebComponents() throws JahiaException {
103
104       // extract data from the application.xml file
105
try {
106          File JavaDoc tmpFile = m_ArchFile.extractFile(APPLICATION_XML_FILE);
107
108          //System.out.println(" tmpxmlfile is " + tmpFile.getAbsolutePath() );
109

110          m_AppXmlDoc = new Application_Xml(tmpFile.getAbsolutePath());
111          m_AppXmlDoc.extractDocumentData();
112          m_WebComponents = m_AppXmlDoc.getWebComponents();
113          tmpFile.deleteOnExit();
114          tmpFile.delete();
115       } catch (IOException JavaDoc ioe){
116
117          String JavaDoc errMsg = "Failed extracting application.xml file data " ;
118          JahiaConsole.println("JahiaEarFileHandler:: buildWebComponents", errMsg + "\n" + ioe.toString());
119          throw new JahiaException ("JahiaEarFileHandler", errMsg ,
120                                     JahiaException.SERVICE_ERROR, JahiaException.ERROR_SEVERITY);
121
122       }
123
124    }
125
126
127    /**
128     * Returns the WebComponents list
129     *
130     * @return (Vector) the list of Web Component Definitions
131     */

132    public Vector JavaDoc getWebComponents(){
133
134       return m_WebComponents;
135
136    }
137
138
139    /**
140     * Unzip the contents of the jar file in it's current folder
141     *
142     */

143    public void unzip() throws JahiaException {
144
145       // Unzip the file
146
m_ArchFile.unzip();
147
148    }
149
150
151    /**
152     * Unzip the contents of the jar file in a gived folder
153     *
154     * @param (String) path , the path where to extract file
155     */

156    public void unzip(String JavaDoc path) throws JahiaException {
157
158       // Unzip the file
159
m_ArchFile.unzip(path);
160
161    }
162
163
164    /**
165     * Unzip an entry in a gived folder
166     *
167     * @param (String) entryName , the name of the entry
168     * @param (String) path , the path where to extract file
169     */

170    public void extractEntry( String JavaDoc entryName,
171                              String JavaDoc path) throws JahiaException {
172
173       // Unzip the entry
174
m_ArchFile.extractEntry(entryName, path);
175
176    }
177
178
179    /**
180     * Close the Jar file
181     *
182     */

183    public void closeArchiveFile(){
184
185       if ( m_ArchFile != null ) {
186          m_ArchFile.closeArchiveFile();
187       }
188    }
189
190
191 } // End Class JahiaEarFileHandler
192
Popular Tags