| 1 31 32 package org.opencms.setup; 33 34 import org.opencms.configuration.CmsConfigurationException; 35 import org.opencms.configuration.CmsConfigurationManager; 36 import org.opencms.configuration.CmsImportExportConfiguration; 37 import org.opencms.configuration.CmsModuleConfiguration; 38 import org.opencms.configuration.CmsSearchConfiguration; 39 import org.opencms.configuration.CmsSystemConfiguration; 40 import org.opencms.configuration.CmsVfsConfiguration; 41 import org.opencms.configuration.CmsWorkplaceConfiguration; 42 import org.opencms.configuration.I_CmsXmlConfiguration; 43 import org.opencms.db.CmsDbPool; 44 import org.opencms.file.CmsObject; 45 import org.opencms.file.CmsResource; 46 import org.opencms.i18n.CmsEncoder; 47 import org.opencms.loader.CmsImageLoader; 48 import org.opencms.main.CmsLog; 49 import org.opencms.main.CmsRuntimeException; 50 import org.opencms.main.CmsShell; 51 import org.opencms.main.CmsSystemInfo; 52 import org.opencms.main.I_CmsShellCommands; 53 import org.opencms.main.Messages; 54 import org.opencms.main.OpenCms; 55 import org.opencms.main.OpenCmsServlet; 56 import org.opencms.module.CmsModule; 57 import org.opencms.module.CmsModuleManager; 58 import org.opencms.report.CmsShellReport; 59 import org.opencms.setup.comptest.CmsSetupTestResult; 60 import org.opencms.setup.comptest.CmsSetupTestSimapi; 61 import org.opencms.setup.comptest.I_CmsSetupTest; 62 import org.opencms.setup.xml.CmsSetupXmlHelper; 63 import org.opencms.util.CmsFileUtil; 64 import org.opencms.util.CmsPropertyUtils; 65 import org.opencms.util.CmsStringUtil; 66 import org.opencms.util.CmsUUID; 67 import org.opencms.xml.CmsXmlException; 68 69 import java.io.File ; 70 import java.io.FileInputStream ; 71 import java.io.FileReader ; 72 import java.io.FileWriter ; 73 import java.io.IOException ; 74 import java.io.LineNumberReader ; 75 import java.util.ArrayList ; 76 import java.util.Collection ; 77 import java.util.Collections ; 78 import java.util.Comparator ; 79 import java.util.HashMap ; 80 import java.util.HashSet ; 81 import java.util.Iterator ; 82 import java.util.List ; 83 import java.util.Map ; 84 import java.util.Properties ; 85 import java.util.SortedMap ; 86 import java.util.TreeMap ; 87 import java.util.Vector ; 88 89 import javax.servlet.ServletConfig ; 90 import javax.servlet.http.HttpServletRequest ; 91 import javax.servlet.jsp.JspWriter ; 92 import javax.servlet.jsp.PageContext ; 93 94 import org.apache.commons.collections.ExtendedProperties; 95 96 117 public class CmsSetupBean extends Object implements Cloneable , I_CmsShellCommands { 118 119 120 public static final String FOLDER_BACKUP = "backup" + File.separatorChar; 121 122 123 public static final String FOLDER_DATABASE = "database" + File.separatorChar; 124 125 126 public static final String FOLDER_LIB = "lib" + File.separatorChar; 127 128 129 public static final String FOLDER_SETUP = "setup" + File.separatorChar; 130 131 132 public static final String FOLDER_WEBINF = "WEB-INF" + File.separatorChar; 133 134 135 public static final String GENERIC_PROVIDER = "generic"; 136 137 138 public static final String HTML_MESSAGE_FILE = "org/opencms/setup/htmlmsg.properties"; 139 140 141 public static final String MAXDB_PROVIDER = "maxdb"; 142 143 144 public static final String MYSQL_PROVIDER = "mysql"; 145 146 147 public static final String ORACLE_PROVIDER = "oracle"; 148 149 150 public static final String POSTGRESQL_PROVIDER = "postgresql"; 151 152 153 public static final String [] REQUIRED_DB_SETUP_FILES = { 154 "step_4_database_setup.jsp", 155 "database.properties", 156 "create_db.sql", 157 "create_tables.sql", 158 "drop_db.sql", 159 "drop_tables.sql"}; 160 161 162 private static Properties m_htmlProps; 163 164 165 protected Map m_availableModules; 166 167 168 protected CmsObject m_cms; 169 170 171 protected List m_installModules; 172 173 174 protected String m_logFile = FOLDER_WEBINF + CmsLog.FOLDER_LOGS + "setup.log"; 175 176 177 protected String m_logsFolder = FOLDER_WEBINF + CmsLog.FOLDER_LOGS; 178 179 180 protected Map m_moduleDependencies; 181 182 183 protected Map m_moduleFilenames; 184 185 186 protected String m_modulesFolder = FOLDER_WEBINF + CmsSystemInfo.FOLDER_PACKAGES + CmsSystemInfo.FOLDER_MODULES; 187 188 189 protected int m_newLoggingOffset; 190 191 192 protected int m_oldLoggingOffset; 193 194 195 protected String m_webAppRfsPath; 196 197 198 private String m_configRfsPath; 199 200 201 private String m_databaseKey; 202 203 204 private List m_databaseKeys; 205 206 207 private Map m_databaseProperties; 208 209 210 private String m_dbCreatePwd; 211 212 213 private String m_defaultWebApplication; 214 215 216 private List m_errors; 217 218 219 private ExtendedProperties m_extProperties; 220 221 222 private String m_provider; 223 224 225 private Map m_replacer; 226 227 228 private ServletConfig m_servletConfig; 229 230 231 private String m_servletMapping; 232 233 234 private List m_sortedDatabaseKeys; 235 236 237 private CmsSetupWorkplaceImportThread m_workplaceImportThread; 238 239 240 private CmsSetupXmlHelper m_xmlHelper; 241 242 245 public CmsSetupBean() { 246 247 initHtmlParts(); 248 } 249 250 258 public void backupConfiguration(String filename, String originalFilename) { 259 260 File backupFolder = new File (m_configRfsPath + FOLDER_BACKUP); 262 if (!backupFolder.exists()) { 263 backupFolder.mkdirs(); 264 } 265 266 originalFilename = FOLDER_BACKUP + originalFilename; 268 File file = new File (m_configRfsPath + originalFilename); 269 if (file.exists()) { 270 copyFile(originalFilename, filename); 271 } else { 272 copyFile(filename, originalFilename); 273 } 274 } 275 276 279 public void checkEthernetAddress() { 280 281 if (CmsStringUtil.isEmpty(getEthernetAddress())) { 283 setEthernetAddress(CmsUUID.getDummyEthernetAddress()); 284 } 285 } 286 287 293 public void copyFile(String source, String target) { 294 295 try { 296 CmsFileUtil.copy(m_configRfsPath + source, m_configRfsPath + target); 297 } catch (IOException e) { 298 m_errors.add("Could not copy " + source + " to " + target + " \n"); 299 m_errors.add(e.toString() + "\n"); 300 } 301 } 302 303 310 public String displayError(String pathPrefix) { 311 312 if (pathPrefix == null) { 313 pathPrefix = ""; 314 } 315 StringBuffer html = new StringBuffer (512); 316 html.append("<table border='0' cellpadding='5' cellspacing='0' style='width: 100%; height: 100%;'>"); 317 html.append("\t<tr>"); 318 html.append("\t\t<td style='vertical-align: middle; height: 100%;'>"); 319 html.append(getHtmlPart("C_BLOCK_START", "Error")); 320 html.append("\t\t\t<table border='0' cellpadding='0' cellspacing='0' style='width: 100%;'>"); 321 html.append("\t\t\t\t<tr>"); 322 html.append("\t\t\t\t\t<td><img SRC='").append(pathPrefix).append("resources/error.png' border='0'></td>"); 323 html.append("\t\t\t\t\t<td> </td>"); 324 html.append("\t\t\t\t\t<td style='width: 100%;'>"); 325 html.append("\t\t\t\t\t\tThe Alkacon OpenCms setup wizard has not been started correctly!<br>"); 326 html.append("\t\t\t\t\t\tPlease click <a HREF='").append(pathPrefix); 327 html.append("index.jsp'>here</a> to restart the wizard."); 328 html.append("\t\t\t\t\t</td>"); 329 html.append("\t\t\t\t</tr>"); 330 html.append("\t\t\t</table>"); 331 html.append(getHtmlPart("C_BLOCK_END")); 332 html.append("\t\t</td>"); 333 html.append("\t</tr>"); 334 html.append("</table>"); 335 return html.toString(); 336 } 337 338 348 public Map getAvailableModules() { 349 350 if (m_availableModules == null || m_availableModules.isEmpty()) { 351 m_availableModules = new HashMap (); 352 m_moduleDependencies = new HashMap (); 353 m_moduleFilenames = new HashMap (); 354 355 try { 356 Map modules = CmsModuleManager.getAllModulesFromPath(getModuleFolder()); 357 Iterator itMods = modules.keySet().iterator(); 358 while (itMods.hasNext()) { 359 CmsModule module = (CmsModule)itMods.next(); 360 m_availableModules.put(module.getName(), module); 362 m_moduleFilenames.put(module.getName(), modules.get(module)); 363 } 364 } catch (CmsConfigurationException e) { 365 throw new CmsRuntimeException(e.getMessageContainer()); 366 } 367 } 368 return m_availableModules; 369 } 370 371 376 public String getConfigRfsPath() { 377 378 return m_configRfsPath; 379 } 380 381 386 public String getDatabase() { 387 388 if (m_databaseKey == null) { 389 m_databaseKey = getExtProperty("db.name"); 390 } 391 392 if (CmsStringUtil.isEmpty(m_databaseKey)) { 393 m_databaseKey = (String )getSortedDatabases().get(0); 394 } 395 396 return m_databaseKey; 397 } 398 399 405 public String getDatabaseConfigPage(String key) { 406 407 String configUri = FOLDER_DATABASE + key + File.separatorChar + "step_4_database_setup.jsp"; 409 return configUri.replace(File.separatorChar, '/'); 410 } 411 412 419 public List getDatabaseLibs(String databaseKey) { 420 421 return CmsStringUtil.splitAsList((String )((Map )getDatabaseProperties().get(databaseKey)).get(databaseKey 422 + ".libs"), ',', true); 423 } 424 425 431 public String getDatabaseName(String databaseKey) { 432 433 return (String )((Map )getDatabaseProperties().get(databaseKey)).get(databaseKey + ".name"); 434 } 435 436 442 public Map getDatabaseProperties() { 443 444 if (m_databaseProperties != null) { 445 return m_databaseProperties; 446 } 447 448 readDatabaseConfig(); 449 return m_databaseProperties; 450 } 451 452 458 public List getDatabases() { 459 460 File databaseSetupFolder = null; 461 File [] childResources = null; 462 File childResource = null; 463 File setupFile = null; 464 boolean hasMissingSetupFiles = false; 465 466 if (m_databaseKeys != null) { 467 return m_databaseKeys; 468 } 469 470 try { 471 m_databaseKeys = new ArrayList (); 472 databaseSetupFolder = new File (m_webAppRfsPath + FOLDER_SETUP + FOLDER_DATABASE); 473 474 if (databaseSetupFolder.exists()) { 475 childResources = databaseSetupFolder.listFiles(); 476 477 if (childResources != null) { 478 for (int i = 0; i < childResources.length; i++) { 479 childResource = childResources[i]; 480 hasMissingSetupFiles = false; 481 482 if (childResource.exists() && childResource.isDirectory() && childResource.canRead()) { 483 for (int j = 0; j < REQUIRED_DB_SETUP_FILES.length; j++) { 484 setupFile = new File (childResource.getPath() 485 + File.separatorChar 486 + REQUIRED_DB_SETUP_FILES[j]); 487 488 if (!setupFile.exists() || !setupFile.isFile() || !setupFile.canRead()) { 489 hasMissingSetupFiles = true; 490 System.err.println("[" 491 + getClass().getName() 492 + "] missing or unreadable database setup file: " 493 + setupFile.getPath()); 494 break; 495 } 496 } 497 498 if (!hasMissingSetupFiles) { 499 m_databaseKeys.add(childResource.getName().trim()); 500 } 501 } 502 } 503 } 504 } 505 } catch (Exception e) { 506 System.err.println(e.toString()); 507 e.printStackTrace(System.err); 508 } 509 510 return m_databaseKeys; 511 } 512 513 518 public String getDb() { 519 520 return getDbProperty(m_databaseKey + ".dbname"); 521 } 522 523 528 public String getDbConStrParams() { 529 530 return getDbProperty(m_databaseKey + ".constr.params"); 531 } 532 533 538 public String getDbCreateConStr() { 539 540 return getDbProperty(m_databaseKey + ".constr"); 541 } 542 543 548 public String getDbCreatePwd() { 549 550 return (m_dbCreatePwd != null) ? m_dbCreatePwd : ""; 551 } 552 553 558 public String getDbCreateUser() { 559 560 return getDbProperty(m_databaseKey + ".user"); 561 } 562 563 569 public String getDbDriver() { 570 571 return getDbProperty(m_databaseKey + ".driver"); 572 } 573 574 580 public String getDbProperty(String key) { 581 582 String databaseKey = key.substring(0, key.indexOf('.')); 584 Map databaseProperties = (Map )getDatabaseProperties().get(databaseKey); 585 586 Object value = databaseProperties.get(key); 587 return (value != null) ? (String )value : ""; 588 } 589 590 596 public String getDbTestQuery() { 597 598 return getDbProperty(m_databaseKey + ".testQuery"); 599 } 600 601 606 public String getDbWorkConStr() { 607 608 if (m_provider.equals(POSTGRESQL_PROVIDER)) { 609 return getDbProperty(m_databaseKey + ".constr.newDb"); 610 } else { 611 return getExtProperty(CmsDbPool.KEY_DATABASE_POOL + '.' + getPool() + ".jdbcUrl"); 612 } 613 } 614 615 620 public String getDbWorkPwd() { 621 622 return getExtProperty(CmsDbPool.KEY_DATABASE_POOL + '.' + getPool() + ".password"); 623 } 624 625 630 public String getDbWorkUser() { 631 632 String user = getExtProperty(CmsDbPool.KEY_DATABASE_POOL + '.' + getPool() + ".user"); 633 if (CmsStringUtil.isEmptyOrWhitespaceOnly(user)) { 634 return getDbCreateUser(); 635 } 636 return user; 637 } 638 639 643 public String getDefaultContentEncoding() { 644 645 return getExtProperty("defaultContentEncoding"); 646 } 647 648 655 public String getDefaultWebApplication() { 656 657 return m_defaultWebApplication; 658 } 659 660 667 public String getDisplayForModule(CmsModule module) { 668 669 String name = module.getNiceName(); 670 String group = module.getGroup(); 671 String version = module.getVersion().getVersion(); 672 String display = name; 673 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(group)) { 674 display = group + ": " + display; 675 } 676 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(version)) { 677 display += " (" + version + ")"; 678 } 679 return display; 680 } 681 682 687 public List getErrors() { 688 689 return m_errors; 690 } 691 692 697 public String getEthernetAddress() { 698 699 return getExtProperty("server.ethernet.address"); 700 } 701 702 709 public String getHtmlHelpIcon(String id, String pathPrefix) { 710 711 String value = m_htmlProps.getProperty("C_HELP_IMG"); 712 if (value == null) { 713 return ""; 714 } else { 715 value = CmsStringUtil.substitute(value, "$replace$", id); 716 return CmsStringUtil.substitute(value, "$path$", pathPrefix); 717 } 718 } 719 720 726 public String getHtmlPart(String part) { 727 728 return getHtmlPart(part, ""); 729 } 730 731 738 public String getHtmlPart(String part, String replaceString) { 739 740 String value = m_htmlProps.getProperty(part); 741 if (value == null) { 742 return ""; 743 } else { 744 return CmsStringUtil.substitute(value, "$replace$", replaceString); 745 } 746 } 747 748 753 public String getLibFolder() { 754 755 return getWebAppRfsPath() + FOLDER_WEBINF + FOLDER_LIB; 756 } 757 758 763 public String getLogName() { 764 765 return new StringBuffer (m_webAppRfsPath).append(m_logFile).toString(); 766 } 767 768 773 public Map getModuleDependencies() { 774 775 if (m_moduleDependencies == null || m_moduleDependencies.isEmpty()) { 776 try { 777 m_moduleDependencies = CmsModuleManager.buildDepsForAllModules(getModuleFolder(), true); 779 } catch (CmsConfigurationException e) { 780 throw new CmsRuntimeException(e.getMessageContainer()); 781 } 782 } 783 return m_moduleDependencies; 784 } 785 786 791 public String getModuleFolder() { 792 793 return new StringBuffer (m_webAppRfsPath).append(m_modulesFolder).toString(); 794 } 795 796 801 public List getModulesToInstall() { 802 803 if (m_installModules == null || m_installModules.isEmpty()) { 804 return Collections.EMPTY_LIST; 805 } 806 return Collections.unmodifiableList(m_installModules); 807 } 808 809 814 public String getPool() { 815 816 return CmsStringUtil.splitAsArray(getExtProperty("db.pools"), ",")[0]; 817 } 818 819 824 public ExtendedProperties getProperties() { 825 826 return m_extProperties; 827 } 828 829 834 public Map getReplacer() { 835 836 return m_replacer; 837 } 838 839 844 public String getServerName() { 845 846 return getExtProperty("server.name"); 847 } 848 849 854 public ServletConfig getServletConfig() { 855 856 return m_servletConfig; 857 } 858 859 866 public String getServletMapping() { 867 868 return m_servletMapping; 869 } 870 871 877 public List getSortedDatabases() { 878 879 if (m_sortedDatabaseKeys == null) { 880 List databases = m_databaseKeys; 881 List sortedDatabases = new ArrayList (databases.size()); 882 SortedMap mappedDatabases = new TreeMap (); 883 for (int i = 0; i < databases.size(); i++) { 884 String key = (String )databases.get(i); 885 Integer ranking = new Integer (0); 886 try { 887 ranking = Integer.valueOf(getDbProperty(key + ".ranking")); 888 } catch (Exception e) { 889 } 891 mappedDatabases.put(ranking, key); 892 } 893 894 while (mappedDatabases.size() > 0) { 895 Integer key = (Integer )mappedDatabases.lastKey(); 897 String database = (String )mappedDatabases.get(key); 898 sortedDatabases.add(database); 899 mappedDatabases.remove(key); 900 } 901 m_sortedDatabaseKeys = sortedDatabases; 902 } 903 return m_sortedDatabaseKeys; 904 } 905 906 911 public String getWebAppRfsPath() { 912 913 return m_webAppRfsPath; 914 } 915 916 921 public boolean getWizardEnabled() { 922 923 return Boolean.valueOf(getExtProperty("wizard.enabled")).booleanValue(); 924 } 925 926 931 public CmsSetupWorkplaceImportThread getWorkplaceImportThread() { 932 933 return m_workplaceImportThread; 934 } 935 936 941 public String getWorkplaceSite() { 942 943 return getExtProperty("site.workplace"); 944 } 945 946 951 public CmsSetupXmlHelper getXmlHelper() { 952 953 if (m_xmlHelper == null) { 954 m_xmlHelper = new CmsSetupXmlHelper(getConfigRfsPath()); 956 } 957 return m_xmlHelper; 958 } 959 960 965 public String htmlModuleHelpDescriptions() { 966 967 StringBuffer html = new StringBuffer (1024); 968 Iterator itModules = sortModules(getAvailableModules().values()).iterator(); 969 for (int i = 0; itModules.hasNext(); i++) { 970 String moduleName = (String )itModules.next(); 971 CmsModule module = (CmsModule)getAvailableModules().get(moduleName); 972 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(module.getDescription())) { 973 html.append(getHtmlPart("C_HELP_START", "" + i)); 974 html.append(module.getDescription()); 975 html.append("\n"); 976 html.append(getHtmlPart("C_HELP_END")); 977 html.append("\n"); 978 } 979 } 980 return html.toString(); 981 } 982 983 988 public String htmlModules() { 989 990 StringBuffer html = new StringBuffer (1024); 991 Iterator itModules = sortModules(getAvailableModules().values()).iterator(); 992 for (int i = 0; itModules.hasNext(); i++) { 993 String moduleName = (String )itModules.next(); 994 CmsModule module = (CmsModule)getAvailableModules().get(moduleName); 995 html.append(htmlModule(module, i)); 996 } 997 return html.toString(); 998 } 999 1000 1007 public void importModulesFromSetupBean() throws Exception { 1008 1009 1018 if (m_cms != null && m_installModules != null) { 1019 for (int i = 0; i < m_installModules.size(); i++) { 1020 String filename = (String )m_moduleFilenames.get(m_installModules.get(i)); 1021 try { 1022 importModuleFromDefault(filename); 1023 } catch (Exception e) { 1024 e.printStackTrace(System.err); 1026 } 1027 } 1028 } 1029 } 1030 1031 1036 public void init(PageContext pageContext) { 1037 1038 String webAppRfsPath = pageContext.getServletConfig().getServletContext().getRealPath("/"); 1040 1041 String servletMapping = pageContext.getServletContext().getInitParameter( 1043 OpenCmsServlet.SERVLET_PARAM_OPEN_CMS_SERVLET); 1044 1045 String defaultWebApplication = pageContext.getServletContext().getInitParameter( 1047 OpenCmsServlet.SERVLET_PARAM_DEFAULT_WEB_APPLICATION); 1048 1049 m_servletConfig = pageContext.getServletConfig(); 1050 1051 init(webAppRfsPath, servletMapping, defaultWebApplication); 1052 } 1053 1054 1062 public void init(String webAppRfsPath, String servletMapping, String defaultWebApplication) { 1063 1064 try { 1065 m_availableModules = null; 1067 m_databaseKey = null; 1068 m_databaseKeys = null; 1069 m_databaseProperties = null; 1070 m_extProperties = null; 1071 m_installModules = null; 1072 m_moduleDependencies = null; 1073 m_sortedDatabaseKeys = null; 1074 m_moduleFilenames = null; 1075 1076 if (servletMapping == null) { 1077 servletMapping = "/opencms/*"; 1078 } 1079 if (defaultWebApplication == null) { 1080 defaultWebApplication = "ROOT"; 1081 } 1082 m_servletMapping = servletMapping; 1083 m_defaultWebApplication = defaultWebApplication; 1084 1085 setWebAppRfsPath(webAppRfsPath); 1086 m_errors = new ArrayList (); 1087 1088 if (CmsStringUtil.isNotEmpty(webAppRfsPath)) { 1089 m_extProperties = loadProperties(m_configRfsPath + CmsSystemInfo.FILE_PROPERTIES); 1091 readDatabaseConfig(); 1092 } 1093 1094 if (m_workplaceImportThread != null) { 1095 if (m_workplaceImportThread.isAlive()) { 1096 m_workplaceImportThread.kill(); 1097 } 1098 m_workplaceImportThread = null; 1099 m_newLoggingOffset = 0; 1100 m_oldLoggingOffset = 0; 1101 } 1102 } catch (Exception e) { 1103 e.printStackTrace(); 1104 m_errors.add(e.toString()); 1105 } 1106 } 1107 1108 1112 public void initHtmlParts() { 1113 1114 if (m_htmlProps != null) { 1115 return; 1117 } 1118 try { 1119 m_htmlProps = new Properties (); 1120 m_htmlProps.load(getClass().getClassLoader().getResourceAsStream(HTML_MESSAGE_FILE)); 1121 } catch (Exception e) { 1122 e.printStackTrace(); 1123 m_errors.add(e.toString()); 1124 } 1125 } 1126 1127 1130 public void initShellCmsObject(CmsObject cms, CmsShell shell) { 1131 1132 m_cms = cms; 1133 } 1134 1135 1142 public String isChecked(String value1, String value2) { 1143 1144 if (value1 == null || value2 == null) { 1145 return ""; 1146 } 1147 1148 if (value1.trim().equalsIgnoreCase(value2.trim())) { 1149 return "checked"; 1150 } 1151 1152 return ""; 1153 } 1154 1155 1160 public boolean isInitialized() { 1161 1162 return m_extProperties != null; 1163 } 1164 1165 1170 public String jsModuleDependencies() { 1171 1172 List moduleNames = sortModules(getAvailableModules().values()); 1173 1174 StringBuffer jsCode = new StringBuffer (1024); 1175 jsCode.append("\t// an array holding the dependent modules for the n-th module\n"); 1176 jsCode.append("\tvar moduleDependencies = new Array("); 1177 jsCode.append(moduleNames.size()); 1178 jsCode.append(");\n"); 1179 for (int i = 0; i < moduleNames.size(); i++) { 1180 String moduleName = (String )moduleNames.get(i); 1181 List dependencies = (List )getModuleDependencies().get(moduleName); 1182 jsCode.append("\tmoduleDependencies[" + i + "] = new Array("); 1183 if (dependencies != null) { 1184 for (int j = 0; j < dependencies.size(); j++) { 1185 jsCode.append("\"" + dependencies.get(j) + "\""); 1186 if (j < dependencies.size() - 1) { 1187 jsCode.append(", "); 1188 } 1189 } 1190 } 1191 jsCode.append(");\n"); 1192 } 1193 jsCode.append("\n\n"); 1194 return jsCode.toString(); 1195 } 1196 1197 1202 public String jsModuleNames() { 1203 1204 List moduleNames = sortModules(getAvailableModules().values()); 1205 StringBuffer jsCode = new StringBuffer (1024); 1206 jsCode.append("\t// an array from 1...n holding the module package names\n"); 1207 jsCode.append("\tvar modulePackageNames = new Array("); 1208 jsCode.append(moduleNames.size()); 1209 jsCode.append(");\n"); 1210 for (int i = 0; i < moduleNames.size(); i++) { 1211 String moduleName = (String )moduleNames.get(i); 1212 jsCode.append("\tmodulePackageNames[" + i + "] = \"" + moduleName + "\";\n"); 1213 } 1214 jsCode.append("\n\n"); 1215 return jsCode.toString(); 1216 } 1217 1218 1225 public ExtendedProperties loadProperties(String file) throws IOException { 1226 1227 return CmsPropertyUtils.loadProperties(file); 1228 } 1229 1230 1234 public void lockWizard() { 1235 1236 setExtProperty("wizard.enabled", CmsStringUtil.FALSE); 1237 } 1238 1239 1242 public void prepareStep10() { 1243 1244 if (isInitialized()) { 1245 lockWizard(); 1247 saveProperties(getProperties(), CmsSystemInfo.FILE_PROPERTIES, false); 1249 } 1250 } 1251 1252 1259 public boolean prepareStep8() throws CmsXmlException { 1260 1261 if (isInitialized()) { 1262 checkEthernetAddress(); 1263 backupConfiguration( 1265 CmsImportExportConfiguration.DEFAULT_XML_FILE_NAME, 1266 CmsImportExportConfiguration.DEFAULT_XML_FILE_NAME + CmsConfigurationManager.POSTFIX_ORI); 1267 backupConfiguration( 1268 CmsModuleConfiguration.DEFAULT_XML_FILE_NAME, 1269 CmsModuleConfiguration.DEFAULT_XML_FILE_NAME + CmsConfigurationManager.POSTFIX_ORI); 1270 backupConfiguration( 1271 CmsSearchConfiguration.DEFAULT_XML_FILE_NAME, 1272 CmsSearchConfiguration.DEFAULT_XML_FILE_NAME + CmsConfigurationManager.POSTFIX_ORI); 1273 backupConfiguration( 1274 CmsSystemConfiguration.DEFAULT_XML_FILE_NAME, 1275 CmsSystemConfiguration.DEFAULT_XML_FILE_NAME + CmsConfigurationManager.POSTFIX_ORI); 1276 backupConfiguration(CmsVfsConfiguration.DEFAULT_XML_FILE_NAME, CmsVfsConfiguration.DEFAULT_XML_FILE_NAME 1277 + CmsConfigurationManager.POSTFIX_ORI); 1278 backupConfiguration( 1279 CmsWorkplaceConfiguration.DEFAULT_XML_FILE_NAME, 1280 CmsWorkplaceConfiguration.DEFAULT_XML_FILE_NAME + CmsConfigurationManager.POSTFIX_ORI); 1281 backupConfiguration( 1282 CmsConfigurationManager.DEFAULT_XML_FILE_NAME, 1283 CmsConfigurationManager.DEFAULT_XML_FILE_NAME + CmsConfigurationManager.POSTFIX_ORI); 1284 saveProperties(getProperties(), CmsSystemInfo.FILE_PROPERTIES, true); 1286 1287 CmsSetupTestResult testResult = new CmsSetupTestSimapi().execute(this); 1288 if (testResult.getResult().equals(I_CmsSetupTest.RESULT_FAILED)) { 1289 StringBuffer xp = new StringBuffer (256); 1291 xp.append("/").append(CmsConfigurationManager.N_ROOT); 1292 xp.append("/").append(CmsVfsConfiguration.N_VFS); 1293 xp.append("/").append(CmsVfsConfiguration.N_RESOURCES); 1294 xp.append("/").append(CmsVfsConfiguration.N_RESOURCELOADERS); 1295 xp.append("/").append(CmsVfsConfiguration.N_LOADER); 1296 xp.append("[@").append(I_CmsXmlConfiguration.A_CLASS); 1297 xp.append("='").append(CmsImageLoader.class.getName()); 1298 xp.append("']/").append(I_CmsXmlConfiguration.N_PARAM); 1299 xp.append("[@").append(I_CmsXmlConfiguration.A_NAME); 1300 xp.append("='").append(CmsImageLoader.CONFIGURATION_SCALING_ENABLED).append("']"); 1301 1302 getXmlHelper().setValue( 1303 CmsVfsConfiguration.DEFAULT_XML_FILE_NAME, 1304 xp.toString(), 1305 Boolean.FALSE.toString()); 1306 } 1307 StringBuffer xp = new StringBuffer (256); 1309 xp.append("/").append(CmsConfigurationManager.N_ROOT); 1310 xp.append("/").append(CmsSystemConfiguration.N_SYSTEM); 1311 xp.append("/").append(CmsSystemConfiguration.N_SITES); 1312 xp.append("/").append(CmsSystemConfiguration.N_WORKPLACE_SERVER); 1313 1314 getXmlHelper().setValue(CmsSystemConfiguration.DEFAULT_XML_FILE_NAME, xp.toString(), getWorkplaceSite()); 1315 1316 xp = new StringBuffer (256); 1318 xp.append("/").append(CmsConfigurationManager.N_ROOT); 1319 xp.append("/").append(CmsSystemConfiguration.N_SYSTEM); 1320 xp.append("/").append(CmsSystemConfiguration.N_SITES); 1321 xp.append("/").append(I_CmsXmlConfiguration.N_SITE); 1322 xp.append("[@").append(I_CmsXmlConfiguration.A_URI); 1323 xp.append("='").append(CmsResource.VFS_FOLDER_SITES); 1324 xp.append("/default/']/@").append(CmsSystemConfiguration.A_SERVER); 1325 1326 getXmlHelper().setValue(CmsSystemConfiguration.DEFAULT_XML_FILE_NAME, xp.toString(), getWorkplaceSite()); 1327 1328 getXmlHelper().writeAll(); 1329 } 1330 return true; 1331 } 1332 1333 1336 public void prepareStep8b() { 1337 1338 if (!isInitialized()) { 1339 return; 1340 } 1341 1342 if ((m_workplaceImportThread != null) && (m_workplaceImportThread.isFinished())) { 1343 return; 1345 } 1346 1347 if (m_workplaceImportThread == null) { 1348 m_workplaceImportThread = new CmsSetupWorkplaceImportThread(this); 1349 } 1350 1351 if (!m_workplaceImportThread.isAlive()) { 1352 m_workplaceImportThread.start(); 1353 } 1354 } 1355 1356 1362 public void prepareStep8bOutput(JspWriter out) throws IOException { 1363 1364 m_oldLoggingOffset = m_newLoggingOffset; 1365 m_newLoggingOffset = m_workplaceImportThread.getLoggingThread().getMessages().size(); 1366 if (isInitialized()) { 1367 for (int i = m_oldLoggingOffset; i < m_newLoggingOffset; i++) { 1368 String str = m_workplaceImportThread.getLoggingThread().getMessages().get(i).toString(); 1369 str = CmsEncoder.escapeWBlanks(str, CmsEncoder.ENCODING_UTF_8); 1370 out.println("output[" + (i - m_oldLoggingOffset) + "] = \"" + str + "\";"); 1371 } 1372 } else { 1373 out.println("output[0] = 'ERROR';"); 1374 } 1375 1376 boolean threadFinished = m_workplaceImportThread.isFinished(); 1377 boolean allWritten = m_oldLoggingOffset >= m_workplaceImportThread.getLoggingThread().getMessages().size(); 1378 1379 out.println("function initThread() {"); 1380 if (isInitialized()) { 1381 out.print("send();"); 1382 if (threadFinished && allWritten) { 1383 out.println("setTimeout('top.display.finish()', 1000);"); 1384 } else { 1385 int timeout = 5000; 1386 if (getWorkplaceImportThread().getLoggingThread().getMessages().size() < 20) { 1387 timeout = 2000; 1388 } 1389 out.println("setTimeout('location.reload()', " + timeout + ");"); 1390 } 1391 } 1392 out.println("}"); 1393 } 1394 1395 1402 public void saveProperties(ExtendedProperties properties, String file, boolean backup) { 1403 1404 if (new File (m_configRfsPath + file).isFile()) { 1405 String backupFile = file + CmsConfigurationManager.POSTFIX_ORI; 1406 String tempFile = file + ".tmp"; 1407 1408 m_errors.clear(); 1409 1410 if (backup) { 1411 copyFile(file, FOLDER_BACKUP + backupFile); 1413 } 1414 1415 copyFile(file, tempFile); 1417 1418 save(properties, tempFile, file); 1420 1421 File temp = new File (m_configRfsPath + tempFile); 1423 temp.delete(); 1424 } else { 1425 m_errors.add("No valid file: " + file + "\n"); 1426 } 1427 1428 } 1429 1430 1435 public void setDatabase(String databaseKey) { 1436 1437 m_databaseKey = databaseKey; 1438 1439 String vfsDriver = getDbProperty(m_databaseKey + ".vfs.driver"); 1440 String userDriver = getDbProperty(m_databaseKey + ".user.driver"); 1441 String projectDriver = getDbProperty(m_databaseKey + ".project.driver"); 1442 String workflowDriver = getDbProperty(m_databaseKey + ".workflow.driver"); 1443 String backupDriver = getDbProperty(m_databaseKey + ".backup.driver"); 1444 String sqlManager = getDbProperty(m_databaseKey + ".sqlmanager"); 1445 1446 setExtProperty("db.name", m_databaseKey); 1447 setExtProperty("db.vfs.driver", vfsDriver); 1448 setExtProperty("db.vfs.sqlmanager", sqlManager); 1449 setExtProperty("db.user.driver", userDriver); 1450 setExtProperty("db.user.sqlmanager", sqlManager); 1451 setExtProperty("db.project.driver", projectDriver); 1452 setExtProperty("db.project.sqlmanager", sqlManager); 1453 setExtProperty("db.workflow.driver", workflowDriver); 1454 setExtProperty("db.workflow.sqlmanager", sqlManager); 1455 setExtProperty("db.backup.driver", backupDriver); 1456 setExtProperty("db.backup.sqlmanager", sqlManager); 1457 } 1458 1459 1464 public void setDb(String db) { 1465 1466 setDbProperty(m_databaseKey + ".dbname", db); 1467 } 1468 1469 1474 public void setDbConStrParams(String value) { 1475 1476 setDbProperty(m_databaseKey + ".constr.params", value); 1477 } 1478 1479 1484 public void setDbCreateConStr(String dbCreateConStr) { 1485 1486 setDbProperty(m_databaseKey + ".constr", dbCreateConStr); 1487 } 1488 1489 1497 public void setDbCreatePwd(String dbCreatePwd) { 1498 1499 m_dbCreatePwd = dbCreatePwd; 1500 } 1501 1502 1507 public void setDbCreateUser(String dbCreateUser) { 1508 1509 setDbProperty(m_databaseKey + ".user", dbCreateUser); 1510 } 1511 1512 1517 public void setDbDriver(String driver) { 1518 1519 setDbProperty(m_databaseKey + ".driver", driver); 1520 } 1521 1522 1530 public boolean setDbParamaters(HttpServletRequest request, String provider) { 1531 1532 String conStr = request.getParameter("dbCreateConStr"); 1533 1534 m_provider = provider; 1536 1537 boolean isFormSubmitted = ((request.getParameter("submit") != null) && (conStr != null)); 1538 if (conStr == null) { 1539 conStr = ""; 1540 } 1541 String database = ""; 1542 if (provider.equals(MYSQL_PROVIDER)) { 1543 database = request.getParameter("db"); 1544 } else if (provider.equals(POSTGRESQL_PROVIDER)) { 1545 database = request.getParameter("dbName"); 1546 } 1547 if (provider.equals(MYSQL_PROVIDER) || provider.equals(POSTGRESQL_PROVIDER)) { 1548 isFormSubmitted = (isFormSubmitted && (database != null)); 1549 } 1550 1551 if (isInitialized()) { 1552 String createDb = request.getParameter("createDb"); 1553 if (createDb == null) { 1554 createDb = ""; 1555 } 1556 1557 String createTables = request.getParameter("createTables"); 1558 if (createTables == null) { 1559 createTables = ""; 1560 } 1561 1562 if (isFormSubmitted) { 1563 if (provider.equals(POSTGRESQL_PROVIDER)) { 1564 setDb(database); 1565 1566 String templateDb = request.getParameter("templateDb"); 1567 setDbProperty(getDatabase() + ".templateDb", templateDb); 1568 setDbProperty(getDatabase() + ".newDb", database); 1569 1570 if (!conStr.endsWith("/")) { 1571 conStr += "/"; 1572 } 1573 setDbProperty(getDatabase() + ".constr", conStr + getDbProperty(getDatabase() + ".templateDb")); 1574 setDbProperty(getDatabase() + ".constr.newDb", conStr + getDbProperty(getDatabase() + ".newDb")); 1575 conStr += database; 1576 } else if (provider.equals(MYSQL_PROVIDER) || provider.equals(POSTGRESQL_PROVIDER)) { 1577 if (!conStr.endsWith("/")) { 1578 conStr += "/"; 1579 } 1580 conStr += database; 1581 } 1582 setDbWorkConStr(conStr); 1583 if (provider.equals(POSTGRESQL_PROVIDER)) { 1584 setDb(database); 1585 } 1586 String dbCreateUser = request.getParameter("dbCreateUser"); 1587 String dbCreatePwd = request.getParameter("dbCreatePwd"); 1588 1589 String dbWorkUser = request.getParameter("dbWorkUser"); 1590 String dbWorkPwd = request.getParameter("dbWorkPwd"); 1591 1592 setDbCreateUser(dbCreateUser); 1593 setDbCreatePwd(dbCreatePwd); 1594 1595 if (dbWorkUser.equals("")) { 1596 dbWorkUser = request.getContextPath(); 1597 } 1598 if (dbWorkUser.equals("")) { 1599 dbWorkUser = "opencms"; 1600 } 1601 if (dbWorkUser.startsWith("/")) { 1602 dbWorkUser = dbWorkUser.substring(1, dbWorkUser.length()); 1603 } 1604 setDbWorkUser(dbWorkUser); 1605 setDbWorkPwd(dbWorkPwd); 1606 1607 if (provider.equals(ORACLE_PROVIDER)) { 1608 String dbDefaultTablespace = request.getParameter("dbDefaultTablespace"); 1609 String dbTemporaryTablespace = request.getParameter("dbTemporaryTablespace"); 1610 String dbIndexTablespace = request.getParameter("dbIndexTablespace"); 1611 1612 setDbProperty(getDatabase() + ".defaultTablespace", dbDefaultTablespace); 1613 setDbProperty(getDatabase() + ".temporaryTablespace", dbTemporaryTablespace); 1614 setDbProperty(getDatabase() + ".indexTablespace", dbIndexTablespace); 1615 } 1616 Map replacer = new HashMap (); 1617 if (!provider.equals(MYSQL_PROVIDER)) { 1618 replacer.put("${user}", dbWorkUser); 1619 replacer.put("${password}", dbWorkPwd); 1620 } 1621 if (provider.equals(MYSQL_PROVIDER) || provider.equals(POSTGRESQL_PROVIDER)) { 1622 replacer.put("${database}", database); 1623 } 1624 if (provider.equals(ORACLE_PROVIDER)) { 1625 replacer.put("${defaultTablespace}", getDbProperty(getDatabase() + ".defaultTablespace")); 1626 replacer.put("${indexTablespace}", getDbProperty(getDatabase() + ".indexTablespace")); 1627 replacer.put("${temporaryTablespace}", getDbProperty(getDatabase() + ".temporaryTablespace")); 1628 } 1629 setReplacer(replacer); 1630 1631 if (provider.equals(GENERIC_PROVIDER) 1632 || provider.equals(ORACLE_PROVIDER) 1633 || provider.equals(MAXDB_PROVIDER)) { 1634 request.getSession().setAttribute("createTables", createTables); 1635 } 1636 request.getSession().setAttribute("createDb", createDb); 1637 } else { 1638 String dbName = "opencms"; 1639 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(request.getContextPath())) { 1641 dbName = request.getContextPath().substring(1); 1642 } 1643 if (provider.equals(ORACLE_PROVIDER) 1644 || provider.equals(POSTGRESQL_PROVIDER) 1645 || provider.equals(MAXDB_PROVIDER)) { 1646 setDbWorkUser(dbName); 1647 } else { 1648 setDb(dbName); 1649 } 1650 } 1651 } 1652 return isFormSubmitted; 1653 } 1654 1655 1661 public void setDbProperty(String key, String value) { 1662 1663 String databaseKey = key.substring(0, key.indexOf('.')); 1665 Map databaseProperties = (Map )getDatabaseProperties().get(databaseKey); 1666 databaseProperties.put(key, value); 1667 } 1668 1669 1674 public void setDbWorkConStr(String dbWorkConStr) { 1675 1676 String driver = getDbProperty(m_databaseKey + ".driver"); 1677 String pool = '.' + getPool() + '.'; 1678 1679 setExtProperty(CmsDbPool.KEY_DATABASE_POOL + pool + CmsDbPool.KEY_JDBC_DRIVER, driver); 1680 setExtProperty(CmsDbPool.KEY_DATABASE_POOL + pool + CmsDbPool.KEY_JDBC_URL, dbWorkConStr); 1681 setExtProperty(CmsDbPool.KEY_DATABASE_POOL + pool + CmsDbPool.KEY_TEST_QUERY, getDbTestQuery()); 1682 setExtProperty(CmsDbPool.KEY_DATABASE_POOL + pool + CmsDbPool.KEY_JDBC_URL_PARAMS, getDbConStrParams()); 1683 } 1684 1685 1690 public void setDbWorkPwd(String dbWorkPwd) { 1691 1692 setExtProperty(CmsDbPool.KEY_DATABASE_POOL + '.' + getPool() + '.' + CmsDbPool.KEY_PASSWORD, dbWorkPwd); 1693 } 1694 1695 1700 public void setDbWorkUser(String dbWorkUser) { 1701 1702 setExtProperty(CmsDbPool.KEY_DATABASE_POOL + '.' + getPool() + '.' + CmsDbPool.KEY_POOL_USER, dbWorkUser); 1703 } 1704 1705 1710 public void setEthernetAddress(String ethernetAddress) { 1711 1712 setExtProperty("server.ethernet.address", ethernetAddress); 1713 } 1714 1715 1720 public void setInstallModules(String value) { 1721 1722 m_installModules = CmsStringUtil.splitAsList(value, "|", true); 1723 try { 1724 m_installModules = CmsModuleManager.topologicalSort(m_installModules, getModuleFolder()); 1725 } catch (CmsConfigurationException e) { 1726 throw new RuntimeException (e); 1727 } 1728 } 1729 1730 1735 public void setReplacer(Map map) { 1736 1737 m_replacer = map; 1738 } 1739 1740 1745 public void setServerName(String name) { 1746 1747 setExtProperty("server.name", name); 1748 } 1749 1750 1755 public void setWorkplaceSite(String newSite) { 1756 1757 String oldSite = getWorkplaceSite(); 1758 String siteList = getExtProperty("site.root.list"); 1760 siteList = CmsStringUtil.substitute(siteList, oldSite, newSite); 1762 setExtProperty("site.root.list", siteList); 1763 setExtProperty("site.workplace", newSite); 1764 } 1765 1766 1769 public void shellExit() { 1770 1771 System.out.println(); 1772 System.out.println(); 1773 System.out.println("The setup is finished!\nThe OpenCms system used for the setup will now shut down."); 1774 } 1775 1776 1779 public void shellStart() { 1780 1781 System.out.println(); 1782 System.out.println("Starting Workplace import and database setup for OpenCms!"); 1783 1784 String [] copy = Messages.COPYRIGHT_BY_ALKACON; 1785 for (int i = copy.length - 1; i >= 0; i--) { 1786 System.out.println(copy[i]); 1787 } 1788 System.out.println("This is OpenCms " + OpenCms.getSystemInfo().getVersionName()); 1789 System.out.println(); 1790 System.out.println(); 1791 } 1792 1793 1800 public List sortModules(Collection modules) { 1801 1802 List aux = new ArrayList (modules); 1803 Collections.sort(aux, new Comparator () { 1804 1805 public int compare(Object o1, Object o2) { 1806 1807 CmsModule module1 = (CmsModule)o1; 1808 CmsModule module2 = (CmsModule)o2; 1809 return getDisplayForModule(module1).compareTo(getDisplayForModule(module2)); 1810 } 1811 }); 1812 1813 List ret = new ArrayList (aux.size()); 1814 for (Iterator it = aux.iterator(); it.hasNext();) { 1815 CmsModule module = (CmsModule)it.next(); 1816 ret.add(module.getName()); 1817 } 1818 return ret; 1819 } 1820 1821 1826 public boolean validateJdbc() { 1827 1828 boolean result = false; 1829 String libFolder = getLibFolder(); 1830 Iterator it = getDatabaseLibs(getDatabase()).iterator(); 1831 while (it.hasNext()) { 1832 String libName = (String )it.next(); 1833 File libFile = new File (libFolder, libName); 1834 if (libFile.exists()) { 1835 result = true; 1836 } 1837 } 1838 return result; 1839 } 1840 1841 1847 protected String getExtProperty(String key) { 1848 1849 Object value = m_extProperties.get(key); 1850 return (value != null) ? value.toString() : ""; 1851 } 1852 1853 1861 protected String htmlModule(CmsModule module, int pos) { 1862 1863 StringBuffer html = new StringBuffer (256); 1864 html.append("\t<tr>\n"); 1865 html.append("\t\t<td style='vertical-align: top;'>\n"); 1866 html.append("\t\t\t<input type='checkbox' name='availableModules' value='"); 1867 html.append(module.getName()); 1868 html.append("' checked='checked' onClick=\"checkDependencies('"); 1869 html.append(module.getName()); 1870 html.append("');\">\n"); 1871 html.append("\t\t</td>\n"); 1872 html.append("\t\t<td style='vertical-align: top; width: 100%; padding-top: 4px;'>\n\t\t\t"); 1873 html.append(getDisplayForModule(module)); 1874 html.append("\n\t\t</td>\n"); 1875 html.append("\t\t<td style='vertical-align: top; text-align: right;'>\n"); 1876 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(module.getDescription())) { 1877 html.append("\t\t\t"); 1878 html.append(getHtmlHelpIcon("" + pos, "")); 1879 } 1880 html.append("\t\t</td>\n"); 1881 html.append("\t</tr>\n"); 1882 return html.toString(); 1883 } 1884 1885 1893 protected void importModuleFromDefault(String importFile) throws Exception { 1894 1895 String fileName = getModuleFolder() + importFile; 1896 OpenCms.getImportExportManager().importData( 1897 m_cms, 1898 fileName, 1899 null, 1900 new CmsShellReport(m_cms.getRequestContext().getLocale())); 1901 } 1902 1903 1907 protected void readDatabaseConfig() { 1908 1909 String databaseKey = null; 1910 FileInputStream input = null; 1911 String configPath = null; 1912 Properties databaseProperties = null; 1913 File databaseSetupFolder = null; 1914 File [] childResources = null; 1915 File childResource = null; 1916 File setupFile = null; 1917 boolean hasMissingSetupFiles = false; 1918 1919 m_databaseKeys = new ArrayList (); 1920 m_databaseProperties = new HashMap (); 1921 1922 try { 1923 databaseSetupFolder = new File (m_webAppRfsPath + FOLDER_SETUP + FOLDER_DATABASE); 1924 1925 if (databaseSetupFolder.exists()) { 1926 childResources = databaseSetupFolder.listFiles(); 1927 1928 if (childResources != null) { 1929 for (int i = 0; i < childResources.length; i++) { 1930 childResource = childResources[i]; 1931 hasMissingSetupFiles = false; 1932 1933 if (childResource.exists() && childResource.isDirectory() && childResource.canRead()) { 1934 for (int j = 0; j < REQUIRED_DB_SETUP_FILES.length; j++) { 1935 setupFile = new File (childResource.getPath() 1936 + File.separatorChar 1937 + REQUIRED_DB_SETUP_FILES[j]); 1938 1939 if (!setupFile.exists() || !setupFile.isFile() || !setupFile.canRead()) { 1940 hasMissingSetupFiles = true; 1941 System.err.println("[" 1942 + getClass().getName() 1943 + "] missing or unreadable database setup file: " 1944 + setupFile.getPath()); 1945 break; 1946 } 1947 1948 if (!hasMissingSetupFiles) { 1949 m_databaseKeys.add(childResource.getName().trim()); 1950 } 1951 } 1952 } 1953 } 1954 } 1955 1956 for (int i = 0; i < m_databaseKeys.size(); i++) { 1957 databaseKey = (String )m_databaseKeys.get(i); 1958 configPath = m_webAppRfsPath 1959 + "setup" 1960 + File.separatorChar 1961 + "database" 1962 + File.separatorChar 1963 + databaseKey 1964 + File.separatorChar 1965 + "database.properties"; 1966 1967 try { 1968 input = new FileInputStream (new File (configPath)); 1969 databaseProperties = new Properties (); 1970 databaseProperties.load(input); 1971 m_databaseProperties.put(databaseKey, databaseProperties); 1972 } catch (Exception e) { 1973 System.err.println(e.toString()); 1974 e.printStackTrace(System.err); 1975 continue; 1976 } 1977 } 1978 } 1979 } catch (Exception e) { 1980 System.err.println(e.toString()); 1981 e.printStackTrace(System.err); 1982 } finally { 1983 try { 1984 if (input != null) { 1985 input.close(); 1986 } 1987 } catch (Exception e) { 1988 } 1990 } 1991 } 1992 1993 1998 protected void setExtProperty(String key, String value) { 1999 2000 m_extProperties.put(key, value); 2001 } 2002 2003 2010 private void save(ExtendedProperties properties, String source, String target) { 2011 2012 try { 2013 HashSet alreadyWritten = new HashSet (); 2014 2015 LineNumberReader lnr = new LineNumberReader (new FileReader (new File (m_configRfsPath + source))); 2016 2017 FileWriter fw = new FileWriter (new File (m_configRfsPath + target)); 2018 2019 while (true) { 2020 String line = lnr.readLine(); 2021 if (line == null) { 2022 break; 2023 } 2024 line = line.trim(); 2025 2026 if ("".equals(line)) { 2027 fw.write("\n"); 2029 } else if (line.startsWith("#")) { 2030 fw.write(line); 2032 fw.write("\n"); 2033 } else { 2034 2035 int index = line.indexOf('='); 2036 int index1 = line.indexOf("\\="); 2037 if (line.indexOf('=') > -1 && index1 != index - 1) { 2038 2039 String key = line.substring(0, line.indexOf('=')).trim(); 2040 if (alreadyWritten.contains(key)) { 2041 continue; 2042 } 2043 fw.write((key + "=")); 2045 try { 2046 Object obj = properties.get(key); 2047 String value = ""; 2048 2049 if (obj != null && obj instanceof Vector ) { 2050 String [] values = {}; 2051 values = (String [])((Vector )obj).toArray(values); 2052 StringBuffer buf = new StringBuffer (); 2053 2054 for (int i = 0; i < values.length; i++) { 2055 2056 values[i] = CmsStringUtil.substitute(values[i], ",", "\\,"); 2058 values[i] = CmsStringUtil.substitute(values[i], "=", "\\="); 2059 2060 buf.append("\t" + values[i] + ((i < values.length - 1) ? ",\\\n" : "")); 2061 } 2062 value = buf.toString(); 2063 2064 fw.write("\\\n" + value); 2066 2067 } else if (obj != null) { 2068 2069 value = ((String )obj).trim(); 2070 2071 value = CmsStringUtil.substitute(value, ",", "\\,"); 2073 value = CmsStringUtil.substitute(value, "=", "\\="); 2074 2075 fw.write(value); 2077 } 2078 2079 } catch (NullPointerException e) { 2080 } 2082 fw.write("\n"); 2084 2085 alreadyWritten.add(key); 2087 } 2088 } 2089 } 2090 2091 lnr.close(); 2092 fw.close(); 2093 } catch (Exception e) { 2094 m_errors.add("Could not save properties to " + target + " \n"); 2095 m_errors.add(e.toString() + "\n"); 2096 } 2097 } 2098 2099 2104 private void setWebAppRfsPath(String webInfRfsPath) { 2105 2106 m_webAppRfsPath = webInfRfsPath; 2107 if ("".equals(webInfRfsPath)) { 2108 m_configRfsPath = ""; 2110 return; 2111 } 2112 if (!m_webAppRfsPath.endsWith(File.separator)) { 2113 m_webAppRfsPath += File.separator; 2117 } 2118 m_configRfsPath = m_webAppRfsPath + FOLDER_WEBINF + CmsSystemInfo.FOLDER_CONFIG; 2119 } 2120} | Popular Tags |