Search in sources :

Example 1 with IElementWriter

use of org.freeplane.core.io.IElementWriter in project freeplane by freeplane.

the class TreeXmlWriter method addElement.

@SuppressWarnings("unchecked")
public void addElement(final Object userObject, final XMLElement element) throws IOException {
    final boolean isString = userObject instanceof String;
    if (elementStarted == false && xmlElement != null) {
        xmlwriter.write(xmlElement, !isString, 0, true, false);
    }
    final String name = element.getName();
    xmlElement = element;
    elementStarted = false;
    {
        final Iterator<IAttributeWriter> iterator = getAttributeWriters().iterator(name);
        while (iterator.hasNext()) {
            final IAttributeWriter as = iterator.next();
            as.writeAttributes(this, userObject, name);
        }
        if (userObject instanceof List<?>) {
            addExtensionAttributes(userObject, (List<IExtension>) userObject);
        }
    }
    if (isString) {
        addElementContent((String) userObject);
    } else {
        final Iterator<IElementWriter> iterator = getNodeWriters().iterator(name);
        while (iterator.hasNext()) {
            final IElementWriter nw = iterator.next();
            nw.writeContent(this, userObject, name);
        }
        if (userObject instanceof List<?>) {
            addExtensionNodes(userObject, (List<IExtension>) userObject);
        }
    }
    if (elementStarted == false) {
        xmlwriter.write(xmlElement, true, 0, true, true);
        elementStarted = true;
    } else {
        xmlwriter.endElement(name, true);
    }
}
Also used : IAttributeWriter(org.freeplane.core.io.IAttributeWriter) IElementWriter(org.freeplane.core.io.IElementWriter) IExtension(org.freeplane.core.extension.IExtension) Iterator(java.util.Iterator) ListIterator(java.util.ListIterator) List(java.util.List)

Aggregations

Iterator (java.util.Iterator)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 IExtension (org.freeplane.core.extension.IExtension)1 IAttributeWriter (org.freeplane.core.io.IAttributeWriter)1 IElementWriter (org.freeplane.core.io.IElementWriter)1