Search in sources :

Example 1 with XMLParseException

use of de.pdark.decentxml.XMLParseException in project sling by apache.

the class JcrNode method initChildren.

void initChildren() {
    try {
        if (resourceChildrenAdded) {
            throw new IllegalStateException("Children already loaded");
        }
        Set<String> childrenNames = new HashSet<>();
        for (Iterator<JcrNode> it = children.iterator(); it.hasNext(); ) {
            JcrNode node = it.next();
            childrenNames.add(node.getName());
        }
        if (resource != null && resource instanceof IFolder) {
            IFolder folder = (IFolder) resource;
            IResource[] members = folder.members();
            List<IResource> membersList = new LinkedList<>(Arrays.asList(members));
            outerLoop: while (membersList.size() > 0) {
                for (Iterator<IResource> it = membersList.iterator(); it.hasNext(); ) {
                    IResource iResource = it.next();
                    if (isDotVltFile(iResource)) {
                        it.remove();
                        continue;
                    }
                    if (childShouldNotBeShown(iResource)) {
                        it.remove();
                        continue;
                    }
                    if (isVaultFile(iResource)) {
                        GenericJcrRootFile gjrf;
                        try {
                            gjrf = new GenericJcrRootFile(this, (IFile) iResource);
                            it.remove();
                            // gjrf.getChildren();
                            gjrf.pickResources(membersList);
                        } catch (XMLParseException e) {
                            // don't try to parse it
                            // errors will be reported by the XML validation infrastructure
                            it.remove();
                        }
                        // add them if they're not already added
                        for (JcrNode node : children) {
                            if (!childrenNames.contains(node.getName())) {
                                childrenNames.add(node.getName());
                            }
                        }
                        continue outerLoop;
                    }
                }
                List<JcrNode> newNodes = new LinkedList<>();
                for (Iterator<IResource> it = membersList.iterator(); it.hasNext(); ) {
                    IResource iResource = (IResource) it.next();
                    JcrNode node;
                    if (DirNode.isDirNode(iResource)) {
                        node = new DirNode(this, (Element) null, iResource);
                    } else {
                        node = new JcrNode(this, (Element) null, iResource);
                    }
                    childrenNames.add(node.getName());
                    newNodes.add(node);
                    it.remove();
                }
            }
        }
        resourceChildrenAdded = true;
    } catch (CoreException e) {
        e.printStackTrace();
        org.apache.sling.ide.eclipse.ui.internal.Activator.getDefault().getPluginLogger().error("Error initializing children: " + e, e);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
        org.apache.sling.ide.eclipse.ui.internal.Activator.getDefault().getPluginLogger().error("Error initializing children: " + e, e);
    } catch (SAXException e) {
        e.printStackTrace();
        org.apache.sling.ide.eclipse.ui.internal.Activator.getDefault().getPluginLogger().error("Error initializing children: " + e, e);
    } catch (IOException e) {
        e.printStackTrace();
        org.apache.sling.ide.eclipse.ui.internal.Activator.getDefault().getPluginLogger().error("Error initializing children: " + e, e);
    }
}
Also used : IOException(java.io.IOException) LinkedList(java.util.LinkedList) SAXException(org.xml.sax.SAXException) CoreException(org.eclipse.core.runtime.CoreException) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLParseException(de.pdark.decentxml.XMLParseException) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with XMLParseException

use of de.pdark.decentxml.XMLParseException in project sling by apache.

the class TolerantXMLTokenizer method parseAttribute.

@Override
protected void parseAttribute(Token token) {
    token.setType(Type.ATTRIBUTE);
    parseName("attribute");
    if (pos == token.getStartOffset())
        throw new XMLParseException("Expected attribute name", source, pos);
    skipWhiteSpace();
    expect('=');
    skipWhiteSpace();
    char c = 0;
    if (pos < source.length())
        c = source.charAt(pos);
    if (c != '\'' && c != '"')
        throw new XMLParseException("Expected single or double quotes", source, pos);
    char endChar = c;
    while (true) {
        pos++;
        if (pos >= source.length()) {
            int i = Math.min(20, source.length() - token.getStartOffset());
            throw new XMLParseException("Missing end quote (" + endChar + ") of attribute: " + lookAheadForErrorMessage(null, token.getStartOffset(), i), token);
        }
        c = source.charAt(pos);
        if (c == endChar)
            break;
        if (c == '<') {
            Location l = new Location(source, pos);
            System.err.println("Illegal character in attribute value: '" + c + "' in " + originDetails + " at " + l);
        }
    }
    // Skip end-char
    pos++;
}
Also used : XMLParseException(de.pdark.decentxml.XMLParseException) Location(de.pdark.decentxml.Location)

Aggregations

XMLParseException (de.pdark.decentxml.XMLParseException)2 Location (de.pdark.decentxml.Location)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 IFolder (org.eclipse.core.resources.IFolder)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 SAXException (org.xml.sax.SAXException)1