1 23 24 package org.infoglue.cmsinstaller; 25 26 import java.io.*; 27 import java.util.Iterator ; 28 import java.util.List ; 29 30 import org.dom4j.Document; 31 import org.dom4j.Element; 32 import org.dom4j.io.SAXReader; 33 34 41 42 43 public class InfoGlueCommandLineInstaller 44 { 45 DatabaseCommander commander = null; 46 47 private static String database = "MySQL"; 49 private static String databaseName = "infoglue"; 50 private static String databaseSuffix = ""; 51 private static String databaseServer = "localhost"; 52 private static String databasePort = "3306"; 53 private static String databaseInstance = ""; 54 private static String createDatabase = "No"; 55 private static String createInitialData = "No"; 56 private static String createExamples = "Yes"; 57 private static String databaseUser = "root"; 58 private static String databasePassword = ""; 59 private static String infoglueDatabaseUserName = ""; 60 private static String infoglueDatabasePassword = ""; 61 private static String upgradeDatabaseEncoding = ""; 62 63 private static String hostName = "localhost"; 64 private static String portNumber = "8080"; 65 private static String applicationSuffix = ""; 66 private static String smtpHostName = "your.emailserver.com"; 67 68 private static String applicationServer = "Tomcat 5.x"; 69 private static String tomcatHomePath = "C:\\Program\\Apache Software Foundation\\Tomcat 5.5"; 70 private static String tomcatHomePath2 = "C:\\Program\\Apache Software Foundation\\Tomcat 5.0"; 71 private static String tomcatHomePathLinux = "/usr/local/tomcat5"; 72 private static String installCMS = "Yes"; 75 private static String installWorkingDeliver = "Yes"; 76 private static String installPreviewDeliver = "No"; 77 private static String installLiveDeliver = "No"; 78 private static String applicationPath = ""; 79 80 private static String superUserName = "root"; 81 private static String superUserPassword = ServerDialog.generatePassword(6); 82 83 private static String enablePortal = "false"; 84 private static String actionDispatcher = "webwork.dispatcher.ServletDispatcher"; 85 86 private final static String introductionHeader = "Welcome to the installation of InfoGlue CMS"; 88 private final static String 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 private final static String dbIntroductionHeader = "Database setup"; 92 private final static String 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 databaseLabel = "Database type (Valid are \"MySQL\", \"Oracle\", \"SQL Server\" and \"DB2\"): [" + database + "] "; 95 private final static String databaseNameLabel = "Database name: [" + databaseName + "] "; 96 private final static String databaseSuffixLabel = "Database suffix: [" + databaseSuffix + "] "; 97 private final static String databaseServerLabel = "Database server: [" + databaseServer + "] "; 99 private final static String databasePortLabel = "Database port: [" + databasePort + "] "; 100 private final static String databaseInstanceLabel = "Database instance: [] "; 101 private final static String 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 createDatabaseLabel = "Do you want the database to create a new database for infoglue automatically.\n"; 104 private final static String createInitialDataLabel = "Do you want the installer to set up tables and initial data?. \n[no]"; 105 private final static String createExamplesLabel = "Do you want the installer to set up the included examples?. \n[yes]"; 106 private final static String databaseUserLabel = "User name (Must have administrative priviliges in the database): [" + databaseUser + "] "; 107 private final static String databasePasswordLabel = "User password: [" + databasePassword + "] "; 108 private final static String infoglueDatabaseUserNameLabel = "InfoGlue database user: [" + infoglueDatabaseUserName + "] "; 109 private final static String infoglueDatabasePasswordLabel = "InfoGlue database password: [" + infoglueDatabasePassword + "] "; 110 private final static String upgradeDatabaseEncodingIntroductionText = "Do you want the installer to upgrade the database content to Unicode(utf-8)?"; 111 112 private final static String serverIntroductionHeader = "Server setup"; 114 private final static String 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 applicationServerLabel = "Application server (Valid are \"Tomcat 5.x\", \"Tomcat 4.x\" and \"JBoss 4.0\"): [" + applicationServer + "]: "; 117 private final static String hostNameLabel = "Host Name: [" + hostName + "]: "; 118 private final static String portNumberLabel = "HTTP Port: [" + portNumber + "]: "; 119 private final static String applicationSuffixLabel = "Application suffix (used in shared environments): [" + applicationSuffix + "] "; 120 private final static String smtpHostNameLabel = "SMTP Host: [" + smtpHostName + "]: "; 122 private final static String enablePortalLabel = "Activate JSR 168 support: [" + enablePortal + "]: "; 124 private final static String applicationServerHomePathLabel = "Application server HOME: [" + tomcatHomePath + "]"; 125 private final static String installCMSLabel = "Install CMS Administrative tools: [" + installCMS + "] "; 126 private final static String installWorkingDeliverLabel = "Install working deliver: [" + installWorkingDeliver + "] "; 127 private final static String installPreviewDeliverLabel = "Install preview deliver (For complete setups): [" + installPreviewDeliver + "] "; 128 private final static String installLiveDeliverLabel = "Install live deliver (For complete setups): [" + installLiveDeliver + "] "; 129 private final static String applicationPathLabel = "Applications directory: [" + tomcatHomePath + File.separator + "webapps" + "]"; 130 private final static String superUserNameLabel = "Super user name(unlimited access to cms): [" + superUserName + "]: "; 131 private final static String superUserPasswordLabel = "Super user password: [" + superUserPassword + "]: "; 132 133 private final static String finishIntroductionHeader = "Complete Installation"; 135 private final static String 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 private final static String doneIntroductionHeader = "Installation of InfoGlue CMS completed"; 139 private final static String 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 [] args) throws Exception 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 fileName) throws Exception 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 children = root.elements(); 182 System.out.println("children:" + children.size()); 183 184 Iterator i = children.iterator(); 185 while(i.hasNext()) 186 { 187 Element child = (Element)i.next(); 188 String name = child.attributeValue("name"); 189 String 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("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 getTomcatHomePath() 264 { 265 File directory = new File(tomcatHomePath); 266 File directory2 = new File(tomcatHomePath2); 267 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 if(directory.exists()) 281 { 282 return tomcatHomePathLinux; 283 } 284 else 285 { 286 String catalinaHome = "" + System.getProperty("CATALINA_HOME"); 287 directory = new File(catalinaHome); 288 if(directory.exists()) 290 { 291 return tomcatHomePathLinux; 292 } 293 else 294 { 295 catalinaHome = "" + System.getProperty("catalina.home"); 296 directory = new File(catalinaHome); 297 if(directory.exists()) 299 { 300 return catalinaHome; 301 } 302 else 303 { 304 return ""; 305 } 306 } 307 } 308 } 309 310 } 311 312 315 316 public static String getTomcatContextPath() 317 { 318 String 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 328 { 329 if(database.equalsIgnoreCase("MySQL")) 330 { 331 String 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: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 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 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 ("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 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 [] {"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 [] {}, infoglueDatabaseUserName, false); 418 infoglueDatabasePassword = getInputWithDefault(infoglueDatabasePasswordLabel, new String [] {}, 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 [] {"yes", "no"}, createDatabase, true); 426 427 createInitialData = getInputWithDefault(createInitialDataLabel, new String [] {"yes", "no"}, createInitialData, true); 428 createExamples = getInputWithDefault(createExamplesLabel, new String [] {"yes", "no"}, createExamples, true); 429 430 if(createDatabase.equalsIgnoreCase("yes") || createInitialData.equalsIgnoreCase("yes")) 431 { 432 databaseUser = getInputWithDefault(databaseUserLabel, new String [] {}, databaseUser, false); 433 databasePassword = getInputWithDefault(databasePasswordLabel, new String [] {}, databasePassword, true); 434 } 435 else 436 { 437 upgradeDatabaseEncoding = getInputWithDefault(upgradeDatabaseEncodingIntroductionText, new String [] {"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 448 } 449 catch(Exception 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 [] {"Tomcat 4.x", "Tomcat 5.x", "JBoss 4.0"}, applicationServer, true); 469 470 hostName = getInputWithDefault(hostNameLabel, new String [] {}, hostName, true); 471 portNumber = getInputWithDefault(portNumberLabel, new String [] {}, portNumber, true); 472 473 applicationSuffix = getInputWithDefault(applicationSuffixLabel, new String [] {}, applicationSuffix, true); 474 installCMS = getInputWithDefault(installCMSLabel, new String [] {"yes", "no"}, installCMS, true); 475 installWorkingDeliver = getInputWithDefault(installWorkingDeliverLabel, new String [] {"yes", "no"}, installWorkingDeliver, true); 476 installPreviewDeliver = getInputWithDefault(installPreviewDeliverLabel, new String [] {"yes", "no"}, installPreviewDeliver, true); 477 installLiveDeliver = getInputWithDefault(installLiveDeliverLabel, new String [] {"yes", "no"}, installLiveDeliver, true); 478 smtpHostName = getInputWithDefault(smtpHostNameLabel, new String [] {}, smtpHostName, false); 479 enablePortal = getInputWithDefault(enablePortalLabel, new String [] {}, enablePortal, false); 480 481 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 [] {}, superUserName, false); 489 superUserPassword = getInputWithDefault(superUserPasswordLabel, new String [] {}, superUserPassword, false); 490 491 actionDispatcher = getServletDispatcher(enablePortal); 492 493 495 } 496 catch(Exception e) 497 { 498 Logger.logInfo("An exception occurred:" + e.getMessage()); 499 showServerDialog(); 500 } 501 } 502 503 private String getServletDispatcher(String enablePortal) 504 { 505 String 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 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(""); 545 try 546 { 547 getInputWithDefault(""); 548 } 549 catch(Exception e) 550 { 551 Logger.logInfo("An exception occurred:" + e.getMessage()); 552 showDoneDialog(); 553 } 554 } 555 556 private String getExistingDirectory(String message, String directory, String neededSubDirectory) throws Exception 557 { 558 System.out.print(message); 559 String 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 getInputWithDefault(String defaultValue) throws Exception 572 { 573 String value = ""; 574 575 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 getInputWithDefault(String message, String [] validStrings, String defaultValue, boolean allowEmpty) throws Exception 609 { 610 System.out.print(message); 611 612 String value = ""; 613 614 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 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 672 { 673 DatabaseCommander commander = null; 674 675 String 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:jtds:sqlserver://" + databaseServer + ":" + databasePort + ((databaseInstance.equalsIgnoreCase("")) ? "" : ";INSTANCE=" + databaseInstance); 685 System.out.println("url 6:" + url); 686 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 userName = infoglueDatabaseUserName; 710 String password = infoglueDatabasePassword; 711 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.createOSPropertiesFile(); 720 Logger.logInfo("Done setting up database"); 721 } 722 723 727 728 public void setupPropertyFiles(InstallationCommander installationCommander) throws Exception 729 { 730 String 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&useUnicode=true&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 } 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 comment = "#"; 753 String 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 782 { 783 setupDatabaseEnvironment(); 784 785 InstallationCommander commander = InstallationCommander.getInstallationCommander(applicationServer, applicationPath, applicationSuffix, tomcatHomePath, installCMS, installWorkingDeliver, installPreviewDeliver, installLiveDeliver, getTomcatContextPath()); 786 setupPropertyFiles(commander); 787 788 commander.installFiles(database); 789 } 790 791 792 public String getDatabaseDriverName(String 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 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 getDatabaseDialectName(String 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 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 |