1 23 24 package org.infoglue.cms.util; 25 26 import java.io.ByteArrayInputStream ; 27 import java.io.File ; 28 import java.io.FileInputStream ; 29 import java.net.InetAddress ; 30 import java.util.ArrayList ; 31 import java.util.Collection ; 32 import java.util.Collections ; 33 import java.util.Enumeration ; 34 import java.util.HashMap ; 35 import java.util.Iterator ; 36 import java.util.List ; 37 import java.util.Map ; 38 import java.util.Properties ; 39 40 import org.apache.log4j.Logger; 41 import org.infoglue.cms.controllers.kernel.impl.simple.ServerNodeController; 42 import org.infoglue.cms.entities.management.ServerNodeVO; 43 import org.infoglue.deliver.util.CacheController; 44 import org.infoglue.deliver.util.Timer; 45 46 import com.opensymphony.module.propertyset.PropertySet; 47 import com.opensymphony.module.propertyset.PropertySetManager; 48 49 50 51 61 62 public class CmsPropertyHandler 63 { 64 private final static Logger logger = Logger.getLogger(CmsPropertyHandler.class.getName()); 65 66 private static Properties cachedProperties = null; 67 private static PropertySet propertySet = null; 68 69 private static String serverNodeName = null; 70 71 private static String globalSettingsServerNodeId= "-1"; 72 private static String localSettingsServerNodeId = null; 73 74 private static String applicationName = null; 75 private static String contextRootPath = null; 76 private static String operatingMode = null; 77 private static File propertyFile = null; 78 79 public static void setApplicationName(String theApplicationName) 80 { 81 CmsPropertyHandler.applicationName = theApplicationName; 82 } 83 84 public static void setContextRootPath(String contextRootPath) 85 { 86 CmsPropertyHandler.contextRootPath = contextRootPath; 87 } 88 89 public static void setOperatingMode(String operatingMode) 90 { 91 CmsPropertyHandler.operatingMode = operatingMode; 92 } 93 94 public static String getApplicationName() 95 { 96 return applicationName; 97 } 98 99 public static void setPropertyFile(File aPropertyFile) 100 { 101 propertyFile = aPropertyFile; 102 } 103 104 107 108 private static void initializeProperties() 109 { 110 try 111 { 112 Timer timer = new Timer(); 113 timer.setActive(false); 114 115 System.out.println("Initializing properties from file....."); 116 117 cachedProperties = new Properties (); 118 if(propertyFile != null) 119 cachedProperties.load(new FileInputStream (propertyFile)); 120 else 121 cachedProperties.load(CmsPropertyHandler.class.getResourceAsStream("/" + applicationName + ".properties")); 122 123 Enumeration enumeration = cachedProperties.keys(); 124 while(enumeration.hasMoreElements()) 125 { 126 String key = (String )enumeration.nextElement(); 127 if(key.indexOf("webwork.") > 0) 128 { 129 webwork.config.Configuration.set(key, cachedProperties.getProperty(key)); 130 } 131 } 132 133 timer.printElapsedTime("Initializing properties from file took"); 134 135 Map args = new HashMap (); 136 args.put("globalKey", "infoglue"); 137 try 138 { 139 propertySet = PropertySetManager.getInstance("jdbc", args); 140 logger.info("propertySet: " + propertySet); 141 } 142 catch(Exception e) 143 { 144 propertySet = null; 145 logger.error("Could not get property set: " + e.getMessage(), e); 146 } 147 148 timer.printElapsedTime("Initializing properties from jdbc"); 149 150 serverNodeName = cachedProperties.getProperty("serverNodeName"); 151 152 if(serverNodeName == null || serverNodeName.length() == 0) 153 { 154 try 155 { 156 InetAddress localhost = InetAddress.getLocalHost(); 157 serverNodeName = localhost.getHostName(); 158 } 159 catch(Exception e) 160 { 161 System.out.println("Error initializing serverNodeName:" + e.getMessage()); 162 } 163 } 164 165 System.out.println("serverNodeName:" + serverNodeName); 166 167 initializeLocalServerNodeId(); 168 169 timer.printElapsedTime("Initializing properties from local server jdbc"); 170 } 171 catch(Exception e) 172 { 173 cachedProperties = null; 174 logger.error("Error loading properties from file " + "/" + applicationName + ".properties" + ". Reason:" + e.getMessage()); 175 e.printStackTrace(); 176 } 177 178 } 179 180 183 184 public static void initializeLocalServerNodeId() 185 { 186 try 187 { 188 List serverNodeVOList = ServerNodeController.getController().getServerNodeVOList(); 189 Iterator serverNodeVOListIterator = serverNodeVOList.iterator(); 190 while(serverNodeVOListIterator.hasNext()) 191 { 192 ServerNodeVO serverNodeVO = (ServerNodeVO)serverNodeVOListIterator.next(); 193 if(serverNodeVO.getName().equalsIgnoreCase(serverNodeName)) 194 { 195 localSettingsServerNodeId = serverNodeVO.getId().toString(); 196 break; 197 } 198 } 199 } 200 catch(Exception e) 201 { 202 logger.warn("An error occurred trying to get localSettingsServerNodeId: " + e.getMessage(), e); 203 } 204 205 System.out.println("localSettingsServerNodeId:" + localSettingsServerNodeId); 206 } 207 208 211 212 public static Properties getProperties() 213 { 214 if(cachedProperties == null) 215 initializeProperties(); 216 217 return cachedProperties; 218 } 219 220 221 224 225 public static String getProperty(String key) 226 { 227 String value; 228 if(cachedProperties == null) 229 initializeProperties(); 230 231 value = cachedProperties.getProperty(key); 232 if (value != null) 233 value = value.trim(); 234 235 return value; 236 } 237 238 239 242 243 public static void setProperty(String key, String value) 244 { 245 if(cachedProperties == null) 246 initializeProperties(); 247 248 cachedProperties.setProperty(key, value); 249 250 CacheController.clearCache("serverNodePropertiesCache"); 251 } 252 253 public static String getServerNodeProperty(String key, boolean inherit) 254 { 255 return getServerNodeProperty(null, key, inherit, null); 256 } 257 258 public static String getServerNodeProperty(String key, boolean inherit, String defaultValue) 259 { 260 return getServerNodeProperty(null, key, inherit, defaultValue); 261 } 262 263 270 271 public static String getServerNodeProperty(String prefix, String key, boolean inherit, String defaultValue) 272 { 273 String value = null; 274 275 String cacheKey = "" + prefix + "_" + key + "_" + inherit; 276 String cacheName = "serverNodePropertiesCache"; 277 logger.info("cacheKey:" + cacheKey); 278 value = (String )CacheController.getCachedObject(cacheName, cacheKey); 279 if(value != null) 280 { 281 return value.trim(); 282 } 283 284 Timer timer = new Timer(); 285 logger.info("Getting jdbc-property:" + cacheKey); 286 if(propertySet != null) 287 { 288 if(localSettingsServerNodeId != null) 289 { 290 if(prefix != null) 291 { 292 value = propertySet.getString("serverNode_" + localSettingsServerNodeId + "_" + prefix + "_" + key); 293 if(value == null || value.equals("") || value.equalsIgnoreCase("inherit") && inherit) 295 { 296 value = propertySet.getString("serverNode_" + globalSettingsServerNodeId + "_" + prefix + "_" + key); 297 if(value == null || value.equals("") || value.equalsIgnoreCase("inherit") && inherit) 299 { 300 value = propertySet.getString("serverNode_" + globalSettingsServerNodeId + "_" + key); 301 } 303 304 } 305 } 306 else 307 { 308 value = propertySet.getString("serverNode_" + localSettingsServerNodeId + "_" + key); 309 if(value == null || value.equals("") || value.equalsIgnoreCase("inherit") && inherit) 311 { 312 value = propertySet.getString("serverNode_" + globalSettingsServerNodeId + "_" + key); 313 } 315 } 316 } 317 else 318 { 319 if(prefix != null) 320 { 321 value = propertySet.getString("serverNode_" + globalSettingsServerNodeId + "_" + prefix + "_" + key); 322 if(value == null || value.equals("") || value.equalsIgnoreCase("inherit") && inherit) 324 { 325 value = propertySet.getString("serverNode_" + globalSettingsServerNodeId + "_" + key); 326 } 328 } 329 else 330 { 331 value = propertySet.getString("serverNode_" + globalSettingsServerNodeId + "_" + key); 332 } 334 } 335 } 336 337 if(value == null || value.equals("") || value.equalsIgnoreCase("inherit") && inherit) 338 { 339 value = getProperty(key); 340 } 342 343 if((value == null || value.indexOf(key) > -1) && defaultValue != null) 344 value = defaultValue; 345 346 if(value != null) 347 value = value.trim(); 348 349 CacheController.cacheObject(cacheName, cacheKey, value); 350 351 logger.info("Getting property " + cacheKey + " took:" + timer.getElapsedTime()); 352 353 return value; 354 } 355 356 357 364 365 public static String getServerNodeDataProperty(String prefix, String key, boolean inherit, String defaultValue) 366 { 367 String value = null; 368 369 String cacheKey = "" + prefix + "_" + key + "_" + inherit; 370 String cacheName = "serverNodePropertiesCache"; 371 logger.info("cacheKey:" + cacheKey); 372 value = (String )CacheController.getCachedObject(cacheName, cacheKey); 373 if(value != null) 374 { 375 return value; 376 } 377 378 Timer timer = new Timer(); 379 380 logger.info("Getting jdbc-property:" + cacheKey); 381 if(localSettingsServerNodeId != null) 382 { 383 if(prefix != null) 384 { 385 value = getDataPropertyValue("serverNode_" + localSettingsServerNodeId + "_" + prefix + "_" + key); 386 if(value == null || value.equals("") || value.equalsIgnoreCase("inherit") && inherit) 388 { 389 value = getDataPropertyValue("serverNode_" + globalSettingsServerNodeId + "_" + prefix + "_" + key); 390 if(value == null || value.equals("") || value.equalsIgnoreCase("inherit") && inherit) 392 { 393 value = getDataPropertyValue("serverNode_" + globalSettingsServerNodeId + "_" + key); 394 } 396 397 } 398 } 399 else 400 { 401 value = getDataPropertyValue("serverNode_" + localSettingsServerNodeId + "_" + key); 402 if(value == null || value.equals("") || value.equalsIgnoreCase("inherit") && inherit) 404 { 405 value = getDataPropertyValue("serverNode_" + globalSettingsServerNodeId + "_" + key); 406 } 408 } 409 } 410 else 411 { 412 if(prefix != null) 413 { 414 value = getDataPropertyValue("serverNode_" + globalSettingsServerNodeId + "_" + prefix + "_" + key); 415 } 417 else 418 { 419 value = getDataPropertyValue("serverNode_" + globalSettingsServerNodeId + "_" + key); 420 } 422 } 423 424 if(value == null && defaultValue != null) 425 value = defaultValue; 426 427 CacheController.cacheObject(cacheName, cacheKey, value); 428 429 logger.info("Getting property " + cacheKey + " took:" + timer.getElapsedTime()); 430 431 return value; 432 } 433 434 public static String getDataPropertyValue(String fullKey) 435 { 436 String result = null; 437 438 try 439 { 440 byte[] valueBytes = propertySet.getData(fullKey); 441 442 result = (valueBytes != null ? new String (valueBytes, "utf-8") : ""); 443 } 444 catch(Exception e) 445 { 446 e.printStackTrace(); 447 } 448 449 return result; 450 } 451 452 public static String getContextRootPath() 453 { 454 return contextRootPath; } 456 457 public static String getOperatingMode() 458 { 459 if(operatingMode == null) 460 return getProperty("operatingMode"); 461 else 462 return operatingMode; } 464 465 public static String getInputCharacterEncoding(String defaultEncoding) 468 { 469 String applicationName = CmsPropertyHandler.getApplicationName(); 472 String newInputCharacterEncoding = CmsPropertyHandler.getServerNodeProperty("inputCharacterEncoding", true, defaultEncoding); 473 if(!applicationName.equalsIgnoreCase("cms")) 474 newInputCharacterEncoding = CmsPropertyHandler.getServerNodeProperty("deliver", "inputCharacterEncoding", true, defaultEncoding); 475 476 return newInputCharacterEncoding; 479 } 481 482 public static String getUp2dateUrl() 483 { 484 return getProperty("up2dateUrl"); 485 } 486 487 public static String getURLComposerClass() 488 { 489 return getProperty("URLComposerClass"); 490 } 491 492 public static String getMaxClients() 493 { 494 return getProperty("maxClients"); 495 } 496 497 public static String getAdministratorUserName() 498 { 499 return getProperty("administratorUserName"); 500 } 501 502 public static String getAdministratorPassword() 503 { 504 return getProperty("administratorPassword"); 505 } 506 507 public static String getAdministratorEmail() 508 { 509 return getProperty("administratorEmail"); 510 } 511 512 public static String getDbRelease() 513 { 514 return getProperty("dbRelease"); 515 } 516 517 public static String getDbUser() 518 { 519 return getProperty("dbUser"); 520 } 521 522 public static String getDbPassword() 523 { 524 return getProperty("dbPassword"); 525 } 526 527 public static String getMasterServer() 528 { 529 return getProperty("masterServer"); 530 } 531 public static String getSlaveServer() 532 { 533 return getProperty("slaveServer"); 534 } 535 536 public static String getBuildName() 537 { 538 return getProperty("buildName"); 539 } 540 public static String getAdminToolsPath() 541 { 542 return getProperty("adminToolsPath"); 543 } 544 public static String getDbScriptPath() 545 { 546 return getProperty("dbScriptPath"); 547 } 548 549 public static String getDigitalAssetUploadPath() 550 { 551 return getServerNodeProperty("digitalAssetUploadPath", true); 552 } 553 554 public static String getExtranetCookieTimeout() 555 { 556 return getServerNodeProperty("extranetCookieTimeout", true, "1800"); 557 } 558 559 public static String getWebServicesBaseUrl() 560 { 561 return getServerNodeProperty("webServicesBaseUrl", true); 562 } 563 564 public static String getPublicationThreadDelay() 565 { 566 return getServerNodeProperty("publicationThreadDelay", true, "5000"); 567 } 568 569 public static String getPathsToRecacheOnPublishing() 570 { 571 return getServerNodeProperty("pathsToRecacheOnPublishing", true); 572 } 573 574 public static String getDisableTemplateDebug() 575 { 576 return getServerNodeProperty("disableTemplateDebug", true, "false"); 577 } 578 579 public static String getTree() 580 { 581 return getServerNodeProperty("tree", true, "html"); 582 } 583 584 public static String getTreeMode() 585 { 586 return getServerNodeProperty("treemode", true, "dynamic"); 587 } 588 589 public static String getPreviewDeliveryUrl() 590 { 591 return getServerNodeProperty("previewDeliveryUrl", true); 592 } 593 594 public static String getStagingDeliveryUrl() 595 { 596 return getServerNodeProperty("stagingDeliveryUrl", true); 597 } 598 599 public static String getEditionPageSize() 600 { 601 return getServerNodeProperty("edition.pageSize", true, "10"); 602 } 603 604 public static String getContentTreeSort() 605 { 606 return getServerNodeProperty("content.tree.sort", true, "name"); 607 } 608 609 public static String getStructureTreeSort() 610 { 611 return getServerNodeProperty("structure.tree.sort", true, "name"); 612 } 613 614 public static String getStructureTreeIsHiddenProperty() 615 { 616 return getServerNodeProperty("structure.tree.isHidden", true); 617 } 618 619 public static String getDisableEmptyUrls() 620 { 621 return getServerNodeProperty("disableEmptyUrls", true, "yes"); 622 } 623 624 public static String getCacheUpdateAction() 625 { 626 return getServerNodeProperty("cacheUpdateAction", true, "UpdateCache.action"); 627 } 628 629 public static String getLogPath() 630 { 631 return getServerNodeProperty("logPath", true); 632 } 633 634 public static String getLogTransactions() 635 { 636 return getServerNodeProperty("logTransactions", true, "false"); 637 } 638 639 public static String getEnableExtranetCookies() 640 { 641 return getServerNodeProperty("enableExtranetCookies", true, "false"); 642 } 643 644 public static String getUseAlternativeBrowserLanguageCheck() 645 { 646 return getServerNodeProperty("useAlternativeBrowserLanguageCheck", true, "false"); 647 } 648 649 public static String getCaseSensitiveRedirects() 650 { 651 return getServerNodeProperty("caseSensitiveRedirects", true, "false"); 652 } 653 654 public static String getUseDNSNameInURI() 655 { 656 return getServerNodeProperty("useDNSNameInURI", true, "false"); 657 } 658 659 public static String getWysiwygEditor() 660 { 661 return getServerNodeProperty("wysiwygEditor", true, "FCKEditor"); 662 } 663 664 public static String getProtectContentTypes() 665 { 666 return getServerNodeProperty("protectContentTypes", true, "false"); 667 } 668 669 public static String getProtectWorkflows() 670 { 671 return getServerNodeProperty("protectWorkflows", true, "false"); 672 } 673 674 public static String getProtectCategories() 675 { 676 return getServerNodeProperty("protectCategories", true, "false"); 677 } 678 679 public static String getMaxRows() 680 { 681 return getServerNodeProperty("maxRows", true, "100"); 682 } 683 684 public static String getShowContentVersionFirst() 685 { 686 return getServerNodeProperty("showContentVersionFirst", true, "true"); 687 } 688 689 public static String getShowComponentsFirst() 690 { 691 return getServerNodeProperty("showComponentsFirst", true, "true"); 692 } 693 694 public static String getShowAllWorkflows() 695 { 696 return getServerNodeProperty("showAllWorkflows", true, "true"); 697 } 698 699 public static String getIsPageCacheOn() 700 { 701 return getServerNodeProperty("isPageCacheOn", true, "true"); 702 } 703 704 public static String getEditOnSite() 705 { 706 return getServerNodeProperty("editOnSite", true, "true"); 707 } 708 709 public static String getUseSelectivePageCacheUpdate() 710 { 711 return getServerNodeProperty("useSelectivePageCacheUpdate", true, "true"); 712 } 713 714 public static String getExpireCacheAutomatically() 715 { 716 return getServerNodeProperty("expireCacheAutomatically", true, "false"); 717 } 718 719 public static String getCacheExpireInterval() 720 { 721 return getServerNodeProperty("cacheExpireInterval", true, "1800"); 722 } 723 724 public static String getDeliverRequestTimeout() 725 { 726 return getServerNodeProperty("deliverRequestTimeout", true, "60000"); 727 } 728 729 public static String getSessionTimeout() 730 { 731 return getServerNodeProperty("session.timeout", true, "1800"); 732 } 733 734 public static String getCompressPageCache() 735 { 736 return getServerNodeProperty("compressPageCache", true, "true"); 737 } 738 739 public static String getCompressPageResponse() 740 { 741 return getServerNodeProperty("compressPageResponse", true, "false"); 742 } 743 744 public static String getSiteNodesToRecacheOnPublishing() 745 { 746 return getServerNodeProperty("siteNodesToRecacheOnPublishing", true); 747 } 748 749 public static String getRecachePublishingMethod() 750 { 751 return getServerNodeProperty("recachePublishingMethod", true); 752 } 753 754 public static String getRecacheUrl() 755 { 756 return getServerNodeProperty("recacheUrl", true); 757 } 758 759 public static String getUseUpdateSecurity() 760 { 761 return getServerNodeProperty("useUpdateSecurity", true, "true"); 762 } 763 764 public static String getAllowedAdminIP() 765 { 766 return getServerNodeProperty("allowedAdminIP", true); 767 } 768 769 public static String getPageKey() 770 { 771 return getServerNodeProperty("pageKey", true); 772 } 773 774 public static String getCmsFullBaseUrl() 775 { 776 return getServerNodeProperty("cmsFullBaseUrl", true); 777 } 778 779 public static String getCmsBaseUrl() 780 { 781 return getServerNodeProperty("cmsBaseUrl", true); 782 } 783 784 public static String getComponentEditorUrl() 785 { 786 return getServerNodeProperty("componentEditorUrl", true); 787 } 788 789 public static String getComponentRendererUrl() 790 { 791 return getServerNodeProperty("componentRendererUrl", true); 792 } 793 794 public static String getComponentRendererAction() 795 { 796 return getServerNodeProperty("componentRendererAction", true); 797 } 798 799 public static String getEditOnSiteUrl() 800 { 801 return getServerNodeProperty("editOnSiteUrl", true); 802 } 803 804 public static String getUseFreeMarker() 805 { 806 return getServerNodeProperty("useFreeMarker", true, "false"); 807 } 808 809 public static String getWebServerAddress() 810 { 811 return getServerNodeProperty("webServerAddress", true); 812 } 813 814 public static String getApplicationBaseAction() 815 { 816 return getServerNodeProperty("applicationBaseAction", true); 817 } 818 819 public static String getDigitalAssetBaseUrl() 820 { 821 return getServerNodeProperty("digitalAssetBaseUrl", true); 822 } 823 824 public static String getImagesBaseUrl() 825 { 826 return getServerNodeProperty("imagesBaseUrl", true); 827 } 828 829 public static String getDigitalAssetPath() 830 { 831 return getServerNodeProperty("digitalAssetPath", true); 832 } 833 834 public static String getEnableNiceURI() 835 { 836 return getServerNodeProperty("enableNiceURI", true, "true"); 837 } 838 839 public static String getNiceURIEncoding() 840 { 841 return getServerNodeProperty("niceURIEncoding", true, "UTF-8"); 842 } 843 844 public static String getNiceURIAttributeName() 845 { 846 return getServerNodeProperty("niceURIAttributeName", true, "NiceURIName"); 847 } 848 849 public static String getRequestArgumentDelimiter() 850 { 851 return getServerNodeProperty("requestArgumentDelimiter", true, "&"); 852 } 853 854 public static String getErrorUrl() 855 { 856 return getServerNodeProperty("errorUrl", true); 857 } 858 859 public static String getErrorBusyUrl() 860 { 861 return getServerNodeProperty("errorBusyUrl", true); 862 } 863 864 public static String getExternalThumbnailGeneration() 865 { 866 return getServerNodeProperty("externalThumbnailGeneration", true); 867 } 868 869 public static String getURIEncoding() 870 { 871 return getServerNodeProperty("URIEncoding", true, "UTF-8"); 872 } 873 874 public static String getWorkflowEncoding() 875 { 876 return getServerNodeProperty("workflowEncoding", true, "UTF-8"); 877 } 878 879 public static String getFormsEncoding() 880 { 881 return getServerNodeProperty("formsEncoding", true, "UTF-8"); 882 } 883 884 public static String getUseShortTableNames() 885 { 886 return getServerNodeProperty("useShortTableNames", true, "false"); 887 } 888 889 public static String getLogDatabaseMessages() 890 { 891 return getServerNodeProperty("logDatabaseMessages", true, "false"); 892 } 893 894 public static String getStatisticsEnabled() 895 { 896 return getServerNodeProperty("statistics.enabled", true, "false"); 897 } 898 899 public static String getStatisticsLogPath() 900 { 901 return getServerNodeProperty("statisticsLogPath", true); 902 } 903 904 public static String getStatisticsLogOneFilePerDay() 905 { 906 return getServerNodeProperty("statisticsLogOneFilePerDay", true, "false"); 907 } 908 909 public static String getStatisticsLogger() 910 { 911 return getServerNodeProperty("statisticsLogger", true, "W3CExtendedLogger"); 912 } 913 914 public static String getEnablePortal() 915 { 916 return getServerNodeProperty("enablePortal", true, "true"); 917 } 918 919 public static String getPortletBase() 920 { 921 return getServerNodeProperty("portletBase", true); 922 } 923 924 public static String getMailSmtpHost() 925 { 926 return getServerNodeProperty("mail.smtp.host", true); 927 } 928 929 public static String getMailSmtpAuth() 930 { 931 return getServerNodeProperty("mail.smtp.auth", true); 932 } 933 934 public static String getMailSmtpUser() 935 { 936 return getServerNodeProperty("mail.smtp.user", true); 937 } 938 939 public static String getMailSmtpPassword() 940 { 941 return getServerNodeProperty("mail.smtp.password", true); 942 } 943 944 public static String getMailContentType() 945 { 946 return getServerNodeProperty("mail.contentType", true, "text/html"); 947 } 948 949 public static String getSystemEmailSender() 950 { 951 return getServerNodeProperty("systemEmailSender", true); 952 } 953 954 public static String getWarningEmailReceiver() 955 { 956 return getServerNodeProperty("warningEmailReceiver", true); 957 } 958 959 public static String getExportFormat() 960 { 961 return getServerNodeProperty("exportFormat", true, "1"); 962 } 963 964 public static String getHelpUrl() 965 { 966 return getServerNodeProperty("helpUrl", true); 967 } 968 969 public static String getProtectDeliverWorking() 970 { 971 return getServerNodeProperty("protectDeliverWorking", true, "false"); 972 } 973 974 public static String getProtectDeliverPreview() 975 { 976 return getServerNodeProperty("protectDeliverPreview", true, "false"); 977 } 978 979 public static String getPreferredLanguageCode(String userName) 980 { 981 return propertySet.getString("principal_" + userName + "_languageCode"); 982 } 983 984 public static String getPreferredToolId(String userName) 985 { 986 return propertySet.getString("principal_" + userName + "_defaultToolId"); 987 } 988 989 public static List getInternalDeliveryUrls() 990 { 991 List urls = new ArrayList (); 992 993 String internalDeliverUrlsString = CmsPropertyHandler.getServerNodeDataProperty(null, "internalDeliveryUrls", true, null); 994 if(internalDeliverUrlsString != null && !internalDeliverUrlsString.equals("")) 996 { 997 try 998 { 999 Properties properties = new Properties (); 1000 properties.load(new ByteArrayInputStream (internalDeliverUrlsString.getBytes("UTF-8"))); 1001 1002 int i = 0; 1003 String deliverUrl = null; 1004 while((deliverUrl = properties.getProperty("" + i)) != null) 1005 { 1006 urls.add(deliverUrl); 1007 i++; 1008 } 1009 1010 } 1011 catch(Exception e) 1012 { 1013 logger.error("Error loading properties from string. Reason:" + e.getMessage()); 1014 e.printStackTrace(); 1015 } 1016 } 1017 else 1018 { 1019 int i = 0; 1020 String deliverUrl = null; 1021 while((deliverUrl = CmsPropertyHandler.getProperty("internalDeliverUrl." + i)) != null) 1022 { 1023 urls.add(deliverUrl); 1024 i++; 1025 } 1026 } 1027 1028 return urls; 1029 } 1030 1031 public static List getPublicDeliveryUrls() 1032 { 1033 List urls = new ArrayList (); 1034 1035 String publicDeliverUrlString = CmsPropertyHandler.getServerNodeDataProperty(null, "publicDeliveryUrls", true, null); 1036 if(publicDeliverUrlString != null && !publicDeliverUrlString.equals("")) 1038 { 1039 try 1040 { 1041 Properties properties = new Properties (); 1042 properties.load(new ByteArrayInputStream (publicDeliverUrlString.getBytes("UTF-8"))); 1043 1044 int i = 0; 1045 String deliverUrl = null; 1046 while((deliverUrl = properties.getProperty("" + i)) != null) 1047 { 1048 urls.add(deliverUrl); 1049 i++; 1050 } 1051 1052 } 1053 catch(Exception e) 1054 { 1055 logger.error("Error loading properties from string. Reason:" + e.getMessage()); 1056 e.printStackTrace(); 1057 } 1058 } 1059 else 1060 { 1061 int i = 0; 1062 String deliverUrl = null; 1063 while((deliverUrl = CmsPropertyHandler.getProperty("publicDeliverUrl." + i)) != null) 1064 { 1065 urls.add(deliverUrl); 1066 i++; 1067 } 1068 } 1069 1070 return urls; 1071 } 1072 1073 public static String getPropertySetValue(String key) 1074 { 1075 String value = null; 1076 1077 String cacheKey = "" + key; 1078 String cacheName = "propertySetCache"; 1079 value = (String )CacheController.getCachedObject(cacheName, cacheKey); 1081 if(value != null) 1082 { 1083 logger.info("Returning property " + cacheKey + " value " + value); 1084 return value; 1085 } 1086 1087 value = propertySet.getString(key); 1088 logger.info("propertySetCache did not have value... refetched:" + value); 1089 1090 CacheController.cacheObject(cacheName, cacheKey, value); 1091 1092 return value; 1093 } 1094 1095 public static String getAnonymousPassword() 1096 { 1097 String password = "anonymous"; 1098 String specifiedPassword = getServerNodeProperty("deliver", "security.anonymous.password", true, "anonymous"); 1100 if(specifiedPassword != null && !specifiedPassword.equalsIgnoreCase("") && specifiedPassword.indexOf("security.anonymous.password") == -1) 1101 password = specifiedPassword; 1102 1103 1105 return password; 1106 } 1107 1108 public static String getAnonymousUser() 1109 { 1110 String userName = "anonymous"; 1111 String specifiedUserName = getServerNodeProperty("deliver", "security.anonymous.username", true, "anonymous"); 1113 if(specifiedUserName != null && !specifiedUserName.equalsIgnoreCase("") && specifiedUserName.indexOf("security.anonymous.username") == -1) 1114 userName = specifiedUserName; 1115 1116 1118 return userName; 1119 } 1120 1121} 1122 | Popular Tags |