/** * Similar to the XMLRepresentation interface, this method will append an XML representation of * some preferences to an existing node. * * @param prefs the preferences node to write out. * @param deep - true to include a subtree with all child preferences nodes. * @param domDoc the document in which the node will reside. * @param node the node to which a child is applied. */ public static void toXML( Preferences prefs, boolean deep, org.w3c.dom.Document domDoc, Element node, Map options) throws IOException { String[] keys; String[] children; Element childElement, entry; String value; int i; // System.err.println( "node = "+prefs.name() ); try { keys = prefs.keys(); childElement = (Element) node.appendChild(domDoc.createElement("map")); for (i = 0; i < keys.length; i++) { value = prefs.get(keys[i], null); // System.err.println( " key = "+keys[i]+"; value = "+value ); if (value == null) continue; entry = (Element) childElement.appendChild(domDoc.createElement("entry")); entry.setAttribute("key", keys[i]); entry.setAttribute("value", value); } if (deep) { children = prefs.childrenNames(); for (i = 0; i < children.length; i++) { childElement = (Element) node.appendChild(domDoc.createElement("node")); childElement.setAttribute("name", children[i]); toXML(prefs.node(children[i]), deep, domDoc, childElement, options); } } } catch (DOMException e1) { throw IOUtil.map(e1); } catch (BackingStoreException e2) { throw IOUtil.map(e2); } }
/** * Similar to the XMLRepresentation interface, this method will parse an XML representation of * some preferences and restore it's values. * * @param prefs the preferences node to import to. * @param domDoc the document in which the node resides. * @param rootElement the node whose children to parse. */ public static void fromXML( Preferences prefs, org.w3c.dom.Document domDoc, Element rootElement, Map options) throws IOException { NodeList nl, nl2; Element childElement, entry; Node node; int i, j; try { nl = rootElement.getChildNodes(); for (i = 0; i < nl.getLength(); i++) { node = nl.item(i); if (!(node instanceof Element)) continue; childElement = (Element) node; nl2 = childElement.getElementsByTagName("entry"); for (j = 0; j < nl2.getLength(); j++) { entry = (Element) nl2.item(j); prefs.put(entry.getAttribute("key"), entry.getAttribute("value")); // System.err.println( "auto : node = "+(prefs.name() )+"; key = "+entry.getAttribute( // "key" )+"; val = "+entry.getAttribute( "value" ) ); } break; } for (; i < nl.getLength(); i++) { node = nl.item(i); if (!(node instanceof Element)) continue; childElement = (Element) node; fromXML(prefs.node(childElement.getAttribute("name")), domDoc, childElement, options); } } catch (DOMException e1) { throw IOUtil.map(e1); } }