?? sysconfig.java
字號:
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package eti.bi.common.System;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import eti.bi.alphaminer.core.Plugin.Plugin;
import eti.bi.alphaminer.core.Plugin.PluginFactory;
import eti.bi.alphaminer.core.help.AlphaminerHelpHandler;
import eti.bi.alphaminer.operation.operator.INodeInfo;
import eti.bi.common.Constants;
import eti.bi.common.SystemAdapter;
import eti.bi.common.Locale.Resource;
import eti.bi.exception.BaseException;
import eti.bi.util.ResourceLoader;
/**
*
* This is a class that manages the system configuration of the BI platform. The
* location of the configuration file is stored in the Constants.CONFIG_FILE.
* Other classes can just get the system config by calling the static method
* getProperty of this class.
*
* TODO: Implement dynamic loading of configuration file such that the new
* modified value can be effected without restarting server.
*
* @since 1.0
* @version $Revision$ $Date$
* @author $Author$
*/
public class SysConfig {
private static String HOME = "";
private static String CONFIG_HOME = "config";
private static Properties exceptionMessage;
public static Properties m_ConfigProp;
private static String currentworkspacepath;
/**
* Initialize this class by loading the values from the configuration the
* first time.
*/
public static void loadConfig(String aConfigFile) throws IOException {
File file = new File(aConfigFile);
InputStream is = new FileInputStream(file);
m_ConfigProp = new Properties();
m_ConfigProp.load(is);
is.close();
}
public static void loadExceptionMessage(String exceptionMessageFile) {
File exceptionFile = new File(exceptionMessageFile);
if((!exceptionFile.exists())||(!exceptionFile.canRead())) {
System.out.println("Can't load the exception message file: "+exceptionMessageFile);
SysLog.error("Can't load the exception message file: "+exceptionMessageFile);
return;
}
InputStream in=null;
try {
in = new FileInputStream(exceptionFile);
exceptionMessage = new Properties();
exceptionMessage.load(in);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
if(in!=null) {
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public static void setHome(String a_Home_Path) {
HOME = a_Home_Path;
CONFIG_HOME = HOME + File.separator + "config";
}
public static String getHome() {
return HOME;
}
public static String getOperatorImageHome() {
return ResourceLoader.getPath() + File.separator + "images" + File.separator;
}
public static String getConfigHome() {
return CONFIG_HOME;
}
public static String getSystemHome() {
return HOME+File.separator+"System";
}
public static void setCurrentWorkSpacePath(String aPath) {
currentworkspacepath = aPath;
}
public static String getLocaleHomen() {
return CONFIG_HOME+File.separator+"Locale";
}
/**
* init Alphaminer help
* @throws MalformedURLException
* */
public static void initAlphaminerHelp() throws MalformedURLException {
AlphaminerHelpHandler alphaminerhelp= AlphaminerHelpHandler.getInstance();
alphaminerhelp.reset();
//system help
URL url = SystemAdapter.JarURL(Resource.getWholePath()+"!/AlphaminerHelp/"+"AlphaMiner.hs");
ClassLoader classloader = SysConfig.class.getClassLoader();
alphaminerhelp.addUrl(classloader, url);
//plugin help
List<Plugin> plugins = PluginFactory.getAllRegisteredPlugins();
Iterator<Plugin> iterator = plugins.iterator();
Plugin plugin;
while(iterator.hasNext()) {
plugin = iterator.next();
classloader = plugin.getClassLoader();
url = SystemAdapter.JarURL(plugin.getArchive().getName()+"!/"+Resource.getLocalePathinJar(plugin.getPluginLocalePath())+"AlphaminerHelp/AlphaMiner.hs");
alphaminerhelp.addUrl(classloader, url);
}
AlphaminerHelpHandler.getInstance().create();
}
/**
* Gets a property with the key from the system configuration.
*
* @param key
* the key of the property
* @return String the value of the property. null if no such key.
*/
public static String getProperty(String key) {
if (key == null || key.trim().length() <= 0) {
return "";
}
//File aFile = new File(HOME);
if(key.equals("temp")) {
return HOME+File.separator+"temp";
}
else if(key.equals("SYSTEM_VARIABLE_HOME")) {
return CONFIG_HOME+File.separator+"SystemVariable";
}
else if (key.equals("TEMP_CASES")) {
return SystemTempFile.getCaseTempHome();
}
else if(key.equals("TEMP_PLUGIN_LIB")) {
return SystemTempFile.getTempLibHome();
} else if (key.equals(Constants.BIML_REPOSITORY_KEY)) {
return currentworkspacepath;
} else if (key.equals("workspacesdefinition")) {
return CONFIG_HOME + File.separator + "Workspace" + File.separator + "workspaces.xml";
} else if(key.equals("localesdefinition")) {
return CONFIG_HOME + File.separator + "Locale" + File.separator + "Locale.xml";
}
else if (key.equals("PLUGIN_HOME")) {
return HOME + File.separator + m_ConfigProp.getProperty("PLUGIN_HOME");
}else if(key.equals("ALPHAMINERHELP")) {
return SystemAdapter.JarURLString("jar:file:/"+Resource.getWholePath()+"/AlphaminerHelp.jar!/"+"AlphaMiner.hs");
}else {
return escapeBackSlash(expandProperty(m_ConfigProp.getProperty(key)));
}
}
public static String getExceptionMessage(String aMessage) throws BaseException{
if(exceptionMessage==null) {
throw new BaseException("Exception message hasn't been initialized!");
}
return exceptionMessage.getProperty(aMessage);
}
/**
* clear temp file when quit this application
* */
public synchronized static void clearTempFile() {
SystemTempFile.clear();
}
/**
* delete all files or all directory
* @return
* */
public synchronized static void deleteAllFile(File file) {
if(file==null||!file.exists()) {
return;
}
if(file.isDirectory()) {
File[] files = file.listFiles();
for(int i=0;i<files.length;i++) {
deleteAllFile(files[i]);
}
file.delete();
}
else if(file.isFile()) {
file.delete();
}
}
/**
* Gets a property with the key from the system configuration. If no such
* key is found, then return the defaultValue specified by the user.
*
*
* @param key
* the key of the property
* @return String the value of the property or defaultValue if no such key.
*/
public static String getProperty(String key, String defaultValue) {
return escapeBackSlash(expandProperty(m_ConfigProp.getProperty(key, defaultValue)));
}
public static void loadConfig(InputStream inStream) throws IOException {
m_ConfigProp.load(inStream);
}
public static void store(OutputStream out, String header) throws IOException {
m_ConfigProp.store(out, header);
}
public static Enumeration propertyNames() {
return m_ConfigProp.propertyNames();
}
public static Object setProperty(String key, String value) {
return m_ConfigProp.setProperty(key, value);
}
public static String expandProperty(String s) {
if (s == null)
return null;
int i = s.indexOf("${", 0);
if (i == -1)
return s;
StringBuffer stringbuffer = new StringBuffer(s.length());
int j = s.length();
int k = 0;
while (i < j) {
if (i > k) {
stringbuffer.append(s.substring(k, i));
k = i;
}
int l;
for (l = i + 2; l < j && s.charAt(l) != '}'; l++)
;
if (l == j) {
stringbuffer.append(s.substring(i, l));
break;
}
String s1 = s.substring(i + 2, l);
if (s1.equals("/")) {
stringbuffer.append(File.separatorChar);
} else {
String s2 = System.getProperty(s1);
if (s2 != null)
stringbuffer.append(s2);
// else
// throw new Exception("unable to expand property " + s1);
}
k = l + 1;
i = s.indexOf("${", k);
if (i == -1) {
if (k < j)
stringbuffer.append(s.substring(k, j));
break;
}
}
return stringbuffer.toString();
}
private static String escapeBackSlash(String aString) {
if (aString == null)
return null;
StringBuffer sb = new StringBuffer();
int i = aString.indexOf('\\');
if (i < 0)
return aString;
sb.append(aString.substring(0, i)).append("\\\\").append(escapeBackSlash(aString.substring(i + 1)));
return sb.toString();
}
public static String getAlphaminerVersion() {
return "2.0";
}
public static URL getAlgorithmURL(INodeInfo nodeinfo) throws MalformedURLException {
if(nodeinfo==null||nodeinfo.getJafFile()==null) {
return new URL("file",null,getConfigHome()+File.separator+"Algorithms"+File.separator+"algorithms.xml");
}
else{
return new URL("jar:file:/"+nodeinfo.getJafFile().getName()+"!/"+PluginFactory.getPlugin(nodeinfo.getPluginIdex()).getPluginConfigPath()+"/Algorithms/algorithms.xml");
}
}
public static void exit() {
clearTempFile();
SystemVariable.Clean();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -