Search in sources :

Example 1 with XMLParseException

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

the class XMLParser method processElementContent.

@Override
protected void processElementContent(final String defaultNamespace, final Properties namespaces, final String fullName, final String name, final String prefix) throws IOException, XMLParseException, Exception {
    if (skipNextElementContent) {
        boolean inComment = false;
        final TreeXmlReader builder = (TreeXmlReader) getBuilder();
        final StringBuilder waitingBuf = new StringBuilder();
        int level = 1;
        for (; ; ) {
            final IXMLReader reader = getReader();
            char ch = reader.read();
            if (inComment) {
                waitingBuf.append(ch);
                if (ch != '-') {
                    continue;
                }
                ch = reader.read();
                waitingBuf.append(ch);
                if (ch != '-') {
                    continue;
                }
                ch = reader.read();
                waitingBuf.append(ch);
                if (ch != '>') {
                    continue;
                }
                inComment = false;
                continue;
            }
            if (ch == '<') {
                ch = reader.read();
                if (ch == '/') {
                    level--;
                    if (level == 0) {
                        break;
                    }
                } else if (ch == '!') {
                    final char read1 = reader.read();
                    final char read2 = reader.read();
                    if (read1 != '-' || read2 != '-') {
                        throw new XMLParseException(reader.getSystemID(), reader.getLineNr(), "Invalid input: <!" + read1 + read2);
                    }
                    inComment = true;
                    waitingBuf.append("<!--");
                    continue;
                } else {
                    level++;
                }
                waitingBuf.append('<');
            } else if (ch == '/') {
                ch = reader.read();
                if (ch == '>') {
                    level--;
                    if (level == 0) {
                        throw new XMLParseException(reader.getSystemID(), reader.getLineNr(), "Invalid input: />");
                    }
                } else if (ch == '<') {
                    waitingBuf.append('/');
                    reader.unread(ch);
                    continue;
                }
                waitingBuf.append('/');
            }
            waitingBuf.append(ch);
        }
        builder.setElementContent(waitingBuf.toString());
        return;
    }
    super.processElementContent(defaultNamespace, namespaces, fullName, name, prefix);
}
Also used : IXMLReader(org.freeplane.n3.nanoxml.IXMLReader) XMLParseException(org.freeplane.n3.nanoxml.XMLParseException)

Example 2 with XMLParseException

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

the class MFileManager method loadAndLock.

/**
 *@deprecated -- use MapIO
 */
@Deprecated
public void loadAndLock(final URL url, final MapModel map) throws FileNotFoundException, IOException, XMLParseException, URISyntaxException {
    final File file = Compat.urlToFile(url);
    if (file == null) {
        super.loadCatchExceptions(url, map);
        return;
    }
    if (!file.exists()) {
        throw new FileNotFoundException(TextUtils.format("file_not_found", file.getPath()));
    }
    if (!file.canWrite()) {
        map.setReadOnly(true);
    }
    try {
        final String lockingUser = tryToLock(map, file);
        if (lockingUser != null) {
            UITools.informationMessage(Controller.getCurrentController().getViewController().getFrame(), TextUtils.format("map_locked_by_open", file.getName(), lockingUser));
            map.setReadOnly(true);
        }
    } catch (final Exception e) {
        LogUtils.severe(e);
        UITools.informationMessage(Controller.getCurrentController().getViewController().getFrame(), TextUtils.format("locking_failed_by_open", file.getName()));
        map.setReadOnly(true);
    }
    if (file.length() != 0) {
        // DOCEAR - fixed: set the file for the map before parsing the xml, necessary for some events
        setFile(map, file);
        NodeModel root = loadTree(map, file);
        assert (map.getRootNode() == root);
    }
    if (map.getRootNode() == null)
        map.createNewRoot();
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) XMLException(org.freeplane.n3.nanoxml.XMLException) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) XMLParseException(org.freeplane.n3.nanoxml.XMLParseException) MapConversionException(org.freeplane.features.url.MapConversionException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 3 with XMLParseException

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

Aggregations

XMLParseException (org.freeplane.n3.nanoxml.XMLParseException)3 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 NodeModel (org.freeplane.features.map.NodeModel)1 MapConversionException (org.freeplane.features.url.MapConversionException)1 IXMLReader (org.freeplane.n3.nanoxml.IXMLReader)1 XMLElement (org.freeplane.n3.nanoxml.XMLElement)1 XMLException (org.freeplane.n3.nanoxml.XMLException)1