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.util;
006:
007: import java.io.ByteArrayInputStream;
008: import java.io.ByteArrayOutputStream;
009: import java.io.IOException;
010: import java.io.InputStream;
011: import java.util.Properties;
012:
013: public final class ConfigManager {
014: private static Properties props = new Properties();
015: private static String[] moduleID;
016:
017: public static void init(final Properties aProps) {
018: props = aProps;
019: moduleID = StringHelper.tokenize(props
020: .getProperty(Constants.PROPERTY_MODULE_ID), "|", true,
021: 2);
022: }//init()
023:
024: public static String getModulePrefixID() {
025: return moduleID[0];
026: }//getModulePrefixID()
027:
028: public static String getModuleSuffixID() {
029: return moduleID[1];
030: }//getModuleSuffixID()
031:
032: public static String getLogLocation() {
033: return props.getProperty(Constants.LOG_LOCATION);
034: }
035:
036: public static String getLogLevel() {
037: return props.getProperty(Constants.LOG_LEVEL);
038:
039: }
040:
041: public static String getProperty(final String aKey) {
042: return getProperty(aKey, "");
043: }//getProperty()
044:
045: public static String getProperty(final String aKey,
046: final String aDefaultValue) {
047: return props.getProperty(aKey, aDefaultValue);
048: }//getProperty()
049:
050: public static boolean getBoolean(final String aKey) {
051: return getBoolean(aKey, false);
052: }//getBoolean()
053:
054: public static boolean getBoolean(final String aKey,
055: final boolean aDefaultValue) {
056: return Boolean
057: .valueOf(
058: getProperty(aKey, new Boolean(aDefaultValue)
059: .toString())).booleanValue();
060: }//getBoolean()
061:
062: public static Properties readProps(final String aResourceName) {
063: final ByteArrayInputStream bIn = new ByteArrayInputStream(
064: bootStrapResourceReader(aResourceName));
065:
066: final Properties props = new Properties();
067: try {
068: props.load(bIn);
069: } catch (IOException e) {
070: e.printStackTrace();
071: }
072:
073: return props;
074: }//readProps()
075:
076: /**
077: * copied the code from Resource Class
078: */
079: private static byte[] bootStrapResourceReader(final String aFileName) {
080: try {
081: InputStream in = (ConfigManager.class)
082: .getResourceAsStream(aFileName);
083: byte[] data = new byte[2048];
084: ByteArrayOutputStream bOut = new ByteArrayOutputStream();
085:
086: int count = 0;
087: while ((count = in.read(data)) != -1) {
088: bOut.write(data, 0, count);
089: }//while loop
090:
091: data = bOut.toByteArray();
092: bOut.close();
093: in.close();
094:
095: return data;
096: } catch (Exception e) {
097: componentPanic("Error Reading BootStrap Properties File: "
098: + aFileName, e);
099: return new byte[0];
100: }//try/catch
101: }//bootStrapResourceReader()
102:
103: public static void componentPanic(final String aMessage,
104: final Exception e) {
105: e.printStackTrace();
106: throw new RuntimeException(aMessage + "\n" + e.toString());
107: }//componentPanic()
108:
109: public static void main(String[] args) {
110: System.out
111: .println(new String(bootStrapResourceReader(args[0])));
112: }//main()
113:
114: }//class ConfigManager
|