package com.smtscript.lib; import java.util.Map.Entry; import org.mozilla.javascript.NativeObject; import com.smtscript.utils.SMTStatic; public class JSStaticSystem extends JSStaticAbstract { private static String PROP_IN_FILE_PERFIX = "B34556BC3DBD4CC9B4C1C05FD0AB1DB3:"; public String getSysProperty(String key) throws Exception { String value = System.getProperty(key); if(value == null) throw new Exception("can't find system property : " + key); return value; } public String getSysProperty(String key, String defVal) throws Exception { String value = System.getProperty(key); if(value == null) return defVal; return value; } public void setSysProperty(String key, String value) { System.setProperty(key, value); } public String getEnvValue(String key) { return System.getenv(key); } public boolean hasSysProperty(String key) { String value = System.getProperty(key); return (value != null); } public void setSysPropertis(NativeObject nvConfig) { for(Entry entry : nvConfig.entrySet()) { String key = (String)entry.getKey(); String value = System.getProperty(key); if(value != null) { if(value.startsWith(PROP_IN_FILE_PERFIX)) { value = value.substring(PROP_IN_FILE_PERFIX.length()); value = SMTStatic.readAllText(value, "UTF-8"); } SMTStatic.putJSNotNullValue(nvConfig, key, value); } } } public void pushSysPropertis(NativeObject nvConfig) { for(Entry entry : nvConfig.entrySet()) { String key = (String)entry.getKey(); String value = (String)entry.getValue(); System.setProperty(key, value); } } }