KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cmsinstaller > ConfigurationFileCommander


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.cmsinstaller;
25 import java.io.*;
26
27 public class ConfigurationFileCommander
28 {
29     private String JavaDoc hostName = null;
30     private String JavaDoc portNumber = null;
31     private String JavaDoc tomcatPath = null;
32     private String JavaDoc smtpHostName = null;
33     private String JavaDoc nameSuffix = null;
34     private String JavaDoc applicationPath = null;
35     private String JavaDoc installPreview = null;
36     private String JavaDoc superUserName = null;
37     private String JavaDoc superUserPassword = null;
38     private String JavaDoc actionDispatcher = null;
39     private String JavaDoc enablePortal = null;
40     private String JavaDoc jdbcDriver = null;
41     private String JavaDoc connectionUrl = null;
42     private String JavaDoc userName = null;
43     private String JavaDoc password = null;
44     private String JavaDoc databaseDialectClass = null;
45     
46     public ConfigurationFileCommander(String JavaDoc hostName, String JavaDoc tomcatPath, String JavaDoc smtpHostName, String JavaDoc portNumber, String JavaDoc nameSuffix, String JavaDoc applicationPath, String JavaDoc installPreview, String JavaDoc superUserName, String JavaDoc superUserPassword, String JavaDoc actionDispatcher, String JavaDoc enablePortal, String JavaDoc jdbcDriver, String JavaDoc connectionUrl, String JavaDoc userName, String JavaDoc password, String JavaDoc 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 JavaDoc
67     {
68         FileInputStream fis = new FileInputStream("configTemplates/cms.properties");
69         String JavaDoc result = "";
70         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
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 JavaDoc
100     {
101         FileInputStream fis = new FileInputStream("configTemplates/deliver.properties");
102         String JavaDoc result = "";
103         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
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 JavaDoc 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 JavaDoc
136     {
137         FileInputStream fis = new FileInputStream("configTemplates/deliver.properties");
138         String JavaDoc result = "";
139         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
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 JavaDoc 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 JavaDoc
172     {
173         FileInputStream fis = new FileInputStream("configTemplates/deliver.properties");
174         String JavaDoc result = "";
175         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
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 JavaDoc 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 JavaDoc
209     {
210         FileInputStream fis = new FileInputStream("configTemplates/cms-web.xml");
211         String JavaDoc result = "";
212         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
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 JavaDoc
232     {
233         FileInputStream fis = new FileInputStream("configTemplates/deliver-web.xml");
234         String JavaDoc result = "";
235         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
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 JavaDoc
256     {
257         FileInputStream fis = new FileInputStream("configTemplates/hibernate.cfg.xml");
258         String JavaDoc result = "";
259         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
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 JavaDoc[] args) throws Exception JavaDoc
285     {
286         System.out.println("Testing...");
287         
288         FileInputStream fis = new FileInputStream("configTemplates/deliver.properties");
289         String JavaDoc result = "";
290         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
291         
292         int c;
293         while((c = fis.read()) != -1)
294         {
295             sb.append((char)c);
296         }
297         result = sb.toString();
298         
299         String JavaDoc applicationPath = "c:/Program/jboss-4.0.4.GA/server/default/deploy";
300         String JavaDoc applicationServerHomePath = "c:/Program/jboss-4.0.4.GA";
301         
302         applicationPath = applicationPath.replace('\\', '/');
303         applicationServerHomePath = applicationServerHomePath.replace('\\', '/');
304     
305         String JavaDoc 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