📄 configure.java
字号:
/**
* DuMP3 version morpheus_0.2.9 - a duplicate/similar file finder in Java<BR>
* Copyright 2005 Alexander Grässer<BR>
* All Rights Reserved, http://dump3.sourceforge.net/<BR>
* <BR>
* This file is part of DuMP3.<BR>
* <BR>
* DuMP3 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.<BR>
* <BR>
* DuMP3 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.<BR>
* <BR>
* You should have received a copy of the GNU General Public License along with DuMP3; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
* Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.za.grasser.duplicate;
import java.io.File;
import org.apache.log4j.Logger;
import org.jconfig.Configuration;
import org.jconfig.ConfigurationManager;
import org.jconfig.handler.XMLFileHandler;
/**
* This class ...
*
* @author <a href="http://sourceforge.net/sendmessage.php?touser=733840">pyropunk at sourceforge dot net</a>
* @version $Revision: 1.4 $
*/
public class Configure {
/**
* <code>DUMP3</code> Configure -
*/
private static final String DUMP3 = "dump3";
/**
* <code>log</code> Configure -
*/
private static final Logger log = Logger.getLogger(Configure.class);
/**
* <code>manager</code> Configure -
*/
private static final ConfigurationManager manager = ConfigurationManager.getInstance();
/**
* <code>handler</code> Configure -
*/
private static final XMLFileHandler handler = new XMLFileHandler();
/**
* <code>configuration</code> Configure -
*/
private static Configuration configuration = null;
/**
* Configure constructor
*/
private Configure() {
super();
}
/**
* @return Configuration
*/
public static Configuration getConfiguration() {
if (configuration == null) {
load();
}
return configuration;
}
/**
* load the configuration from file
*
* @return Configuration
*/
public static Configuration load() {
if (configuration == null) {
final File file = new File("./config.xml");
handler.setFile(file);
try {
manager.load(handler, DUMP3);
configuration = ConfigurationManager.getConfiguration(DUMP3);
} catch (final Exception e) {
log.error("Configuration error.", e);
configuration = ConfigurationManager.getConfiguration();
}
}
return configuration;
}
/**
* @param key
* @param deflt
* @param cat
* @return String
*/
public static String getProperty(final String key, final String deflt, final String cat) {
String s = configuration.getProperty(key, null, cat);
if (s == null) {
s = deflt;
if (deflt != null) {
configuration.setProperty(key, s, cat);
}
}
return s;
}
/**
* @param key
* @param deflt
* @param cat
* @return String[]
*/
public static String[] getArray(final String key, final String[] deflt, final String cat) {
String[] s = configuration.getArray(key, null, cat);
if (s == null) {
s = deflt;
if (s != null) {
if (s.length > 0) {
final StringBuffer t = new StringBuffer(s[0].length() * s.length);
t.append(s[0]);
for (int i = 1; i < s.length; i++) {
t.append(',').append(s[i]);
}
configuration.setProperty(key, t.toString(), cat);
} else {
configuration.setProperty(key, "", cat);
}
}
}
return s;
}
/**
* @param key
* @param deflt
* @param cat
* @return boolean
*/
public static boolean getBooleanProperty(final String key, final boolean deflt, final String cat) {
final String s = getProperty(key, String.valueOf(deflt), cat);
try {
return Boolean.parseBoolean(s);
} catch (final NoSuchMethodError nsm) {
return "true".equalsIgnoreCase(s);
}
}
/**
* @param key
* @param deflt
* @param cat
* @return double
*/
public static double getDoubleProperty(final String key, final double deflt, final String cat) {
final String s = getProperty(key, ("" + deflt), cat);
return Double.parseDouble(s);
}
/**
* @param key
* @param deflt
* @param cat
* @return float
*/
public static float getFloatProperty(final String key, final float deflt, final String cat) {
final String s = getProperty(key, ("" + deflt), cat);
return Float.parseFloat(s);
}
/**
* @param key
* @param deflt
* @param cat
* @return int
*/
public static int getIntProperty(final String key, final int deflt, final String cat) {
final String s = getProperty(key, ("" + deflt), cat);
return Integer.parseInt(s);
}
/**
* @param key
* @param deflt
* @param cat
* @return long
*/
public static long getLongProperty(final String key, final long deflt, final String cat) {
final String s = getProperty(key, ("" + deflt), cat);
return Long.parseLong(s);
}
/**
* save the configuration to file
*/
public static void save() {
try {
manager.save(handler, getConfiguration());
} catch (final Exception e) {
log.error("Configuration error.", e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -