Search in sources :

Example 46 with Element

use of org.w3c.dom.Element in project jmonkeyengine by jMonkeyEngine.

the class DOMOutputCapsule method writeStringSavableMap.

@Override
public void writeStringSavableMap(Map<String, ? extends Savable> map, String name, Map<String, ? extends Savable> defVal) throws IOException {
    if (map == null) {
        return;
    }
    if (map.equals(defVal)) {
        return;
    }
    Element stringMap = appendElement(name);
    Iterator<String> keyIterator = map.keySet().iterator();
    while (keyIterator.hasNext()) {
        String key = keyIterator.next();
        Element mapEntry = appendElement("MapEntry");
        mapEntry.setAttribute("key", key);
        Savable s = map.get(key);
        write(s, "Savable", null);
        currentElement = stringMap;
    }
    currentElement = (Element) stringMap.getParentNode();
}
Also used : Savable(com.jme3.export.Savable) Element(org.w3c.dom.Element)

Example 47 with Element

use of org.w3c.dom.Element in project jmonkeyengine by jMonkeyEngine.

the class DOMOutputCapsule method write.

@Override
public void write(FloatBuffer value, String name, FloatBuffer defVal) throws IOException {
    if (value == null) {
        return;
    }
    Element el = appendElement(name);
    el.setAttribute("size", String.valueOf(value.limit()));
    StringBuilder buf = new StringBuilder();
    int pos = value.position();
    value.rewind();
    int ctr = 0;
    while (value.hasRemaining()) {
        ctr++;
        buf.append(value.get());
        buf.append(" ");
    }
    if (ctr != value.limit()) {
        throw new IOException("'" + name + "' buffer contention resulted in write data consistency.  " + ctr + " values written when should have written " + value.limit());
    }
    if (buf.length() > 0) {
        //remove last space
        buf.setLength(buf.length() - 1);
    }
    value.position(pos);
    el.setAttribute(dataAttributeName, buf.toString());
    currentElement = (Element) el.getParentNode();
}
Also used : Element(org.w3c.dom.Element) IOException(java.io.IOException)

Example 48 with Element

use of org.w3c.dom.Element in project jmonkeyengine by jMonkeyEngine.

the class DOMOutputCapsule method write.

@Override
public void write(Savable[][] value, String name, Savable[][] defVal) throws IOException {
    if (value == null)
        return;
    if (Arrays.deepEquals(value, defVal))
        return;
    Element el = appendElement(name);
    el.setAttribute("size_outer", String.valueOf(value.length));
    el.setAttribute("size_inner", String.valueOf(value[0].length));
    for (Savable[] bs : value) {
        for (Savable b : bs) {
            write(b, b.getClass().getSimpleName(), null);
        }
    }
    currentElement = (Element) currentElement.getParentNode();
}
Also used : Savable(com.jme3.export.Savable) Element(org.w3c.dom.Element)

Example 49 with Element

use of org.w3c.dom.Element in project jmonkeyengine by jMonkeyEngine.

the class DOMOutputCapsule method writeSavableArrayListArray2D.

@Override
public void writeSavableArrayListArray2D(ArrayList[][] value, String name, ArrayList[][] defVal) throws IOException {
    if (value == null)
        return;
    if (Arrays.deepEquals(value, defVal))
        return;
    Element el = appendElement(name);
    int size = value.length;
    el.setAttribute(XMLExporter.ATTRIBUTE_SIZE, String.valueOf(size));
    for (int i = 0; i < size; i++) {
        ArrayList[] vi = value[i];
        writeSavableArrayListArray(vi, "SavableArrayListArray_" + i, null);
    }
    currentElement = (Element) el.getParentNode();
}
Also used : Element(org.w3c.dom.Element)

Example 50 with Element

use of org.w3c.dom.Element in project jmonkeyengine by jMonkeyEngine.

the class DOMOutputCapsule method appendElement.

/**
     * appends a new Element with the given name to currentElement, sets
     * currentElement to be new Element, and returns the new Element as well
     */
private Element appendElement(String name) {
    Element ret = doc.createElement(name);
    if (currentElement == null) {
        ret.setAttribute("format_version", Integer.toString(FormatVersion.VERSION));
        doc.appendChild(ret);
    } else {
        currentElement.appendChild(ret);
    }
    currentElement = ret;
    return ret;
}
Also used : Element(org.w3c.dom.Element)

Aggregations

Element (org.w3c.dom.Element)9072 Document (org.w3c.dom.Document)2651 NodeList (org.w3c.dom.NodeList)2103 Node (org.w3c.dom.Node)1855 ArrayList (java.util.ArrayList)957 DocumentBuilder (javax.xml.parsers.DocumentBuilder)793 IOException (java.io.IOException)732 Test (org.junit.Test)693 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)591 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)489 HashMap (java.util.HashMap)434 SAXException (org.xml.sax.SAXException)406 File (java.io.File)358 Attr (org.w3c.dom.Attr)333 InputStream (java.io.InputStream)309 QName (javax.xml.namespace.QName)292 Map (java.util.Map)285 JAXBElement (javax.xml.bind.JAXBElement)285 NamedNodeMap (org.w3c.dom.NamedNodeMap)266 List (java.util.List)264