Search in sources :

Example 6 with Location

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

the class StaxUtils method addLocation.

private static boolean addLocation(Document doc, Node node, Location loc, boolean recordLoc) {
    if (recordLoc && loc != null && (loc.getColumnNumber() != 0 || loc.getLineNumber() != 0)) {
        try {
            final int charOffset = loc.getCharacterOffset();
            final int colNum = loc.getColumnNumber();
            final int linNum = loc.getLineNumber();
            final String pubId = loc.getPublicId() == null ? doc.getDocumentURI() : loc.getPublicId();
            final String sysId = loc.getSystemId() == null ? doc.getDocumentURI() : loc.getSystemId();
            Location loc2 = new Location() {

                public int getCharacterOffset() {
                    return charOffset;
                }

                public int getColumnNumber() {
                    return colNum;
                }

                public int getLineNumber() {
                    return linNum;
                }

                public String getPublicId() {
                    return pubId;
                }

                public String getSystemId() {
                    return sysId;
                }
            };
            node.setUserData("location", loc2, LocationUserDataHandler.INSTANCE);
        } catch (Throwable ex) {
            // possibly not DOM level 3, won't be able to record this then
            return false;
        }
    }
    return recordLoc;
}
Also used : Location(javax.xml.stream.Location)

Example 7 with Location

use of javax.xml.stream.Location in project gephi by gephi.

the class LoadTask method readWorkspace.

private WorkspaceImpl readWorkspace(ProjectImpl project, String entryName, ZipFile zipFile) throws Exception {
    ZipEntry entry = zipFile.getEntry(entryName);
    if (entry != null) {
        InputStream is = null;
        try {
            is = zipFile.getInputStream(entry);
            InputStreamReader isReader = null;
            Xml10FilterReader filterReader = null;
            XMLStreamReader reader = null;
            try {
                XMLInputFactory inputFactory = XMLInputFactory.newInstance();
                if (inputFactory.isPropertySupported("javax.xml.stream.isValidating")) {
                    inputFactory.setProperty("javax.xml.stream.isValidating", Boolean.FALSE);
                }
                inputFactory.setXMLReporter(new XMLReporter() {

                    @Override
                    public void report(String message, String errorType, Object relatedInformation, Location location) throws XMLStreamException {
                    }
                });
                isReader = new InputStreamReader(is, "UTF-8");
                filterReader = new Xml10FilterReader(isReader);
                reader = inputFactory.createXMLStreamReader(filterReader);
                return GephiReader.readWorkspace(reader, project);
            } finally {
                if (reader != null) {
                    reader.close();
                }
                if (filterReader != null) {
                    filterReader.close();
                }
                if (isReader != null) {
                    isReader.close();
                }
            }
        } finally {
            if (is != null) {
                is.close();
            }
        }
    }
    return null;
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLReporter(javax.xml.stream.XMLReporter) InputStreamReader(java.io.InputStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) XMLInputFactory(javax.xml.stream.XMLInputFactory) Location(javax.xml.stream.Location)

Example 8 with Location

use of javax.xml.stream.Location in project gephi by gephi.

the class ImporterGraphML method execute.

@Override
public boolean execute(ContainerLoader container) {
    this.container = container;
    this.report = new Report();
    Progress.start(progress);
    try {
        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        if (inputFactory.isPropertySupported("javax.xml.stream.isValidating")) {
            inputFactory.setProperty("javax.xml.stream.isValidating", Boolean.FALSE);
        }
        inputFactory.setXMLReporter(new XMLReporter() {

            @Override
            public void report(String message, String errorType, Object relatedInformation, Location location) throws XMLStreamException {
            }
        });
        xmlReader = inputFactory.createXMLStreamReader(reader);
        while (xmlReader.hasNext()) {
            Integer eventType = xmlReader.next();
            if (eventType.equals(XMLEvent.START_ELEMENT)) {
                String name = xmlReader.getLocalName();
                if (GRAPHML.equalsIgnoreCase(name)) {
                } else if (GRAPH.equalsIgnoreCase(name)) {
                    readGraph(xmlReader);
                } else if (NODE.equalsIgnoreCase(name)) {
                    readNode(xmlReader, null);
                } else if (EDGE.equalsIgnoreCase(name)) {
                    readEdge(xmlReader);
                } else if (ATTRIBUTE.equalsIgnoreCase(name)) {
                    readAttribute(xmlReader);
                }
            } else if (eventType.equals(XMLStreamReader.END_ELEMENT)) {
                String name = xmlReader.getLocalName();
                if (NODE.equalsIgnoreCase(name)) {
                }
            }
        }
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        throw new RuntimeException(e);
    } finally {
        try {
            xmlReader.close();
        } catch (XMLStreamException e) {
        }
    }
    Progress.finish(progress);
    return !cancel;
}
Also used : BigInteger(java.math.BigInteger) XMLReporter(javax.xml.stream.XMLReporter) XMLStreamException(javax.xml.stream.XMLStreamException) Report(org.gephi.io.importer.api.Report) XMLInputFactory(javax.xml.stream.XMLInputFactory) XMLStreamException(javax.xml.stream.XMLStreamException) Location(javax.xml.stream.Location)

Example 9 with Location

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

the class StaxStreamXMLReader method handleDtd.

private void handleDtd() throws SAXException {
    if (getLexicalHandler() != null) {
        javax.xml.stream.Location location = reader.getLocation();
        getLexicalHandler().startDTD(null, location.getPublicId(), location.getSystemId());
    }
    if (getLexicalHandler() != null) {
        getLexicalHandler().endDTD();
    }
}
Also used : Location(javax.xml.stream.Location)

Example 10 with Location

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

the class StaxStreamXMLReader method handleStartDocument.

private void handleStartDocument() throws SAXException {
    if (XMLStreamConstants.START_DOCUMENT == reader.getEventType()) {
        String xmlVersion = reader.getVersion();
        if (ObjectHelper.isNotEmpty(xmlVersion)) {
            this.xmlVersion = xmlVersion;
        }
        this.encoding = reader.getCharacterEncodingScheme();
    }
    if (getContentHandler() != null) {
        final Location location = reader.getLocation();
        getContentHandler().setDocumentLocator(new Locator2() {

            public int getColumnNumber() {
                return location != null ? location.getColumnNumber() : -1;
            }

            public int getLineNumber() {
                return location != null ? location.getLineNumber() : -1;
            }

            public String getPublicId() {
                return location != null ? location.getPublicId() : null;
            }

            public String getSystemId() {
                return location != null ? location.getSystemId() : null;
            }

            public String getXMLVersion() {
                return xmlVersion;
            }

            public String getEncoding() {
                return encoding;
            }
        });
        getContentHandler().startDocument();
        if (reader.standaloneSet()) {
            setStandalone(reader.isStandalone());
        }
    }
}
Also used : Locator2(org.xml.sax.ext.Locator2) 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