Search in sources :

Example 56 with XMLElement

use of org.freeplane.n3.nanoxml.XMLElement in project freeplane by freeplane.

the class StdXMLBuilder method startElement.

/**
 * This method is called when a new XML element is encountered.
 *
 * @see #endElement
 * @param name
 *            the name of the element.
 * @param nsPrefix
 *            the prefix used to identify the namespace. If no namespace has
 *            been specified, this parameter is null.
 * @param nsURI
 *            the URI associated with the namespace. If no namespace has
 *            been specified, or no URI is associated with nsPrefix, this
 *            parameter is null.
 * @param systemID
 *            the system ID of the XML data source.
 * @param lineNr
 *            the line in the source where the element starts.
 */
public void startElement(final String name, final String nsPrefix, final String nsURI, final String systemID, final int lineNr) {
    String fullName = name;
    if (nsPrefix != null) {
        fullName = nsPrefix + ':' + name;
    }
    final XMLElement elt = new XMLElement(fullName, nsURI, systemID, lineNr);
    last = elt;
    if (stack.empty()) {
        root = elt;
    } else {
        final XMLElement top = (XMLElement) stack.peek();
        top.addChild(elt);
    }
    stack.push(elt);
}
Also used : XMLElement(org.freeplane.n3.nanoxml.XMLElement)

Example 57 with XMLElement

use of org.freeplane.n3.nanoxml.XMLElement in project freeplane by freeplane.

the class StdXMLBuilder method endElement.

/**
 * This method is called when the end of an XML elemnt is encountered.
 *
 * @see #startElement
 * @param name
 *            the name of the element.
 * @param nsPrefix
 *            the prefix used to identify the namespace. If no namespace has
 *            been specified, this parameter is null.
 * @param nsURI
 *            the URI associated with the namespace. If no namespace has
 *            been specified, or no URI is associated with nsPrefix, this
 *            parameter is null.
 */
public void endElement(final String name, final String nsPrefix, final String nsURI) {
    final XMLElement elt = (XMLElement) stack.pop();
    if (elt.getChildrenCount() == 1) {
        final XMLElement child = elt.getChildAtIndex(0);
        if (child.getName() == null) {
            elt.setContent(child.getContent());
            elt.removeChildAtIndex(0);
        }
    }
}
Also used : XMLElement(org.freeplane.n3.nanoxml.XMLElement)

Example 58 with XMLElement

use of org.freeplane.n3.nanoxml.XMLElement in project freeplane by freeplane.

the class StdXMLBuilder method addAttribute.

/**
 * This method is called when a new attribute of an XML element is
 * encountered.
 *
 * @param key
 *            the key (name) of the attribute.
 * @param nsPrefix
 *            the prefix used to identify the namespace. If no namespace has
 *            been specified, this parameter is null.
 * @param nsURI
 *            the URI associated with the namespace. If no namespace has
 *            been specified, or no URI is associated with nsPrefix, this
 *            parameter is null.
 * @param value
 *            the value of the attribute.
 * @param type
 *            the type of the attribute. If no type is known, "CDATA" is
 *            returned.
 * @throws java.lang.Exception
 *             If an exception occurred while processing the event.
 */
public void addAttribute(final String key, final String nsPrefix, final String nsURI, final String value, final String type) throws Exception {
    String fullName = key;
    if (nsPrefix != null) {
        fullName = nsPrefix + ':' + key;
    }
    final XMLElement top = stack.peek();
    if (top.hasAttribute(fullName)) {
        throw new XMLParseException(top.getSystemID(), top.getLineNr(), "Duplicate attribute: " + key);
    }
    if (nsPrefix != null) {
        top.setAttribute(fullName, nsURI, value);
    } else {
        top.setAttribute(fullName, value);
    }
}
Also used : XMLElement(org.freeplane.n3.nanoxml.XMLElement) XMLParseException(org.freeplane.n3.nanoxml.XMLParseException)

Example 59 with XMLElement

use of org.freeplane.n3.nanoxml.XMLElement in project freeplane by freeplane.

the class StdXMLBuilder method addPCData.

/**
 * This method is called when a PCDATA element is encountered. A Java reader
 * is supplied from which you can read the data. The reader will only read
 * the data of the element. You don't need to check for boundaries. If you
 * don't read the full element, the rest of the data is skipped. You also
 * don't have to care about entities; they are resolved by the parser.
 *
 * @param reader
 *            the Java reader from which you can retrieve the data.
 * @param systemID
 *            the system ID of the XML data source.
 * @param lineNr
 *            the line in the source where the element starts.
 */
public void addPCData(final Reader reader, final String systemID, final int lineNr) {
    int bufSize = 2048;
    int sizeRead = 0;
    final StringBuilder str = new StringBuilder(bufSize);
    final char[] buf = new char[bufSize];
    for (; ; ) {
        if (sizeRead >= bufSize) {
            bufSize *= 2;
            str.ensureCapacity(bufSize);
        }
        int size;
        try {
            size = reader.read(buf);
        } catch (final IOException e) {
            break;
        }
        if (size < 0) {
            break;
        }
        str.append(buf, 0, size);
        sizeRead += size;
    }
    final XMLElement elt = prototype.createElement(null, systemID, lineNr);
    elt.setContent(str.toString());
    if (!stack.empty()) {
        final XMLElement top = (XMLElement) stack.peek();
        top.addChild(elt);
    }
}
Also used : IOException(java.io.IOException) XMLElement(org.freeplane.n3.nanoxml.XMLElement)

Example 60 with XMLElement

use of org.freeplane.n3.nanoxml.XMLElement 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

XMLElement (org.freeplane.n3.nanoxml.XMLElement)63 IOException (java.io.IOException)8 IXMLParser (org.freeplane.n3.nanoxml.IXMLParser)7 IXMLReader (org.freeplane.n3.nanoxml.IXMLReader)7 StdXMLReader (org.freeplane.n3.nanoxml.StdXMLReader)7 BufferedInputStream (java.io.BufferedInputStream)5 File (java.io.File)5 FileInputStream (java.io.FileInputStream)5 ASelectableCondition (org.freeplane.features.filter.condition.ASelectableCondition)5 NodeModel (org.freeplane.features.map.NodeModel)5 XMLWriter (org.freeplane.n3.nanoxml.XMLWriter)4 Color (java.awt.Color)3 FileWriter (java.io.FileWriter)3 Writer (java.io.Writer)3 IXMLElement (net.n3.nanoxml.IXMLElement)3 XMLElement (net.n3.nanoxml.XMLElement)3 XMLException (org.freeplane.n3.nanoxml.XMLException)3 Point (java.awt.Point)2 FilenameFilter (java.io.FilenameFilter)2 HashMap (java.util.HashMap)2