Search in sources :

Example 1 with ProjectsImpl

use of org.gephi.project.impl.ProjectsImpl 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) 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)

Aggregations

DataInputStream (java.io.DataInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ZipEntry (java.util.zip.ZipEntry)1 Location (javax.xml.stream.Location)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 XMLReporter (javax.xml.stream.XMLReporter)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)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