KickJava   Java API By Example, From Geeks To Geeks.

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


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.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.dom4j.Document;
31 import org.dom4j.Element;
32 import org.dom4j.io.SAXReader;
33
34 /**
35  * This is the main class for the installer. What the installer should do is as follows:
36  *
37  * 1. Ask for the root-access to the database we should use and set up a new database.
38  * 2. All tables and access rights should be set upp by the installer as well as a small example site.
39  * 3. Unpack the webarchive into the correct forlder and set up the property-files as the user specifies them.
40  */

41
42
43 public class InfoGlueCommandLineInstaller
44 {
45     DatabaseCommander commander = null;
46     
47     //Variables
48
private static String JavaDoc database = "MySQL";
49     private static String JavaDoc databaseName = "infoglue";
50     private static String JavaDoc databaseSuffix = "";
51     private static String JavaDoc databaseServer = "localhost";
52     private static String JavaDoc databasePort = "3306";
53     private static String JavaDoc databaseInstance = "";
54     private static String JavaDoc createDatabase = "No";
55     private static String JavaDoc createInitialData = "No";
56     private static String JavaDoc createExamples = "Yes";
57     private static String JavaDoc databaseUser = "root";
58     private static String JavaDoc databasePassword = "";
59     private static String JavaDoc infoglueDatabaseUserName = "";
60     private static String JavaDoc infoglueDatabasePassword = "";
61     private static String JavaDoc upgradeDatabaseEncoding = "";
62
63     private static String JavaDoc hostName = "localhost";
64     private static String JavaDoc portNumber = "8080";
65     private static String JavaDoc applicationSuffix = "";
66     private static String JavaDoc smtpHostName = "your.emailserver.com";
67     
68     private static String JavaDoc applicationServer = "Tomcat 5.x";
69     private static String JavaDoc tomcatHomePath = "C:\\Program\\Apache Software Foundation\\Tomcat 5.5";
70     private static String JavaDoc tomcatHomePath2 = "C:\\Program\\Apache Software Foundation\\Tomcat 5.0";
71     private static String JavaDoc tomcatHomePathLinux = "/usr/local/tomcat5";
72     //private static String tomcatVersion = "5";
73
//private static String tomcatHomePathLinux = "/usr/local/tomcat4";
74
private static String JavaDoc installCMS = "Yes";
75     private static String JavaDoc installWorkingDeliver = "Yes";
76     private static String JavaDoc installPreviewDeliver = "No";
77     private static String JavaDoc installLiveDeliver = "No";
78     private static String JavaDoc applicationPath = "";
79     
80     private static String JavaDoc superUserName = "root";
81     private static String JavaDoc superUserPassword = ServerDialog.generatePassword(6);
82     
83     private static String JavaDoc enablePortal = "false";
84     private static String JavaDoc actionDispatcher = "webwork.dispatcher.ServletDispatcher";
85         
86     //Introduction dialog
87
private final static String JavaDoc introductionHeader = "Welcome to the installation of InfoGlue CMS";
88     private final static String JavaDoc introductionMessage = "This wizard will take you though the \ndifferent steps of setting up the cms to \nwork on your server.\n\nPress enter to continue.";
89
90     //Database dialog
91
private final static String JavaDoc dbIntroductionHeader = "Database setup";
92     private final static String JavaDoc dbIntroductionMessage = "For the system to work you will have to state which database you wish to use.\n\nPlease supply the information needed below.";
93     
94     private final static String JavaDoc databaseLabel = "Database type (Valid are \"MySQL\", \"Oracle\", \"SQL Server\" and \"DB2\"): [" + database + "] ";
95     private final static String JavaDoc databaseNameLabel = "Database name: [" + databaseName + "] ";
96     private final static String JavaDoc databaseSuffixLabel = "Database suffix: [" + databaseSuffix + "] ";
97     //private final static String databaseDriverNameLabel = "Database driver name: [" + databaseDriverName + "] ";
98
private final static String JavaDoc databaseServerLabel = "Database server: [" + databaseServer + "] ";
99     private final static String JavaDoc databasePortLabel = "Database port: [" + databasePort + "] ";
100     private final static String JavaDoc databaseInstanceLabel = "Database instance: [] ";
101     //private final static String createDatabaseLabel = "Do you want to us to create a new InfoGlue instance in the \ngiven database? If yes, supply the information needed \nbelow so we can access the database as a priviliged user.\n [no]";
102
private final static String JavaDoc createDatabaseIntroLabel = "The installer can automatically create a database and set up some basic data \nto make the basic functionality and examples work. \nIf you would like the installer to do these tasks you mark the options you \nwant below and then supply the installer with an administrative db-account. \nThe account must have rights to create databases and tables on \nthe server stated above.\n";
103     private final static String JavaDoc createDatabaseLabel = "Do you want the database to create a new database for infoglue automatically.\n";
104     private final static String JavaDoc createInitialDataLabel = "Do you want the installer to set up tables and initial data?. \n[no]";
105     private final static String JavaDoc createExamplesLabel = "Do you want the installer to set up the included examples?. \n[yes]";
106     private final static String JavaDoc databaseUserLabel = "User name (Must have administrative priviliges in the database): [" + databaseUser + "] ";
107     private final static String JavaDoc databasePasswordLabel = "User password: [" + databasePassword + "] ";
108     private final static String JavaDoc infoglueDatabaseUserNameLabel = "InfoGlue database user: [" + infoglueDatabaseUserName + "] ";
109     private final static String JavaDoc infoglueDatabasePasswordLabel = "InfoGlue database password: [" + infoglueDatabasePassword + "] ";
110     private final static String JavaDoc upgradeDatabaseEncodingIntroductionText = "Do you want the installer to upgrade the database content to Unicode(utf-8)?";
111
112     //Server dialog
113
private final static String JavaDoc serverIntroductionHeader = "Server setup";
114     private final static String JavaDoc serverIntroductionMessage = "For the system to work we also have \nto set up the properties below so they \ncorresponds to your configuration.\n\n Please supply the information needed below.";
115     
116     private final static String JavaDoc applicationServerLabel = "Application server (Valid are \"Tomcat 5.x\", \"Tomcat 4.x\" and \"JBoss 4.0\"): [" + applicationServer + "]: ";
117     private final static String JavaDoc hostNameLabel = "Host Name: [" + hostName + "]: ";
118     private final static String JavaDoc portNumberLabel = "HTTP Port: [" + portNumber + "]: ";
119     private final static String JavaDoc applicationSuffixLabel = "Application suffix (used in shared environments): [" + applicationSuffix + "] ";
120     //private final static String digitalAssetPathLabel = "Digital asset path: [" + database + "]: ";
121
private final static String JavaDoc smtpHostNameLabel = "SMTP Host: [" + smtpHostName + "]: ";
122     //private final static String tomcatVersionLabel = "Tomcat version: [" + tomcatVersion + "] (4 or 5): ";
123
private final static String JavaDoc enablePortalLabel = "Activate JSR 168 support: [" + enablePortal + "]: ";
124     private final static String JavaDoc applicationServerHomePathLabel = "Application server HOME: [" + tomcatHomePath + "]";
125     private final static String JavaDoc installCMSLabel = "Install CMS Administrative tools: [" + installCMS + "] ";
126     private final static String JavaDoc installWorkingDeliverLabel = "Install working deliver: [" + installWorkingDeliver + "] ";
127     private final static String JavaDoc installPreviewDeliverLabel = "Install preview deliver (For complete setups): [" + installPreviewDeliver + "] ";
128     private final static String JavaDoc installLiveDeliverLabel = "Install live deliver (For complete setups): [" + installLiveDeliver + "] ";
129     private final static String JavaDoc applicationPathLabel = "Applications directory: [" + tomcatHomePath + File.separator + "webapps" + "]";
130     private final static String JavaDoc superUserNameLabel = "Super user name(unlimited access to cms): [" + superUserName + "]: ";
131     private final static String JavaDoc superUserPasswordLabel = "Super user password: [" + superUserPassword + "]: ";
132     
133     //Finish dialog
134
private final static String JavaDoc finishIntroductionHeader = "Complete Installation";
135     private final static String JavaDoc finishIntroductionMessage = "It's now time to complete the installation \nby copying the codebase to the webcontainer.\n\n Please press enter to complete the installation.";
136
137     //Done dialog
138
private final static String JavaDoc doneIntroductionHeader = "Installation of InfoGlue CMS completed";
139     private final static String JavaDoc doneIntroductionMessage = "InfoGlue CMS was installed successfully. \nYou can now start the tomcat server and launch \nyour favourite browser with the location \nhttp://localhost:8080/infoglueCMS/ViewCMSTool.action. \n\n.";
140
141     
142     public static void main(String JavaDoc[] args) throws Exception JavaDoc
143     {
144         if(args.length > 0 && args[0].equalsIgnoreCase("silent"))
145         {
146             InfoGlueCommandLineInstaller infoGlueInstaller = new InfoGlueCommandLineInstaller();
147             if(args.length > 1)
148             {
149                 System.out.println("file:" + args[1]);
150                 infoGlueInstaller.initSilentMode(args[1]);
151             }
152             else
153             {
154                 System.out.println("no file as argument");
155                 infoGlueInstaller.initSilentMode("installconf.xml");
156             }
157             
158             infoGlueInstaller.checkDatabase();
159             infoGlueInstaller.finishInstallation();
160         }
161         else
162         {
163             InfoGlueCommandLineInstaller infoGlueInstaller = new InfoGlueCommandLineInstaller();
164             infoGlueInstaller.showIntroductionDialog();
165             infoGlueInstaller.showDatabaseDialog();
166             infoGlueInstaller.showServerDialog();
167             infoGlueInstaller.showFinishDialog();
168             infoGlueInstaller.showDoneDialog();
169         }
170     }
171         
172     private void initSilentMode(String JavaDoc fileName) throws Exception JavaDoc
173     {
174         File file = new File(fileName);
175         SAXReader xmlReader = new SAXReader();
176         Document document = xmlReader.read(file);
177         
178         Element root = document.getRootElement();
179         System.out.println("root:" + root.getName());
180             
181         List JavaDoc children = root.elements();
182         System.out.println("children:" + children.size());
183         
184         Iterator JavaDoc i = children.iterator();
185         while(i.hasNext())
186         {
187             Element child = (Element)i.next();
188             String JavaDoc name = child.attributeValue("name");
189             String JavaDoc value = child.attributeValue("value");
190             System.out.println("name:" + name);
191             System.out.println("value:" + value);
192             
193             if(name.equalsIgnoreCase("database"))
194                 database = value;
195             if(name.equalsIgnoreCase("databaseName"))
196                 databaseName = value;
197             if(name.equalsIgnoreCase("databaseSuffix"))
198                 databaseSuffix = value;
199             if(name.equalsIgnoreCase("databaseServer"))
200                 databaseServer = value;
201             if(name.equalsIgnoreCase("databasePort"))
202                 databasePort = value;
203             if(name.equalsIgnoreCase("databaseInstance"))
204                 databaseInstance = value;
205             if(name.equalsIgnoreCase("createDatabase"))
206                 createDatabase = value;
207             if(name.equalsIgnoreCase("createInitialData"))
208                 createInitialData = value;
209             if(name.equalsIgnoreCase("createExamples"))
210                 createExamples = value;
211             if(name.equalsIgnoreCase("databaseUser"))
212                 databaseUser = value;
213             if(name.equalsIgnoreCase("databasePassword"))
214                 databasePassword = value;
215             if(name.equalsIgnoreCase("infoglueDatabaseUserName"))
216                 infoglueDatabaseUserName = value;
217             if(name.equalsIgnoreCase("infoglueDatabasePassword"))
218                 infoglueDatabasePassword = value;
219             if(name.equalsIgnoreCase("upgradeDatabaseEncoding"))
220                 upgradeDatabaseEncoding = value;
221             if(name.equalsIgnoreCase("applicationServer"))
222                 applicationServer = value;
223             if(name.equalsIgnoreCase("hostName"))
224                 hostName = value;
225             if(name.equalsIgnoreCase("portNumber"))
226                 portNumber = value;
227             if(name.equalsIgnoreCase("applicationSuffix"))
228                 applicationSuffix = value;
229             if(name.equalsIgnoreCase("smtpHostName"))
230                 smtpHostName = value;
231             if(name.equalsIgnoreCase("tomcatHomePath") || name.equalsIgnoreCase("applicationServerHomePath"))
232                 tomcatHomePath = value;
233             //if(name.equalsIgnoreCase("tomcatVersion"))
234
// tomcatVersion = value;
235
if(name.equalsIgnoreCase("installCMS"))
236                 installCMS = value;
237             if(name.equalsIgnoreCase("installWorkingDeliver"))
238                 installWorkingDeliver = value;
239             if(name.equalsIgnoreCase("installPreviewDeliver"))
240                 installPreviewDeliver = value;
241             if(name.equalsIgnoreCase("installLiveDeliver"))
242                 installLiveDeliver = value;
243             if(name.equalsIgnoreCase("applicationPath"))
244                 applicationPath = value;
245             if(name.equalsIgnoreCase("enablePortal"))
246             {
247                 enablePortal = value;
248                 actionDispatcher = getServletDispatcher(enablePortal);
249             }
250             if(name.equalsIgnoreCase("superUserName"))
251                 superUserName = value;
252             if(name.equalsIgnoreCase("superUserPassword"))
253                 superUserPassword = value;
254         }
255     }
256
257         
258     public InfoGlueCommandLineInstaller()
259     {
260     }
261
262
263     public static String JavaDoc getTomcatHomePath()
264     {
265         File directory = new File(tomcatHomePath);
266         File directory2 = new File(tomcatHomePath2);
267         //Logger.logInfo("directory:" + directory.getAbsolutePath() + ":" + directory.exists());
268
if(directory.exists())
269         {
270             return tomcatHomePath;
271         }
272         else if(directory2.exists())
273         {
274             return tomcatHomePath2;
275         }
276         else
277         {
278             directory = new File(tomcatHomePathLinux);
279             //Logger.logInfo("directory:" + directory.getAbsolutePath() + ":" + directory.exists());
280
if(directory.exists())
281             {
282                 return tomcatHomePathLinux;
283             }
284             else
285             {
286                 String JavaDoc catalinaHome = "" + System.getProperty("CATALINA_HOME");
287                 directory = new File(catalinaHome);
288                 //Logger.logInfo("directory:" + directory.getAbsolutePath() + ":" + directory.exists());
289
if(directory.exists())
290                 {
291                     return tomcatHomePathLinux;
292                 }
293                 else
294                 {
295                     catalinaHome = "" + System.getProperty("catalina.home");
296                     directory = new File(catalinaHome);
297                     //Logger.logInfo("directory:" + directory.getAbsolutePath() + ":" + directory.exists());
298
if(directory.exists())
299                     {
300                         return catalinaHome;
301                     }
302                     else
303                     {
304                         return "";
305                     }
306                 }
307             }
308         }
309         
310     }
311
312     /**
313      * This method gets the path where to store the context files.
314      */

315
316     public static String JavaDoc getTomcatContextPath()
317     {
318         String JavaDoc tomcatContextPath = "webapps";
319         
320         if(applicationServer.startsWith("Tomcat 5"))
321             tomcatContextPath = "conf" + File.separator + "Catalina" + File.separator + "localhost";
322         
323         return tomcatContextPath;
324     }
325
326
327     public void checkDatabase() throws Exception JavaDoc
328     {
329         if(database.equalsIgnoreCase("MySQL"))
330         {
331             String JavaDoc url = "jdbc:mysql://" + databaseServer + ":" + databasePort + "/mysql";
332             commander = new MySQLDatabaseCommander(getDatabaseDriverName(database), databaseServer, databasePort, databaseInstance, url, databaseUser, databasePassword, infoglueDatabaseUserName, infoglueDatabasePassword, databaseName + databaseSuffix, databaseSuffix, hostName, getCreateDatabase(), getCreateInitialData(), getCreateExamples(), getCreateExamples(), getCreateExamples());
333         }
334         else if(database.equalsIgnoreCase("SQL Server"))
335         {
336             //String url = "jdbc:microsoft:sqlserver://" + databaseServer + ":1433";
337
String JavaDoc url = "jdbc:jtds:sqlserver://" + databaseServer + ":" + databasePort + ((databaseInstance.equalsIgnoreCase("")) ? "" : ";INSTANCE=" + databaseInstance);
338             commander = new SQLServerDatabaseCommander(getDatabaseDriverName(database), databaseServer, databasePort, databaseInstance, url, databaseUser, databasePassword, infoglueDatabaseUserName, infoglueDatabasePassword, databaseName + databaseSuffix, databaseSuffix, hostName, getCreateDatabase(), getCreateInitialData(), getCreateExamples(), getCreateExamples(), getCreateExamples());
339         }
340         else if(database.equalsIgnoreCase("Oracle"))
341         {
342             String JavaDoc url = "jdbc:oracle:thin:@" + databaseServer + ":" + databasePort + ":" + databaseName + databaseSuffix;
343             commander = new OracleDatabaseCommander(getDatabaseDriverName(database), databaseServer, databasePort, databaseInstance, url, databaseUser, databasePassword, infoglueDatabaseUserName, infoglueDatabasePassword, databaseName + databaseSuffix, databaseSuffix, hostName, getCreateDatabase(), getCreateInitialData(), getCreateExamples(), getCreateExamples(), getCreateExamples());
344         }
345         else if(database.equalsIgnoreCase("DB2"))
346         {
347             String JavaDoc url = "jdbc:db2://" + databaseServer + ":" + databasePort + "/" + databaseName + databaseSuffix;
348             commander = new DB2DatabaseCommander(getDatabaseDriverName(database), databaseServer, databasePort, databaseInstance, url, databaseUser, databasePassword, infoglueDatabaseUserName, infoglueDatabasePassword, databaseName + databaseSuffix, databaseSuffix, hostName, getCreateDatabase(), getCreateInitialData(), getCreateExamples(), getCreateExamples(), getCreateExamples());
349         }
350         else
351         {
352             Logger.logInfo("Database supplied:" + database);
353             throw new Exception JavaDoc("Only 'MySQL', 'SQL Server' and 'Oracle' are supported at this moment.");
354         }
355         
356         System.out.println("createDatabase:" + createDatabase);
357         if(createDatabase.equalsIgnoreCase("yes"))
358         {
359             commander.testSetupDummyDatabase();
360         }
361         else
362         {
363             commander.testConnectDatabase();
364         }
365     }
366
367
368     public void showIntroductionDialog()
369     {
370         Logger.logInfo("");
371         Logger.logInfo("***********************************************");
372         Logger.logInfo("* " + introductionHeader + " *");
373         Logger.logInfo("***********************************************");
374         Logger.logInfo("");
375         Logger.logInfo(introductionMessage);
376         try
377         {
378             getInputWithDefault("");
379         }
380         catch(Exception JavaDoc e)
381         {
382             Logger.logInfo("An exception occurred:" + e.getMessage());
383             showIntroductionDialog();
384         }
385     }
386
387
388     public void showDatabaseDialog()
389     {
390
391         Logger.logInfo("");
392         Logger.logInfo(dbIntroductionHeader);
393         Logger.logInfo("");
394         Logger.logInfo(dbIntroductionMessage);
395         Logger.logInfo("");
396         try
397         {
398             database = getInputWithDefault(databaseLabel, new String JavaDoc[] {"MySQL", "SQL Server", "Oracle", "DB2"}, database, true);
399             System.out.print(databaseNameLabel);
400             databaseName = getInputWithDefault(databaseName);
401             
402             if(database.equalsIgnoreCase("MySQL"))
403                 databasePort = "3306";
404             else if(database.equalsIgnoreCase("SQL Server"))
405                 databasePort = "1433";
406             else if(database.equalsIgnoreCase("Oracle"))
407                 databasePort = "1521";
408             else if(database.equalsIgnoreCase("DB2"))
409                 databasePort = "50000";
410             
411             System.out.print(databaseSuffixLabel);
412             databaseSuffix = getInputWithDefault(databaseSuffix);
413             System.out.print(databaseServerLabel);
414             databaseServer = getInputWithDefault(databaseServer);
415             System.out.print(databasePortLabel);
416             databasePort = getInputWithDefault(databasePort);
417             infoglueDatabaseUserName = getInputWithDefault(infoglueDatabaseUserNameLabel, new String JavaDoc[] {}, infoglueDatabaseUserName, false);
418             infoglueDatabasePassword = getInputWithDefault(infoglueDatabasePasswordLabel, new String JavaDoc[] {}, infoglueDatabasePassword, false);
419
420             System.out.println();
421             System.out.print(createDatabaseIntroLabel);
422             System.out.println();
423             
424             if(!database.equalsIgnoreCase("Oracle") || !database.equalsIgnoreCase("DB2"))
425                 createDatabase = getInputWithDefault(createDatabaseLabel, new String JavaDoc[] {"yes", "no"}, createDatabase, true);
426             
427             createInitialData = getInputWithDefault(createInitialDataLabel, new String JavaDoc[] {"yes", "no"}, createInitialData, true);
428             createExamples = getInputWithDefault(createExamplesLabel, new String JavaDoc[] {"yes", "no"}, createExamples, true);
429             
430             if(createDatabase.equalsIgnoreCase("yes") || createInitialData.equalsIgnoreCase("yes"))
431             {
432                 databaseUser = getInputWithDefault(databaseUserLabel, new String JavaDoc[] {}, databaseUser, false);
433                 databasePassword = getInputWithDefault(databasePasswordLabel, new String JavaDoc[] {}, databasePassword, true);
434             }
435             else
436             {
437                 upgradeDatabaseEncoding = getInputWithDefault(upgradeDatabaseEncodingIntroductionText, new String JavaDoc[] {"yes", "no"}, "no", true);
438                 if(getUpgradeDatabaseEncoding())
439                 {
440                     getInputWithDefault("You MUST backup your database before continuing as this can seriously affect you data.\nPress enter when done.");
441                 }
442             }
443                         
444             this.checkDatabase();
445             
446             //setupDatabaseEnvironment();
447

448         }
449         catch(Exception JavaDoc e)
450         {
451             Logger.logInfo("An exception occurred:" + e.getMessage());
452             showDatabaseDialog();
453         }
454     }
455
456
457     public void showServerDialog()
458     {
459
460         Logger.logInfo("");
461         Logger.logInfo(serverIntroductionHeader);
462         Logger.logInfo("");
463         Logger.logInfo(serverIntroductionMessage);
464         Logger.logInfo("");
465
466         try
467         {
468             applicationServer = getInputWithDefault(applicationServerLabel, new String JavaDoc[] {"Tomcat 4.x", "Tomcat 5.x", "JBoss 4.0"}, applicationServer, true);
469
470             hostName = getInputWithDefault(hostNameLabel, new String JavaDoc[] {}, hostName, true);
471             portNumber = getInputWithDefault(portNumberLabel, new String JavaDoc[] {}, portNumber, true);
472
473             applicationSuffix = getInputWithDefault(applicationSuffixLabel, new String JavaDoc[] {}, applicationSuffix, true);
474             installCMS = getInputWithDefault(installCMSLabel, new String JavaDoc[] {"yes", "no"}, installCMS, true);
475             installWorkingDeliver = getInputWithDefault(installWorkingDeliverLabel, new String JavaDoc[] {"yes", "no"}, installWorkingDeliver, true);
476             installPreviewDeliver = getInputWithDefault(installPreviewDeliverLabel, new String JavaDoc[] {"yes", "no"}, installPreviewDeliver, true);
477             installLiveDeliver = getInputWithDefault(installLiveDeliverLabel, new String JavaDoc[] {"yes", "no"}, installLiveDeliver, true);
478             smtpHostName = getInputWithDefault(smtpHostNameLabel, new String JavaDoc[] {}, smtpHostName, false);
479             enablePortal = getInputWithDefault(enablePortalLabel, new String JavaDoc[] {}, enablePortal, false);
480                     
481             //tomcatVersion = getInputWithDefault(tomcatVersionLabel, new String[] {"4", "5"}, tomcatVersion, false);
482
tomcatHomePath = getExistingDirectory("Application server HOME: [" + getTomcatHomePath() + "]", tomcatHomePath, "webapps");
483             if(enablePortal.equals("false"))
484                 applicationPath = getExistingDirectory("Applications HOME: [" + tomcatHomePath + File.separator + "webapps]", tomcatHomePath + File.separator + "webapps", null);
485             else
486                 applicationPath = tomcatHomePath + File.separator + "webapps";
487                     
488             superUserName = getInputWithDefault(superUserNameLabel, new String JavaDoc[] {}, superUserName, false);
489             superUserPassword = getInputWithDefault(superUserPasswordLabel, new String JavaDoc[] {}, superUserPassword, false);
490             
491             actionDispatcher = getServletDispatcher(enablePortal);
492             
493             //setupPropertyFiles();
494

495         }
496         catch(Exception JavaDoc e)
497         {
498             Logger.logInfo("An exception occurred:" + e.getMessage());
499             showServerDialog();
500         }
501     }
502
503     private String JavaDoc getServletDispatcher(String JavaDoc enablePortal)
504     {
505         String JavaDoc actionDispatcher = "webwork.dispatcher.ServletDispatcher";
506         if(enablePortal.equalsIgnoreCase("true"))
507             actionDispatcher = "org.infoglue.deliver.portal.dispatcher.PortalServletDispatcher";
508
509         return actionDispatcher;
510     }
511
512     public void showFinishDialog()
513     {
514
515         Logger.logInfo("");
516         Logger.logInfo(finishIntroductionHeader);
517         Logger.logInfo("");
518         Logger.logInfo(finishIntroductionMessage);
519         Logger.logInfo("");
520         try
521         {
522             getInputWithDefault("");
523             
524             finishInstallation();
525             
526         }
527         catch(Exception JavaDoc e)
528         {
529             Logger.logInfo("An exception occurred:" + e.getMessage());
530             e.printStackTrace();
531             showFinishDialog();
532         }
533     }
534
535
536     public void showDoneDialog()
537     {
538
539         Logger.logInfo("");
540         Logger.logInfo(doneIntroductionHeader);
541         Logger.logInfo("");
542         Logger.logInfo("InfoGlue CMS was installed successfully. You can now start the tomcat server and launch your favourite browser with the location http://" + hostName + ":" + portNumber + "/infoglueCMS" + applicationSuffix + "/ViewCMSTool.action.");
543         //Logger.logInfo(doneIntroductionMessage);
544
Logger.logInfo("");
545         try
546         {
547             getInputWithDefault("");
548         }
549         catch(Exception JavaDoc e)
550         {
551             Logger.logInfo("An exception occurred:" + e.getMessage());
552             showDoneDialog();
553         }
554     }
555
556     private String JavaDoc getExistingDirectory(String JavaDoc message, String JavaDoc directory, String JavaDoc neededSubDirectory) throws Exception JavaDoc
557     {
558         System.out.print(message);
559         String JavaDoc temp = getInputWithDefault(directory);
560         File homeDir = new File(temp);
561         File homeDirSubDirectory = new File(temp + File.separator + neededSubDirectory);
562         if(homeDir.exists() && homeDir.isDirectory() && (neededSubDirectory == null || homeDirSubDirectory.exists()))
563             return temp;
564         else
565         {
566             Logger.logInfo("The directory did not exist.");
567             return getExistingDirectory(message, directory, neededSubDirectory);
568         }
569     }
570
571     public String JavaDoc getInputWithDefault(String JavaDoc defaultValue) throws Exception JavaDoc
572     {
573         String JavaDoc value = "";
574         
575         // block until enter is pressed
576
while (true)
577         {
578             char c = (char)System.in.read();
579             if (c == '\r')
580             {
581                 c = (char)System.in.read();
582                 if (c == '\n')
583                 {
584                    break;
585                 }
586                 else
587                 {
588                    continue;
589                 }
590             }
591             else if (c == '\n')
592             {
593                 break;
594             }
595             else
596             {
597                 value += c;
598             }
599         }
600         
601         if(value.equals(""))
602             value = defaultValue;
603         
604         return value;
605     }
606
607
608     public String JavaDoc getInputWithDefault(String JavaDoc message, String JavaDoc[] validStrings, String JavaDoc defaultValue, boolean allowEmpty) throws Exception JavaDoc
609     {
610         System.out.print(message);
611         
612         String JavaDoc value = "";
613         
614         // block until enter is pressed
615
while (true)
616         {
617             char c = (char)System.in.read();
618             if (c == '\r')
619             {
620                 c = (char)System.in.read();
621                 if (c == '\n')
622                 {
623                    break;
624                 }
625                 else
626                 {
627                    continue;
628                 }
629             }
630             else if (c == '\n')
631             {
632                 break;
633             }
634             else
635             {
636                 value += c;
637             }
638         }
639         
640         if(!allowEmpty && value.equals(""))
641         {
642             value = getInputWithDefault(message, validStrings, defaultValue, allowEmpty);
643         }
644         else
645         {
646             if(value.equals(""))
647                 value = defaultValue;
648             
649             boolean isValid = false;
650             for(int i=0; i<validStrings.length; i++)
651             {
652                 String JavaDoc validString = validStrings[i];
653                 if(validString.equalsIgnoreCase(value))
654                 {
655                     isValid = true;
656                     break;
657                 }
658             }
659             
660             if(validStrings.length == 0)
661                 isValid = true;
662             
663             if(!isValid)
664                 value = getInputWithDefault(message, validStrings, defaultValue, allowEmpty);
665         }
666                 
667         return value;
668     }
669
670
671     public void setupDatabaseEnvironment() throws Exception JavaDoc
672     {
673         DatabaseCommander commander = null;
674         
675         String JavaDoc url = "";
676         if(database.equals("MySQL"))
677         {
678             url = "jdbc:mysql://" + databaseServer + ":" + databasePort + "/mysql";
679             commander = new MySQLDatabaseCommander(getDatabaseDriverName(database), databaseServer, databasePort, databaseInstance, url, databaseUser, databasePassword, infoglueDatabaseUserName, infoglueDatabasePassword, databaseName + databaseSuffix, databaseSuffix, hostName, getCreateDatabase(), getCreateInitialData(), getCreateExamples(), getCreateExamples(), getCreateExamples());
680         }
681         else if(database.equals("SQL Server"))
682         {
683             //url = "jdbc:microsoft:sqlserver://" + databaseServer + ":1433";
684
url = "jdbc:jtds:sqlserver://" + databaseServer + ":" + databasePort + ((databaseInstance.equalsIgnoreCase("")) ? "" : ";INSTANCE=" + databaseInstance);
685             System.out.println("url 6:" + url);
686             //url = "jdbc:jtds:sqlserver://" + databaseServer + ":" + databasePort + "";
687
commander = new SQLServerDatabaseCommander(getDatabaseDriverName(database), databaseServer, databasePort, databaseInstance, url, databaseUser, databasePassword, infoglueDatabaseUserName, infoglueDatabasePassword, databaseName + databaseSuffix, databaseSuffix, hostName, getCreateDatabase(), getCreateInitialData(), getCreateExamples(), getCreateExamples(), getCreateExamples());
688         }
689         else if(database.equalsIgnoreCase("Oracle"))
690         {
691             url = "jdbc:oracle:thin:" + databaseServer + ":" + databasePort + ":" + databaseName + databaseSuffix;
692             commander = new OracleDatabaseCommander(getDatabaseDriverName(database), databaseServer, databasePort, databaseInstance, url, databaseUser, databasePassword, infoglueDatabaseUserName, infoglueDatabasePassword, databaseName + databaseSuffix, databaseSuffix, hostName, getCreateDatabase(), getCreateInitialData(), getCreateExamples(), getCreateExamples(), getCreateExamples());
693         }
694         else if(database.equalsIgnoreCase("DB2"))
695         {
696             url = "jdbc:db2://" + databaseServer + ":" + databasePort + "/" + databaseName + databaseSuffix;
697             commander = new DB2DatabaseCommander(getDatabaseDriverName(database), databaseServer, databasePort, databaseInstance, url, databaseUser, databasePassword, infoglueDatabaseUserName, infoglueDatabasePassword, databaseName + databaseSuffix, databaseSuffix, hostName, getCreateDatabase(), getCreateInitialData(), getCreateExamples(), getCreateExamples(), getCreateExamples());
698         }
699
700         commander.createCastorRootFile();
701         
702         if(createDatabase.equalsIgnoreCase("yes") || createInitialData.equalsIgnoreCase("yes"))
703         {
704             Logger.logInfo("Setting up database on " + url);
705             commander.setupDatabase();
706         }
707         else
708         {
709             String JavaDoc userName = infoglueDatabaseUserName;
710             String JavaDoc password = infoglueDatabasePassword;
711             //new UpgradeManager(getUpgradeDatabaseEncoding(), "ISO-8859-1").upgradeTo1_3(commander, databaseServer, databasePort, databaseName + databaseSuffix, userName, password);
712
//new UpgradeManager(getUpgradeDatabaseEncoding(), "ISO-8859-1").upgradeTo1_3_2(commander, databaseServer, databasePort, databaseName + databaseSuffix, userName, password);
713
new UpgradeManager(getUpgradeDatabaseEncoding(), "ISO-8859-1").upgradeToCurrentVersion(commander, databaseServer, databasePort, databaseName + databaseSuffix, userName, password);
714         }
715
716         Logger.logInfo("Creating castor db-file");
717         commander.createCastorFile();
718         //commander.createOSWorkflowFile();
719
commander.createOSPropertiesFile();
720         Logger.logInfo("Done setting up database");
721     }
722     
723     /**
724      * This method sets up the needed propertyfiles.
725      * @throws Exception
726      */

727
728     public void setupPropertyFiles(InstallationCommander installationCommander) throws Exception JavaDoc
729     {
730         String JavaDoc url = "";
731         if(database.equals("MySQL"))
732         {
733             MySQLDatabaseCommander mySQLDatabaseCommander = (MySQLDatabaseCommander)commander;
734             if(mySQLDatabaseCommander.getMysqlVersion().indexOf("4.1") > -1 && mySQLDatabaseCommander.getCharset() != null)
735                 url = "jdbc:mysql://" + databaseServer + ":" + databasePort + "/" + databaseName + databaseSuffix + "?autoReconnect=true";
736             else
737                 url = "jdbc:mysql://" + databaseServer + ":" + databasePort + "/" + databaseName + databaseSuffix + "?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF-8";
738             
739         }
740         else if(database.equals("SQL Server"))
741         {
742             url = "jdbc:jtds:sqlserver://" + databaseServer + ":" + databasePort + ((databaseInstance.equalsIgnoreCase("")) ? ";DatabaseName=" + databaseName + databaseSuffix + ";SelectMethod=Cursor" : ";INSTANCE=" + databaseInstance + ";DatabaseName=" + databaseName + databaseSuffix + ";SelectMethod=Cursor");
743             //url = "jdbc:jtds:sqlserver://" + databaseServer + ":1433;DatabaseName=" + databaseName + databaseSuffix + ";SelectMethod=Cursor";
744
//url = "jdbc:microsoft:sqlserver://" + databaseServer + ":1433;DatabaseName=" + databaseName + databaseSuffix + ";SelectMethod=Cursor";
745
}
746         else if(database.equals("Oracle"))
747             url = "jdbc:oracle:thin:@" + databaseServer + ":" + databasePort + ":" + databaseName + databaseSuffix;
748         else if(database.equals("DB2"))
749             url = "jdbc:db2://" + databaseServer + ":" + databasePort + "/" + databaseName + databaseSuffix;
750
751         
752         String JavaDoc comment = "#";
753         String JavaDoc installPreview = installPreviewDeliver;
754         if(installPreview.equalsIgnoreCase("yes"))
755             comment = "";
756                     
757         ConfigurationFileCommander commander = new ConfigurationFileCommander(hostName, tomcatHomePath, smtpHostName, portNumber, applicationSuffix, applicationPath, comment, superUserName, superUserPassword, actionDispatcher, enablePortal, getDatabaseDriverName(database), url, infoglueDatabaseUserName, infoglueDatabasePassword, getDatabaseDialectName(database));
758         commander.createCMSPropertyFile();
759         commander.createDeliverWorkingPropertyFile(installationCommander);
760         commander.createDeliverPreviewPropertyFile(installationCommander);
761         commander.createDeliverLivePropertyFile(installationCommander);
762         commander.createCMSWebappFile();
763         commander.createDeliverWebappFile();
764         commander.createHibernateConfigFile();
765         TomcatConfigFilesUpdater tomcatConfigFilesUpdater = new TomcatConfigFilesUpdater();
766         tomcatConfigFilesUpdater.setAppDir(applicationPath + File.separator + "infoglueCMS" + applicationSuffix);
767         tomcatConfigFilesUpdater.setAppName("infoglueCMS" + applicationSuffix);
768         tomcatConfigFilesUpdater.setDriverName(getDatabaseDriverName(database));
769         tomcatConfigFilesUpdater.setConnUrl(url);
770         tomcatConfigFilesUpdater.setLogDir(tomcatHomePath + File.separator + "infoglueCMS" + applicationSuffix + File.separator + "logs");
771         tomcatConfigFilesUpdater.setPath(tomcatHomePath + File.separator + "conf");
772         tomcatConfigFilesUpdater.setUsrName(infoglueDatabaseUserName);
773         tomcatConfigFilesUpdater.setUsrPass(infoglueDatabasePassword);
774         tomcatConfigFilesUpdater.updateConfiguration();
775         
776         tomcatConfigFilesUpdater.updateConfiguration("infoglueDeliverWorking" + applicationSuffix, applicationPath + File.separator + "infoglueDeliverWorking" + applicationSuffix, applicationPath + File.separator + "infoglueDeliverWorking" + applicationSuffix + File.separator + "logs");
777         tomcatConfigFilesUpdater.updateConfiguration("infoglueDeliverPreview" + applicationSuffix, applicationPath + File.separator + "infoglueDeliverPreview" + applicationSuffix, applicationPath + File.separator + "infoglueDeliverPreview" + applicationSuffix + File.separator + "logs");
778         tomcatConfigFilesUpdater.updateConfiguration("infoglueDeliverLive" + applicationSuffix, applicationPath + File.separator + "infoglueDeliverLive" + applicationSuffix, applicationPath + File.separator + "infoglueDeliverLive" + applicationSuffix + File.separator + "logs");
779     }
780
781     public void finishInstallation() throws Exception JavaDoc
782     {
783         setupDatabaseEnvironment();
784
785         InstallationCommander commander = InstallationCommander.getInstallationCommander(applicationServer, applicationPath, applicationSuffix, tomcatHomePath, installCMS, installWorkingDeliver, installPreviewDeliver, installLiveDeliver, getTomcatContextPath()/*, this.tomcatVersion*/);
786         setupPropertyFiles(commander);
787
788         commander.installFiles(database);
789     }
790     
791     
792     public String JavaDoc getDatabaseDriverName(String JavaDoc databaseType)
793     {
794         if(databaseType.equalsIgnoreCase("MySQL"))
795             return "com.mysql.jdbc.Driver";
796         else if(databaseType.equalsIgnoreCase("SQL Server"))
797             return "net.sourceforge.jtds.jdbc.Driver";
798             //return "com.microsoft.jdbc.sqlserver.SQLServerDriver";
799
else if(databaseType.equalsIgnoreCase("Oracle"))
800             return "oracle.jdbc.driver.OracleDriver";
801         else if(databaseType.equalsIgnoreCase("DB2"))
802             return "com.ibm.db2.jcc.DB2Driver";
803         else
804             return "";
805     }
806
807     public String JavaDoc getDatabaseDialectName(String JavaDoc databaseType)
808     {
809         if(databaseType.equalsIgnoreCase("MySQL"))
810             return "net.sf.hibernate.dialect.MySQLDialect";
811         else if(databaseType.equalsIgnoreCase("SQL Server"))
812             return "net.sf.hibernate.dialect.SQLServerDialect";
813             //return "com.microsoft.jdbc.sqlserver.SQLServerDriver";
814
else if(databaseType.equalsIgnoreCase("Oracle"))
815             return "net.sf.hibernate.dialect.OracleDialect";
816         else if(databaseType.equalsIgnoreCase("DB2"))
817             return "net.sf.hibernate.dialect.DB2Dialect";
818         else
819             return "";
820     }
821     
822     public boolean getUpgradeDatabaseEncoding()
823     {
824         if(upgradeDatabaseEncoding.equalsIgnoreCase("yes"))
825             return true;
826         else
827             return false;
828     }
829     
830     public boolean getCreateDatabase()
831     {
832         if(createDatabase.equalsIgnoreCase("yes"))
833             return true;
834         else
835             return false;
836     }
837
838     public boolean getCreateInitialData()
839     {
840         if(createInitialData.equalsIgnoreCase("yes"))
841             return true;
842         else
843             return false;
844     }
845     
846     public boolean getCreateExamples()
847     {
848         if(createExamples.equalsIgnoreCase("yes"))
849             return true;
850         else
851             return false;
852     }
853 }
Popular Tags