Author: roy
Date: 2008-11-09 22:07:33 +0100 (Sun, 09 Nov 2008)
New Revision: 328
Added:
src/main/resources/defaultconfig.properties
Modified:
src/main/java/nl/improved/sqlclient/SQLProperties.java
Log:
some property settings
Modified: src/main/java/nl/improved/sqlclient/SQLProperties.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLProperties.java 2008-11-07 21:32:35 UTC (rev 327)
+++ src/main/java/nl/improved/sqlclient/SQLProperties.java 2008-11-09 21:07:33 UTC (rev 328)
@@ -15,11 +15,17 @@
*/
package nl.improved.sqlclient;
-import java.util.Map;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
public class SQLProperties {
- public static enum PropertyName {VERSION};
+ public static enum PropertyName {VERSION, CONFIG_VERSION, MOUSE_HANDLING};
private static SQLProperties instance;
@@ -27,14 +33,37 @@
private SQLProperties() {
props = new Properties();
+ Properties defaultProperties = new Properties();
try {
- props.load(getClass().getResourceAsStream("/META-INF/maven/nl.improved/sqlshell/pom.properties"));
+ defaultProperties.load(getClass().getResourceAsStream("/defaultconfig.properties"));
+ } catch (IOException ex) {ex.printStackTrace(); }
+ try {
+ File configFile = getPropertyFile();
+ if (configFile.exists()) {
+ props.load(new FileInputStream(configFile));
+ }
+ } catch(Exception e) {/* ignore */}
+ if (!props.getProperty(PropertyName.CONFIG_VERSION.name(), "0")
+ .equals(defaultProperties.getProperty(PropertyName.CONFIG_VERSION.name(), "0"))) {
+ try {
+ migrateProperies(defaultProperties, props);
+ props = defaultProperties;
+ } catch (IOException ex) {
+ Logger.getLogger(SQLProperties.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+ try {
+ Properties pomProps = new Properties();
+ pomProps.load(getClass().getResourceAsStream("/META-INF/maven/nl.improved/sqlshell/pom.properties"));
props.put(PropertyName.VERSION, props.get("version"));
} catch(Exception e) {
//System.err.println("Failed to load pom.properties");
}
}
+ private static File getPropertyFile() {
+ return new File(System.getProperty("user.home")+File.separator+".sqlshell"+File.separator+"config.properties");
+ }
private static SQLProperties getInstance() {
if (instance == null) {
instance = new SQLProperties();
@@ -43,7 +72,7 @@
}
public static String getProperty(PropertyName property) {
- return (String)getInstance().props.get(property);
+ return (String)getInstance().props.get(property.name());
}
public static String getProperty(PropertyName property, String defaultValue) {
@@ -53,4 +82,13 @@
}
return prop;
}
+
+ private void migrateProperies(Properties defaultProps, Properties currentProps) throws IOException {
+ for (Object key : currentProps.keySet()) {
+ if (!key.equals(PropertyName.CONFIG_VERSION.name())) {
+ defaultProps.put(key, currentProps.getProperty((String)key));
+ }
+ }
+ defaultProps.save(new FileOutputStream(getPropertyFile()), "SQLShell properties file");
+ }
}
Added: src/main/resources/defaultconfig.properties
===================================================================
--- src/main/resources/defaultconfig.properties 2008-11-07 21:32:35 UTC (rev 327)
+++ src/main/resources/defaultconfig.properties 2008-11-09 21:07:33 UTC (rev 328)
@@ -0,0 +1,9 @@
+#this is the sqlshell propertiesfile
+#Please don't change this value.. it is used to upgrade your properties file
+CONFIG_VERSION=1
+#
+#Set the mouse handling for the 'Charva' implementation. Possible values:
+#native (default) : ignore mouse events in java and use default system behaviour
+#paste : use middle mouse button to paste the clipboard contents
+#all : paste and implement selection and copy the selection to the clipboard
+MOUSE_HANDLING=native
|