- 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>
public class GraphMLExporter<V,E> extends BaseExporter<V,E> implements 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 Classes Modifier and Type Class Description static classGraphMLExporter.AttributeCategoryDenotes the category of a GraphML-Attribute.private classGraphMLExporter.AttributeDetails
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringATTRIBUTE_KEY_PREFIXprivate static java.lang.StringEDGE_LABEL_DEFAULT_ATTRIBUTE_NAMEprivate static java.lang.StringEDGE_WEIGHT_DEFAULT_ATTRIBUTE_NAMEprivate java.lang.StringedgeLabelAttributeNameprivate java.lang.StringedgeWeightAttributeNameprivate booleanexportEdgeLabelsWhether to try to print edge labels.private booleanexportEdgeWeightsWhether to print edge weights in case the graph is weighted.private booleanexportVertexLabelsWhether to try to print vertex labels.private java.util.Map<java.lang.String,GraphMLExporter.AttributeDetails>registeredAttributesprivate inttotalAttributesprivate static java.lang.StringVERTEX_LABEL_DEFAULT_ATTRIBUTE_NAMEprivate java.lang.StringvertexLabelAttributeName-
Fields inherited from class org.jgrapht.nio.BaseExporter
edgeAttributeProvider, edgeIdProvider, graphAttributeProvider, graphIdProvider, vertexAttributeProvider, vertexIdProvider
-
-
Constructor Summary
Constructors Constructor Description GraphMLExporter()Constructs a new GraphMLExporter with integer id provider for the vertices.GraphMLExporter(java.util.function.Function<V,java.lang.String> vertexIdProvider)Constructs a new GraphMLExporter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidexportGraph(Graph<V,E> g, java.io.Writer writer)Exports a graph in GraphML format.java.lang.StringgetEdgeLabelAttributeName()Get the attribute name for edge labelsjava.lang.StringgetEdgeWeightAttributeName()Get the attribute name for edge weightsjava.lang.StringgetVertexLabelAttributeName()Get the attribute name for vertex labelsbooleanisExportEdgeLabels()Whether the exporter will print edge labels.booleanisExportEdgeWeights()Whether the exporter will print edge weights.booleanisExportVertexLabels()Whether the exporter will print vertex labels.voidregisterAttribute(java.lang.String name, GraphMLExporter.AttributeCategory category, AttributeType type)Register a GraphML-AttributevoidregisterAttribute(java.lang.String name, GraphMLExporter.AttributeCategory category, AttributeType type, java.lang.String defaultValue)Register a GraphML-AttributevoidsetEdgeLabelAttributeName(java.lang.String edgeLabelAttributeName)Set the attribute name to use for edge labels.voidsetEdgeWeightAttributeName(java.lang.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(java.lang.String vertexLabelAttributeName)Set the attribute name to use for vertex labels.voidunregisterAttribute(java.lang.String name)Unregister a GraphML-Attributeprivate voidwriteAttribute(javax.xml.transform.sax.TransformerHandler handler, java.lang.String name, GraphMLExporter.AttributeDetails details)private voidwriteData(javax.xml.transform.sax.TransformerHandler handler, java.lang.String key, java.lang.String value)private voidwriteEdges(javax.xml.transform.sax.TransformerHandler handler, Graph<V,E> g)private voidwriteFooter(javax.xml.transform.sax.TransformerHandler handler)private voidwriteGraphEnd(javax.xml.transform.sax.TransformerHandler handler)private voidwriteGraphStart(javax.xml.transform.sax.TransformerHandler handler, Graph<V,E> g)private voidwriteHeader(javax.xml.transform.sax.TransformerHandler handler)private voidwriteKeys(javax.xml.transform.sax.TransformerHandler handler)private voidwriteNodes(javax.xml.transform.sax.TransformerHandler handler, Graph<V,E> g)-
Methods inherited from class org.jgrapht.nio.BaseExporter
getEdgeAttribute, getEdgeAttributeProvider, getEdgeAttributes, getEdgeId, getEdgeIdProvider, getGraphAttribute, getGraphAttributeProvider, getGraphId, getGraphIdProvider, getVertexAttribute, getVertexAttributeProvider, getVertexAttributes, getVertexId, getVertexIdProvider, setEdgeAttributeProvider, setEdgeIdProvider, setGraphAttributeProvider, setGraphIdProvider, setVertexAttributeProvider, setVertexIdProvider
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jgrapht.nio.GraphExporter
exportGraph, exportGraph
-
-
-
-
Field Detail
-
registeredAttributes
private java.util.Map<java.lang.String,GraphMLExporter.AttributeDetails> registeredAttributes
-
ATTRIBUTE_KEY_PREFIX
private static final java.lang.String ATTRIBUTE_KEY_PREFIX
- See Also:
- Constant Field Values
-
totalAttributes
private int totalAttributes
-
VERTEX_LABEL_DEFAULT_ATTRIBUTE_NAME
private static final java.lang.String VERTEX_LABEL_DEFAULT_ATTRIBUTE_NAME
- See Also:
- Constant Field Values
-
EDGE_WEIGHT_DEFAULT_ATTRIBUTE_NAME
private static final java.lang.String EDGE_WEIGHT_DEFAULT_ATTRIBUTE_NAME
- See Also:
- Constant Field Values
-
EDGE_LABEL_DEFAULT_ATTRIBUTE_NAME
private static final java.lang.String EDGE_LABEL_DEFAULT_ATTRIBUTE_NAME
- See Also:
- Constant Field Values
-
vertexLabelAttributeName
private java.lang.String vertexLabelAttributeName
-
edgeWeightAttributeName
private java.lang.String edgeWeightAttributeName
-
edgeLabelAttributeName
private java.lang.String edgeLabelAttributeName
-
exportEdgeWeights
private boolean exportEdgeWeights
Whether to print edge weights in case the graph is weighted.
-
exportVertexLabels
private boolean exportVertexLabels
Whether to try to print vertex labels. They must be found in the corresponding attribute provider.
-
exportEdgeLabels
private boolean exportEdgeLabels
Whether to try to print edge labels. They must be found in the corresponding attribute provider.
-
-
Constructor Detail
-
GraphMLExporter
public GraphMLExporter()
Constructs a new GraphMLExporter with integer id provider for the vertices.
-
GraphMLExporter
public GraphMLExporter(java.util.function.Function<V,java.lang.String> vertexIdProvider)
Constructs a new GraphMLExporter.- Parameters:
vertexIdProvider- for generating vertex identifiers. Must not be null.
-
-
Method Detail
-
registerAttribute
public void registerAttribute(java.lang.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(java.lang.String name, GraphMLExporter.AttributeCategory category, AttributeType type, java.lang.String defaultValue)Register a GraphML-Attribute- Parameters:
name- the attribute namecategory- the attribute categorytype- the attribute typedefaultValue- default value
-
unregisterAttribute
public void unregisterAttribute(java.lang.String name)
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
public java.lang.String getVertexLabelAttributeName()
Get the attribute name for vertex labels- Returns:
- the attribute name
-
setVertexLabelAttributeName
public void setVertexLabelAttributeName(java.lang.String vertexLabelAttributeName)
Set the attribute name to use for vertex labels.- Parameters:
vertexLabelAttributeName- the attribute name
-
getEdgeLabelAttributeName
public java.lang.String getEdgeLabelAttributeName()
Get the attribute name for edge labels- Returns:
- the attribute name
-
setEdgeLabelAttributeName
public void setEdgeLabelAttributeName(java.lang.String edgeLabelAttributeName)
Set the attribute name to use for edge labels.- Parameters:
edgeLabelAttributeName- the attribute name
-
getEdgeWeightAttributeName
public java.lang.String getEdgeWeightAttributeName()
Get the attribute name for edge weights- Returns:
- the attribute name
-
setEdgeWeightAttributeName
public void setEdgeWeightAttributeName(java.lang.String edgeWeightAttributeName)
Set the attribute name to use for edge weights.- Parameters:
edgeWeightAttributeName- the attribute name
-
exportGraph
public void exportGraph(Graph<V,E> g, java.io.Writer writer)
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
private void writeHeader(javax.xml.transform.sax.TransformerHandler handler) throws org.xml.sax.SAXException- Throws:
org.xml.sax.SAXException
-
writeGraphStart
private void writeGraphStart(javax.xml.transform.sax.TransformerHandler handler, Graph<V,E> g) throws org.xml.sax.SAXException- Throws:
org.xml.sax.SAXException
-
writeGraphEnd
private void writeGraphEnd(javax.xml.transform.sax.TransformerHandler handler) throws org.xml.sax.SAXException- Throws:
org.xml.sax.SAXException
-
writeFooter
private void writeFooter(javax.xml.transform.sax.TransformerHandler handler) throws org.xml.sax.SAXException- Throws:
org.xml.sax.SAXException
-
writeKeys
private void writeKeys(javax.xml.transform.sax.TransformerHandler handler) throws org.xml.sax.SAXException- Throws:
org.xml.sax.SAXException
-
writeData
private void writeData(javax.xml.transform.sax.TransformerHandler handler, java.lang.String key, java.lang.String value) throws org.xml.sax.SAXException- Throws:
org.xml.sax.SAXException
-
writeAttribute
private void writeAttribute(javax.xml.transform.sax.TransformerHandler handler, java.lang.String name, GraphMLExporter.AttributeDetails details) throws org.xml.sax.SAXException- Throws:
org.xml.sax.SAXException
-
writeNodes
private void writeNodes(javax.xml.transform.sax.TransformerHandler handler, Graph<V,E> g) throws org.xml.sax.SAXException- Throws:
org.xml.sax.SAXException
-
-