private static void exportNode(StringTokenizer ancestors, Preferences prefs, boolean withSubTree, BufferedWriter out) throws IOException, BackingStoreException { if (ancestors.hasMoreTokens()) { String name = ancestors.nextToken(); flushStartTag("node", new String[] { "name" }, new String[] { name }, out); if (ancestors.hasMoreTokens()) { flushEmptyElement("map", out); exportNode(ancestors, prefs, withSubTree, out); } else { exportEntries(prefs, out); if (withSubTree) { exportSubTree(prefs, out); } } flushEndTag("node", out); } }
@Override public void exportNode(OutputStream ostream) throws IOException, BackingStoreException { if (ostream == null) { throw new NullPointerException("ostream == null"); } checkState(); XMLParser.exportPrefs(this, ostream, false); }
private static void flushStartTag(String tagName, String[] attrKeys, String[] attrValues, BufferedWriter out) throws IOException { flushIndent(++indent, out); out.write("<"); out.write(tagName); flushPairs(attrKeys, attrValues, out); out.write(">"); out.newLine(); }
private static void exportEntries(String[] keys, String[] values, BufferedWriter out) throws IOException { if (keys.length == 0) { flushEmptyElement("map", out); return; } flushStartTag("map", out); for (int i = 0; i < keys.length; i++) { if (values[i] != null) { flushEmptyElement("entry", new String[] { "key", "value" }, new String[] { keys[i], values[i] }, out); } } flushEndTag("map", out); }
private static void exportSubTree(Preferences prefs, BufferedWriter out) throws BackingStoreException, IOException { String[] names = prefs.childrenNames(); if (names.length > 0) { for (int i = 0; i < names.length; i++) { Preferences child = prefs.node(names[i]); flushStartTag("node", new String[] { "name" }, new String[] { names[i] }, out); exportEntries(child, out); exportSubTree(child, out); flushEndTag("node", out); } } }
/*************************************************************************** * utilities for Preferences export **************************************************************************/ static void exportPrefs(Preferences prefs, OutputStream stream, boolean withSubTree) throws IOException, BackingStoreException { indent = -1; BufferedWriter out = new BufferedWriter(new OutputStreamWriter(stream, "UTF-8")); out.write(HEADER); out.newLine(); out.newLine(); out.write(DOCTYPE); out.write(" '"); out.write(PREFS_DTD_NAME); out.write("'>"); out.newLine(); out.newLine(); flushStartTag("preferences", new String[] { "EXTERNAL_XML_VERSION" }, new String[] { String.valueOf(XML_VERSION) }, out); flushStartTag("root", new String[] { "type" }, new String[] { prefs.isUserNode() ? "user" : "system" }, out); flushEmptyElement("map", out); StringTokenizer ancestors = new StringTokenizer(prefs.absolutePath(), "/"); exportNode(ancestors, prefs, withSubTree, out); flushEndTag("root", out); flushEndTag("preferences", out); out.flush(); out = null; }
private static void flushEmptyElement(String tagName, BufferedWriter out) throws IOException { flushIndent(++indent, out); out.write("<"); out.write(tagName); out.write(" />"); out.newLine(); indent--; }
private static void exportEntries(Preferences prefs, BufferedWriter out) throws BackingStoreException, IOException { String[] keys = prefs.keys(); String[] values = new String[keys.length]; for (int i = 0; i < keys.length; i++) { values[i] = prefs.get(keys[i], null); } exportEntries(keys, values, out); }
private static void flushPairs(String[] attrKeys, String[] attrValues, BufferedWriter out) throws IOException { for (int i = 0; i < attrKeys.length; i++) { out.write(" "); out.write(attrKeys[i]); out.write("=\""); out.write(htmlEncode(attrValues[i])); out.write("\""); } }
private static void exportSubTree(Preferences prefs, BufferedWriter out) throws BackingStoreException, IOException { String[] names = prefs.childrenNames(); if (names.length > 0) { for (int i = 0; i < names.length; i++) { Preferences child = prefs.node(names[i]); flushStartTag("node", new String[] { "name" }, new String[] { names[i] }, out); exportEntries(child, out); exportSubTree(child, out); flushEndTag("node", out); } } }
/*************************************************************************** * utilities for Preferences export **************************************************************************/ static void exportPrefs(Preferences prefs, OutputStream stream, boolean withSubTree) throws IOException, BackingStoreException { indent = -1; BufferedWriter out = new BufferedWriter(new OutputStreamWriter(stream, "UTF-8")); out.write(HEADER); out.newLine(); out.newLine(); out.write(DOCTYPE); out.write(" '"); out.write(PREFS_DTD_NAME); out.write("'>"); out.newLine(); out.newLine(); flushStartTag("preferences", new String[] { "EXTERNAL_XML_VERSION" }, new String[] { String.valueOf(XML_VERSION) }, out); flushStartTag("root", new String[] { "type" }, new String[] { prefs.isUserNode() ? "user" : "system" }, out); flushEmptyElement("map", out); StringTokenizer ancestors = new StringTokenizer(prefs.absolutePath(), "/"); exportNode(ancestors, prefs, withSubTree, out); flushEndTag("root", out); flushEndTag("preferences", out); out.flush(); out = null; }
private static void exportEntries(String[] keys, String[] values, BufferedWriter out) throws IOException { if (keys.length == 0) { flushEmptyElement("map", out); return; } flushStartTag("map", out); for (int i = 0; i < keys.length; i++) { if (values[i] != null) { flushEmptyElement("entry", new String[] { "key", "value" }, new String[] { keys[i], values[i] }, out); } } flushEndTag("map", out); }
private static void flushEndTag(String tagName, BufferedWriter out) throws IOException { flushIndent(indent--, out); out.write("</"); out.write(tagName); out.write(">"); out.newLine(); }
values[i] = properties.getProperty(keys[i]); exportEntries(keys, values, out); out.close(); if (!temporaryForWriting.renameTo(xmlFile)) {
private static void flushPairs(String[] attrKeys, String[] attrValues, BufferedWriter out) throws IOException { for (int i = 0; i < attrKeys.length; i++) { out.write(" "); out.write(attrKeys[i]); out.write("=\""); out.write(htmlEncode(attrValues[i])); out.write("\""); } }
private static void exportNode(StringTokenizer ancestors, Preferences prefs, boolean withSubTree, BufferedWriter out) throws IOException, BackingStoreException { if (ancestors.hasMoreTokens()) { String name = ancestors.nextToken(); flushStartTag("node", new String[] { "name" }, new String[] { name }, out); if (ancestors.hasMoreTokens()) { flushEmptyElement("map", out); exportNode(ancestors, prefs, withSubTree, out); } else { exportEntries(prefs, out); if (withSubTree) { exportSubTree(prefs, out); } } flushEndTag("node", out); } }
private static void exportSubTree(Preferences prefs, BufferedWriter out) throws BackingStoreException, IOException { String[] names = prefs.childrenNames(); if (names.length > 0) { for (int i = 0; i < names.length; i++) { Preferences child = prefs.node(names[i]); flushStartTag("node", new String[] { "name" }, new String[] { names[i] }, out); exportEntries(child, out); exportSubTree(child, out); flushEndTag("node", out); } } }
/*************************************************************************** * utilities for Preferences export **************************************************************************/ static void exportPrefs(Preferences prefs, OutputStream stream, boolean withSubTree) throws IOException, BackingStoreException { indent = -1; BufferedWriter out = new BufferedWriter(new OutputStreamWriter(stream, "UTF-8")); out.write(HEADER); out.newLine(); out.newLine(); out.write(DOCTYPE); out.write(" '"); out.write(PREFS_DTD_NAME); out.write("'>"); out.newLine(); out.newLine(); flushStartTag("preferences", new String[] { "EXTERNAL_XML_VERSION" }, new String[] { String.valueOf(XML_VERSION) }, out); flushStartTag("root", new String[] { "type" }, new String[] { prefs.isUserNode() ? "user" : "system" }, out); flushEmptyElement("map", out); StringTokenizer ancestors = new StringTokenizer(prefs.absolutePath(), "/"); exportNode(ancestors, prefs, withSubTree, out); flushEndTag("root", out); flushEndTag("preferences", out); out.flush(); out = null; }
private static void exportEntries(String[] keys, String[] values, BufferedWriter out) throws IOException { if (keys.length == 0) { flushEmptyElement("map", out); return; } flushStartTag("map", out); for (int i = 0; i < keys.length; i++) { if (values[i] != null) { flushEmptyElement("entry", new String[] { "key", "value" }, new String[] { keys[i], values[i] }, out); } } flushEndTag("map", out); }
private static void flushEmptyElement(String tagName, String[] attrKeys, String[] attrValues, BufferedWriter out) throws IOException { flushIndent(++indent, out); out.write("<"); out.write(tagName); flushPairs(attrKeys, attrValues, out); out.write(" />"); out.newLine(); indent--; }