- java.lang.Object
-
- org.jgrapht.nio.BaseExporter<V,E>
-
- org.jgrapht.nio.gexf.GEXFExporter<V,E>
-
- Type Parameters:
V- the graph vertex typeE- the graph edge type
- All Implemented Interfaces:
GraphExporter<V,E>
public class GEXFExporter<V,E> extends BaseExporter<V,E> implements GraphExporter<V,E>
Exports a graph as GEXF (Graph Exchange XML Format).For a description of the format see https://gephi.org/gexf/format/schema.html. A nice primer for the format is located at https://gephi.org/gexf/1.2draft/gexf-12draft-primer.pdf.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGEXFExporter.AttributeCategoryDenotes the category of a GEXF-Attribute.private classGEXFExporter.AttributeDetailsstatic classGEXFExporter.ParameterParameters that affect the behavior of the exporter.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Stringcreatorprivate java.lang.Stringdescriptionprivate static java.util.Set<java.lang.String>EDGE_RESERVED_ATTRIBUTESprivate java.lang.Stringkeywordsprivate static java.lang.StringLABEL_ATTRIBUTE_NAMEprivate java.util.Set<GEXFExporter.Parameter>parametersprivate java.util.Map<java.lang.String,GEXFExporter.AttributeDetails>registeredEdgeAttributesprivate java.util.Map<java.lang.String,GEXFExporter.AttributeDetails>registeredVertexAttributesprivate inttotalEdgeAttributesprivate inttotalVertexAttributesprivate static java.lang.StringTYPE_ATTRIBUTE_NAMEprivate static java.util.Set<java.lang.String>VERTEX_RESERVED_ATTRIBUTESprivate static java.lang.StringWEIGHT_ATTRIBUTE_NAME-
Fields inherited from class org.jgrapht.nio.BaseExporter
edgeAttributeProvider, edgeIdProvider, graphAttributeProvider, graphIdProvider, vertexAttributeProvider, vertexIdProvider
-
-
Constructor Summary
Constructors Constructor Description GEXFExporter()Constructs a new exporter with integer id providers for the vertices and the edges.GEXFExporter(java.util.function.Function<V,java.lang.String> vertexIdProvider, java.util.function.Function<E,java.lang.String> edgeIdProvider)Constructs a new exporter.
-
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.StringgetCreator()Get the creator for the meta field.java.lang.StringgetDescription()Get the description for the meta field.java.lang.StringgetKeywords()Get the keywords for the meta field.booleanisParameter(GEXFExporter.Parameter p)Return if a particular parameter of the exporter is enabledvoidregisterAttribute(java.lang.String name, GEXFExporter.AttributeCategory category, GEXFAttributeType type)Register a GEXF AttributevoidregisterAttribute(java.lang.String name, GEXFExporter.AttributeCategory category, GEXFAttributeType type, java.lang.String defaultValue)Register a GEXF AttributevoidregisterAttribute(java.lang.String name, GEXFExporter.AttributeCategory category, GEXFAttributeType type, java.lang.String defaultValue, java.lang.String options)Register a GEXF AttributevoidsetCreator(java.lang.String creator)Set the creator for the meta field.voidsetDescription(java.lang.String description)Set the description for the meta field.voidsetKeywords(java.lang.String keywords)Set the keywords for the meta field.voidsetParameter(GEXFExporter.Parameter p, boolean value)Set the value of a parameter of the exportervoidunregisterAttribute(java.lang.String name, GEXFExporter.AttributeCategory category)Unregister a GraphML-Attributeprivate voidwriteAttribute(javax.xml.transform.sax.TransformerHandler handler, java.lang.String name, GEXFExporter.AttributeDetails details)private voidwriteAttributeValue(javax.xml.transform.sax.TransformerHandler handler, java.lang.String key, java.lang.String value)private voidwriteEdgeAttributes(javax.xml.transform.sax.TransformerHandler handler)private voidwriteEdgeAttributeValues(javax.xml.transform.sax.TransformerHandler handler, E e)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 voidwriteMeta(javax.xml.transform.sax.TransformerHandler handler)private voidwriteVertexAttributes(javax.xml.transform.sax.TransformerHandler handler)private voidwriteVertexAttributeValues(javax.xml.transform.sax.TransformerHandler handler, V v)private voidwriteVertices(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
-
LABEL_ATTRIBUTE_NAME
private static final java.lang.String LABEL_ATTRIBUTE_NAME
- See Also:
- Constant Field Values
-
WEIGHT_ATTRIBUTE_NAME
private static final java.lang.String WEIGHT_ATTRIBUTE_NAME
- See Also:
- Constant Field Values
-
TYPE_ATTRIBUTE_NAME
private static final java.lang.String TYPE_ATTRIBUTE_NAME
- See Also:
- Constant Field Values
-
VERTEX_RESERVED_ATTRIBUTES
private static final java.util.Set<java.lang.String> VERTEX_RESERVED_ATTRIBUTES
-
EDGE_RESERVED_ATTRIBUTES
private static final java.util.Set<java.lang.String> EDGE_RESERVED_ATTRIBUTES
-
totalVertexAttributes
private int totalVertexAttributes
-
registeredVertexAttributes
private java.util.Map<java.lang.String,GEXFExporter.AttributeDetails> registeredVertexAttributes
-
totalEdgeAttributes
private int totalEdgeAttributes
-
registeredEdgeAttributes
private java.util.Map<java.lang.String,GEXFExporter.AttributeDetails> registeredEdgeAttributes
-
parameters
private final java.util.Set<GEXFExporter.Parameter> parameters
-
creator
private java.lang.String creator
-
keywords
private java.lang.String keywords
-
description
private java.lang.String description
-
-
Constructor Detail
-
GEXFExporter
public GEXFExporter()
Constructs a new exporter with integer id providers for the vertices and the edges.
-
GEXFExporter
public GEXFExporter(java.util.function.Function<V,java.lang.String> vertexIdProvider, java.util.function.Function<E,java.lang.String> edgeIdProvider)
Constructs a new exporter.- Parameters:
vertexIdProvider- for generating vertex identifiers. Must not be null.edgeIdProvider- for generating edge identifiers. Must not be null.
-
-
Method Detail
-
isParameter
public boolean isParameter(GEXFExporter.Parameter p)
Return if a particular parameter of the exporter is enabled- Parameters:
p- the parameter- Returns:
trueif the parameter is set,falseotherwise
-
setParameter
public void setParameter(GEXFExporter.Parameter p, boolean value)
Set the value of a parameter of the exporter- Parameters:
p- the parametervalue- the value to set
-
registerAttribute
public void registerAttribute(java.lang.String name, GEXFExporter.AttributeCategory category, GEXFAttributeType type)Register a GEXF Attribute- Parameters:
name- the attribute namecategory- the attribute categorytype- the attribute type
-
registerAttribute
public void registerAttribute(java.lang.String name, GEXFExporter.AttributeCategory category, GEXFAttributeType type, java.lang.String defaultValue)Register a GEXF Attribute- Parameters:
name- the attribute namecategory- the attribute categorytype- the attribute typedefaultValue- default value
-
registerAttribute
public void registerAttribute(java.lang.String name, GEXFExporter.AttributeCategory category, GEXFAttributeType type, java.lang.String defaultValue, java.lang.String options)Register a GEXF Attribute- Parameters:
name- the attribute namecategory- the attribute categorytype- the attribute typedefaultValue- default valueoptions- the possible options
-
unregisterAttribute
public void unregisterAttribute(java.lang.String name, GEXFExporter.AttributeCategory category)Unregister a GraphML-Attribute- Parameters:
name- the attribute namecategory- the attribute category
-
getCreator
public java.lang.String getCreator()
Get the creator for the meta field.- Returns:
- the creator for the meta field
-
setCreator
public void setCreator(java.lang.String creator)
Set the creator for the meta field.- Parameters:
creator- the creator for the meta field
-
getKeywords
public java.lang.String getKeywords()
Get the keywords for the meta field.- Returns:
- the keywords for the meta field
-
setKeywords
public void setKeywords(java.lang.String keywords)
Set the keywords for the meta field.- Parameters:
keywords- the keywords for the meta field
-
getDescription
public java.lang.String getDescription()
Get the description for the meta field.- Returns:
- the description for the meta field
-
setDescription
public void setDescription(java.lang.String description)
Set the description for the meta field.- Parameters:
description- the description for the meta field
-
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
-
writeMeta
private void writeMeta(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
-
writeVertexAttributes
private void writeVertexAttributes(javax.xml.transform.sax.TransformerHandler handler) throws org.xml.sax.SAXException- Throws:
org.xml.sax.SAXException
-
writeEdgeAttributes
private void writeEdgeAttributes(javax.xml.transform.sax.TransformerHandler handler) throws org.xml.sax.SAXException- Throws:
org.xml.sax.SAXException
-
writeAttribute
private void writeAttribute(javax.xml.transform.sax.TransformerHandler handler, java.lang.String name, GEXFExporter.AttributeDetails details) throws org.xml.sax.SAXException- Throws:
org.xml.sax.SAXException
-
writeVertexAttributeValues
private void writeVertexAttributeValues(javax.xml.transform.sax.TransformerHandler handler, V v) throws org.xml.sax.SAXException- Throws:
org.xml.sax.SAXException
-
writeEdgeAttributeValues
private void writeEdgeAttributeValues(javax.xml.transform.sax.TransformerHandler handler, E e) throws org.xml.sax.SAXException- Throws:
org.xml.sax.SAXException
-
writeAttributeValue
private void writeAttributeValue(javax.xml.transform.sax.TransformerHandler handler, java.lang.String key, java.lang.String value) throws org.xml.sax.SAXException- Throws:
org.xml.sax.SAXException
-
writeVertices
private void writeVertices(javax.xml.transform.sax.TransformerHandler handler, Graph<V,E> g) throws org.xml.sax.SAXException- Throws:
org.xml.sax.SAXException
-
-