001: /*
002: * @(#)SystemProperties.java 1.10 01/08/01 Sun Microsystems
003: *
004: * Please read the License Agreement and other supplemental license terms, if
005: * any, accompanying this software package before using any of the software
006: * provided. If you do not agree to the terms of the License Agreement or any
007: * other supplemental terms, please promptly destroy or return the software to
008: * Sun Microsystems, Inc.
009: *
010: * "CONFIDENTIAL AND PROPRIETARY" Copyright ? 2001 Sun Microsystems, Inc. All
011: * rights reserved.
012: */
013:
014: package com.sun.portal.util;
015:
016: import java.io.File;
017: import java.io.FileInputStream;
018: import java.util.Properties;
019: import java.util.logging.Level;
020: import java.util.logging.Logger;
021:
022: import com.sun.portal.log.common.PortalLogger;
023:
024: /*
025: * <P> Utility class that provides access to system properties for the portal
026: * server srap.
027: *
028: * <P> Allows access to property values and properties objects loaded from: <UL>
029: * <LI><CODE> /etc/opt/SUNWportal/platform.conf.instance_name </CODE> (Platform)
030: * </UL>
031: *
032: */
033:
034: public class SystemProperties {
035: // static Logger logger = Logger.getLogger("com.sun.portal.sra.config");
036: private static Logger logger = PortalLogger
037: .getLogger(SystemProperties.class);
038:
039: private static Properties platformProp = new Properties();
040:
041: static {
042: init(System.getProperty("SRAP_CONFIG_DIR",
043: "/etc/opt/SUNWportal")
044: + File.separatorChar
045: + "platform.conf."
046: + System.getProperty("conf.suffix", "default"));
047: }
048:
049: public static void init(String filename) {
050:
051: FileInputStream stream = null;
052: try {
053:
054: File file = new File(filename);
055: stream = new FileInputStream(file);
056: platformProp.load(stream);
057: stream.close();
058: } catch (Exception e) {
059: System.err.println(e.getMessage());
060: // logger.severe(e.getMessage());
061: Object[] params = { e.getMessage() };
062: logger.log(Level.SEVERE, "PSSR_CSPU095", params);
063: } finally {
064: if (stream != null) {
065: try {
066: stream.close();
067: } catch (Exception e) {
068: System.err.println(e.getMessage());
069: // logger.severe(e.getMessage());
070: Object[] params = { e.getMessage() };
071: logger.log(Level.SEVERE, "PSSR_CSPU096", params);
072: }
073: }
074: }
075: }
076:
077: /*
078: * <P> Get system property.
079: *
080: * @param key key to search for. @return property value
081: */
082:
083: public static String get(String key) {
084:
085: // Fix for 4908629 - Sandeep Soni
086: String s = platformProp.getProperty(key, null);
087:
088: if (s != null)
089: s = s.trim();
090:
091: return s;
092: }
093:
094: /*
095: * <P> Get system property.
096: *
097: * @param key key @param def default value @return property value
098: */
099:
100: public static String get(String key, String def) {
101:
102: // Fix for 4908629 - Sandeep Soni
103: String s = platformProp.getProperty(key, def);
104:
105: if (s != null)
106: s = s.trim();
107:
108: return s;
109: }
110:
111: }
|