Search in sources :

Example 1 with Issue

use of org.gephi.io.importer.api.Issue in project gephi by gephi.

the class ImporterGraphML method readNode.

private void readNode(XMLStreamReader reader, NodeDraft parent) throws Exception {
    String id = "";
    //Attributes
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String attName = reader.getAttributeName(i).getLocalPart();
        if (NODE_ID.equalsIgnoreCase(attName)) {
            id = reader.getAttributeValue(i);
        }
    }
    if (id.isEmpty()) {
        report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_nodeid"), Issue.Level.SEVERE));
        return;
    }
    NodeDraft node = null;
    if (container.nodeExists(id)) {
        node = container.getNode(id);
    } else {
        node = container.factory().newNodeDraft(id);
    }
    //TODO - PARENT REL
    if (!container.nodeExists(id)) {
        container.addNode(node);
    }
    boolean end = false;
    while (reader.hasNext() && !end) {
        int type = reader.next();
        switch(type) {
            case XMLStreamReader.START_ELEMENT:
                String name = xmlReader.getLocalName();
                if (ATTVALUE.equalsIgnoreCase(xmlReader.getLocalName())) {
                    readNodeAttValue(reader, node);
                } else if (NODE.equalsIgnoreCase(name)) {
                    readNode(reader, node);
                }
                break;
            case XMLStreamReader.END_ELEMENT:
                if (NODE.equalsIgnoreCase(xmlReader.getLocalName())) {
                    end = true;
                }
                break;
        }
    }
}
Also used : Issue(org.gephi.io.importer.api.Issue) NodeDraft(org.gephi.io.importer.api.NodeDraft)

Example 2 with Issue

use of org.gephi.io.importer.api.Issue in project gephi by gephi.

the class ImporterGraphML method readAttribute.

