/** * Decodes the given XML node using {@link #decode(Node, Object)}. * * @param node XML node to be decoded. * @return Returns an object that represents the given node. */ public Object decode(Node node) { return decode(node, null); }
/** * Decodes the given XML node using {@link #decode(Node, Object)}. * * @param node XML node to be decoded. * @return Returns an object that represents the given node. */ public Object decode(Node node) { return decode(node, null); }
mxGraph graph = new mxGraph(); try { Document document = mxXmlUtils.parseXml(mxUtils.readFile(filePath)); mxCodec codec = new mxCodec(document); codec.decode(document.getDocumentElement(), graph.getModel()); } catch (Exception ex) { ex.printStackTrace(); }
dec.decode(xml, into);
dec.decode(xml, into);
Document doc = mxXmlUtils.parseXml(erXmlString); mxGraph graph = new mxGraph(); mxCodec codec = new mxCodec(doc); codec.decode(doc.getDocumentElement(), graph.getModel()); mxGraphComponent graphComponent = new mxGraphComponent(graph); BufferedImage image = mxCellRenderer.createBufferedImage(graphComponent.getGraph(), null, 1, Color.WHITE, graphComponent.isAntiAlias(), null, graphComponent.getCanvas()); mxPngEncodeParam param = mxPngEncodeParam.getDefaultEncodeParam(image); param.setCompressedText(new String[] { "mxGraphModel", erXmlString }); FileOutputStream outputStream = new FileOutputStream(new File(filename)); mxPngImageEncoder encoder = new mxPngImageEncoder(outputStream, param); if (image != null) { encoder.encode(image); return image; } outputStream.close(); return null; }
/** * Returns the decoded object for the element with the specified ID in * {@link #document}. If the object is not known then {@link #lookup(String)} * is used to find an object. If no object is found, then the element with * the respective ID from the document is parsed using {@link #decode(Node)}. * * @param id ID of the object to be returned. * @return Returns the object for the given ID. */ public Object getObject(String id) { Object obj = null; if (id != null) { obj = objects.get(id); if (obj == null) { obj = lookup(id); if (obj == null) { Node node = getElementById(id); if (node != null) { obj = decode(node); } } } } return obj; }
/** * Returns the decoded object for the element with the specified ID in * {@link #document}. If the object is not known then {@link #lookup(String)} * is used to find an object. If no object is found, then the element with * the respective ID from the document is parsed using {@link #decode(Node)}. * * @param id ID of the object to be returned. * @return Returns the object for the given ID. */ public Object getObject(String id) { Object obj = null; if (id != null) { obj = objects.get(id); if (obj == null) { obj = lookup(id); if (obj == null) { Node node = getElementById(id); if (node != null) { obj = decode(node); } } } } return obj; }
/** * Reads the specified child into the given object. */ protected void decodeChild(mxCodec dec, Node child, Object obj) { String fieldname = getFieldName(((Element) child).getAttribute("as")); if (fieldname == null || !isExcluded(obj, fieldname, child, false)) { Object template = getFieldTemplate(obj, fieldname, child); Object value = null; if (child.getNodeName().equals("add")) { value = ((Element) child).getAttribute("value"); if (value == null) { value = child.getTextContent(); } } else { value = dec.decode(child, template); // log.log(Level.FINEST, "Decoded " + child.getNodeName() + "." // + fieldname + "=" + value); } addObjectValue(obj, fieldname, value, template); } }
/** * Reads the specified child into the given object. */ protected void decodeChild(mxCodec dec, Node child, Object obj) { String fieldname = getFieldName(((Element) child).getAttribute("as")); if (fieldname == null || !isExcluded(obj, fieldname, child, false)) { Object template = getFieldTemplate(obj, fieldname, child); Object value = null; if (child.getNodeName().equals("add")) { value = ((Element) child).getAttribute("value"); if (value == null) { value = child.getTextContent(); } } else { value = dec.decode(child, template); // System.out.println("Decoded " + child.getNodeName() + "." // + fieldname + "=" + value); } addObjectValue(obj, fieldname, value, template); } }