Search in sources :

Example 16 with Location

use of javax.xml.stream.Location in project karaf by apache.

the class StaxParser method parseResource.

private static ResourceImpl parseResource(URI repositoryUrl, XMLStreamReader reader) {
    try {
        if (reader.getAttributeCount() > 0) {
            throw new IllegalStateException("Unexpected attribute '" + reader.getAttributeLocalName(0) + "'");
        }
        ResourceImpl resource = new ResourceImpl();
        int event;
        while ((event = reader.nextTag()) == START_ELEMENT) {
            String element = reader.getLocalName();
            switch(element) {
                case CAPABILITY:
                    CapabilityImpl cap = parseCapability(reader, resource);
                    // Resolve relative resource urls now
                    if (repositoryUrl != null && ContentNamespace.CONTENT_NAMESPACE.equals(cap.getNamespace())) {
                        Object url = cap.getAttributes().get(ContentNamespace.CAPABILITY_URL_ATTRIBUTE);
                        if (url instanceof String) {
                            url = repositoryUrl.resolve(url.toString()).toString();
                            cap.getAttributes().put(ContentNamespace.CAPABILITY_URL_ATTRIBUTE, url);
                        }
                    }
                    resource.addCapability(cap);
                    break;
                case REQUIREMENT:
                    resource.addRequirement(parseRequirement(reader, resource));
                    break;
                default:
                    while ((event = reader.next()) != END_ELEMENT) {
                        switch(event) {
                            case START_ELEMENT:
                                throw new IllegalStateException("Unexpected element '" + reader.getLocalName() + "' inside 'resource' element");
                            case CHARACTERS:
                                throw new IllegalStateException("Unexpected text inside 'resource' element");
                            default:
                                break;
                        }
                    }
                    break;
            }
        }
        // Sanity check
        sanityCheckEndElement(reader, event, RESOURCE);
        return resource;
    } catch (Exception e) {
        Location loc = reader.getLocation();
        if (loc != null) {
            throw new IllegalStateException("Error while parsing resource at line " + loc.getLineNumber() + " and column " + loc.getColumnNumber(), e);
        } else {
            throw new IllegalStateException("Error while parsing resource", e);
        }
    }
}
Also used : ResourceImpl(org.apache.karaf.features.internal.resolver.ResourceImpl) CapabilityImpl(org.apache.karaf.features.internal.resolver.CapabilityImpl) XMLStreamException(javax.xml.stream.XMLStreamException) Location(javax.xml.stream.Location)

Aggregations

Location (javax.xml.stream.Location)16 XMLStreamException (javax.xml.stream.XMLStreamException)6 XMLInputFactory (javax.xml.stream.XMLInputFactory)5 XMLReporter (javax.xml.stream.XMLReporter)5 DataInputStream (java.io.DataInputStream)3 InputStream (java.io.InputStream)3 InputStreamReader (java.io.InputStreamReader)3 ZipEntry (java.util.zip.ZipEntry)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 Locator2 (org.xml.sax.ext.Locator2)3 BigInteger (java.math.BigInteger)1 StartDocument (javax.xml.stream.events.StartDocument)1 XmlFormat (org.apache.juneau.xml.annotation.XmlFormat)1 CapabilityImpl (org.apache.karaf.features.internal.resolver.CapabilityImpl)1 ResourceImpl (org.apache.karaf.features.internal.resolver.ResourceImpl)1 Report (org.gephi.io.importer.api.Report)1 ProjectControllerImpl (org.gephi.project.impl.ProjectControllerImpl)1 ProjectImpl (org.gephi.project.impl.ProjectImpl)1 ProjectInformationImpl (org.gephi.project.impl.ProjectInformationImpl)1 ProjectsImpl (org.gephi.project.impl.ProjectsImpl)1