1 20 package org.jahia.data.webapps; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.Vector ; 25 26 import org.jahia.exceptions.JahiaException; 27 import org.jahia.utils.JahiaConsole; 28 import org.jahia.utils.zip.JahiaArchiveFileHandler; 29 30 43 public class JahiaEarFileHandler { 44 45 46 private static final String APPLICATION_XML_FILE = "META-INF/application.xml"; 47 48 private String m_FilePath; 49 50 private JahiaArchiveFileHandler m_ArchFile; 51 52 private Vector m_WebComponents = new Vector (); 53 54 private Application_Xml m_AppXmlDoc ; 55 56 60 public JahiaEarFileHandler (String filePath) 61 throws JahiaException { 62 63 m_FilePath = filePath; 64 File f = new File (filePath); 65 try { 66 67 m_ArchFile = new JahiaArchiveFileHandler( f.getAbsolutePath() ); 68 69 } catch (IOException e ) { 70 71 String 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 102 protected void buildWebComponents() throws JahiaException { 103 104 try { 106 File tmpFile = m_ArchFile.extractFile(APPLICATION_XML_FILE); 107 108 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 ioe){ 116 117 String 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 132 public Vector getWebComponents(){ 133 134 return m_WebComponents; 135 136 } 137 138 139 143 public void unzip() throws JahiaException { 144 145 m_ArchFile.unzip(); 147 148 } 149 150 151 156 public void unzip(String path) throws JahiaException { 157 158 m_ArchFile.unzip(path); 160 161 } 162 163 164 170 public void extractEntry( String entryName, 171 String path) throws JahiaException { 172 173 m_ArchFile.extractEntry(entryName, path); 175 176 } 177 178 179 183 public void closeArchiveFile(){ 184 185 if ( m_ArchFile != null ) { 186 m_ArchFile.closeArchiveFile(); 187 } 188 } 189 190 191 } | Popular Tags |