Search in sources :

Example 26 with XMLOutputFactory

use of javax.xml.stream.XMLOutputFactory 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 27 with XMLOutputFactory

use of javax.xml.stream.XMLOutputFactory in project gexf4j by francesco-ficarola.

the class StaxGraphWriter method writeToStream.

@Override
public void writeToStream(Gexf gexf, Writer out, String encoding) throws IOException {
    try {
        XMLOutputFactory xmlOutputFactory = WstxOutputFactory.newInstance();
        XMLStreamWriter streamWriter = xmlOutputFactory.createXMLStreamWriter(out);
        PrettyPrintHandler handler = new PrettyPrintHandler(streamWriter);
        streamWriter = (XMLStreamWriter) Proxy.newProxyInstance(XMLStreamWriter.class.getClassLoader(), new Class[] { XMLStreamWriter.class }, handler);
        streamWriter.writeStartDocument(encoding, "1.0");
        new GexfEntityWriter(streamWriter, gexf);
        streamWriter.writeEndDocument();
        streamWriter.flush();
        streamWriter.close();
    } catch (XMLStreamException e) {
        throw new IOException("XML Exception: " + e.getMessage(), e);
    }
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) PrettyPrintHandler(it.uniroma1.dis.wsngroup.gexf4j.core.utils.PrettyPrintHandler) XMLStreamException(javax.xml.stream.XMLStreamException) GexfEntityWriter(it.uniroma1.dis.wsngroup.gexf4j.core.impl.writer.GexfEntityWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) IOException(java.io.IOException)

Example 28 with XMLOutputFactory

use of javax.xml.stream.XMLOutputFactory in project gephi by gephi.

the class SaveTask method newXMLWriter.

private static XMLStreamWriter newXMLWriter(OutputStream outputStream) throws Exception {
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
    outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.FALSE);
    return outputFactory.createXMLStreamWriter(outputStream, "UTF-8");
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory)

Example 29 with XMLOutputFactory

use of javax.xml.stream.XMLOutputFactory in project spring-framework by spring-projects.

the class AbstractMarshallerTests method marshalStaxResultEventWriter.

@Test
public void marshalStaxResultEventWriter() throws Exception {
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
    StringWriter writer = new StringWriter();
    XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
    Result result = StaxUtils.createStaxResult(eventWriter);
    marshaller.marshal(flights, result);
    assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING));
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) StringWriter(java.io.StringWriter) XMLEventWriter(javax.xml.stream.XMLEventWriter) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) StAXResult(javax.xml.transform.stax.StAXResult) DOMResult(javax.xml.transform.dom.DOMResult) Test(org.junit.Test)

Example 30 with XMLOutputFactory

use of javax.xml.stream.XMLOutputFactory in project spring-framework by spring-projects.

the class AbstractMarshallerTests method marshalJaxp14StaxResultStreamWriter.

@Test
public void marshalJaxp14StaxResultStreamWriter() throws Exception {
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
    StringWriter writer = new StringWriter();
    XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
    StAXResult result = new StAXResult(streamWriter);
    marshaller.marshal(flights, result);
    assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING));
}
Also used : StAXResult(javax.xml.transform.stax.StAXResult) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) StringWriter(java.io.StringWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) Test(org.junit.Test)

Aggregations

XMLOutputFactory (javax.xml.stream.XMLOutputFactory)42 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)28 StringWriter (java.io.StringWriter)18 XMLStreamException (javax.xml.stream.XMLStreamException)15 XMLEventWriter (javax.xml.stream.XMLEventWriter)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 Test (org.junit.Test)8 StAXResult (javax.xml.transform.stax.StAXResult)7 IOException (java.io.IOException)6 DOMResult (javax.xml.transform.dom.DOMResult)6 StreamResult (javax.xml.transform.stream.StreamResult)6 Result (javax.xml.transform.Result)5 PcrManifest (com.intel.mountwilson.manifest.data.PcrManifest)3 OutputStream (java.io.OutputStream)3 SAXResult (javax.xml.transform.sax.SAXResult)3 IManifest (com.intel.mountwilson.manifest.data.IManifest)2 Headers (com.sun.net.httpserver.Headers)2 OutputStreamWriter (java.io.OutputStreamWriter)2 InetSocketAddress (java.net.InetSocketAddress)2 Path (java.nio.file.Path)2