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;
}
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);
}
}
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");
}
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));
}
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));
}
Aggregations