1 23 24 package org.infoglue.cmsinstaller; 25 import java.io.*; 26 27 public class ConfigurationFileCommander 28 { 29 private String hostName = null; 30 private String portNumber = null; 31 private String tomcatPath = null; 32 private String smtpHostName = null; 33 private String nameSuffix = null; 34 private String applicationPath = null; 35 private String installPreview = null; 36 private String superUserName = null; 37 private String superUserPassword = null; 38 private String actionDispatcher = null; 39 private String enablePortal = null; 40 private String jdbcDriver = null; 41 private String connectionUrl = null; 42 private String userName = null; 43 private String password = null; 44 private String databaseDialectClass = null; 45 46 public ConfigurationFileCommander(String hostName, String tomcatPath, String smtpHostName, String portNumber, String nameSuffix, String applicationPath, String installPreview, String superUserName, String superUserPassword, String actionDispatcher, String enablePortal, String jdbcDriver, String connectionUrl, String userName, String password, String databaseDialectClass) 47 { 48 this.hostName = hostName; 49 this.tomcatPath = tomcatPath; 50 this.smtpHostName = smtpHostName; 51 this.portNumber = portNumber; 52 this.nameSuffix = nameSuffix; 53 this.applicationPath = applicationPath; 54 this.installPreview = installPreview; 55 this.superUserName = superUserName; 56 this.superUserPassword = superUserPassword; 57 this.actionDispatcher = actionDispatcher; 58 this.enablePortal = enablePortal; 59 this.jdbcDriver = jdbcDriver; 60 this.connectionUrl = connectionUrl; 61 this.userName = userName; 62 this.password = password; 63 this.databaseDialectClass = databaseDialectClass; 64 } 65 66 public void createCMSPropertyFile() throws Exception 67 { 68 FileInputStream fis = new FileInputStream("configTemplates/cms.properties"); 69 String result = ""; 70 StringBuffer sb = new StringBuffer (); 71 72 int c; 73 while((c = fis.read()) != -1) 74 { 75 sb.append((char)c); 76 } 77 result = sb.toString(); 78 79 applicationPath = applicationPath.replace('\\', '/'); 80 81 result = result.replaceAll("\\{hostName\\}", this.hostName); 82 result = result.replaceAll("\\{portNumber\\}", this.portNumber); 83 result = result.replaceAll("\\{applicationPath\\}", applicationPath); 84 result = result.replaceAll("\\{applicationName\\}", "infoglueCMS" + this.nameSuffix); 85 result = result.replaceAll("\\{applicationSuffix\\}", this.nameSuffix); 86 result = result.replaceAll("\\{mailServer\\}", this.smtpHostName); 87 result = result.replaceAll("\\{mail.contentType\\}", "text/html"); 88 result = result.replaceAll("\\{installPreview\\}", this.installPreview); 89 result = result.replaceAll("\\{superUserName\\}", this.superUserName); 90 result = result.replaceAll("\\{superUserPassword\\}", this.superUserPassword); 91 result = result.replaceAll("\\@edition.pageSize\\@", "10"); 92 result = result.replaceAll("@edition.pageSize@", "10"); 93 94 PrintWriter pw = new PrintWriter(new FileOutputStream("localConfigs/cms.properties")); 95 pw.println(result); 96 pw.close(); 97 } 98 99 public void createDeliverWorkingPropertyFile(InstallationCommander installationCommander) throws Exception 100 { 101 FileInputStream fis = new FileInputStream("configTemplates/deliver.properties"); 102 String result = ""; 103 StringBuffer sb = new StringBuffer (); 104 105 int c; 106 while((c = fis.read()) != -1) 107 { 108 sb.append((char)c); 109 } 110 result = sb.toString(); 111 112 applicationPath = applicationPath.replace('\\', '/'); 113 this.tomcatPath = tomcatPath.replace('\\', '/'); 114 String portletBase = installationCommander.getPortletBase().replace('\\', '/'); 115 116 result = result.replaceAll("\\{hostName\\}", this.hostName); 117 result = result.replaceAll("\\{portNumber\\}", this.portNumber); 118 result = result.replaceAll("\\{applicationPath\\}", applicationPath); 119 result = result.replaceAll("\\{applicationName\\}", "infoglueDeliverWorking" + this.nameSuffix); 120 result = result.replaceAll("\\{mailServer\\}", this.smtpHostName); 121 result = result.replaceAll("\\{operatingMode\\}", "0"); 122 result = result.replaceAll("\\{cmsApplicationName\\}", "infoglueCMS" + this.nameSuffix); 123 result = result.replaceAll("\\{enableEditOnSight\\}", "true"); 124 result = result.replaceAll("\\{applicationSuffix\\}", this.nameSuffix); 125 result = result.replaceAll("\\{enablePortal\\}", this.enablePortal); 126 result = result.replaceAll("\\{portletBase\\}", portletBase); 127 result = result.replaceAll("\\{niceURIEncoding\\}", "UTF-8"); 128 129 PrintWriter pw = new PrintWriter(new FileOutputStream("localConfigs/deliverWorking.properties")); 130 pw.println(result); 131 pw.close(); 132 133 } 134 135 public void createDeliverPreviewPropertyFile(InstallationCommander installationCommander) throws Exception 136 { 137 FileInputStream fis = new FileInputStream("configTemplates/deliver.properties"); 138 String result = ""; 139 StringBuffer sb = new StringBuffer (); 140 141 int c; 142 while((c = fis.read()) != -1) 143 { 144 sb.append((char)c); 145 } 146 result = sb.toString(); 147 148 applicationPath = applicationPath.replace('\\', '/'); 149 this.tomcatPath = tomcatPath.replace('\\', '/'); 150 String portletBase = installationCommander.getPortletBase().replace('\\', '/'); 151 152 result = result.replaceAll("\\{hostName\\}", this.hostName); 153 result = result.replaceAll("\\{portNumber\\}", this.portNumber); 154 result = result.replaceAll("\\{applicationPath\\}", applicationPath); 155 result = result.replaceAll("\\{applicationName\\}", "infoglueDeliverPreview" + this.nameSuffix); 156 result = result.replaceAll("\\{mailServer\\}", this.smtpHostName); 157 result = result.replaceAll("\\{operatingMode\\}", "2"); 158 result = result.replaceAll("\\{cmsApplicationName\\}", "infoglueCMS" + this.nameSuffix); 159 result = result.replaceAll("\\{enableEditOnSight\\}", "false"); 160 result = result.replaceAll("\\{applicationSuffix\\}", this.nameSuffix); 161 result = result.replaceAll("\\{enablePortal\\}", this.enablePortal); 162 result = result.replaceAll("\\{portletBase\\}", portletBase); 163 result = result.replaceAll("\\{niceURIEncoding\\}", "UTF-8"); 164 165 PrintWriter pw = new PrintWriter(new FileOutputStream("localConfigs/deliverPreview.properties")); 166 pw.println(result); 167 pw.close(); 168 169 } 170 171 public void createDeliverLivePropertyFile(InstallationCommander installationCommander) throws Exception 172 { 173 FileInputStream fis = new FileInputStream("configTemplates/deliver.properties"); 174 String result = ""; 175 StringBuffer sb = new StringBuffer (); 176 177 int c; 178 while((c = fis.read()) != -1) 179 { 180 sb.append((char)c); 181 } 182 result = sb.toString(); 183 184 applicationPath = applicationPath.replace('\\', '/'); 185 this.tomcatPath = tomcatPath.replace('\\', '/'); 186 String portletBase = installationCommander.getPortletBase().replace('\\', '/'); 187 188 result = result.replaceAll("\\{hostName\\}", this.hostName); 189 result = result.replaceAll("\\{portNumber\\}", this.portNumber); 190 result = result.replaceAll("\\{applicationPath\\}", applicationPath); 191 result = result.replaceAll("\\{applicationName\\}", "infoglueDeliverLive" + this.nameSuffix); 192 result = result.replaceAll("\\{mailServer\\}", this.smtpHostName); 193 result = result.replaceAll("\\{operatingMode\\}", "3"); 194 result = result.replaceAll("\\{cmsApplicationName\\}", "infoglueCMS" + this.nameSuffix); 195 result = result.replaceAll("\\{enableEditOnSight\\}", "false"); 196 result = result.replaceAll("\\{applicationSuffix\\}", this.nameSuffix); 197 result = result.replaceAll("\\{enablePortal\\}", this.enablePortal); 198 result = result.replaceAll("\\{portletBase\\}", portletBase); 199 result = result.replaceAll("\\{niceURIEncoding\\}", "UTF-8"); 200 201 PrintWriter pw = new PrintWriter(new FileOutputStream("localConfigs/deliverLive.properties")); 202 pw.println(result); 203 pw.close(); 204 205 } 206 207 208 public void createCMSWebappFile() throws Exception 209 { 210 FileInputStream fis = new FileInputStream("configTemplates/cms-web.xml"); 211 String result = ""; 212 StringBuffer sb = new StringBuffer (); 213 214 int c; 215 while((c = fis.read()) != -1) 216 { 217 sb.append((char)c); 218 } 219 result = sb.toString(); 220 221 applicationPath = applicationPath.replace('\\', '/'); 222 223 result = result.replaceAll("\\@actionDispatcher\\@", this.actionDispatcher); 224 result = result.replaceAll("@actionDispatcher@", this.actionDispatcher); 225 226 PrintWriter pw = new PrintWriter(new FileOutputStream("localConfigs/cms-web.xml")); 227 pw.println(result); 228 pw.close(); 229 } 230 231 public void createDeliverWebappFile() throws Exception 232 { 233 FileInputStream fis = new FileInputStream("configTemplates/deliver-web.xml"); 234 String result = ""; 235 StringBuffer sb = new StringBuffer (); 236 237 int c; 238 while((c = fis.read()) != -1) 239 { 240 sb.append((char)c); 241 } 242 result = sb.toString(); 243 244 applicationPath = applicationPath.replace('\\', '/'); 245 246 result = result.replaceAll("\\@actionDispatcher\\@", this.actionDispatcher); 247 result = result.replaceAll("@actionDispatcher@", this.actionDispatcher); 248 249 PrintWriter pw = new PrintWriter(new FileOutputStream("localConfigs/deliver-web.xml")); 250 pw.println(result); 251 pw.close(); 252 253 } 254 255 public void createHibernateConfigFile() throws Exception 256 { 257 FileInputStream fis = new FileInputStream("configTemplates/hibernate.cfg.xml"); 258 String result = ""; 259 StringBuffer sb = new StringBuffer (); 260 261 int c; 262 while((c = fis.read()) != -1) 263 { 264 sb.append((char)c); 265 } 266 result = sb.toString(); 267 268 applicationPath = applicationPath.replace('\\', '/'); 269 270 result = result.replaceAll("\\{jdbcDriver\\}", this.jdbcDriver); 271 result = result.replaceAll("\\{connectionUrl\\}", this.connectionUrl); 272 273 result = result.replaceAll("\\{userName\\}", this.userName); 274 result = result.replaceAll("\\{password\\}", this.password); 275 result = result.replaceAll("\\{databaseDialectClass\\}", this.databaseDialectClass); 276 277 PrintWriter pw = new PrintWriter(new FileOutputStream("localConfigs/hibernate.cfg.xml")); 278 pw.println(result); 279 pw.close(); 280 281 } 282 283 284 public static void main(String [] args) throws Exception 285 { 286 System.out.println("Testing..."); 287 288 FileInputStream fis = new FileInputStream("configTemplates/deliver.properties"); 289 String result = ""; 290 StringBuffer sb = new StringBuffer (); 291 292 int c; 293 while((c = fis.read()) != -1) 294 { 295 sb.append((char)c); 296 } 297 result = sb.toString(); 298 299 String applicationPath = "c:/Program/jboss-4.0.4.GA/server/default/deploy"; 300 String applicationServerHomePath = "c:/Program/jboss-4.0.4.GA"; 301 302 applicationPath = applicationPath.replace('\\', '/'); 303 applicationServerHomePath = applicationServerHomePath.replace('\\', '/'); 304 305 String portletBase = applicationServerHomePath + File.separator + "server" + File.separator + "default" + File.separator + "deploy"; 306 307 result = result.replaceAll("\\{hostName\\}", "localhost"); 308 result = result.replaceAll("\\{portNumber\\}", "8082"); 309 result = result.replaceAll("\\{applicationPath\\}", applicationPath); 310 result = result.replaceAll("\\{applicationName\\}", "infoglueDeliverWorking235"); 311 result = result.replaceAll("\\{mailServer\\}", "smtp.gu.se"); 312 result = result.replaceAll("\\{operatingMode\\}", "0"); 313 result = result.replaceAll("\\{cmsApplicationName\\}", "infoglueCMS235"); 314 result = result.replaceAll("\\{enableEditOnSight\\}", "true"); 315 result = result.replaceAll("\\{applicationSuffix\\}", "235"); 316 result = result.replaceAll("\\{enablePortal\\}", "true"); 317 result = result.replaceAll("\\{portletBase\\}", applicationPath); 318 result = result.replaceAll("\\{niceURIEncoding\\}", "UTF-8"); 319 320 System.out.println("result:" + result); 321 322 PrintWriter pw = new PrintWriter(new FileOutputStream("localConfigs/deliverWorkingTest.properties")); 323 pw.println(result); 324 pw.close(); 325 } 326 327 } 328 | Popular Tags |