/** * Creates a DOM representation of the object. Result is appended to the Node <code>parent</code>. * * @param parent */ public void makeElement(Node parent) { Document doc; if (parent instanceof Document) { doc = (Document) parent; } else { doc = parent.getOwnerDocument(); } Element element = doc.createElement("fixme"); int size; if (this.author_ != null) { URelaxer.setAttributePropertyByString(element, "author", this.author_); } if (this.id_ != null) { URelaxer.setAttributePropertyByString(element, "id", this.id_); } if (this.xmlLang_ != null) { URelaxer.setAttributePropertyByString(element, "xml:lang", this.xmlLang_); } size = this.content_.size(); for (int i = 0; i < size; i++) { IFdContentMixMixed value = (IFdContentMixMixed) this.content_.get(i); value.makeElement(element); } parent.appendChild(element); }
/** * Creates a DOM representation of the object. Result is appended to the Node <code>parent</code>. * * @param parent */ public void makeElement(Node parent) { Document doc; if (parent instanceof Document) { doc = (Document) parent; } else { doc = parent.getOwnerDocument(); } Element element = doc.createElement("table"); int size; if (this.id_ != null) { URelaxer.setAttributePropertyByString(element, "id", this.id_); } if (this.xmlLang_ != null) { URelaxer.setAttributePropertyByString(element, "xml:lang", this.xmlLang_); } if (this.caption_ != null) { this.caption_.makeElement(element); } size = this.tr_.size(); for (int i = 0; i < size; i++) { FcTr value = (FcTr) this.tr_.get(i); value.makeElement(element); } parent.appendChild(element); }
/** * Writes a table to a XML-file * * @param t - Output Model * @param destination - File Destination */ public static void writeXML(Model t, String destination) { try { // Create the XML document builder, and document that will be used DocumentBuilderFactory xmlBuilder = DocumentBuilderFactory.newInstance(); DocumentBuilder Builder = xmlBuilder.newDocumentBuilder(); Document xmldoc = Builder.newDocument(); // create Document node, and get it into the file Element Documentnode = xmldoc.createElement("SPREADSHEET"); xmldoc.appendChild(Documentnode); // create element nodes, and their attributes (Cells, and row/column // data) and their content for (int row = 1; row < t.getRows(); row++) { for (int col = 1; col < t.getCols(col); col++) { Element cell = xmldoc.createElement("CELL"); // set attributes cell.setAttribute("column", Integer.toString(col)); cell.setAttribute("row", Integer.toString(col)); // set content cell.appendChild(xmldoc.createTextNode((String) t.getContent(row, col))); // append node to document node Documentnode.appendChild(cell); } } // Creating a datastream for the DOM tree TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); // Indentation to make the XML file look better transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); // remove the java version transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); DOMSource stream = new DOMSource(xmldoc); StreamResult target = new StreamResult(new File(destination)); // write the file transformer.transform(stream, target); } catch (ParserConfigurationException e) { System.out.println("Can't create the XML document builder"); } catch (TransformerConfigurationException e) { System.out.println("Can't create transformer"); } catch (TransformerException e) { System.out.println("Can't write to file"); } }
protected void setAttribute(String name, String attName, String attValue) { Element elt = getElement(name); if (elt == null) { elt = doc.createElement(name); docElt.appendChild(elt); } elt.setAttribute(attName, attValue); }
private Element generateGraphicsNode(Document doc, ClassGraphics gr) { Element graphicsEl = doc.createElement(EL_GRAPHICS); Element bounds = doc.createElement(EL_BOUNDS); graphicsEl.appendChild(bounds); bounds.setAttribute(ATR_X, Integer.toString(gr.getBoundX())); bounds.setAttribute(ATR_Y, Integer.toString(gr.getBoundY())); bounds.setAttribute(ATR_WIDTH, Integer.toString(gr.getBoundWidth())); bounds.setAttribute(ATR_HEIGHT, Integer.toString(gr.getBoundHeight())); for (Shape shape : gr.getShapes()) { if (shape instanceof Rect) { Rect rect = (Rect) shape; Element rectEl = doc.createElement(EL_RECT); graphicsEl.appendChild(rectEl); rectEl.setAttribute(ATR_X, Integer.toString(rect.getX())); rectEl.setAttribute(ATR_Y, Integer.toString(rect.getY())); rectEl.setAttribute(ATR_WIDTH, Integer.toString(rect.getWidth())); rectEl.setAttribute(ATR_HEIGHT, Integer.toString(rect.getHeight())); rectEl.setAttribute(ATR_COLOUR, Integer.toString(rect.getColor().getRGB())); rectEl.setAttribute(ATR_FILLED, Boolean.toString(rect.isFilled())); rectEl.setAttribute(ATR_FIXED, Boolean.toString(rect.isFixed())); rectEl.setAttribute(ATR_STROKE, Float.toString(rect.getStroke().getLineWidth())); rectEl.setAttribute(ATR_LINETYPE, Float.toString(rect.getLineType())); rectEl.setAttribute(ATR_TRANSPARENCY, Integer.toString(rect.getTransparency())); } else if (shape instanceof Text) { Text text = (Text) shape; Element textEl = doc.createElement(EL_TEXT); textEl.setAttribute(ATR_STRING, text.getText()); textEl.setAttribute(ATR_X, Integer.toString(text.getX())); textEl.setAttribute(ATR_Y, Integer.toString(text.getY())); textEl.setAttribute(ATR_FONTNAME, text.getFont().getName()); textEl.setAttribute(ATR_FONTSIZE, Integer.toString(text.getFont().getSize())); textEl.setAttribute(ATR_FONTSTYLE, Integer.toString(text.getFont().getStyle())); textEl.setAttribute(ATR_TRANSPARENCY, Integer.toString(text.getTransparency())); textEl.setAttribute(ATR_COLOUR, Integer.toString(text.getColor().getRGB())); graphicsEl.appendChild(textEl); } // TODO handle the rest of shapes } return graphicsEl; }
private void create() { try { tracks = new Vector(); hash = new Hashtable(); createDOM(); doc = db.newDocument(); docElt = doc.createElement(docElementName); doc.appendChild(docElt); } catch (Exception e) { e.printStackTrace(); } }
/** @param name creates a node with this name */ public XML(String name) { try { // TODO is there a more efficient way of doing this? wow. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.newDocument(); node = document.createElement(name); this.parent = null; } catch (ParserConfigurationException pce) { throw new RuntimeException(pce); } }
private Element generatePortNode(Document doc, Port port) { Element portEl = doc.createElement(EL_PORT); portEl.setAttribute(ATR_NAME, port.getName()); portEl.setAttribute(ATR_TYPE, port.getType()); portEl.setAttribute(ATR_X, Integer.toString(port.getX())); portEl.setAttribute(ATR_Y, Integer.toString(port.getY())); portEl.setAttribute(ATR_PORT_CONNECTION, port.isArea() ? "area" : ""); portEl.setAttribute(ATR_STRICT, Boolean.toString(port.isStrict())); portEl.setAttribute(ATR_MULTI, Boolean.toString(port.isMulti())); return portEl; }
private Node generateFieldNode(Document doc, ClassField field) { Element fieldEl = doc.createElement(EL_FIELD); fieldEl.setAttribute(ATR_NAME, field.getName()); fieldEl.setAttribute(ATR_TYPE, field.getType()); if (field.isInput()) fieldEl.setAttribute(ATR_NATURE, "input"); else if (field.isGoal()) fieldEl.setAttribute(ATR_NATURE, "goal"); if (field.getValue() != null) fieldEl.setAttribute(ATR_VALUE, field.getValue()); return fieldEl; }
/** * Creates a DOM representation of the object. Result is appended to the Node <code>parent</code>. * * @param parent */ public void makeElement(Node parent) { Document doc; if (parent instanceof Document) { doc = (Document) parent; } else { doc = parent.getOwnerDocument(); } Element element = doc.createElement("header"); int size; if (this.id_ != null) { URelaxer.setAttributePropertyByString(element, "id", this.id_); } if (this.xmlLang_ != null) { URelaxer.setAttributePropertyByString(element, "xml:lang", this.xmlLang_); } this.title_.makeElement(element); if (this.subtitle_ != null) { this.subtitle_.makeElement(element); } if (this.version_ != null) { this.version_.makeElement(element); } if (this.type_ != null) { this.type_.makeElement(element); } if (this.authors_ != null) { this.authors_.makeElement(element); } size = this.notice_.size(); for (int i = 0; i < size; i++) { FtNotice value = (FtNotice) this.notice_.get(i); value.makeElement(element); } if (this.abstract_ != null) { this.abstract_.makeElement(element); } parent.appendChild(element); }
/** * @webref xml:method * @brief Appends a new child to the element */ public XML addChild(String tag) { Document document = node.getOwnerDocument(); Node newChild = document.createElement(tag); return appendChild(newChild); }
public void addPackageClass(PackageClass pClass) { Document doc; try { doc = getDocument(); } catch (Exception e) { e.printStackTrace(); return; } String name = pClass.getName(); // check if such class exists and remove duplicates Element rootEl = doc.getDocumentElement(); NodeList classEls = rootEl.getElementsByTagName(EL_CLASS); for (int i = 0; i < classEls.getLength(); i++) { Element nameEl = getElementByName((Element) classEls.item(i), EL_NAME); if (name.equals(nameEl.getTextContent())) { rootEl.removeChild(classEls.item(i)); } } Element classNode = doc.createElement(EL_CLASS); doc.getDocumentElement().appendChild(classNode); classNode.setAttribute(ATR_TYPE, PackageClass.ComponentType.SCHEME.getXmlName()); classNode.setAttribute(ATR_STATIC, "false"); Element className = doc.createElement(EL_NAME); className.setTextContent(name); classNode.appendChild(className); Element desrc = doc.createElement(EL_DESCRIPTION); desrc.setTextContent(pClass.getDescription()); classNode.appendChild(desrc); Element icon = doc.createElement(EL_ICON); icon.setTextContent(pClass.getIcon()); classNode.appendChild(icon); // graphics classNode.appendChild(generateGraphicsNode(doc, pClass.getGraphics())); // ports List<Port> ports = pClass.getPorts(); if (!ports.isEmpty()) { Element portsEl = doc.createElement(EL_PORTS); classNode.appendChild(portsEl); for (Port port : ports) { portsEl.appendChild(generatePortNode(doc, port)); } } // fields Collection<ClassField> fields = pClass.getFields(); if (!fields.isEmpty()) { Element fieldsEl = doc.createElement(EL_FIELDS); classNode.appendChild(fieldsEl); for (ClassField cf : fields) { fieldsEl.appendChild(generateFieldNode(doc, cf)); } } // write try { writeDocument(doc, new FileOutputStream(xmlFile)); } catch (FileNotFoundException e) { e.printStackTrace(); } }