Search in sources :

Example 1 with IndentingXMLStreamWriter

use of javanet.staxutils.IndentingXMLStreamWriter in project gephi by gephi.

the class ExporterGEXF method execute.

@Override
public boolean execute() {
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    GraphModel graphModel = graphController.getGraphModel(workspace);
    Graph graph = exportVisible ? graphModel.getGraphVisible() : graphModel.getGraph();
    Progress.start(progress);
    graph.readLock();
    //Is it a dynamic graph?
    exportDynamic = exportDynamic && graphModel.isDynamic();
    //Calculate min & max
    calculateMinMax(graph);
    Progress.switchToDeterminate(progress, graph.getNodeCount() + graph.getEdgeCount());
    try {
        XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
        outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.FALSE);
        XMLStreamWriter xmlWriter = outputFactory.createXMLStreamWriter(writer);
        xmlWriter = new IndentingXMLStreamWriter(xmlWriter);
        xmlWriter.writeStartDocument("UTF-8", "1.0");
        xmlWriter.setPrefix("", GEXF_NAMESPACE);
        xmlWriter.writeStartElement(GEXF_NAMESPACE, GEXF);
        xmlWriter.writeNamespace("", GEXF_NAMESPACE);
        xmlWriter.writeAttribute(GEXF_VERSION, "1.3");
        if (exportColors || exportPosition || exportSize) {
            xmlWriter.writeNamespace(VIZ, VIZ_NAMESPACE);
        }
        xmlWriter.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
        xmlWriter.writeAttribute("xsi:schemaLocation", GEXF_NAMESPACE_LOCATION);
        writeMeta(xmlWriter);
        writeGraph(xmlWriter, graph);
        xmlWriter.writeEndElement();
        xmlWriter.writeEndDocument();
        xmlWriter.close();
    } catch (Exception e) {
        Logger.getLogger(ExporterGEXF.class.getName()).log(Level.SEVERE, null, e);
    } finally {
        graph.readUnlock();
        Progress.finish(progress);
    }
    return !cancel;
}
Also used : IndentingXMLStreamWriter(javanet.staxutils.IndentingXMLStreamWriter) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) IndentingXMLStreamWriter(javanet.staxutils.IndentingXMLStreamWriter)

Example 2 with IndentingXMLStreamWriter

use of javanet.staxutils.IndentingXMLStreamWriter in project CFLint by cflint.

the class DefaultCFlintResultMarshaller method output.

@Override
public void output(BugList bugList, Writer writer, boolean showStats) throws MarshallerException {
    try {
        final XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
        XMLStreamWriter xtw = new IndentingXMLStreamWriter(xmlOutputFactory.createXMLStreamWriter(writer));
        writeIssues(bugList, xtw, showStats);
        xtw.flush();
    } catch (XMLStreamException e) {
        throw new MarshallerException(e);
    }
}
Also used : IndentingXMLStreamWriter(javanet.staxutils.IndentingXMLStreamWriter) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) MarshallerException(com.cflint.xml.MarshallerException) XMLStreamException(javax.xml.stream.XMLStreamException) IndentingXMLStreamWriter(javanet.staxutils.IndentingXMLStreamWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Aggregations

IndentingXMLStreamWriter (javanet.staxutils.IndentingXMLStreamWriter)2 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)2 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)2 MarshallerException (com.cflint.xml.MarshallerException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1