private void readAttribute(XMLStreamReader reader) throws Exception {
    String id = "";
    String type = "";
    String title = "";
    String defaultStr = "";
    String forStr = "all";
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String attName = reader.getAttributeName(i).getLocalPart();
        if (ATTRIBUTE_ID.equalsIgnoreCase(attName)) {
            id = reader.getAttributeValue(i);
        } else if (ATTRIBUTE_TYPE.equalsIgnoreCase(attName)) {
            type = reader.getAttributeValue(i);
        } else if (ATTRIBUTE_TITLE.equalsIgnoreCase(attName)) {
            title = reader.getAttributeValue(i);
        } else if (ATTRIBUTE_FOR.equalsIgnoreCase(attName)) {
            forStr = reader.getAttributeValue(i);
        }
    }
    if (title.isEmpty()) {
        title = id;
    }
    boolean property = false;
    if (!id.isEmpty()) {
        //Properties
        if (forStr.equalsIgnoreCase("node")) {
            NodeProperties prop = properties.getNodeProperty(id) == null ? properties.getNodeProperty(title) : properties.getNodeProperty(id);
            if (prop != null) {
                nodePropertiesAttributes.put(id, prop);
                report.log(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_log_nodeproperty", title));
                property = true;
            }
        } else if (forStr.equalsIgnoreCase("edge")) {
            EdgeProperties prop = properties.getEdgeProperty(id) == null ? properties.getEdgeProperty(title) : properties.getEdgeProperty(id);
            if (prop != null) {
                edgePropertiesAttributes.put(id, prop);
                report.log(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_log_edgeproperty", title));
                property = true;
            }
        }
        if (property) {
            return;
        }
    } else {
        report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_attributeempty", title), Issue.Level.SEVERE));
        return;
    }
    if (!property && type.isEmpty()) {
        report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_attributetype1", title), Issue.Level.SEVERE));
        type = "string";
    }
    if (!property) {
        //Class type
        if (forStr.isEmpty() || !(forStr.equalsIgnoreCase("node") || forStr.equalsIgnoreCase("edge") || forStr.equalsIgnoreCase("all"))) {
            report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_attributeclass", title), Issue.Level.SEVERE));
            return;
        }
        //Default?
        boolean end = false;
        boolean defaultFlag = false;
        while (reader.hasNext() && !end) {
            int xmltype = reader.next();
            switch(xmltype) {
                case XMLStreamReader.START_ELEMENT:
                    if (ATTRIBUTE_DEFAULT.equalsIgnoreCase(xmlReader.getLocalName())) {
                        defaultFlag = true;
                    }
                    break;
                case XMLStreamReader.CHARACTERS:
                    if (defaultFlag && !xmlReader.isWhiteSpace()) {
                        defaultStr = xmlReader.getText();
                    }
                    break;
                case XMLStreamReader.END_ELEMENT:
                    if (ATTRIBUTE.equalsIgnoreCase(xmlReader.getLocalName())) {
                        end = true;
                    }
                    break;
            }
        }
        //Type
        Class attributeType = String.class;
        if (type.equalsIgnoreCase("boolean") || type.equalsIgnoreCase("bool")) {
            attributeType = boolean.class;
        } else if (type.equalsIgnoreCase("integer") || type.equalsIgnoreCase("int")) {
            attributeType = int.class;
        } else if (type.equalsIgnoreCase("long")) {
            attributeType = Long.class;
        } else if (type.equalsIgnoreCase("float")) {
            attributeType = Float.class;
        } else if (type.equalsIgnoreCase("double")) {
            attributeType = Double.class;
        } else if (type.equalsIgnoreCase("string")) {
            attributeType = String.class;
        } else if (type.equalsIgnoreCase("bigdecimal")) {
            attributeType = BigDecimal.class;
        } else if (type.equalsIgnoreCase("biginteger")) {
            attributeType = BigInteger.class;
        } else if (type.equalsIgnoreCase("byte")) {
            attributeType = Byte.class;
        } else if (type.equalsIgnoreCase("char")) {
            attributeType = Character.class;
        } else if (type.equalsIgnoreCase("short")) {
            attributeType = Short.class;
        } else if (type.equalsIgnoreCase("listboolean")) {
            attributeType = boolean[].class;
        } else if (type.equalsIgnoreCase("listint")) {
            attributeType = int[].class;
        } else if (type.equalsIgnoreCase("listlong")) {
            attributeType = long[].class;
        } else if (type.equalsIgnoreCase("listfloat")) {
            attributeType = float[].class;
        } else if (type.equalsIgnoreCase("listdouble")) {
            attributeType = double[].class;
        } else if (type.equalsIgnoreCase("liststring")) {
            attributeType = String[].class;
        } else if (type.equalsIgnoreCase("listbigdecimal")) {
            attributeType = BigDecimal[].class;
        } else if (type.equalsIgnoreCase("listbiginteger")) {
            attributeType = BigInteger[].class;
        } else if (type.equalsIgnoreCase("listbyte")) {
            attributeType = byte[].class;
        } else if (type.equalsIgnoreCase("listchar")) {
            attributeType = char[].class;
        } else if (type.equalsIgnoreCase("listshort")) {
            attributeType = short[].class;
        } else {
            report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_attributetype2", type), Issue.Level.SEVERE));
            return;
        }
        //Add to model
        ColumnDraft column = null;
        if ("node".equalsIgnoreCase(forStr) || "all".equalsIgnoreCase(forStr)) {
            if (container.getNodeColumn(id) != null) {
                report.log(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_attributecolumn_exist", id));
                return;
            }
            column = container.addNodeColumn(id, attributeType);
            column.setTitle(title);
            report.log(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_log_nodeattribute", title, attributeType.getCanonicalName()));
        } else if ("edge".equalsIgnoreCase(forStr) || "all".equalsIgnoreCase(forStr)) {
            if (container.getEdgeColumn(id) != null) {
                report.log(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_attributecolumn_exist", id));
                return;
            }
            column = container.addEdgeColumn(id, attributeType);
            column.setTitle(title);
            report.log(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_log_edgeattribute", title, attributeType.getCanonicalName()));
        }
        if (column != null && !defaultStr.isEmpty()) {
            try {
                column.setDefaultValueString(defaultStr);
                report.log(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_log_default", defaultStr, title));
            } catch (Exception e) {
                report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_attributedefault", title, attributeType.getCanonicalName()), Issue.Level.SEVERE));
            }
        }
    } else {
        report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_attributeempty", title), Issue.Level.SEVERE));
    }
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft) Issue(org.gephi.io.importer.api.Issue) XMLStreamException(javax.xml.stream.XMLStreamException) NodeProperties(org.gephi.io.importer.api.PropertiesAssociations.NodeProperties) EdgeProperties(org.gephi.io.importer.api.PropertiesAssociations.EdgeProperties) BigInteger(java.math.BigInteger)

Example 3 with Issue

use of org.gephi.io.importer.api.Issue in project gephi by gephi.

the class ImporterGraphML method readNodeAttValue.

private void readNodeAttValue(XMLStreamReader reader, NodeDraft node) throws Exception {
    String fore = "";
    String value = "";
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String attName = reader.getAttributeName(i).getLocalPart();
        if (ATTVALUE_FOR.equalsIgnoreCase(attName)) {
            fore = reader.getAttributeValue(i);
        }
    }
    if (fore.isEmpty()) {
        report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_datakey", node), Issue.Level.SEVERE));
        return;
    }
    boolean end = false;
    while (reader.hasNext() && !end) {
        int xmltype = reader.next();
        switch(xmltype) {
            case XMLStreamReader.CHARACTERS:
                if (!xmlReader.isWhiteSpace()) {
                    value += xmlReader.getText();
                }
                break;
            case XMLStreamReader.END_ELEMENT:
                if (ATTVALUE.equalsIgnoreCase(xmlReader.getLocalName())) {
                    end = true;
                }
                break;
        }
    }
    if (!value.isEmpty()) {
        //Property
        NodeProperties prop = nodePropertiesAttributes.get(fore);
        if (prop != null) {
            try {
                switch(prop) {
                    case X:
                        node.setX(parseFloat(value));
                        break;
                    case Y:
                        node.setY(parseFloat(value));
                        break;
                    case Z:
                        node.setZ(parseFloat(value));
                        break;
                    case SIZE:
                        node.setSize(parseFloat(value));
                        break;
                    case LABEL:
                        node.setLabel(value);
                        break;
                    case COLOR:
                        node.setColor(value);
                        break;
                    case R:
                        if (node.getColor() == null) {
                            node.setColor(Integer.parseInt(value), 0, 0);
                        } else {
                            node.setColor(Integer.parseInt(value), node.getColor().getGreen(), node.getColor().getBlue());
                        }
                        break;
                    case G:
                        if (node.getColor() == null) {
                            node.setColor(0, Integer.parseInt(value), 0);
                        } else {
                            node.setColor(node.getColor().getRed(), Integer.parseInt(value), node.getColor().getBlue());
                        }
                        break;
                    case B:
                        if (node.getColor() == null) {
                            node.setColor(0, 0, Integer.parseInt(value));
                        } else {
                            node.setColor(node.getColor().getRed(), node.getColor().getGreen(), Integer.parseInt(value));
                        }
                        break;
                }
            } catch (Exception e) {
                report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_datavalue", fore, node, prop.toString()), Issue.Level.SEVERE));
            }
            return;
        }
        //Data attribute value
        ColumnDraft column = container.getNodeColumn(fore);
        if (column != null) {
            try {
                node.parseAndSetValue(column.getId(), value);
            } catch (Exception e) {
                report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_datavalue", fore, node, column.getTitle()), Issue.Level.SEVERE));
            }
        }
    }
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft) Issue(org.gephi.io.importer.api.Issue) NodeProperties(org.gephi.io.importer.api.PropertiesAssociations.NodeProperties) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 4 with Issue

use of org.gephi.io.importer.api.Issue in project gephi by gephi.

the class ImporterGraphML method readEdge.

private void readEdge(XMLStreamReader reader) throws Exception {
    String id = "";
    String source = "";
    String target = "";
    String directed = "";
    //Attributes
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String attName = reader.getAttributeName(i).getLocalPart();
        if (EDGE_SOURCE.equalsIgnoreCase(attName)) {
            source = reader.getAttributeValue(i);
        } else if (EDGE_TARGET.equalsIgnoreCase(attName)) {
            target = reader.getAttributeValue(i);
        } else if (EDGE_ID.equalsIgnoreCase(attName)) {
            id = reader.getAttributeValue(i);
        } else if (EDGE_DIRECTED.equalsIgnoreCase(attName)) {
            directed = reader.getAttributeValue(i);
        }
    }
    //Edge Id
    EdgeDraft edge;
    if (!id.isEmpty()) {
        edge = container.factory().newEdgeDraft(id);
    } else {
        edge = container.factory().newEdgeDraft();
    }
    NodeDraft nodeSource = container.getNode(source);
    NodeDraft nodeTarget = container.getNode(target);
    edge.setSource(nodeSource);
    edge.setTarget(nodeTarget);
    //Type
    if (!directed.isEmpty()) {
        if (directed.equalsIgnoreCase("true")) {
            edge.setDirection(EdgeDirection.DIRECTED);
        } else if (directed.equalsIgnoreCase("false")) {
            edge.setDirection(EdgeDirection.UNDIRECTED);
        } else {
            report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_edgetype", directed, edge), Issue.Level.SEVERE));
            edge.setDirection(edgeDefault);
        }
    } else {
        edge.setDirection(edgeDefault);
    }
    boolean end = false;
    while (reader.hasNext() && !end) {
        int type = reader.next();
        switch(type) {
            case XMLStreamReader.START_ELEMENT:
                if (ATTVALUE.equalsIgnoreCase(xmlReader.getLocalName())) {
                    readEdgeAttValue(reader, edge);
                }
                break;
            case XMLStreamReader.END_ELEMENT:
                if (EDGE.equalsIgnoreCase(xmlReader.getLocalName())) {
                    end = true;
                }
                break;
        }
    }
    container.addEdge(edge);
}
Also used : EdgeDraft(org.gephi.io.importer.api.EdgeDraft) Issue(org.gephi.io.importer.api.Issue) NodeDraft(org.gephi.io.importer.api.NodeDraft)

Example 5 with Issue

use of org.gephi.io.importer.api.Issue in project gephi by gephi.

the class ImporterGraphML method readEdgeAttValue.

private void readEdgeAttValue(XMLStreamReader reader, EdgeDraft edge) throws Exception {
    String fore = "";
    String value = "";
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String attName = reader.getAttributeName(i).getLocalPart();
        if (ATTVALUE_FOR.equalsIgnoreCase(attName)) {
            fore = reader.getAttributeValue(i);
        }
    }
    if (fore.isEmpty()) {
        report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_datakey", edge), Issue.Level.SEVERE));
        return;
    }
    boolean end = false;
    while (reader.hasNext() && !end) {
        int xmltype = reader.next();
        switch(xmltype) {
            case XMLStreamReader.CHARACTERS:
                if (!xmlReader.isWhiteSpace()) {
                    value += xmlReader.getText();
                }
                break;
            case XMLStreamReader.END_ELEMENT:
                if (ATTVALUE.equalsIgnoreCase(xmlReader.getLocalName())) {
                    end = true;
                }
                break;
        }
    }
    if (!value.isEmpty()) {
        EdgeProperties prop = edgePropertiesAttributes.get(fore);
        if (prop != null) {
            try {
                switch(prop) {
                    case WEIGHT:
                        edge.setWeight(parseFloat(value));
                        break;
                    case LABEL:
                        edge.setLabel(value);
                        break;
                    case COLOR:
                        edge.setColor(value);
                        break;
                    case R:
                        if (edge.getColor() == null) {
                            edge.setColor(Integer.parseInt(value), 0, 0);
                        } else {
                            edge.setColor(Integer.parseInt(value), edge.getColor().getGreen(), edge.getColor().getBlue());
                        }
                        break;
                    case G:
                        if (edge.getColor() == null) {
                            edge.setColor(0, Integer.parseInt(value), 0);
                        } else {
                            edge.setColor(edge.getColor().getRed(), Integer.parseInt(value), edge.getColor().getBlue());
                        }
                        break;
                    case B:
                        if (edge.getColor() == null) {
                            edge.setColor(0, 0, Integer.parseInt(value));
                        } else {
                            edge.setColor(edge.getColor().getRed(), edge.getColor().getGreen(), Integer.parseInt(value));
                        }
                        break;
                }
            } catch (Exception e) {
                report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_datavalue", fore, edge, prop.toString()), Issue.Level.SEVERE));
            }
            return;
        }
        //Data attribute value
        ColumnDraft column = container.getEdgeColumn(fore);
        if (column != null) {
            try {
                edge.parseAndSetValue(column.getId(), value);
            } catch (Exception e) {
                report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_datavalue", fore, edge, column.getTitle()), Issue.Level.SEVERE));
            }
        }
    }
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft) Issue(org.gephi.io.importer.api.Issue) EdgeProperties(org.gephi.io.importer.api.PropertiesAssociations.EdgeProperties) XMLStreamException(javax.xml.stream.XMLStreamException)

Aggregations

Issue (org.gephi.io.importer.api.Issue)52 NodeDraft (org.gephi.io.importer.api.NodeDraft)14 IOException (java.io.IOException)11 ColumnDraft (org.gephi.io.importer.api.ColumnDraft)10 EdgeDraft (org.gephi.io.importer.api.EdgeDraft)9 StringTokenizer (java.util.StringTokenizer)5 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 XMLStreamException (javax.xml.stream.XMLStreamException)3 Interval (org.gephi.graph.api.Interval)3 EdgeProperties (org.gephi.io.importer.api.PropertiesAssociations.EdgeProperties)3 NodeProperties (org.gephi.io.importer.api.PropertiesAssociations.NodeProperties)3 Color (java.awt.Color)2 ResultSet (java.sql.ResultSet)2 ResultSetMetaData (java.sql.ResultSetMetaData)2 Statement (java.sql.Statement)2 Pattern (java.util.regex.Pattern)2 IntervalSet (org.gephi.graph.api.types.IntervalSet)2 TimestampSet (org.gephi.graph.api.types.TimestampSet)2 ElementDraft (org.gephi.io.importer.api.ElementDraft)2