Class GraphMLExporter<V,E>
java.lang.Object
org.jgrapht.nio.BaseExporter<V,E>
org.jgrapht.nio.graphml.GraphMLExporter<V,E>
- Type Parameters:
V- the graph vertex typeE- the graph edge type
- All Implemented Interfaces:
GraphExporter<V,E>
Exports a graph as GraphML.
For a description of the format see http://en.wikipedia.org/wiki/ GraphML.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDenotes the category of a GraphML-Attribute.private class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final Stringprivate static final Stringprivate Stringprivate Stringprivate booleanWhether to try to print edge labels.private booleanWhether to print edge weights in case the graph is weighted.private booleanWhether to try to print vertex labels.private Map<String, GraphMLExporter<V, E>.AttributeDetails> private intprivate static final Stringprivate StringFields inherited from class BaseExporter
edgeAttributeProvider, edgeIdProvider, graphAttributeProvider, graphIdProvider, vertexAttributeProvider, vertexIdProvider -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new GraphMLExporter with integer id provider for the vertices.GraphMLExporter(Function<V, String> vertexIdProvider) Constructs a new GraphMLExporter. -
Method Summary
Modifier and TypeMethodDescriptionvoidexportGraph(Graph<V, E> g, Writer writer) Exports a graph in GraphML format.Get the attribute name for edge labelsGet the attribute name for edge weightsGet the attribute name for vertex labelsbooleanWhether the exporter will print edge labels.booleanWhether the exporter will print edge weights.booleanWhether the exporter will print vertex labels.voidregisterAttribute(String name, GraphMLExporter.AttributeCategory category, AttributeType type) Register a GraphML-AttributevoidregisterAttribute(String name, GraphMLExporter.AttributeCategory category, AttributeType type, String defaultValue) Register a GraphML-AttributevoidsetEdgeLabelAttributeName(String edgeLabelAttributeName) Set the attribute name to use for edge labels.voidsetEdgeWeightAttributeName(String edgeWeightAttributeName) Set the attribute name to use for edge weights.voidsetExportEdgeLabels(boolean exportEdgeLabels) Set whether the exporter will print edge labels.voidsetExportEdgeWeights(boolean exportEdgeWeights) Set whether the exporter will print edge weights.voidsetExportVertexLabels(boolean exportVertexLabels) Set whether the exporter will print vertex labels.voidsetVertexLabelAttributeName(String vertexLabelAttributeName) Set the attribute name to use for vertex labels.voidunregisterAttribute(String name) Unregister a GraphML-Attributeprivate voidwriteAttribute(TransformerHandler handler, String name, GraphMLExporter<V, E>.AttributeDetails details) private voidwriteData(TransformerHandler handler, String key, String value) private voidwriteEdges(TransformerHandler handler, Graph<V, E> g) private voidwriteFooter(TransformerHandler handler) private voidwriteGraphEnd(TransformerHandler handler) private voidwriteGraphStart(TransformerHandler handler, Graph<V, E> g) private voidwriteHeader(TransformerHandler handler) private voidwriteKeys(TransformerHandler handler) private voidwriteNodes(TransformerHandler handler, Graph<V, E> g) Methods inherited from class BaseExporter
getEdgeAttribute, getEdgeAttributeProvider, getEdgeAttributes, getEdgeId, getEdgeIdProvider, getGraphAttribute, getGraphAttributeProvider, getGraphId, getGraphIdProvider, getVertexAttribute, getVertexAttributeProvider, getVertexAttributes, getVertexId, getVertexIdProvider, setEdgeAttributeProvider, setEdgeIdProvider, setGraphAttributeProvider, setGraphIdProvider, setVertexAttributeProvider, setVertexIdProviderMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface GraphExporter
exportGraph, exportGraph
-
Field Details
-
registeredAttributes
-
ATTRIBUTE_KEY_PREFIX
- See Also:
-
totalAttributes
private int totalAttributes -
VERTEX_LABEL_DEFAULT_ATTRIBUTE_NAME
- See Also:
-
EDGE_WEIGHT_DEFAULT_ATTRIBUTE_NAME
- See Also:
-
EDGE_LABEL_DEFAULT_ATTRIBUTE_NAME
- See Also:
-
vertexLabelAttributeName
-
edgeWeightAttributeName
-
edgeLabelAttributeName
-
exportEdgeWeights
private boolean exportEdgeWeightsWhether to print edge weights in case the graph is weighted. -
exportVertexLabels
private boolean exportVertexLabelsWhether to try to print vertex labels. They must be found in the corresponding attribute provider. -
exportEdgeLabels
private boolean exportEdgeLabelsWhether to try to print edge labels. They must be found in the corresponding attribute provider.
-
-
Constructor Details
-
GraphMLExporter
public GraphMLExporter()Constructs a new GraphMLExporter with integer id provider for the vertices. -
GraphMLExporter
-
-
Method Details
-
registerAttribute
public void registerAttribute(String name, GraphMLExporter.AttributeCategory category, AttributeType type) Register a GraphML-Attribute- Parameters:
name- the attribute namecategory- the attribute categorytype- the attribute type
-
registerAttribute
public void registerAttribute(String name, GraphMLExporter.AttributeCategory category, AttributeType type, String defaultValue) Register a GraphML-Attribute- Parameters:
name- the attribute namecategory- the attribute categorytype- the attribute typedefaultValue- default value
-
unregisterAttribute
Unregister a GraphML-Attribute- Parameters:
name- the attribute name
-
isExportEdgeWeights
public boolean isExportEdgeWeights()Whether the exporter will print edge weights.- Returns:
trueif the exporter prints edge weights,falseotherwise
-
setExportEdgeWeights
public void setExportEdgeWeights(boolean exportEdgeWeights) Set whether the exporter will print edge weights.- Parameters:
exportEdgeWeights- value to set
-
isExportVertexLabels
public boolean isExportVertexLabels()Whether the exporter will print vertex labels.- Returns:
trueif the exporter prints vertex labels,falseotherwise
-
setExportVertexLabels
public void setExportVertexLabels(boolean exportVertexLabels) Set whether the exporter will print vertex labels.- Parameters:
exportVertexLabels- value to set
-
isExportEdgeLabels
public boolean isExportEdgeLabels()Whether the exporter will print edge labels.- Returns:
trueif the exporter prints edge labels,falseotherwise
-
setExportEdgeLabels
public void setExportEdgeLabels(boolean exportEdgeLabels) Set whether the exporter will print edge labels.- Parameters:
exportEdgeLabels- value to set
-
getVertexLabelAttributeName
Get the attribute name for vertex labels- Returns:
- the attribute name
-
setVertexLabelAttributeName
Set the attribute name to use for vertex labels.- Parameters:
vertexLabelAttributeName- the attribute name
-
getEdgeLabelAttributeName
Get the attribute name for edge labels- Returns:
- the attribute name
-
setEdgeLabelAttributeName
Set the attribute name to use for edge labels.- Parameters:
edgeLabelAttributeName- the attribute name
-
getEdgeWeightAttributeName
Get the attribute name for edge weights- Returns:
- the attribute name
-
setEdgeWeightAttributeName
Set the attribute name to use for edge weights.- Parameters:
edgeWeightAttributeName- the attribute name
-
exportGraph
Exports a graph in GraphML format.- Specified by:
exportGraphin interfaceGraphExporter<V,E> - Parameters:
g- the graphwriter- the writer to export the graph- Throws:
ExportException- in case any error occurs during export
-
writeHeader
- Throws:
SAXException
-
writeGraphStart
- Throws:
SAXException
-
writeGraphEnd
- Throws:
SAXException
-
writeKeys
- Throws:
SAXException
-
writeData
- Throws:
SAXException
-
writeAttribute
private void writeAttribute(TransformerHandler handler, String name, GraphMLExporter<V, E>.AttributeDetails details) throws SAXException- Throws:
SAXException
-
writeNodes
- Throws:
SAXException
-
writeEdges
- Throws:
SAXException
-