Esempio n. 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);
    }
  }
  @Test
  public void testPng() throws Exception {
    String path =
        ProcessDefManagerTest.class.getClassLoader().getResource("graphsub.xml").getPath();
    String value = FileUtils.readFileToString(new File(path));
    mxCodec codec = new mxCodec();
    org.w3c.dom.Document doc = mxXmlUtils.parseXml(value);
    codec = new mxCodec(doc);
    mxGraphModel model = (mxGraphModel) codec.decode(doc.getDocumentElement());
    mxGraph graph = new mxGraph();
    graph.setModel(model);
    BufferedImage image =
        mxCellRenderer.createBufferedImage(graph, null, 1, Color.WHITE, true, null);
    byte[] ret = null;
    ByteArrayOutputStream outputStream = null;
    try {
      outputStream = new ByteArrayOutputStream();
      ImageIO.write(image, "png", outputStream);
      ret = outputStream.toByteArray();
      FileUtils.writeByteArrayToFile(new File("/Users/lihao/Downloads/graph.png"), ret);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 private static mxGraphModel getMxGraphModel(String gxml) {
   mxCodec codec = new mxCodec();
   org.w3c.dom.Document doc = mxXmlUtils.parseXml(gxml);
   codec = new mxCodec(doc);
   mxGraphModel model = (mxGraphModel) codec.decode(doc.getDocumentElement());
   return model;
 }
 /**
  * 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;
 }