Search in sources :

Example 36 with XMLElement

use of net.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 37 with XMLElement

use of net.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 38 with XMLElement

use of net.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 39 with XMLElement

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

the class OptionPanelWindowConfigurationStorage method decorateDialog.

public static OptionPanelWindowConfigurationStorage decorateDialog(final String marshalled, final JDialog dialog) {
    final OptionPanelWindowConfigurationStorage storage = new OptionPanelWindowConfigurationStorage();
    final XMLElement xml = storage.unmarschall(marshalled, dialog);
    if (xml != null) {
        storage.panel = xml.getAttribute("panel", null);
        return storage;
    }
    return null;
}
Also used : XMLElement(org.freeplane.n3.nanoxml.XMLElement)

Example 40 with XMLElement

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

the class UnknownElementWriter method writeAttributes.

public void writeAttributes(final ITreeWriter writer, final Object userObject, final IExtension extension) {
    final UnknownElements elements = (UnknownElements) extension;
    final XMLElement unknownElements = elements.getUnknownElements();
    if (unknownElements != null) {
        final Enumeration<String> unknownAttributes = unknownElements.enumerateAttributeNames();
        while (unknownAttributes.hasMoreElements()) {
            final String name = unknownAttributes.nextElement();
            final String value = unknownElements.getAttribute(name, null);
            writer.addAttribute(name, value);
        }
    }
}
Also used : XMLElement(org.freeplane.n3.nanoxml.XMLElement)

Aggregations

XMLElement (org.freeplane.n3.nanoxml.XMLElement)65 IOException (java.io.IOException)8 IXMLParser (org.freeplane.n3.nanoxml.IXMLParser)6 IXMLReader (org.freeplane.n3.nanoxml.IXMLReader)6 StdXMLReader (org.freeplane.n3.nanoxml.StdXMLReader)6 ASelectableCondition (org.freeplane.features.filter.condition.ASelectableCondition)5 NodeModel (org.freeplane.features.map.NodeModel)5 BufferedInputStream (java.io.BufferedInputStream)4 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 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 Point (java.awt.Point)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Locale (java.util.Locale)2