示例#1
0
  /**
   * 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);
    }
  }
 /**
  * Called to store current property value into XML subtree. The property value should be set using
  * the setValue method prior to calling this method.
  *
  * @param doc The XML document to store the XML in - should be used for creating nodes only
  * @return the XML DOM element representing a subtree of XML from which the value should be loaded
  */
 public org.w3c.dom.Node storeToXML(org.w3c.dom.Document doc) {
   org.w3c.dom.Element el = doc.createElement(XML_CURSOR);
   el.setAttribute(ATTR_ID, getAsText());
   return el;
 }