1 23 24 package org.infoglue.cmsinstaller; 25 26 import java.io.*; 27 import java.util.regex.Pattern ; 28 29 public class TomcatConfigFilesUpdater 30 { 31 private String path = null; 32 private String appName = null; 33 private String appDir = null; 34 private String logDir = null; 35 private String connUrl = null; 36 private String usrName = null; 37 private String usrPass = null; 38 private String driverName = null; 39 40 public void setPath(String path) 41 { 42 this.path = path; 43 } 44 45 public void setAppName(String appName) 46 { 47 this.appName = appName; 48 } 49 50 public void setAppDir(String appDir) 51 { 52 this.appDir = appDir; 53 } 54 55 public void setLogDir(String logDir) 56 { 57 this.logDir = logDir; 58 } 59 60 public void setDriverName(String driverName) 61 { 62 this.driverName = driverName; 63 } 64 65 public void setConnUrl(String connUrl) 66 { 67 this.connUrl = connUrl; 68 } 69 70 public void setUsrName(String usrName) 71 { 72 this.usrName = usrName; 73 } 74 75 public void setUsrPass(String usrPass) 76 { 77 this.usrPass = usrPass; 78 } 79 80 81 84 public void updateConfiguration() throws Exception 85 { 86 createInfoGlueCMSContextFile(appName, appDir, logDir, driverName, connUrl, usrName, usrPass); 87 } 88 89 92 public void updateConfiguration(String appName, String appDir, String logDir) throws Exception 93 { 94 createInfoGlueDeliverContextFile(appName, appDir, logDir); 95 } 96 97 100 101 private void createInfoGlueCMSContextFile(String appName, String appDir, String logDir, String driverName, String connectionURL, String userName, String password) throws Exception 102 { 103 FileInputStream fis = new FileInputStream("configTemplates/infoglueCMS.xml"); 104 String result = ""; 105 StringBuffer sb = new StringBuffer (); 106 107 int c; 108 while((c = fis.read()) != -1) 109 { 110 sb.append((char)c); 111 } 112 result = sb.toString(); 113 115 appDir = appDir.replace('\\', '/'); 116 logDir = logDir.replace('\\', '/'); 117 118 Pattern escaper = Pattern.compile("([^a-zA-z0-9])"); 119 String newPassword = escaper.matcher(password).replaceAll("\\\\$1"); 120 123 result = result.replaceAll("\\{appName\\}", appName); 124 result = result.replaceAll("\\{applicationPath\\}", appDir); 125 result = result.replaceAll("\\{driverName\\}", driverName); 126 result = result.replaceAll("\\{connectionURL\\}", connectionURL); 127 result = result.replaceAll("\\{userName\\}", userName); 128 result = result.replaceAll("\\{password\\}", newPassword); 129 result = result.replaceAll("\\{logDir\\}", logDir); 130 131 PrintWriter pw = new PrintWriter(new FileOutputStream("localConfigs/infoglueCMS.xml")); 132 pw.println(result); 133 pw.close(); 134 } 135 136 139 140 private void createInfoGlueDeliverContextFile(String appName, String appDir, String logDir) throws Exception 141 { 142 FileInputStream fis = new FileInputStream("configTemplates/infoglueDeliver.xml"); 143 String result = ""; 144 StringBuffer sb = new StringBuffer (); 145 146 int c; 147 while((c = fis.read()) != -1) 148 { 149 sb.append((char)c); 150 } 151 result = sb.toString(); 152 154 appDir = appDir.replace('\\', '/'); 155 logDir = logDir.replace('\\', '/'); 156 157 result = result.replaceAll("\\{appName\\}", appName); 158 result = result.replaceAll("\\{applicationPath\\}", appDir); 159 result = result.replaceAll("\\{logDir\\}", logDir); 160 161 PrintWriter pw = new PrintWriter(new FileOutputStream("localConfigs/" + appName + ".xml")); 162 pw.println(result); 163 pw.close(); 164 } 165 166 } | Popular Tags |