001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.rewriter;
006:
007: import com.sun.portal.rewriter.rom.RuleSetManager;
008: import com.sun.portal.rewriter.services.DataService;
009: import com.sun.portal.rewriter.services.DataServiceFactory;
010: import com.sun.portal.rewriter.services.DataServiceHelper;
011: import com.sun.portal.rewriter.util.ConfigManager;
012: import com.sun.portal.rewriter.util.Constants;
013: import com.sun.portal.rewriter.util.i18n.EncodingHelper;
014: import com.sun.portal.rewriter.util.i18n.MIMEHelper;
015:
016: import java.util.Properties;
017:
018: /**
019: * Has the info related to initialization of the rewriter component
020: */
021: public class RewriterModule {
022: public static final String REWRITER_LOG = "debug.com.sun.portal.rewriter";
023: public static final String REWRITER_LOG_REST = REWRITER_LOG
024: + ".rest";
025: public static final String REWRITER_LOG_RULRESET_INFO = REWRITER_LOG
026: + ".rulesetinfo";
027: public static final String REWRITER_LOG_URI_INFO = REWRITER_LOG
028: + ".uriinfo";
029: public static final String REWRITER_LOG_ORIGINAL_PAGES = REWRITER_LOG
030: + ".original";
031: public static final String REWRITER_LOG_REWRITTEN_PAGES = REWRITER_LOG
032: + ".rewritten";
033: public static final String REWRITER_LOG_UNAFFECTED_PAGES = REWRITER_LOG
034: + ".unaffected";
035:
036: public static final String RESOURCE_HOME = "/resources";
037:
038: public static final String RESOURCE_RULESET_TEMPLATE_LOCATION = RESOURCE_HOME
039: + "/RuleSetTemplate.xml";
040: public static final String RULESET_TEMPLATE_ID = "ruleset_template";
041:
042: public static final String RESOURCE_GENERIC_RULESET_LOCATION = RESOURCE_HOME
043: + "/GenericRuleSet.xml";
044: public static final String GENRIC_RULESET_ID = "generic_ruleset";
045:
046: public static final String RESOURCE_DEFAULT_RULESET_LOCATION = RESOURCE_HOME
047: + "/DefaultRuleSet.xml";
048: public static final String DEFAULT_RULESET_ID = "default_ruleset";
049:
050: public static final String[][] PORTAL_RULESET_SPEC = {
051: { RESOURCE_GENERIC_RULESET_LOCATION, GENRIC_RULESET_ID },
052: // {RESOURCE_DEFAULT_RULESET_LOCATION, DEFAULT_RULESET_ID},
053: { RESOURCE_RULESET_TEMPLATE_LOCATION, RULESET_TEMPLATE_ID }, };
054:
055: public static final String RESOURCE_RULESET_DTD_LOCATION = RESOURCE_HOME
056: + "/RuleSet.dtd";
057: public static final String RESOURCE_RULESET_V62_DTD_LOCATION = RESOURCE_HOME
058: + "/RuleSetV62.dtd";
059:
060: public static final String RESOURCE_CONVERT_EXPRESSTION_FUNCTION_LOCATION = RESOURCE_HOME
061: + "/ConvertExpression.js";
062: public static final String RESOURCE_URI_UTILS_LOCATION = RESOURCE_HOME
063: + "/URIUtils.js";
064: public static final String RESOURCE_CONVERT_SYSTEM_FUNCTION_LOCATION = RESOURCE_HOME
065: + "/ConvertSystem.js";
066:
067: public static final String RESOURCE_RWCLIPROPS_LOCATION = RESOURCE_HOME
068: + "/RuleSetCLI.properties";
069: public static final String RESOURCE_RWCLISPEC_LOCATION = RESOURCE_HOME
070: + "/RuleSetCLISpec.xml";
071: public static final String RESOURCE_RWCLISPEC_DTD_LOCATION = "/resources/CLISpec.dtd";
072:
073: public static final String RESOURCE_EXT_2_MIME_MAPPING_LOCATION = RESOURCE_HOME
074: + "/Ext2MimeMapping.properties";
075:
076: public static final String RESOURCE_JAVA_2_IANA_ENCODING_MAPPING_LOCATION = RESOURCE_HOME
077: + "/Java2IANAEncodingMappings.properties";
078:
079: public static final String RESOURCE_REWRITER_MODULE_PROPERTIES_LOCATION = RESOURCE_HOME
080: + "/RewriterModule.properties";
081:
082: public static final String PROPERTY_MIME_MAP_LOCATION = "MIME_MAP_LOCATION";
083: public static final String PROPERTY_ENCODING_MAP_LOCATION = "ENCODING_MAP_LOCATION";
084:
085: public static void init(final Properties aDataServiceProps,
086: final Properties aConfigProps, final Properties aI18NProps) {
087: ConfigManager.init(mergeProperties(aConfigProps,
088: getConfigProps()));
089: init(DataServiceFactory.create(aDataServiceProps),
090: aConfigProps, aI18NProps);
091: }//init()
092:
093: public static void init(final DataService aDataService,
094: final Properties aConfigProps, Properties aI18NProps) {
095: ConfigManager.init(mergeProperties(aConfigProps,
096: getConfigProps()));
097:
098: if (aI18NProps == null) {
099: aI18NProps = getMIMEAndEncodingProps();
100: }
101:
102: MIMEHelper.init(aI18NProps
103: .getProperty(PROPERTY_MIME_MAP_LOCATION));
104: EncodingHelper.init(aI18NProps
105: .getProperty(PROPERTY_ENCODING_MAP_LOCATION));
106: //BadCode..
107: new RewriterPool(new RuleSetManager(aDataService));
108: }//init()
109:
110: private static Properties getConfigProps() {
111: return ConfigManager
112: .readProps(RESOURCE_REWRITER_MODULE_PROPERTIES_LOCATION);
113: }//getConfigProps()
114:
115: private static Properties getMIMEAndEncodingProps() {
116: Properties lResult = new Properties();
117: lResult.put(PROPERTY_MIME_MAP_LOCATION,
118: RESOURCE_EXT_2_MIME_MAPPING_LOCATION);
119: lResult.put(PROPERTY_ENCODING_MAP_LOCATION,
120: RESOURCE_JAVA_2_IANA_ENCODING_MAPPING_LOCATION);
121:
122: return lResult;
123: }//getMIMEAndEncodingProps()
124:
125: private static Properties mergeProperties(
126: final Properties aCustomProps,
127: final Properties aDefaultProps) {
128: if (aCustomProps == null) {
129: return aDefaultProps;
130: }
131:
132: // If the user has supplid some treat them as overiding ones
133: // what ever the user has not supplide try taking them form
134: //default
135: aDefaultProps.putAll(aCustomProps);
136: return aDefaultProps;
137: }//mergeProperties()
138:
139: public static void initIDS() {
140: init(DataServiceHelper.getDefaultIDSProps(), null, null);
141: }//initIDS()
142:
143: public synchronized static void initIDSAME() {
144: //BugNo:4895102
145: if (RuleSetManager.getDefault() == null) {
146: init(DataServiceHelper.getDefaultIDSAMEProps(), null, null);
147: }
148: }//initIDSAME()
149:
150: public static void initIDSAME(final String aUserName,
151: final String aPassword) {
152: init(DataServiceHelper.getIDSAMEProps(aUserName, aPassword),
153: null, null);
154: }//initIDSAME()
155:
156: /**
157: * Initialize the rewriter component to be used with a File based service and
158: * default properties.
159: */
160: public static void initFile() {
161: init(DataServiceHelper.getDefaultFileProps(), null, null);
162: }//initFile()
163:
164: public static void initFile(String logLocation, String logLevel) {
165: Properties logProps = new Properties();
166: logProps.put(Constants.LOG_LOCATION, logLocation);
167: logProps.put(Constants.LOG_LEVEL, logLevel);
168: init(DataServiceHelper.getDefaultFileProps(), logProps, null);
169: }
170: }//Class RewriterModule
|