diff options
author | Tom Tromey <tromey@gcc.gnu.org> | 2007-01-09 19:58:05 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2007-01-09 19:58:05 +0000 |
commit | 97b8365cafc3a344a22d3980b8ed885f5c6d8357 (patch) | |
tree | 996a5f57d4a68c53473382e45cb22f574cb3e4db /libjava/classpath/gnu/java/util/prefs | |
parent | c648dedbde727ca3f883bb5fd773aa4af70d3369 (diff) | |
download | gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.zip gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.tar.gz gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.tar.bz2 |
Merged gcj-eclipse branch to trunk.
From-SVN: r120621
Diffstat (limited to 'libjava/classpath/gnu/java/util/prefs')
-rw-r--r-- | libjava/classpath/gnu/java/util/prefs/GConfBasedPreferences.java | 27 | ||||
-rw-r--r-- | libjava/classpath/gnu/java/util/prefs/gconf/GConfNativePeer.java | 53 |
2 files changed, 68 insertions, 12 deletions
diff --git a/libjava/classpath/gnu/java/util/prefs/GConfBasedPreferences.java b/libjava/classpath/gnu/java/util/prefs/GConfBasedPreferences.java index 5702751..a7e2322 100644 --- a/libjava/classpath/gnu/java/util/prefs/GConfBasedPreferences.java +++ b/libjava/classpath/gnu/java/util/prefs/GConfBasedPreferences.java @@ -72,7 +72,6 @@ import java.util.prefs.BackingStoreException; * <br /> * * @author Mario Torre <neugens@limasoftware.net> - * @version 1.0.1 */ public class GConfBasedPreferences extends AbstractPreferences @@ -136,12 +135,20 @@ public class GConfBasedPreferences absolutePath = absolutePath.substring(0, absolutePath.length() - 1); } + // strip invalid characters + // please, note that all names are unescaped into the native peer + int index = absolutePath.lastIndexOf('/'); + if (index > -1) + { + absolutePath = absolutePath.substring(0, index + 1); + absolutePath = absolutePath + GConfNativePeer.escapeString(name); + } + this.node = this.getRealRoot(isUser) + absolutePath; boolean nodeExist = backend.nodeExist(this.node); this.newNode = !nodeExist; - backend.startWatchingNode(this.node); } /** @@ -156,7 +163,15 @@ public class GConfBasedPreferences // we don't check anything here, if the node is a new node this will be // detected in the constructor, so we simply return a new reference to // the requested node. - return new GConfBasedPreferences(this, name, this.isUser); + + GConfBasedPreferences preferenceNode + = new GConfBasedPreferences(this, name, this.isUser); + + // register the node for to GConf so that it can listen + // events outside the scope of the application + backend.startWatchingNode(this.node); + + return preferenceNode; } /** @@ -365,6 +380,10 @@ public class GConfBasedPreferences { String nodeName = ""; + // strip key + // please, note that all names are unescaped into the native peer + key = GConfNativePeer.escapeString(key); + if (this.node.endsWith("/")) { nodeName = this.node + key; @@ -373,7 +392,7 @@ public class GConfBasedPreferences { nodeName = this.node + "/" + key; } - + return nodeName; } diff --git a/libjava/classpath/gnu/java/util/prefs/gconf/GConfNativePeer.java b/libjava/classpath/gnu/java/util/prefs/gconf/GConfNativePeer.java index f1cb627..6049863 100644 --- a/libjava/classpath/gnu/java/util/prefs/gconf/GConfNativePeer.java +++ b/libjava/classpath/gnu/java/util/prefs/gconf/GConfNativePeer.java @@ -45,7 +45,6 @@ import java.util.prefs.BackingStoreException; * Native peer for GConf based preference backend. * * @author Mario Torre <neugens@limasoftware.net> - * @version 1.0.1 */ public final class GConfNativePeer { @@ -150,7 +149,7 @@ public final class GConfNativePeer */ public List getKeys(String node) throws BackingStoreException { - return gconf_client_gconf_client_all_keys(node); + return gconf_client_all_keys(node); } /** @@ -162,10 +161,26 @@ public final class GConfNativePeer */ public List getChildrenNodes(String node) throws BackingStoreException { - return gconf_client_gconf_client_all_nodes(node); + return gconf_client_all_nodes(node); } /** + * Escape the given string so the it is a valid GConf name. + */ + public static String escapeString(String plain) + { + return gconf_escape_key(plain); + } + + /** + * Unescape a string escaped with {@link #escapeString}. + */ + public static String unescapeString(String escaped) + { + return gconf_unescape_key(escaped); + } + + /** * Suggest to the backend GConf daemon to synch with the database. */ public void suggestSync() throws BackingStoreException @@ -270,8 +285,9 @@ public final class GConfNativePeer * Suggest to the GConf native peer a sync with the database. * */ - native static final protected void gconf_client_suggest_sync(); - + native static final protected void gconf_client_suggest_sync() + throws BackingStoreException; + /** * Returns a list of all nodes under the given node. * @@ -279,8 +295,9 @@ public final class GConfNativePeer * @return A list of nodes under the given source node. */ native - static final protected List gconf_client_gconf_client_all_nodes(String node); - + static final protected List gconf_client_all_nodes(String node) + throws BackingStoreException; + /** * Returns a list of all keys stored in the given node. * @@ -288,8 +305,28 @@ public final class GConfNativePeer * @return A list of all keys stored in the given node. */ native - static final protected List gconf_client_gconf_client_all_keys(String node); + static final protected List gconf_client_all_keys(String node) + throws BackingStoreException; + /** + * Escape the input String so that it's a valid element for GConf. + * + * @param plain the String to escape. + * @return An escaped String for use with GConf. + */ + native + static final protected String gconf_escape_key(String plain); + + /** + * Converts a string escaped with gconf_escape_key back into its + * original form. + * + * @param escaped key as returned by gconf_escape_key + * @return An unescaped key. + */ + native + static final protected String gconf_unescape_key(String escaped); + static { System.loadLibrary("gconfpeer"); |