Search in sources :

Example 1 with IElementContentHandler

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

the class TreeXmlReader method elementAttributesProcessed.

/*
	 * (non-Javadoc)
	 * @see
	 * freeplane.persistence.xml.n3.nanoxml.IXMLBuilder#elementAttributesProcessed
	 * (java.lang.String, java.lang.String, java.lang.String)
	 */
public void elementAttributesProcessed(final String name, final String nsPrefix, final String nsURI) throws Exception {
    xmlBuilder.elementAttributesProcessed(name, nsPrefix, nsURI);
    if (saveAsXmlUntil != null || nodeCreator != null) {
        return;
    }
    final Iterator<IElementHandler> iterator = getElementHandlers().iterator(tag);
    final XMLElement lastBuiltElement = xmlBuilder.getLastBuiltElement();
    while (iterator.hasNext() && currentElement == null) {
        nodeCreator = iterator.next();
        try {
            currentElement = nodeCreator.createElement(parentElement, name, lastBuiltElement);
        } catch (Exception e) {
            LogUtils.severe("Can not process element" + name, e);
        }
    }
    if (currentElement != null) {
        if (nodeCreator instanceof IElementContentHandler) {
            parser.notParseNextElementContent();
        }
        attributeHandlersForTag = getAttributeLoaders().get(tag);
        if (attributeHandlersForTag == null) {
            return;
        }
        final Enumeration<String> attributeNames = lastBuiltElement.enumerateAttributeNames();
        while (attributeNames.hasMoreElements()) {
            final String atName = (String) attributeNames.nextElement();
            if (addAttribute(atName, lastBuiltElement.getAttribute(atName, null))) {
                lastBuiltElement.removeAttribute(atName);
            }
        }
    } else {
        currentElement = null;
        nodeCreator = null;
        saveAsXmlUntil = lastBuiltElement;
    }
}
Also used : IElementContentHandler(org.freeplane.core.io.IElementContentHandler) IElementHandler(org.freeplane.core.io.IElementHandler) XMLElement(org.freeplane.n3.nanoxml.XMLElement) XMLException(org.freeplane.n3.nanoxml.XMLException)

Example 2 with IElementContentHandler

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

the class TreeXmlReader method endElement.

/*
	 * (non-Javadoc)
	 * @see
	 * freeplane.persistence.xml.n3.nanoxml.IXMLBuilder#endElement(java.lang
	 * .String, java.lang.String, java.lang.String)
	 */
public void endElement(final String name, final String nsPrefix, final String nsURI) throws Exception {
    final XMLElement lastBuiltElement = xmlBuilder.getParentElement();
    xmlBuilder.endElement(name, nsPrefix, nsURI);
    if (saveAsXmlUntil == lastBuiltElement) {
        saveAsXmlUntil = null;
    }
    if (saveAsXmlUntil != null) {
        return;
    }
    tag = null;
    if (0 == elementStack.size()) {
        return;
    }
    final Object element = currentElement;
    currentElement = elementStack.removeLast();
    try {
        if (nodeCreator instanceof IElementContentHandler) {
            ((IElementContentHandler) nodeCreator).endElement(currentElement, name, element, lastBuiltElement, elementContentAsString);
        } else if (nodeCreator instanceof IElementDOMHandler) {
            ((IElementDOMHandler) nodeCreator).endElement(currentElement, name, element, lastBuiltElement);
        }
    } catch (Exception e) {
        LogUtils.severe("Can not process element" + name, e);
    }
    final XMLElement top = lastBuiltElement.getParent();
    if (nodeCreator != null && top != null && top.hasChildren()) {
        final int lastChildIndex = top.getChildrenCount() - 1;
        top.removeChildAtIndex(lastChildIndex);
    }
    nodeCreator = (IElementHandler) nodeCreatorStack.removeLast();
    elementContentAsString = null;
}
Also used : IElementContentHandler(org.freeplane.core.io.IElementContentHandler) IElementDOMHandler(org.freeplane.core.io.IElementDOMHandler) XMLElement(org.freeplane.n3.nanoxml.XMLElement) XMLException(org.freeplane.n3.nanoxml.XMLException) Point(java.awt.Point)

Aggregations

IElementContentHandler (org.freeplane.core.io.IElementContentHandler)2 XMLElement (org.freeplane.n3.nanoxml.XMLElement)2 XMLException (org.freeplane.n3.nanoxml.XMLException)2 Point (java.awt.Point)1 IElementDOMHandler (org.freeplane.core.io.IElementDOMHandler)1 IElementHandler (org.freeplane.core.io.IElementHandler)1