Search in sources :

Example 1 with XMLReporter

use of javax.xml.stream.XMLReporter in project aalto-xml by FasterXML.

the class CharSourceBootstrapper method verifyXmlEncoding.

/*
    ////////////////////////////////////////////////////
    // Internal methods, main xml decl processing
    ////////////////////////////////////////////////////
     */
/**
 * @return Normalized encoding name
 */
protected String verifyXmlEncoding(String enc) throws XMLStreamException {
    enc = CharsetNames.normalize(enc);
    // Probably no point in comparing at all... is there?
    // But we can report a possible problem?
    String extEnc = _config.getExternalEncoding();
    if (extEnc != null && enc != null && !extEnc.equalsIgnoreCase(enc)) {
        XMLReporter rep = _config.getXMLReporter();
        if (rep != null) {
            Location loc = getLocation();
            rep.report(MessageFormat.format(ErrorConsts.W_MIXED_ENCODINGS, new Object[] { extEnc, enc }), ErrorConsts.WT_XML_DECL, this, loc);
        }
    }
    return enc;
}
Also used : XMLReporter(javax.xml.stream.XMLReporter) Location(javax.xml.stream.Location)

Example 2 with XMLReporter

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

the class ImportUtils method getXMLReader.

public static XMLStreamReader getXMLReader(Reader reader) {
    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 {
                throw new RuntimeException("Error:" + errorType + ", message : " + message);
            // System.out.println("Error:" + errorType + ", message : " + message);
            }
        });
        return inputFactory.createXMLStreamReader(reader);
    } catch (XMLStreamException ex) {
        throw new RuntimeException(NbBundle.getMessage(ImportUtils.class, "ImportUtils.error_io"));
    }
}
Also used : XMLReporter(javax.xml.stream.XMLReporter) XMLStreamException(javax.xml.stream.XMLStreamException) FileObject(org.openide.filesystems.FileObject) XMLInputFactory(javax.xml.stream.XMLInputFactory) Location(javax.xml.stream.Location)

Example 3 with XMLReporter

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

the class LoadTask method readProject.

private ProjectImpl readProject(ZipFile zipFile) throws Exception {
    ZipEntry entry = zipFile.getEntry("Project_xml");
    if (entry == null) {
        // Try legacy
        entry = zipFile.getEntry("Project");
    }
    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);
                ProjectControllerImpl projectController = Lookup.getDefault().lookup(ProjectControllerImpl.class);
                ProjectsImpl projects = projectController.getProjects();
                ProjectImpl project = GephiReader.readProject(reader, projects);
                project.getLookup().lookup(ProjectInformationImpl.class).setFile(file);
                return project;
            } finally {
                if (reader != null) {
                    reader.close();
                }
                if (filterReader != null) {
                    filterReader.close();
                }
            }
        } finally {
            if (is != null) {
                is.close();
            }
        }
    }
    return null;
}
Also used : ProjectControllerImpl(org.gephi.project.impl.ProjectControllerImpl) XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStreamReader(java.io.InputStreamReader) DataInputStream(java.io.DataInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ProjectImpl(org.gephi.project.impl.ProjectImpl) ZipEntry(java.util.zip.ZipEntry) ProjectsImpl(org.gephi.project.impl.ProjectsImpl) XMLReporter(javax.xml.stream.XMLReporter) XMLStreamException(javax.xml.stream.XMLStreamException) XMLInputFactory(javax.xml.stream.XMLInputFactory) ProjectInformationImpl(org.gephi.project.impl.ProjectInformationImpl) Location(javax.xml.stream.Location)

Example 4 with XMLReporter

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

the class LoadTask method readWorkspaceChildrenXML.

private void readWorkspaceChildrenXML(WorkspaceXMLPersistenceProvider persistenceProvider, Workspace workspace, ZipFile zipFile) throws Exception {
    String identifier = persistenceProvider.getIdentifier();
    ZipEntry entry = zipFile.getEntry("Workspace_" + workspace.getId() + "_" + identifier + "_xml");
    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);
                persistenceProvider.readXML(reader, workspace);
            } finally {
                if (reader != null) {
                    reader.close();
                }
                if (filterReader != null) {
                    filterReader.close();
                }
                if (isReader != null) {
                    isReader.close();
                }
            }
        } finally {
            if (is != null) {
                is.close();
            }
        }
    }
}
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) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) XMLInputFactory(javax.xml.stream.XMLInputFactory) Location(javax.xml.stream.Location)

Example 5 with XMLReporter

use of javax.xml.stream.XMLReporter 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)

Aggregations

Location (javax.xml.stream.Location)6 XMLReporter (javax.xml.stream.XMLReporter)6 XMLInputFactory (javax.xml.stream.XMLInputFactory)5 XMLStreamException (javax.xml.stream.XMLStreamException)5 BufferedInputStream (java.io.BufferedInputStream)3 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 BigInteger (java.math.BigInteger)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 FileObject (org.openide.filesystems.FileObject)1