Code formatting

This commit is contained in:
Jindra Petk
2012-12-25 11:33:41 +01:00
parent 24a6b82a94
commit 14ae8e435c
643 changed files with 26017 additions and 27040 deletions

View File

@@ -23,105 +23,100 @@ import java.util.HashMap;
import java.util.List;
public class Configuration {
private static final String CONFIG_NAME="asdec.cfg";
private static final String REPLACEMENTS_NAME="replacements.ini";
private static HashMap<String,Object> config = new HashMap<String,Object>();
private static final String CONFIG_NAME = "asdec.cfg";
private static final String REPLACEMENTS_NAME = "replacements.ini";
private static HashMap<String, Object> config = new HashMap<String, Object>();
public static String getASDecHome() {
String dir = ".";//System.getProperty("user.home");
if (!dir.endsWith(File.separator)) dir += File.separator;
dir += "config" + File.separator;
return dir;
String dir = ".";//System.getProperty("user.home");
if (!dir.endsWith(File.separator)) {
dir += File.separator;
}
dir += "config" + File.separator;
return dir;
}
private static String getReplacementsFile() {
return getASDecHome() + REPLACEMENTS_NAME;
return getASDecHome() + REPLACEMENTS_NAME;
}
private static String getConfigFile() {
return getASDecHome() + CONFIG_NAME;
return getASDecHome() + CONFIG_NAME;
}
/**
* List of replacements
*/
public static java.util.List<Replacement> replacements = new ArrayList<Replacement>();
* List of replacements
*/
public static java.util.List<Replacement> replacements = new ArrayList<Replacement>();
/**
* Saves replacements to file for future use
*/
private static void saveReplacements() {
try {
if(replacements.isEmpty()){
File rf=new File(getReplacementsFile());
if(rf.exists()) rf.delete();
}else{
File f = new File(getASDecHome());
if (!f.exists()) f.mkdir();
PrintWriter pw = new PrintWriter(new FileWriter(getReplacementsFile()));
for (Replacement r : replacements) {
pw.println(r.urlPattern);
pw.println(r.targetFile);
}
pw.close();
* Saves replacements to file for future use
*/
private static void saveReplacements() {
try {
if (replacements.isEmpty()) {
File rf = new File(getReplacementsFile());
if (rf.exists()) {
rf.delete();
}
} catch (IOException e) {
}
}
/**
* Load replacements from file
*/
private static void loadReplacements() {
replacements = new ArrayList<Replacement>();
try {
BufferedReader br = new BufferedReader(new FileReader(getReplacementsFile()));
String s = "";
while ((s = br.readLine()) != null) {
Replacement r = new Replacement(s, br.readLine());
replacements.add(r);
} else {
File f = new File(getASDecHome());
if (!f.exists()) {
f.mkdir();
}
br.close();
} catch (IOException e) {
PrintWriter pw = new PrintWriter(new FileWriter(getReplacementsFile()));
for (Replacement r : replacements) {
pw.println(r.urlPattern);
pw.println(r.targetFile);
}
pw.close();
}
} catch (IOException e) {
}
}
}
}
public static Object getConfig(String cfg)
{
return getConfig(cfg,null);
}
public static Object getConfig(String cfg, Object defaultValue)
{
if(!config.containsKey(cfg))
{
return defaultValue;
}
return config.get(cfg);
}
public static Object setConfig(String cfg,Object value)
{
return config.put(cfg,value);
}
public static void load()
{
ObjectInputStream ois=null;
try {
ois=new ObjectInputStream(new FileInputStream(getConfigFile()));
config=(HashMap<String,Object>)ois.readObject();
/**
* Load replacements from file
*/
private static void loadReplacements() {
replacements = new ArrayList<Replacement>();
try {
BufferedReader br = new BufferedReader(new FileReader(getReplacementsFile()));
String s = "";
while ((s = br.readLine()) != null) {
Replacement r = new Replacement(s, br.readLine());
replacements.add(r);
}
br.close();
} catch (IOException e) {
}
}
public static Object getConfig(String cfg) {
return getConfig(cfg, null);
}
public static Object getConfig(String cfg, Object defaultValue) {
if (!config.containsKey(cfg)) {
return defaultValue;
}
return config.get(cfg);
}
public static Object setConfig(String cfg, Object value) {
return config.put(cfg, value);
}
public static void load() {
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(new FileInputStream(getConfigFile()));
config = (HashMap<String, Object>) ois.readObject();
} catch (FileNotFoundException ex) {
} catch (ClassNotFoundException cnf) {
}catch (IOException ex) {
} catch (IOException ex) {
} finally {
if(ois!=null){
if (ois != null) {
try {
ois.close();
} catch (IOException ex1) {
@@ -129,21 +124,18 @@ public class Configuration {
}
}
}
loadReplacements();
}
public static void save()
{
ObjectOutputStream oos=null;
loadReplacements();
}
public static void save() {
ObjectOutputStream oos = null;
try {
oos=new ObjectOutputStream(new FileOutputStream(getConfigFile()));
oos.writeObject(config);
oos = new ObjectOutputStream(new FileOutputStream(getConfigFile()));
oos.writeObject(config);
} catch (FileNotFoundException ex) {
} catch (IOException ex) {
} finally {
if(oos!=null){
if (oos != null) {
try {
oos.close();
} catch (IOException ex1) {
@@ -151,12 +143,10 @@ public class Configuration {
}
}
}
saveReplacements();
}
saveReplacements();
}
public static List<Replacement> getReplacements() {
return replacements;
}
}