001: /**
002: * $Id: MAPConfigProperties.java,v 1.5 2006/08/05 13:42:40 ss150821 Exp $
003: * Copyright 2002 Sun Microsystems, Inc. Allrights reserved. Use of
004: * this product is subjectto license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users Subject to Standard License
006: * Terms and Conditions.
007: *
008: * Sun, Sun Microsystems, the Sun logo, and Sun ONE are trademarks or
009: * registered trademarks of Sun Microsystems,Inc. in the United States
010: * and other countries.
011: */package com.sun.mobile.util;
012:
013: import java.util.Map;
014: import java.util.Properties;
015: import java.io.FileInputStream;
016: import java.io.FileNotFoundException;
017: import java.io.IOException;
018: import java.io.InputStream;
019:
020: import javax.servlet.ServletContext;
021:
022: public class MAPConfigProperties {
023: private static Properties props = new Properties();
024:
025: private static String CONFIG_PROPERTIES_NAME = "config.properties";
026:
027: private static String MAP_CONFIG_PROPERTIES_SUNOS = "/etc/opt/SUNWma/"
028: + CONFIG_PROPERTIES_NAME;
029:
030: private static String MAP_CONFIG_PROPERTIES_LINUX = "/etc/opt/sun/mobileaccess/"
031: + CONFIG_PROPERTIES_NAME;
032:
033: /*static
034: {
035: props = new Properties();
036:
037: try {
038: props.load(new FileInputStream(MAP_CONFIG_PROPERTIES_SUNOS));
039: } catch (Exception e) {
040: try {
041: props.load(new FileInputStream(MAP_CONFIG_PROPERTIES_LINUX));
042: } catch (Exception ee) {
043: ee.printStackTrace();
044: }
045: }
046: }*/
047:
048: public static void loadProperties(ServletContext ctxt) {
049:
050: InputStream propStream = ctxt
051: .getResourceAsStream("/WEB-INF/classes/"
052: + CONFIG_PROPERTIES_NAME);
053:
054: if (propStream == null) {
055: // config.properties does not exist in the WEB-INF/classes
056: try {
057: propStream = new FileInputStream(
058: MAP_CONFIG_PROPERTIES_SUNOS);
059: } catch (FileNotFoundException e) {
060: try {
061: propStream = new FileInputStream(
062: MAP_CONFIG_PROPERTIES_LINUX);
063: } catch (Exception ee) {
064: ee.printStackTrace();
065: }
066: }
067: }
068:
069: try {
070: props.load(propStream);
071: } catch (IOException e) {
072: e.printStackTrace();
073: }
074: }
075:
076: /**
077: * Get the value for "key"
078: */
079: public static String get(String key) {
080: return ((String) props.get(key));
081: }
082:
083: /**
084: * Get the value for "key". If not found, return defaultValue
085: */
086: public static String get(String key, String defaultValue) {
087: String value = (String) props.get(key);
088: if (value == null) {
089: value = defaultValue;
090: }
091:
092: return value;
093: }
094:
095: /**
096: * Return the Map of keys & properties
097: */
098: public static Map getAll() {
099: return ((Map) props.clone());
100: }
101: }
|