Search in sources :

Example 6 with WorkspaceImpl

use of org.gephi.workspace.impl.WorkspaceImpl in project gephi by gephi.

the class GephiReader method readWorkspaceLegacy.

private static void readWorkspaceLegacy(XMLStreamReader reader, ProjectImpl project) throws Exception {
    WorkspaceImpl workspace = project.getLookup().lookup(WorkspaceProviderImpl.class).newWorkspace();
    WorkspaceInformationImpl info = workspace.getLookup().lookup(WorkspaceInformationImpl.class);
    //Name
    info.setName(reader.getAttributeValue(null, "name"));
    //Status
    String workspaceStatus = reader.getAttributeValue(null, "status");
    if (workspaceStatus.equals("open")) {
        info.open();
    } else if (workspaceStatus.equals("closed")) {
        info.close();
    } else {
        info.invalid();
    }
    Map<String, WorkspaceXMLPersistenceProvider> providers = new LinkedHashMap<>();
    for (WorkspacePersistenceProvider w : Lookup.getDefault().lookupAll(WorkspacePersistenceProvider.class)) {
        String id = w.getIdentifier();
        if (id != null && !id.isEmpty() && w instanceof WorkspaceXMLPersistenceProvider) {
            providers.put(w.getIdentifier(), (WorkspaceXMLPersistenceProvider) w);
        }
    }
    boolean end = false;
    while (reader.hasNext() && !end) {
        Integer eventType = reader.next();
        if (eventType.equals(XMLEvent.START_ELEMENT)) {
            String name = reader.getLocalName();
            WorkspaceXMLPersistenceProvider pp = providers.get(name);
            if (pp != null) {
                try {
                    pp.readXML(reader, workspace);
                } catch (UnsupportedOperationException e) {
                }
            }
        } else if (eventType.equals(XMLStreamReader.END_ELEMENT)) {
            if ("workspace".equalsIgnoreCase(reader.getLocalName())) {
                end = true;
            }
        }
    }
}
Also used : WorkspaceImpl(org.gephi.workspace.impl.WorkspaceImpl) WorkspaceProviderImpl(org.gephi.project.impl.WorkspaceProviderImpl) WorkspaceInformationImpl(org.gephi.workspace.impl.WorkspaceInformationImpl) WorkspacePersistenceProvider(org.gephi.project.spi.WorkspacePersistenceProvider) LinkedHashMap(java.util.LinkedHashMap) WorkspaceXMLPersistenceProvider(org.gephi.project.spi.WorkspaceXMLPersistenceProvider)

Aggregations

WorkspaceImpl (org.gephi.workspace.impl.WorkspaceImpl)6 WorkspaceInformationImpl (org.gephi.workspace.impl.WorkspaceInformationImpl)4 WorkspaceProviderImpl (org.gephi.project.impl.WorkspaceProviderImpl)2 WorkspacePersistenceProvider (org.gephi.project.spi.WorkspacePersistenceProvider)2 WorkspaceXMLPersistenceProvider (org.gephi.project.spi.WorkspaceXMLPersistenceProvider)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 Workspace (org.gephi.project.api.Workspace)1 ProjectControllerImpl (org.gephi.project.impl.ProjectControllerImpl)1 ProjectImpl (org.gephi.project.impl.ProjectImpl)1 WorkspaceBytesPersistenceProvider (org.gephi.project.spi.WorkspaceBytesPersistenceProvider)1