KickJava   Java API By Example, From Geeks To Geeks.

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


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
26 import java.io.*;
27 import java.util.regex.Pattern JavaDoc;
28   
29 public class TomcatConfigFilesUpdater
30 {
31     private String JavaDoc path = null;
32     private String JavaDoc appName = null;
33     private String JavaDoc appDir = null;
34     private String JavaDoc logDir = null;
35     private String JavaDoc connUrl = null;
36     private String JavaDoc usrName = null;
37     private String JavaDoc usrPass = null;
38     private String JavaDoc driverName = null;
39
40     public void setPath(String JavaDoc path)
41     {
42         this.path = path;
43     }
44
45     public void setAppName(String JavaDoc appName)
46     {
47         this.appName = appName;
48     }
49
50     public void setAppDir(String JavaDoc appDir)
51     {
52         this.appDir = appDir;
53     }
54     
55     public void setLogDir(String JavaDoc logDir)
56     {
57         this.logDir = logDir;
58     }
59
60     public void setDriverName(String JavaDoc driverName)
61     {
62         this.driverName = driverName;
63     }
64
65     public void setConnUrl(String JavaDoc connUrl)
66     {
67         this.connUrl = connUrl;
68     }
69
70     public void setUsrName(String JavaDoc usrName)
71     {
72         this.usrName = usrName;
73     }
74
75     public void setUsrPass(String JavaDoc usrPass)
76     {
77         this.usrPass = usrPass;
78     }
79
80     
81     /**
82      * This method updates the config-files needed to deploy a new application with a context.
83      */

84     public void updateConfiguration() throws Exception JavaDoc
85     {
86         createInfoGlueCMSContextFile(appName, appDir, logDir, driverName, connUrl, usrName, usrPass);
87     }
88     
89     /**
90      * This method updates the config-files needed to deploy a new application with a context.
91      */

92     public void updateConfiguration(String JavaDoc appName, String JavaDoc appDir, String JavaDoc logDir) throws Exception JavaDoc
93     {
94         createInfoGlueDeliverContextFile(appName, appDir, logDir);
95     }
96
97     /**
98      * This method creates a new context-node.
99      */

100      
101     private void createInfoGlueCMSContextFile(String JavaDoc appName, String JavaDoc appDir, String JavaDoc logDir, String JavaDoc driverName, String JavaDoc connectionURL, String JavaDoc userName, String JavaDoc password) throws Exception JavaDoc
102     {
103         FileInputStream fis = new FileInputStream("configTemplates/infoglueCMS.xml");
104         String JavaDoc result = "";
105         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
106         
107         int c;
108         while((c = fis.read()) != -1)
109         {
110             sb.append((char)c);
111         }
112         result = sb.toString();
113         //Logger.logInfo("result" + result);
114

115         appDir = appDir.replace('\\', '/');
116         logDir = logDir.replace('\\', '/');
117         
118         Pattern JavaDoc escaper = Pattern.compile("([^a-zA-z0-9])");
119         String JavaDoc newPassword = escaper.matcher(password).replaceAll("\\\\$1");
120         //System.out.println("password:" + password);
121
//System.out.println("newPassword:" + newPassword);
122

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     /**
137      * This method creates a new context-node for the deliver engine.
138      */

139      
140     private void createInfoGlueDeliverContextFile(String JavaDoc appName, String JavaDoc appDir, String JavaDoc logDir) throws Exception JavaDoc
141     {
142         FileInputStream fis = new FileInputStream("configTemplates/infoglueDeliver.xml");
143         String JavaDoc result = "";
144         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
145         
146         int c;
147         while((c = fis.read()) != -1)
148         {
149             sb.append((char)c);
150         }
151         result = sb.toString();
152         //Logger.logInfo("result" + result);
153

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