feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
1619
jdkSrc/jdk8/java/util/prefs/AbstractPreferences.java
Normal file
1619
jdkSrc/jdk8/java/util/prefs/AbstractPreferences.java
Normal file
File diff suppressed because it is too large
Load Diff
58
jdkSrc/jdk8/java/util/prefs/BackingStoreException.java
Normal file
58
jdkSrc/jdk8/java/util/prefs/BackingStoreException.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.util.prefs;
|
||||
|
||||
import java.io.NotSerializableException;
|
||||
|
||||
/**
|
||||
* Thrown to indicate that a preferences operation could not complete because
|
||||
* of a failure in the backing store, or a failure to contact the backing
|
||||
* store.
|
||||
*
|
||||
* @author Josh Bloch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class BackingStoreException extends Exception {
|
||||
/**
|
||||
* Constructs a BackingStoreException with the specified detail message.
|
||||
*
|
||||
* @param s the detail message.
|
||||
*/
|
||||
public BackingStoreException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a BackingStoreException with the specified cause.
|
||||
*
|
||||
* @param cause the cause
|
||||
*/
|
||||
public BackingStoreException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 859796500401108469L;
|
||||
}
|
||||
261
jdkSrc/jdk8/java/util/prefs/Base64.java
Normal file
261
jdkSrc/jdk8/java/util/prefs/Base64.java
Normal file
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.util.prefs;
|
||||
|
||||
/**
|
||||
* Static methods for translating Base64 encoded strings to byte arrays
|
||||
* and vice-versa.
|
||||
*
|
||||
* @author Josh Bloch
|
||||
* @see Preferences
|
||||
* @since 1.4
|
||||
*/
|
||||
class Base64 {
|
||||
/**
|
||||
* Translates the specified byte array into a Base64 string as per
|
||||
* Preferences.put(byte[]).
|
||||
*/
|
||||
static String byteArrayToBase64(byte[] a) {
|
||||
return byteArrayToBase64(a, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the specified byte array into an "alternate representation"
|
||||
* Base64 string. This non-standard variant uses an alphabet that does
|
||||
* not contain the uppercase alphabetic characters, which makes it
|
||||
* suitable for use in situations where case-folding occurs.
|
||||
*/
|
||||
static String byteArrayToAltBase64(byte[] a) {
|
||||
return byteArrayToBase64(a, true);
|
||||
}
|
||||
|
||||
private static String byteArrayToBase64(byte[] a, boolean alternate) {
|
||||
int aLen = a.length;
|
||||
int numFullGroups = aLen/3;
|
||||
int numBytesInPartialGroup = aLen - 3*numFullGroups;
|
||||
int resultLen = 4*((aLen + 2)/3);
|
||||
StringBuffer result = new StringBuffer(resultLen);
|
||||
char[] intToAlpha = (alternate ? intToAltBase64 : intToBase64);
|
||||
|
||||
// Translate all full groups from byte array elements to Base64
|
||||
int inCursor = 0;
|
||||
for (int i=0; i<numFullGroups; i++) {
|
||||
int byte0 = a[inCursor++] & 0xff;
|
||||
int byte1 = a[inCursor++] & 0xff;
|
||||
int byte2 = a[inCursor++] & 0xff;
|
||||
result.append(intToAlpha[byte0 >> 2]);
|
||||
result.append(intToAlpha[(byte0 << 4)&0x3f | (byte1 >> 4)]);
|
||||
result.append(intToAlpha[(byte1 << 2)&0x3f | (byte2 >> 6)]);
|
||||
result.append(intToAlpha[byte2 & 0x3f]);
|
||||
}
|
||||
|
||||
// Translate partial group if present
|
||||
if (numBytesInPartialGroup != 0) {
|
||||
int byte0 = a[inCursor++] & 0xff;
|
||||
result.append(intToAlpha[byte0 >> 2]);
|
||||
if (numBytesInPartialGroup == 1) {
|
||||
result.append(intToAlpha[(byte0 << 4) & 0x3f]);
|
||||
result.append("==");
|
||||
} else {
|
||||
// assert numBytesInPartialGroup == 2;
|
||||
int byte1 = a[inCursor++] & 0xff;
|
||||
result.append(intToAlpha[(byte0 << 4)&0x3f | (byte1 >> 4)]);
|
||||
result.append(intToAlpha[(byte1 << 2)&0x3f]);
|
||||
result.append('=');
|
||||
}
|
||||
}
|
||||
// assert inCursor == a.length;
|
||||
// assert result.length() == resultLen;
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* This array is a lookup table that translates 6-bit positive integer
|
||||
* index values into their "Base64 Alphabet" equivalents as specified
|
||||
* in Table 1 of RFC 2045.
|
||||
*/
|
||||
private static final char intToBase64[] = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
||||
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
||||
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
|
||||
};
|
||||
|
||||
/**
|
||||
* This array is a lookup table that translates 6-bit positive integer
|
||||
* index values into their "Alternate Base64 Alphabet" equivalents.
|
||||
* This is NOT the real Base64 Alphabet as per in Table 1 of RFC 2045.
|
||||
* This alternate alphabet does not use the capital letters. It is
|
||||
* designed for use in environments where "case folding" occurs.
|
||||
*/
|
||||
private static final char intToAltBase64[] = {
|
||||
'!', '"', '#', '$', '%', '&', '\'', '(', ')', ',', '-', '.', ':',
|
||||
';', '<', '>', '@', '[', ']', '^', '`', '_', '{', '|', '}', '~',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
||||
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '?'
|
||||
};
|
||||
|
||||
/**
|
||||
* Translates the specified Base64 string (as per Preferences.get(byte[]))
|
||||
* into a byte array.
|
||||
*
|
||||
* @throw IllegalArgumentException if <tt>s</tt> is not a valid Base64
|
||||
* string.
|
||||
*/
|
||||
static byte[] base64ToByteArray(String s) {
|
||||
return base64ToByteArray(s, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the specified "alternate representation" Base64 string
|
||||
* into a byte array.
|
||||
*
|
||||
* @throw IllegalArgumentException or ArrayOutOfBoundsException
|
||||
* if <tt>s</tt> is not a valid alternate representation
|
||||
* Base64 string.
|
||||
*/
|
||||
static byte[] altBase64ToByteArray(String s) {
|
||||
return base64ToByteArray(s, true);
|
||||
}
|
||||
|
||||
private static byte[] base64ToByteArray(String s, boolean alternate) {
|
||||
byte[] alphaToInt = (alternate ? altBase64ToInt : base64ToInt);
|
||||
int sLen = s.length();
|
||||
int numGroups = sLen/4;
|
||||
if (4*numGroups != sLen)
|
||||
throw new IllegalArgumentException(
|
||||
"String length must be a multiple of four.");
|
||||
int missingBytesInLastGroup = 0;
|
||||
int numFullGroups = numGroups;
|
||||
if (sLen != 0) {
|
||||
if (s.charAt(sLen-1) == '=') {
|
||||
missingBytesInLastGroup++;
|
||||
numFullGroups--;
|
||||
}
|
||||
if (s.charAt(sLen-2) == '=')
|
||||
missingBytesInLastGroup++;
|
||||
}
|
||||
byte[] result = new byte[3*numGroups - missingBytesInLastGroup];
|
||||
|
||||
// Translate all full groups from base64 to byte array elements
|
||||
int inCursor = 0, outCursor = 0;
|
||||
for (int i=0; i<numFullGroups; i++) {
|
||||
int ch0 = base64toInt(s.charAt(inCursor++), alphaToInt);
|
||||
int ch1 = base64toInt(s.charAt(inCursor++), alphaToInt);
|
||||
int ch2 = base64toInt(s.charAt(inCursor++), alphaToInt);
|
||||
int ch3 = base64toInt(s.charAt(inCursor++), alphaToInt);
|
||||
result[outCursor++] = (byte) ((ch0 << 2) | (ch1 >> 4));
|
||||
result[outCursor++] = (byte) ((ch1 << 4) | (ch2 >> 2));
|
||||
result[outCursor++] = (byte) ((ch2 << 6) | ch3);
|
||||
}
|
||||
|
||||
// Translate partial group, if present
|
||||
if (missingBytesInLastGroup != 0) {
|
||||
int ch0 = base64toInt(s.charAt(inCursor++), alphaToInt);
|
||||
int ch1 = base64toInt(s.charAt(inCursor++), alphaToInt);
|
||||
result[outCursor++] = (byte) ((ch0 << 2) | (ch1 >> 4));
|
||||
|
||||
if (missingBytesInLastGroup == 1) {
|
||||
int ch2 = base64toInt(s.charAt(inCursor++), alphaToInt);
|
||||
result[outCursor++] = (byte) ((ch1 << 4) | (ch2 >> 2));
|
||||
}
|
||||
}
|
||||
// assert inCursor == s.length()-missingBytesInLastGroup;
|
||||
// assert outCursor == result.length;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the specified character, which is assumed to be in the
|
||||
* "Base 64 Alphabet" into its equivalent 6-bit positive integer.
|
||||
*
|
||||
* @throw IllegalArgumentException or ArrayOutOfBoundsException if
|
||||
* c is not in the Base64 Alphabet.
|
||||
*/
|
||||
private static int base64toInt(char c, byte[] alphaToInt) {
|
||||
int result = alphaToInt[c];
|
||||
if (result < 0)
|
||||
throw new IllegalArgumentException("Illegal character " + c);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This array is a lookup table that translates unicode characters
|
||||
* drawn from the "Base64 Alphabet" (as specified in Table 1 of RFC 2045)
|
||||
* into their 6-bit positive integer equivalents. Characters that
|
||||
* are not in the Base64 alphabet but fall within the bounds of the
|
||||
* array are translated to -1.
|
||||
*/
|
||||
private static final byte base64ToInt[] = {
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54,
|
||||
55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4,
|
||||
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
|
||||
24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34,
|
||||
35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
|
||||
};
|
||||
|
||||
/**
|
||||
* This array is the analogue of base64ToInt, but for the nonstandard
|
||||
* variant that avoids the use of uppercase alphabetic characters.
|
||||
*/
|
||||
private static final byte altBase64ToInt[] = {
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1,
|
||||
2, 3, 4, 5, 6, 7, 8, -1, 62, 9, 10, 11, -1 , 52, 53, 54, 55, 56, 57,
|
||||
58, 59, 60, 61, 12, 13, 14, -1, 15, 63, 16, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, 17, -1, 18, 19, 21, 20, 26, 27, 28, 29, 30, 31, 32, 33,
|
||||
34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
|
||||
51, 22, 23, 24, 25
|
||||
};
|
||||
|
||||
public static void main(String args[]) {
|
||||
int numRuns = Integer.parseInt(args[0]);
|
||||
int numBytes = Integer.parseInt(args[1]);
|
||||
java.util.Random rnd = new java.util.Random();
|
||||
for (int i=0; i<numRuns; i++) {
|
||||
for (int j=0; j<numBytes; j++) {
|
||||
byte[] arr = new byte[j];
|
||||
for (int k=0; k<j; k++)
|
||||
arr[k] = (byte)rnd.nextInt();
|
||||
|
||||
String s = byteArrayToBase64(arr);
|
||||
byte [] b = base64ToByteArray(s);
|
||||
if (!java.util.Arrays.equals(arr, b))
|
||||
System.out.println("Dismal failure!");
|
||||
|
||||
s = byteArrayToAltBase64(arr);
|
||||
b = altBase64ToByteArray(s);
|
||||
if (!java.util.Arrays.equals(arr, b))
|
||||
System.out.println("Alternate dismal failure!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.util.prefs;
|
||||
|
||||
import java.io.NotSerializableException;
|
||||
|
||||
/**
|
||||
* Thrown to indicate that an operation could not complete because
|
||||
* the input did not conform to the appropriate XML document type
|
||||
* for a collection of preferences, as per the {@link Preferences}
|
||||
* specification.
|
||||
*
|
||||
* @author Josh Bloch
|
||||
* @see Preferences
|
||||
* @since 1.4
|
||||
*/
|
||||
public class InvalidPreferencesFormatException extends Exception {
|
||||
/**
|
||||
* Constructs an InvalidPreferencesFormatException with the specified
|
||||
* cause.
|
||||
*
|
||||
* @param cause the cause (which is saved for later retrieval by the
|
||||
* {@link Throwable#getCause()} method).
|
||||
*/
|
||||
public InvalidPreferencesFormatException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an InvalidPreferencesFormatException with the specified
|
||||
* detail message.
|
||||
*
|
||||
* @param message the detail message. The detail message is saved for
|
||||
* later retrieval by the {@link Throwable#getMessage()} method.
|
||||
*/
|
||||
public InvalidPreferencesFormatException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an InvalidPreferencesFormatException with the specified
|
||||
* detail message and cause.
|
||||
*
|
||||
* @param message the detail message. The detail message is saved for
|
||||
* later retrieval by the {@link Throwable#getMessage()} method.
|
||||
* @param cause the cause (which is saved for later retrieval by the
|
||||
* {@link Throwable#getCause()} method).
|
||||
*/
|
||||
public InvalidPreferencesFormatException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = -791715184232119669L;
|
||||
}
|
||||
104
jdkSrc/jdk8/java/util/prefs/NodeChangeEvent.java
Normal file
104
jdkSrc/jdk8/java/util/prefs/NodeChangeEvent.java
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.util.prefs;
|
||||
|
||||
import java.io.NotSerializableException;
|
||||
|
||||
/**
|
||||
* An event emitted by a <tt>Preferences</tt> node to indicate that
|
||||
* a child of that node has been added or removed.<p>
|
||||
*
|
||||
* Note, that although NodeChangeEvent inherits Serializable interface from
|
||||
* java.util.EventObject, it is not intended to be Serializable. Appropriate
|
||||
* serialization methods are implemented to throw NotSerializableException.
|
||||
*
|
||||
* @author Josh Bloch
|
||||
* @see Preferences
|
||||
* @see NodeChangeListener
|
||||
* @see PreferenceChangeEvent
|
||||
* @since 1.4
|
||||
* @serial exclude
|
||||
*/
|
||||
|
||||
public class NodeChangeEvent extends java.util.EventObject {
|
||||
/**
|
||||
* The node that was added or removed.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private Preferences child;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>NodeChangeEvent</code> instance.
|
||||
*
|
||||
* @param parent The parent of the node that was added or removed.
|
||||
* @param child The node that was added or removed.
|
||||
*/
|
||||
public NodeChangeEvent(Preferences parent, Preferences child) {
|
||||
super(parent);
|
||||
this.child = child;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parent of the node that was added or removed.
|
||||
*
|
||||
* @return The parent Preferences node whose child was added or removed
|
||||
*/
|
||||
public Preferences getParent() {
|
||||
return (Preferences) getSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the node that was added or removed.
|
||||
*
|
||||
* @return The node that was added or removed.
|
||||
*/
|
||||
public Preferences getChild() {
|
||||
return child;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws NotSerializableException, since NodeChangeEvent objects are not
|
||||
* intended to be serializable.
|
||||
*/
|
||||
private void writeObject(java.io.ObjectOutputStream out)
|
||||
throws NotSerializableException {
|
||||
throw new NotSerializableException("Not serializable.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws NotSerializableException, since NodeChangeEvent objects are not
|
||||
* intended to be serializable.
|
||||
*/
|
||||
private void readObject(java.io.ObjectInputStream in)
|
||||
throws NotSerializableException {
|
||||
throw new NotSerializableException("Not serializable.");
|
||||
}
|
||||
|
||||
// Defined so that this class isn't flagged as a potential problem when
|
||||
// searches for missing serialVersionUID fields are done.
|
||||
private static final long serialVersionUID = 8068949086596572957L;
|
||||
}
|
||||
54
jdkSrc/jdk8/java/util/prefs/NodeChangeListener.java
Normal file
54
jdkSrc/jdk8/java/util/prefs/NodeChangeListener.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.util.prefs;
|
||||
|
||||
/**
|
||||
* A listener for receiving preference node change events.
|
||||
*
|
||||
* @author Josh Bloch
|
||||
* @see Preferences
|
||||
* @see NodeChangeEvent
|
||||
* @see PreferenceChangeListener
|
||||
* @since 1.4
|
||||
*/
|
||||
|
||||
public interface NodeChangeListener extends java.util.EventListener {
|
||||
/**
|
||||
* This method gets called when a child node is added.
|
||||
*
|
||||
* @param evt A node change event object describing the parent
|
||||
* and child node.
|
||||
*/
|
||||
void childAdded(NodeChangeEvent evt);
|
||||
|
||||
/**
|
||||
* This method gets called when a child node is removed.
|
||||
*
|
||||
* @param evt A node change event object describing the parent
|
||||
* and child node.
|
||||
*/
|
||||
void childRemoved(NodeChangeEvent evt);
|
||||
}
|
||||
125
jdkSrc/jdk8/java/util/prefs/PreferenceChangeEvent.java
Normal file
125
jdkSrc/jdk8/java/util/prefs/PreferenceChangeEvent.java
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.util.prefs;
|
||||
|
||||
import java.io.NotSerializableException;
|
||||
|
||||
/**
|
||||
* An event emitted by a <tt>Preferences</tt> node to indicate that
|
||||
* a preference has been added, removed or has had its value changed.<p>
|
||||
*
|
||||
* Note, that although PreferenceChangeEvent inherits Serializable interface
|
||||
* from EventObject, it is not intended to be Serializable. Appropriate
|
||||
* serialization methods are implemented to throw NotSerializableException.
|
||||
*
|
||||
* @author Josh Bloch
|
||||
* @see Preferences
|
||||
* @see PreferenceChangeListener
|
||||
* @see NodeChangeEvent
|
||||
* @since 1.4
|
||||
* @serial exclude
|
||||
*/
|
||||
public class PreferenceChangeEvent extends java.util.EventObject {
|
||||
|
||||
/**
|
||||
* Key of the preference that changed.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* New value for preference, or <tt>null</tt> if it was removed.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private String newValue;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>PreferenceChangeEvent</code> instance.
|
||||
*
|
||||
* @param node The Preferences node that emitted the event.
|
||||
* @param key The key of the preference that was changed.
|
||||
* @param newValue The new value of the preference, or <tt>null</tt>
|
||||
* if the preference is being removed.
|
||||
*/
|
||||
public PreferenceChangeEvent(Preferences node, String key,
|
||||
String newValue) {
|
||||
super(node);
|
||||
this.key = key;
|
||||
this.newValue = newValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the preference node that emitted the event.
|
||||
*
|
||||
* @return The preference node that emitted the event.
|
||||
*/
|
||||
public Preferences getNode() {
|
||||
return (Preferences) getSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key of the preference that was changed.
|
||||
*
|
||||
* @return The key of the preference that was changed.
|
||||
*/
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the new value for the preference.
|
||||
*
|
||||
* @return The new value for the preference, or <tt>null</tt> if the
|
||||
* preference was removed.
|
||||
*/
|
||||
public String getNewValue() {
|
||||
return newValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws NotSerializableException, since NodeChangeEvent objects
|
||||
* are not intended to be serializable.
|
||||
*/
|
||||
private void writeObject(java.io.ObjectOutputStream out)
|
||||
throws NotSerializableException {
|
||||
throw new NotSerializableException("Not serializable.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws NotSerializableException, since PreferenceChangeEvent objects
|
||||
* are not intended to be serializable.
|
||||
*/
|
||||
private void readObject(java.io.ObjectInputStream in)
|
||||
throws NotSerializableException {
|
||||
throw new NotSerializableException("Not serializable.");
|
||||
}
|
||||
|
||||
// Defined so that this class isn't flagged as a potential problem when
|
||||
// searches for missing serialVersionUID fields are done.
|
||||
private static final long serialVersionUID = 793724513368024975L;
|
||||
}
|
||||
47
jdkSrc/jdk8/java/util/prefs/PreferenceChangeListener.java
Normal file
47
jdkSrc/jdk8/java/util/prefs/PreferenceChangeListener.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.util.prefs;
|
||||
|
||||
/**
|
||||
* A listener for receiving preference change events.
|
||||
*
|
||||
* @author Josh Bloch
|
||||
* @see Preferences
|
||||
* @see PreferenceChangeEvent
|
||||
* @see NodeChangeListener
|
||||
* @since 1.4
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface PreferenceChangeListener extends java.util.EventListener {
|
||||
/**
|
||||
* This method gets called when a preference is added, removed or when
|
||||
* its value is changed.
|
||||
* <p>
|
||||
* @param evt A PreferenceChangeEvent object describing the event source
|
||||
* and the preference that has changed.
|
||||
*/
|
||||
void preferenceChange(PreferenceChangeEvent evt);
|
||||
}
|
||||
1258
jdkSrc/jdk8/java/util/prefs/Preferences.java
Normal file
1258
jdkSrc/jdk8/java/util/prefs/Preferences.java
Normal file
File diff suppressed because it is too large
Load Diff
60
jdkSrc/jdk8/java/util/prefs/PreferencesFactory.java
Normal file
60
jdkSrc/jdk8/java/util/prefs/PreferencesFactory.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.util.prefs;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* A factory object that generates Preferences objects. Providers of
|
||||
* new {@link Preferences} implementations should provide corresponding
|
||||
* <tt>PreferencesFactory</tt> implementations so that the new
|
||||
* <tt>Preferences</tt> implementation can be installed in place of the
|
||||
* platform-specific default implementation.
|
||||
*
|
||||
* <p><strong>This class is for <tt>Preferences</tt> implementers only.
|
||||
* Normal users of the <tt>Preferences</tt> facility should have no need to
|
||||
* consult this documentation.</strong>
|
||||
*
|
||||
* @author Josh Bloch
|
||||
* @see Preferences
|
||||
* @since 1.4
|
||||
*/
|
||||
public interface PreferencesFactory {
|
||||
/**
|
||||
* Returns the system root preference node. (Multiple calls on this
|
||||
* method will return the same object reference.)
|
||||
* @return the system root preference node
|
||||
*/
|
||||
Preferences systemRoot();
|
||||
|
||||
/**
|
||||
* Returns the user root preference node corresponding to the calling
|
||||
* user. In a server, the returned value will typically depend on
|
||||
* some implicit client-context.
|
||||
* @return the user root preference node corresponding to the calling
|
||||
* user
|
||||
*/
|
||||
Preferences userRoot();
|
||||
}
|
||||
1160
jdkSrc/jdk8/java/util/prefs/WindowsPreferences.java
Normal file
1160
jdkSrc/jdk8/java/util/prefs/WindowsPreferences.java
Normal file
File diff suppressed because it is too large
Load Diff
51
jdkSrc/jdk8/java/util/prefs/WindowsPreferencesFactory.java
Normal file
51
jdkSrc/jdk8/java/util/prefs/WindowsPreferencesFactory.java
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package java.util.prefs;
|
||||
|
||||
/**
|
||||
* Implementation of <tt>PreferencesFactory</tt> to return
|
||||
* WindowsPreferences objects.
|
||||
*
|
||||
* @author Konstantin Kladko
|
||||
* @see Preferences
|
||||
* @see WindowsPreferences
|
||||
* @since 1.4
|
||||
*/
|
||||
class WindowsPreferencesFactory implements PreferencesFactory {
|
||||
|
||||
/**
|
||||
* Returns WindowsPreferences.userRoot
|
||||
*/
|
||||
public Preferences userRoot() {
|
||||
return WindowsPreferences.getUserRoot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns WindowsPreferences.systemRoot
|
||||
*/
|
||||
public Preferences systemRoot() {
|
||||
return WindowsPreferences.getSystemRoot();
|
||||
}
|
||||
}
|
||||
421
jdkSrc/jdk8/java/util/prefs/XmlSupport.java
Normal file
421
jdkSrc/jdk8/java/util/prefs/XmlSupport.java
Normal file
@@ -0,0 +1,421 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.util.prefs;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import javax.xml.parsers.*;
|
||||
import javax.xml.transform.*;
|
||||
import javax.xml.transform.dom.*;
|
||||
import javax.xml.transform.stream.*;
|
||||
import org.xml.sax.*;
|
||||
import org.w3c.dom.*;
|
||||
|
||||
/**
|
||||
* XML Support for java.util.prefs. Methods to import and export preference
|
||||
* nodes and subtrees.
|
||||
*
|
||||
* @author Josh Bloch and Mark Reinhold
|
||||
* @see Preferences
|
||||
* @since 1.4
|
||||
*/
|
||||
class XmlSupport {
|
||||
// The required DTD URI for exported preferences
|
||||
private static final String PREFS_DTD_URI =
|
||||
"http://java.sun.com/dtd/preferences.dtd";
|
||||
|
||||
// The actual DTD corresponding to the URI
|
||||
private static final String PREFS_DTD =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
||||
|
||||
"<!-- DTD for preferences -->" +
|
||||
|
||||
"<!ELEMENT preferences (root) >" +
|
||||
"<!ATTLIST preferences" +
|
||||
" EXTERNAL_XML_VERSION CDATA \"0.0\" >" +
|
||||
|
||||
"<!ELEMENT root (map, node*) >" +
|
||||
"<!ATTLIST root" +
|
||||
" type (system|user) #REQUIRED >" +
|
||||
|
||||
"<!ELEMENT node (map, node*) >" +
|
||||
"<!ATTLIST node" +
|
||||
" name CDATA #REQUIRED >" +
|
||||
|
||||
"<!ELEMENT map (entry*) >" +
|
||||
"<!ATTLIST map" +
|
||||
" MAP_XML_VERSION CDATA \"0.0\" >" +
|
||||
"<!ELEMENT entry EMPTY >" +
|
||||
"<!ATTLIST entry" +
|
||||
" key CDATA #REQUIRED" +
|
||||
" value CDATA #REQUIRED >" ;
|
||||
/**
|
||||
* Version number for the format exported preferences files.
|
||||
*/
|
||||
private static final String EXTERNAL_XML_VERSION = "1.0";
|
||||
|
||||
/*
|
||||
* Version number for the internal map files.
|
||||
*/
|
||||
private static final String MAP_XML_VERSION = "1.0";
|
||||
|
||||
/**
|
||||
* Export the specified preferences node and, if subTree is true, all
|
||||
* subnodes, to the specified output stream. Preferences are exported as
|
||||
* an XML document conforming to the definition in the Preferences spec.
|
||||
*
|
||||
* @throws IOException if writing to the specified output stream
|
||||
* results in an <tt>IOException</tt>.
|
||||
* @throws BackingStoreException if preference data cannot be read from
|
||||
* backing store.
|
||||
* @throws IllegalStateException if this node (or an ancestor) has been
|
||||
* removed with the {@link Preferences#removeNode()} method.
|
||||
*/
|
||||
static void export(OutputStream os, final Preferences p, boolean subTree)
|
||||
throws IOException, BackingStoreException {
|
||||
if (((AbstractPreferences)p).isRemoved())
|
||||
throw new IllegalStateException("Node has been removed");
|
||||
Document doc = createPrefsDoc("preferences");
|
||||
Element preferences = doc.getDocumentElement() ;
|
||||
preferences.setAttribute("EXTERNAL_XML_VERSION", EXTERNAL_XML_VERSION);
|
||||
Element xmlRoot = (Element)
|
||||
preferences.appendChild(doc.createElement("root"));
|
||||
xmlRoot.setAttribute("type", (p.isUserNode() ? "user" : "system"));
|
||||
|
||||
// Get bottom-up list of nodes from p to root, excluding root
|
||||
List<Preferences> ancestors = new ArrayList<>();
|
||||
|
||||
for (Preferences kid = p, dad = kid.parent(); dad != null;
|
||||
kid = dad, dad = kid.parent()) {
|
||||
ancestors.add(kid);
|
||||
}
|
||||
Element e = xmlRoot;
|
||||
for (int i=ancestors.size()-1; i >= 0; i--) {
|
||||
e.appendChild(doc.createElement("map"));
|
||||
e = (Element) e.appendChild(doc.createElement("node"));
|
||||
e.setAttribute("name", ancestors.get(i).name());
|
||||
}
|
||||
putPreferencesInXml(e, doc, p, subTree);
|
||||
|
||||
writeDoc(doc, os);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the preferences in the specified Preferences node into the
|
||||
* specified XML element which is assumed to represent a node
|
||||
* in the specified XML document which is assumed to conform to
|
||||
* PREFS_DTD. If subTree is true, create children of the specified
|
||||
* XML node conforming to all of the children of the specified
|
||||
* Preferences node and recurse.
|
||||
*
|
||||
* @throws BackingStoreException if it is not possible to read
|
||||
* the preferences or children out of the specified
|
||||
* preferences node.
|
||||
*/
|
||||
private static void putPreferencesInXml(Element elt, Document doc,
|
||||
Preferences prefs, boolean subTree) throws BackingStoreException
|
||||
{
|
||||
Preferences[] kidsCopy = null;
|
||||
String[] kidNames = null;
|
||||
|
||||
// Node is locked to export its contents and get a
|
||||
// copy of children, then lock is released,
|
||||
// and, if subTree = true, recursive calls are made on children
|
||||
synchronized (((AbstractPreferences)prefs).lock) {
|
||||
// Check if this node was concurrently removed. If yes
|
||||
// remove it from XML Document and return.
|
||||
if (((AbstractPreferences)prefs).isRemoved()) {
|
||||
elt.getParentNode().removeChild(elt);
|
||||
return;
|
||||
}
|
||||
// Put map in xml element
|
||||
String[] keys = prefs.keys();
|
||||
Element map = (Element) elt.appendChild(doc.createElement("map"));
|
||||
for (int i=0; i<keys.length; i++) {
|
||||
Element entry = (Element)
|
||||
map.appendChild(doc.createElement("entry"));
|
||||
entry.setAttribute("key", keys[i]);
|
||||
// NEXT STATEMENT THROWS NULL PTR EXC INSTEAD OF ASSERT FAIL
|
||||
entry.setAttribute("value", prefs.get(keys[i], null));
|
||||
}
|
||||
// Recurse if appropriate
|
||||
if (subTree) {
|
||||
/* Get a copy of kids while lock is held */
|
||||
kidNames = prefs.childrenNames();
|
||||
kidsCopy = new Preferences[kidNames.length];
|
||||
for (int i = 0; i < kidNames.length; i++)
|
||||
kidsCopy[i] = prefs.node(kidNames[i]);
|
||||
}
|
||||
// release lock
|
||||
}
|
||||
|
||||
if (subTree) {
|
||||
for (int i=0; i < kidNames.length; i++) {
|
||||
Element xmlKid = (Element)
|
||||
elt.appendChild(doc.createElement("node"));
|
||||
xmlKid.setAttribute("name", kidNames[i]);
|
||||
putPreferencesInXml(xmlKid, doc, kidsCopy[i], subTree);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Import preferences from the specified input stream, which is assumed
|
||||
* to contain an XML document in the format described in the Preferences
|
||||
* spec.
|
||||
*
|
||||
* @throws IOException if reading from the specified output stream
|
||||
* results in an <tt>IOException</tt>.
|
||||
* @throws InvalidPreferencesFormatException Data on input stream does not
|
||||
* constitute a valid XML document with the mandated document type.
|
||||
*/
|
||||
static void importPreferences(InputStream is)
|
||||
throws IOException, InvalidPreferencesFormatException
|
||||
{
|
||||
try {
|
||||
Document doc = loadPrefsDoc(is);
|
||||
String xmlVersion =
|
||||
doc.getDocumentElement().getAttribute("EXTERNAL_XML_VERSION");
|
||||
if (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0)
|
||||
throw new InvalidPreferencesFormatException(
|
||||
"Exported preferences file format version " + xmlVersion +
|
||||
" is not supported. This java installation can read" +
|
||||
" versions " + EXTERNAL_XML_VERSION + " or older. You may need" +
|
||||
" to install a newer version of JDK.");
|
||||
|
||||
Element xmlRoot = (Element) doc.getDocumentElement().
|
||||
getChildNodes().item(0);
|
||||
Preferences prefsRoot =
|
||||
(xmlRoot.getAttribute("type").equals("user") ?
|
||||
Preferences.userRoot() : Preferences.systemRoot());
|
||||
ImportSubtree(prefsRoot, xmlRoot);
|
||||
} catch(SAXException e) {
|
||||
throw new InvalidPreferencesFormatException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new prefs XML document.
|
||||
*/
|
||||
private static Document createPrefsDoc( String qname ) {
|
||||
try {
|
||||
DOMImplementation di = DocumentBuilderFactory.newInstance().
|
||||
newDocumentBuilder().getDOMImplementation();
|
||||
DocumentType dt = di.createDocumentType(qname, null, PREFS_DTD_URI);
|
||||
return di.createDocument(null, qname, dt);
|
||||
} catch(ParserConfigurationException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an XML document from specified input stream, which must
|
||||
* have the requisite DTD URI.
|
||||
*/
|
||||
private static Document loadPrefsDoc(InputStream in)
|
||||
throws SAXException, IOException
|
||||
{
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setIgnoringElementContentWhitespace(true);
|
||||
dbf.setValidating(true);
|
||||
dbf.setCoalescing(true);
|
||||
dbf.setIgnoringComments(true);
|
||||
try {
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
db.setEntityResolver(new Resolver());
|
||||
db.setErrorHandler(new EH());
|
||||
return db.parse(new InputSource(in));
|
||||
} catch (ParserConfigurationException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write XML document to the specified output stream.
|
||||
*/
|
||||
private static final void writeDoc(Document doc, OutputStream out)
|
||||
throws IOException
|
||||
{
|
||||
try {
|
||||
TransformerFactory tf = TransformerFactory.newInstance();
|
||||
try {
|
||||
tf.setAttribute("indent-number", new Integer(2));
|
||||
} catch (IllegalArgumentException iae) {
|
||||
//Ignore the IAE. Should not fail the writeout even the
|
||||
//transformer provider does not support "indent-number".
|
||||
}
|
||||
Transformer t = tf.newTransformer();
|
||||
t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doc.getDoctype().getSystemId());
|
||||
t.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||
//Transformer resets the "indent" info if the "result" is a StreamResult with
|
||||
//an OutputStream object embedded, creating a Writer object on top of that
|
||||
//OutputStream object however works.
|
||||
t.transform(new DOMSource(doc),
|
||||
new StreamResult(new BufferedWriter(new OutputStreamWriter(out, "UTF-8"))));
|
||||
} catch(TransformerException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively traverse the specified preferences node and store
|
||||
* the described preferences into the system or current user
|
||||
* preferences tree, as appropriate.
|
||||
*/
|
||||
private static void ImportSubtree(Preferences prefsNode, Element xmlNode) {
|
||||
NodeList xmlKids = xmlNode.getChildNodes();
|
||||
int numXmlKids = xmlKids.getLength();
|
||||
/*
|
||||
* We first lock the node, import its contents and get
|
||||
* child nodes. Then we unlock the node and go to children
|
||||
* Since some of the children might have been concurrently
|
||||
* deleted we check for this.
|
||||
*/
|
||||
Preferences[] prefsKids;
|
||||
/* Lock the node */
|
||||
synchronized (((AbstractPreferences)prefsNode).lock) {
|
||||
//If removed, return silently
|
||||
if (((AbstractPreferences)prefsNode).isRemoved())
|
||||
return;
|
||||
|
||||
// Import any preferences at this node
|
||||
Element firstXmlKid = (Element) xmlKids.item(0);
|
||||
ImportPrefs(prefsNode, firstXmlKid);
|
||||
prefsKids = new Preferences[numXmlKids - 1];
|
||||
|
||||
// Get involved children
|
||||
for (int i=1; i < numXmlKids; i++) {
|
||||
Element xmlKid = (Element) xmlKids.item(i);
|
||||
prefsKids[i-1] = prefsNode.node(xmlKid.getAttribute("name"));
|
||||
}
|
||||
} // unlocked the node
|
||||
// import children
|
||||
for (int i=1; i < numXmlKids; i++)
|
||||
ImportSubtree(prefsKids[i-1], (Element)xmlKids.item(i));
|
||||
}
|
||||
|
||||
/**
|
||||
* Import the preferences described by the specified XML element
|
||||
* (a map from a preferences document) into the specified
|
||||
* preferences node.
|
||||
*/
|
||||
private static void ImportPrefs(Preferences prefsNode, Element map) {
|
||||
NodeList entries = map.getChildNodes();
|
||||
for (int i=0, numEntries = entries.getLength(); i < numEntries; i++) {
|
||||
Element entry = (Element) entries.item(i);
|
||||
prefsNode.put(entry.getAttribute("key"),
|
||||
entry.getAttribute("value"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Export the specified Map<String,String> to a map document on
|
||||
* the specified OutputStream as per the prefs DTD. This is used
|
||||
* as the internal (undocumented) format for FileSystemPrefs.
|
||||
*
|
||||
* @throws IOException if writing to the specified output stream
|
||||
* results in an <tt>IOException</tt>.
|
||||
*/
|
||||
static void exportMap(OutputStream os, Map<String, String> map) throws IOException {
|
||||
Document doc = createPrefsDoc("map");
|
||||
Element xmlMap = doc.getDocumentElement( ) ;
|
||||
xmlMap.setAttribute("MAP_XML_VERSION", MAP_XML_VERSION);
|
||||
|
||||
for (Iterator<Map.Entry<String, String>> i = map.entrySet().iterator(); i.hasNext(); ) {
|
||||
Map.Entry<String, String> e = i.next();
|
||||
Element xe = (Element)
|
||||
xmlMap.appendChild(doc.createElement("entry"));
|
||||
xe.setAttribute("key", e.getKey());
|
||||
xe.setAttribute("value", e.getValue());
|
||||
}
|
||||
|
||||
writeDoc(doc, os);
|
||||
}
|
||||
|
||||
/**
|
||||
* Import Map from the specified input stream, which is assumed
|
||||
* to contain a map document as per the prefs DTD. This is used
|
||||
* as the internal (undocumented) format for FileSystemPrefs. The
|
||||
* key-value pairs specified in the XML document will be put into
|
||||
* the specified Map. (If this Map is empty, it will contain exactly
|
||||
* the key-value pairs int the XML-document when this method returns.)
|
||||
*
|
||||
* @throws IOException if reading from the specified output stream
|
||||
* results in an <tt>IOException</tt>.
|
||||
* @throws InvalidPreferencesFormatException Data on input stream does not
|
||||
* constitute a valid XML document with the mandated document type.
|
||||
*/
|
||||
static void importMap(InputStream is, Map<String, String> m)
|
||||
throws IOException, InvalidPreferencesFormatException
|
||||
{
|
||||
try {
|
||||
Document doc = loadPrefsDoc(is);
|
||||
Element xmlMap = doc.getDocumentElement();
|
||||
// check version
|
||||
String mapVersion = xmlMap.getAttribute("MAP_XML_VERSION");
|
||||
if (mapVersion.compareTo(MAP_XML_VERSION) > 0)
|
||||
throw new InvalidPreferencesFormatException(
|
||||
"Preferences map file format version " + mapVersion +
|
||||
" is not supported. This java installation can read" +
|
||||
" versions " + MAP_XML_VERSION + " or older. You may need" +
|
||||
" to install a newer version of JDK.");
|
||||
|
||||
NodeList entries = xmlMap.getChildNodes();
|
||||
for (int i=0, numEntries=entries.getLength(); i<numEntries; i++) {
|
||||
Element entry = (Element) entries.item(i);
|
||||
m.put(entry.getAttribute("key"), entry.getAttribute("value"));
|
||||
}
|
||||
} catch(SAXException e) {
|
||||
throw new InvalidPreferencesFormatException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Resolver implements EntityResolver {
|
||||
public InputSource resolveEntity(String pid, String sid)
|
||||
throws SAXException
|
||||
{
|
||||
if (sid.equals(PREFS_DTD_URI)) {
|
||||
InputSource is;
|
||||
is = new InputSource(new StringReader(PREFS_DTD));
|
||||
is.setSystemId(PREFS_DTD_URI);
|
||||
return is;
|
||||
}
|
||||
throw new SAXException("Invalid system identifier: " + sid);
|
||||
}
|
||||
}
|
||||
|
||||
private static class EH implements ErrorHandler {
|
||||
public void error(SAXParseException x) throws SAXException {
|
||||
throw x;
|
||||
}
|
||||
public void fatalError(SAXParseException x) throws SAXException {
|
||||
throw x;
|
||||
}
|
||||
public void warning(SAXParseException x) throws SAXException {
|
||||
throw x;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user