
org.yaoqiang.util.Utils Maven / Gradle / Ivy
package org.yaoqiang.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
/**
* Utils
*
* @author Shi Yaoqiang([email protected])
*/
public class Utils {
public static void saveToConfigureFile(String key, String value) {
Properties props = loadProperties(Constants.YAOQIANG_CONF_FILE);
props.put(key, value);
FileOutputStream out = null;
try {
out = new FileOutputStream(new File(Constants.YAOQIANG_USER_HOME + File.separator + Constants.YAOQIANG_CONF_FILE));
props.store(out, "Yaoqiang BPMN Editor Configuration");
} catch (IOException e1) {
e1.printStackTrace();
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
public static void removeConfigure(String key) {
Properties props = loadProperties(Constants.YAOQIANG_CONF_FILE);
props.remove(key);
FileOutputStream out = null;
try {
out = new FileOutputStream(new File(Constants.YAOQIANG_USER_HOME + File.separator + Constants.YAOQIANG_CONF_FILE));
props.store(out, "Yaoqiang BPMN Editor Configuration");
} catch (IOException e1) {
e1.printStackTrace();
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
public static void saveConfigureFile() {
String filename = Constants.YAOQIANG_USER_HOME + File.separator + Constants.YAOQIANG_CONF_FILE;
FileOutputStream out = null;
try {
out = new FileOutputStream(new File(filename));
Constants.SETTINGS.store(out, "Yaoqiang BPMN Editor Configuration");
} catch (IOException e1) {
e1.printStackTrace();
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
public static Properties loadProperties(String propertyFile) {
File file = new File(Constants.YAOQIANG_USER_HOME + File.separator + propertyFile);
Properties props = new Properties();
if (file.exists()) {
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
props.load(fis);
fis.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
return props;
}
public static void saveConfigure(String key, String value, String propertyFile, String comment) {
Properties props = loadProperties(propertyFile);
props.put(key, value);
FileOutputStream out = null;
try {
File configFile = new File(Constants.YAOQIANG_USER_HOME + File.separator + propertyFile);
out = new FileOutputStream(configFile);
props.store(out, comment);
} catch (IOException e1) {
e1.printStackTrace();
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
public static void removeConfigure(String key, String propertyFile, String comment) {
Properties props = loadProperties(propertyFile);
props.remove(key);
FileOutputStream out = null;
try {
File configFile = new File(Constants.YAOQIANG_USER_HOME + File.separator + propertyFile);
out = new FileOutputStream(configFile);
props.store(out, comment);
} catch (IOException e1) {
e1.printStackTrace();
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
public static String getUserPassword(String username) {
return Encryptor.decrypt(Constants.SETTINGS.getProperty("pwd" + Encryptor.encrypt(username), ""));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy