001: package com.sun.portal.util;
002:
003: import java.io.*;
004: import java.util.*;
005:
006: public class Platform {
007:
008: public static String fs = null;
009: public static char fsChar;
010: public static String pathSep = null;
011: public static char pathSepChar;
012: public static String name = null;
013: public static String psConfDir = null;
014:
015: private static Properties psConfig = null;
016: private static ResourceBundle props = null;
017:
018: static {
019: try {
020: name = System.getProperty("os.name");
021:
022: try {
023: if (name.toLowerCase().startsWith("win"))
024: props = ResourceBundle.getBundle(
025: "com.sun.portal.util.platform", new Locale(
026: "win"));
027: else if (name.equals("HP-UX"))
028: props = ResourceBundle.getBundle(
029: "com.sun.portal.util.platform", new Locale(
030: "hp"));
031: else
032: props = ResourceBundle.getBundle(
033: "com.sun.portal.util.platform", new Locale(
034: name.toLowerCase()));
035: } catch (MissingResourceException e) {
036: props = ResourceBundle
037: .getBundle("com.sun.portal.util.platform");
038: }
039:
040: try {
041: fs = props.getString("portal.util.os.file.seperator");
042: fsChar = props.getString(
043: "portal.util.os.file.seperator").charAt(0);
044: } catch (MissingResourceException ee) {
045: fs = File.separator;
046: fsChar = File.separatorChar;
047: }
048:
049: try {
050: pathSep = props
051: .getString("portal.util.os.classpath.seperator");
052: pathSepChar = props.getString(
053: "portal.util.os.classpath.seperator").charAt(0);
054: } catch (MissingResourceException ee) {
055: pathSep = File.pathSeparator;
056: pathSepChar = File.pathSeparatorChar;
057: }
058:
059: try {
060: name = props.getString("portal.util.os.platform");
061: } catch (MissingResourceException ee) {
062: name = System.getProperty("os.name");
063: }
064:
065: } catch (MissingResourceException e) {
066: fs = File.separator;
067: pathSep = File.pathSeparator;
068: name = System.getProperty("os.name");
069: }
070: }
071:
072: public static String getCommand(String command) {
073: String cmd = null;
074: try {
075: cmd = process(props.getString("portal.util.os.command."
076: + command));
077: } catch (Exception e) {
078: return command;
079: }
080: return cmd;
081: }
082:
083: private static String process(String cmd) {
084: String retstr = null;
085: if (psConfig == null) {
086: try {
087: psConfig = getProperties(psConfDir + fs
088: + "PSConfig.properties");
089: } catch (FileNotFoundException e) {
090: try {
091: psConfig = getProperties("PSConfig.properties");
092: } catch (FileNotFoundException ee) {
093: psConfig = null;
094: } catch (IOException Ioe) {
095: psConfig = null;
096: }
097: } catch (IOException ee) {
098: psConfig = null;
099: }
100: }
101: if (psConfig != null) {
102: for (Enumeration en = psConfig.propertyNames(); en
103: .hasMoreElements();) {
104: String str = (String) en.nextElement();
105: if (cmd.startsWith(str)) {
106: retstr = psConfig.getProperty(str);
107: retstr = retstr.concat(cmd.substring(str.length()));
108: }
109: }
110: if (retstr == null)
111: return cmd;
112: } else {
113: return cmd;
114: }
115: return retstr;
116:
117: }
118:
119: private static Properties getProperties(String propsFileName)
120: throws FileNotFoundException, IOException {
121: Properties prs = null;
122: if (prs == null) {
123: InputStream in = new FileInputStream(propsFileName);
124: if (in != null) {
125: prs = new Properties();
126: prs.load(in);
127: in.close();
128: }
129: }
130: return prs;
131: }
132:
133: }
|