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();
}
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();
}
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();
}
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();
}
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;
}
Aggregations