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.services;
006:
007: import com.iplanet.am.util.AdminUtils;
008: import com.sun.portal.rewriter.RewriterModule;
009: import com.sun.portal.rewriter.util.ConfigManager;
010: import com.sun.portal.rewriter.util.Constants;
011: import com.sun.portal.rewriter.util.StringHelper;
012:
013: import java.lang.reflect.Constructor;
014: import java.util.Properties;
015: import java.util.logging.Handler;
016: import java.util.logging.Level;
017: import java.util.logging.Logger;
018: import java.io.File;
019:
020: public class DataServiceHelper {
021: public static Properties getDefaultIDSProps() {
022: final Properties props = new Properties();
023: props.setProperty(Constants.PROPERTY_DATA_SOURCE_TYPE,
024: DataService.IDS);
025:
026: return props;
027: }//getDefaultIDSProps()
028:
029: public static Properties getDefaultIDSAMEProps() {
030: final Properties props = new Properties();
031: props.setProperty(Constants.PROPERTY_DATA_SOURCE_TYPE,
032: DataService.IDSAME);
033:
034: props.setProperty(DataService.PROPERTY_DATA_SERIVCE_USER,
035: StringHelper.normalize(AdminUtils.getAdminDN()));
036: byte[] adminUtilPassword = AdminUtils.getAdminPassword();
037: adminUtilPassword = (adminUtilPassword == null) ? Constants.EMTPY_BYTE_ARRAY
038: : adminUtilPassword;
039: props.setProperty(
040: DataService.PROPERTY_DATA_SERIVCE_USER_PASSWORD,
041: new String(adminUtilPassword));
042: return props;
043: }//getDefaultIDSAMEProps()
044:
045: public static Properties getIDSAMEProps(final String aUserName,
046: final String aPassword) {
047: final Properties props = new Properties();
048: props.setProperty(Constants.PROPERTY_DATA_SOURCE_TYPE,
049: DataService.IDSAME);
050:
051: props.setProperty(DataService.PROPERTY_DATA_SERIVCE_USER,
052: StringHelper.normalize(aUserName));
053: props.setProperty(
054: DataService.PROPERTY_DATA_SERIVCE_USER_PASSWORD,
055: aPassword);
056: return props;
057: }//getIDSAMEProps()
058:
059: public static Properties getDefaultFileProps() {
060: final Properties props = new Properties();
061: props.setProperty(Constants.PROPERTY_DATA_SOURCE_TYPE,
062: Constants.FILE);
063: props.setProperty(DataService.PROPERTY_DATA_SERVICE_BASE, ".");
064:
065: return props;
066: }//getDefaultFileProps()
067:
068: public final static void initLogSystem(final Class aHandlerClass,
069: String path, String logLevel) {
070: try {
071: //it is mandatory to see that, by the time first call to debug class is made
072: //ConfigManager would have been initialized properly..
073: if (path == null || path.length() == 0) {
074: throw new LoggingInitializationException(
075: "Debug Log Location Not Specified.");
076: } else {
077: File dir = new File(path);
078: if (!dir.exists()) {
079: dir.mkdirs();
080: }
081: }
082: String debugFile = ((path != null) ? path
083: + (path.endsWith("/") ? "" : "/") : "")
084: + ConfigManager.getModulePrefixID();
085:
086: String debugFileExt = ConfigManager.getModuleSuffixID();
087: if (debugFileExt.length() > 0) {
088: debugFileExt = "." + debugFileExt;
089: }
090:
091: Handler lHandler = createHandler(aHandlerClass, debugFile
092: + debugFileExt);
093:
094: final Level bLevel;
095: if (logLevel != null) {
096: bLevel = Level.parse(logLevel);
097: } else {
098: bLevel = lHandler.getLevel();
099: }
100:
101: /*Logger.getLogger(RewriterModule.REWRITER_LOG).setLevel(bLevel);
102:
103: Logger.getLogger(RewriterModule.REWRITER_LOG_REST).addHandler(lHandler);
104:
105: Logger.getLogger(RewriterModule.REWRITER_LOG_RULRESET_INFO).addHandler(createHandler(aHandlerClass,
106: debugFile + "_RuleSetInfo" + debugFileExt));
107:
108: Logger.getLogger(RewriterModule.REWRITER_LOG_URI_INFO).addHandler(createHandler(aHandlerClass,
109: debugFile + "_URIInfo" + debugFileExt));
110:
111: Logger.getLogger(RewriterModule.REWRITER_LOG_ORIGINAL_PAGES).addHandler(createHandler(aHandlerClass,
112: debugFile + "_OriginalPages" + debugFileExt));
113:
114: Logger.getLogger(RewriterModule.REWRITER_LOG_UNAFFECTED_PAGES).addHandler(createHandler(aHandlerClass,
115: debugFile + "_UnaffectedPages" + debugFileExt));
116:
117: Logger.getLogger(RewriterModule.REWRITER_LOG_REWRITTEN_PAGES).addHandler(createHandler(aHandlerClass,
118: debugFile + "_RewrittenPages" + debugFileExt));*/
119:
120: } catch (LoggingInitializationException lie) {
121: lie.printStackTrace();
122: } catch (Exception e) {
123: System.out.println("Unable to create instance of "
124: + aHandlerClass.getClass());
125: e.printStackTrace();
126: }
127: }
128:
129: public final static void initLogSystem(final Class aHandlerClass) {
130: /*try {
131: //it is mandatory to see that, by the time first call to debug class is made
132: //ConfigManager would have been initialized properly..
133: String debugFile = ConfigManager.getModulePrefixID();
134:
135: String debugFileExt = ConfigManager.getModuleSuffixID();
136: if (debugFileExt.length() > 0) {
137: debugFileExt = "." + debugFileExt;
138: }
139:
140: Handler lHandler = createHandler(aHandlerClass,
141: debugFile + debugFileExt);
142:
143: final Level bLevel = lHandler.getLevel();
144:
145: Logger.getLogger(RewriterModule.REWRITER_LOG).setLevel(bLevel);
146:
147: Logger.getLogger(RewriterModule.REWRITER_LOG_REST).addHandler(lHandler);
148:
149: Logger.getLogger(RewriterModule.REWRITER_LOG_RULRESET_INFO).addHandler(createHandler(aHandlerClass,
150: debugFile + "_RuleSetInfo" + debugFileExt));
151:
152: Logger.getLogger(RewriterModule.REWRITER_LOG_URI_INFO).addHandler(createHandler(aHandlerClass,
153: debugFile + "_URIInfo" + debugFileExt));
154:
155: Logger.getLogger(RewriterModule.REWRITER_LOG_ORIGINAL_PAGES).addHandler(createHandler(aHandlerClass,
156: debugFile + "_OriginalPages" + debugFileExt));
157:
158: Logger.getLogger(RewriterModule.REWRITER_LOG_UNAFFECTED_PAGES).addHandler(createHandler(aHandlerClass,
159: debugFile + "_UnaffectedPages" + debugFileExt));
160:
161: Logger.getLogger(RewriterModule.REWRITER_LOG_REWRITTEN_PAGES).addHandler(createHandler(aHandlerClass,
162: debugFile + "_RewrittenPages" + debugFileExt));
163: } catch (final Exception e) {
164: System.out.println("Unable to create instance of " +
165: aHandlerClass.getClass());
166: e.printStackTrace();
167: }*/
168: }//initLogSystem()
169:
170: private static final Handler createHandler(
171: final Class aHandlerClass, final String aFileName)
172: throws Exception {
173: Constructor constructor = aHandlerClass
174: .getConstructor(new Class[] { String.class });
175: return (Handler) constructor
176: .newInstance(new Object[] { aFileName });
177: }//createHandler()
178:
179: }//class DataServiceHelper
|