1 23 24 package org.infoglue.cmsinstaller; 25 26 import java.io.*; 27 import java.util.*; 28 import java.util.zip.*; 29 30 public abstract class InstallationCommander 31 { 32 protected String appServer = null; 33 protected String cmsTargetFolder = null; 34 protected String deliverWorkingTargetFolder = null; 35 protected String deliverPreviewTargetFolder = null; 36 protected String deliverLiveTargetFolder = null; 37 protected String applicationServerHomePath = null; 38 protected String tomcatContextFolder = null; 39 protected String createCMS = null; 40 protected String createDeliverWorking = null; 41 protected String createDeliverPreview = null; 42 protected String createDeliverLive = null; 43 protected String appNameSuffix = null; 44 45 public static InstallationCommander getInstallationCommander(String appServer, String targetFolder, String appNameSuffix, String applicationServerHomePath, String createCMS, String createDeliverWorking, String createDeliverPreview, String createDeliverLive, String tomcatContextFolder) 46 { 47 if(appServer.startsWith("Tomcat")) 48 return new TomcatInstallationCommander(appServer, targetFolder, appNameSuffix, applicationServerHomePath, createCMS, createDeliverWorking, createDeliverPreview, createDeliverLive, tomcatContextFolder); 49 else if(appServer.startsWith("JBoss")) 50 return new JBossInstallationCommander(appServer, targetFolder, appNameSuffix, applicationServerHomePath, createCMS, createDeliverWorking, createDeliverPreview, createDeliverLive, tomcatContextFolder); 51 else 52 return null; 53 } 54 55 public InstallationCommander(String appServer, String targetFolder, String appNameSuffix, String applicationServerHomePath, String createCMS, String createDeliverWorking, String createDeliverPreview, String createDeliverLive, String tomcatContextFolder) 56 { 57 this.appServer = appServer; 58 this.applicationServerHomePath = applicationServerHomePath; 59 this.createCMS = createCMS; 60 this.createDeliverWorking = createDeliverWorking; 61 this.createDeliverPreview = createDeliverPreview; 62 this.createDeliverLive = createDeliverLive; 63 this.appNameSuffix = appNameSuffix; 64 this.tomcatContextFolder = tomcatContextFolder; 65 this.cmsTargetFolder = targetFolder + File.separator + "infoglueCMS" + appNameSuffix; 67 this.deliverWorkingTargetFolder = targetFolder + File.separator + "infoglueDeliverWorking" + appNameSuffix; 68 this.deliverPreviewTargetFolder = targetFolder + File.separator + "infoglueDeliverPreview" + appNameSuffix; 69 this.deliverLiveTargetFolder = targetFolder + File.separator + "infoglueDeliverLive" + appNameSuffix; 70 } 71 72 public abstract String getPortletBase(); 73 74 public abstract void installFiles(String databaseTypeName) throws Exception ; 75 76 79 80 protected abstract void moveLocalConfigurationFiles(String databaseTypeName) throws Exception ; 81 82 83 86 87 protected boolean checkIfXMLLibsIsNeeded() 88 { 89 try 90 { 91 Class testClass = Class.forName("org.apache.xml.serialize.XMLSerializer"); 92 return false; 93 } 94 catch(ClassNotFoundException e) 95 { 96 Logger.logInfo("The installer will install the xml-packages as they seem to be missing."); 97 return true; 98 } 99 } 100 101 102 103 106 107 protected void unzipCMSWarFile(String cmsTargetFolder) throws Exception 108 { 109 String warFile = "infoglue-cms.war"; 110 111 Enumeration entries; 112 ZipFile zipFile; 113 114 zipFile = new ZipFile(warFile); 115 entries = zipFile.entries(); 116 117 while(entries.hasMoreElements()) 118 { 119 ZipEntry entry = (ZipEntry)entries.nextElement(); 120 121 if(entry.isDirectory()) 122 { 123 (new File(cmsTargetFolder + File.separator + entry.getName())).mkdir(); 124 continue; 125 } 126 127 copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream(new FileOutputStream(cmsTargetFolder + File.separator + entry.getName()))); 129 } 130 131 zipFile.close(); 132 } 133 134 135 138 139 protected void unzipDeliverWarFile(String path) throws Exception 140 { 141 String warFile = "infoglue-deliver.war"; 142 143 Enumeration entries; 144 ZipFile zipFile; 145 146 zipFile = new ZipFile(warFile); 147 entries = zipFile.entries(); 148 149 while(entries.hasMoreElements()) 150 { 151 ZipEntry entry = (ZipEntry)entries.nextElement(); 152 153 if(entry.isDirectory()) 154 { 155 (new File(path + File.separator + entry.getName())).mkdir(); 156 continue; 157 } 158 159 copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream(new FileOutputStream(path + File.separator + entry.getName()))); 161 } 162 163 zipFile.close(); 164 } 165 166 167 170 171 protected void copyInputStream(InputStream in, OutputStream out) throws IOException 172 { 173 byte[] buffer = new byte[1024]; 174 int len; 175 176 while((len = in.read(buffer)) >= 0) 177 out.write(buffer, 0, len); 178 179 in.close(); 180 out.close(); 181 } 182 183 186 187 public void zipDir(String dir2zip, int numberOfCharsToRemove, ZipOutputStream zos) throws Exception 188 { 189 File zipDir = new File(dir2zip); 191 192 String [] dirList = zipDir.list(); 194 195 byte[] readBuffer = new byte[2156]; 196 197 int bytesIn = 0; 198 199 for(int i=0; i<dirList.length; i++) 200 { 201 File f = new File(zipDir, dirList[i]); 202 if(f.isDirectory()) 203 { 204 String filePath = f.getPath(); 205 zipDir(filePath, numberOfCharsToRemove, zos); 206 continue; 207 } 208 209 FileInputStream fis = new FileInputStream(f); 210 211 ZipEntry anEntry = new ZipEntry(f.getPath().substring(numberOfCharsToRemove)); 212 System.out.println("Adding " + f.getPath().substring(numberOfCharsToRemove)); 213 214 zos.putNextEntry(anEntry); 215 216 while((bytesIn = fis.read(readBuffer)) != -1) 217 { 218 zos.write(readBuffer, 0, bytesIn); 219 } 220 221 fis.close(); 222 } 223 } 224 225 public void modifyOSCachePropertyFile(String targetFolder) throws Exception 226 { 227 FileInputStream fis = new FileInputStream(targetFolder + File.separator + "WEB-INF/classes/oscache.properties"); 228 String result = ""; 229 StringBuffer sb = new StringBuffer (); 230 231 int c; 232 while((c = fis.read()) != -1) 233 { 234 sb.append((char)c); 235 } 236 result = sb.toString(); 237 fis.close(); 238 239 result = result.replaceAll("@cachePath@", targetFolder + File.separator + "cache"); 240 result = result.replaceAll("\\@cachePath\\@", targetFolder + File.separator + "cache"); 241 242 PrintWriter pw = new PrintWriter(new FileOutputStream(targetFolder + File.separator + "WEB-INF/classes/oscache.properties")); 243 pw.println(result); 244 pw.close(); 245 246 } 247 248 249 protected void deleteRecursive(File file) throws IOException 250 { 251 File[] files = file.listFiles(); 252 253 for(int i=0; i<files.length; ++i) 254 { 255 if(files[i].isDirectory()) 256 deleteRecursive(files[i]); 257 258 files[i].delete(); 259 } 260 } 261 262 263 } 264 | Popular Tags |