use of javax.xml.stream.XMLOutputFactory in project jdk8u_jdk by JetBrains.
the class SurrogatesTest method generateAndReadXml.
// Generates xml content with XMLStreamWriter and read it to check
// for correctness of xml and generated data
void generateAndReadXml(String content) throws Exception {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
XMLOutputFactory factory = XMLOutputFactory.newInstance();
OutputStreamWriter streamWriter = new OutputStreamWriter(stream);
XMLStreamWriter writer = factory.createXMLStreamWriter(streamWriter);
// Generate xml with selected stream writer type
generateXML(writer, content);
String output = stream.toString();
System.out.println("Generated xml: " + output);
// Read generated xml with StAX parser
readXML(output.getBytes(), content);
}
use of javax.xml.stream.XMLOutputFactory in project jdk8u_jdk by JetBrains.
the class JAXP15RegTest method testXMLOutputFactory.
public void testXMLOutputFactory() {
XMLOutputFactory factory = XMLOutputFactory.newInstance();
factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);
success("testXMLOutputFactory passed");
}
use of javax.xml.stream.XMLOutputFactory in project tdi-studio-se by Talend.
the class DeviceIdManager method createRegistrationEnvelope.
/**
* This method helps to create a xml envelope needed for device registration request.
*
* @param prefix Sets the required prefix for the device name.
* @param applicationId app GUID
* @param deviceName name of the device
* @param password password for the device
* @return xml envelope comprising device add request
*/
private static String createRegistrationEnvelope(String prefix, UUID applicationId, String deviceName, String password) {
// The format of the envelope is the following:
// <DeviceAddRequest>
// <ClientInfo name="[app GUID]" version="1.0"/>
// <Authentication>
// <Membername>[prefix][device name]</Membername>
// <Password>[device password]</Password>
// </Authentication>
// </DeviceAddRequest>
// Instantiate the writer and write the envelope
XMLOutputFactory factory = XMLOutputFactory.newInstance();
StringWriter envelope = new StringWriter();
XMLStreamWriter xml = null;
try {
xml = factory.createXMLStreamWriter(envelope);
// Create the node
xml.writeStartElement("DeviceAddRequest");
// Write the ClientInfo node
xml.writeStartElement("ClientInfo");
xml.writeAttribute("name", applicationId.toString());
xml.writeAttribute("version", "1.0");
xml.writeEndElement();
// Write the Authentication node
xml.writeStartElement("Authentication");
xml.writeStartElement("Membername");
xml.writeCharacters(prefix + deviceName);
xml.writeEndElement();
xml.writeStartElement("Password");
xml.writeCharacters(password);
xml.writeEndElement();
// </Authentication>
xml.writeEndElement();
// </DeviceAddRequest>
xml.writeEndElement();
} catch (XMLStreamException e) {
Log.error(e.getMessage());
} finally {
if (xml != null) {
try {
xml.flush();
xml.close();
} catch (XMLStreamException e) {
Log.error(e.getMessage());
// Ignore if it is already closed
}
}
}
return envelope.toString();
}
use of javax.xml.stream.XMLOutputFactory in project voltdb by VoltDB.
the class JDBCSQLXML method createStAXResult.
/**
* Retrieves a new DOMResult for setting the XML value designated by this
* SQLXML instance.
*
* @param resultClass The class of the result, or null.
* @throws java.sql.SQLException if there is an error processing the XML
* value
* @return for setting the XML value designated by this SQLXML instance.
*/
@SuppressWarnings("unchecked")
protected <T extends Result> T createStAXResult(Class<T> resultClass) throws SQLException {
StAXResult result = null;
OutputStream outputStream = this.setBinaryStreamImpl();
Constructor ctor;
XMLOutputFactory factory;
XMLStreamWriter xmlStreamWriter;
try {
factory = XMLOutputFactory.newInstance();
xmlStreamWriter = factory.createXMLStreamWriter(outputStream);
if (resultClass == null) {
result = new StAXResult(xmlStreamWriter);
} else {
ctor = resultClass.getConstructor(XMLStreamWriter.class);
result = (StAXResult) ctor.newInstance(xmlStreamWriter);
}
} catch (SecurityException ex) {
throw Exceptions.resultInstantiation(ex);
} catch (IllegalArgumentException ex) {
throw Exceptions.resultInstantiation(ex);
} catch (IllegalAccessException ex) {
throw Exceptions.resultInstantiation(ex);
} catch (InvocationTargetException ex) {
throw Exceptions.resultInstantiation(ex.getTargetException());
} catch (FactoryConfigurationError ex) {
throw Exceptions.resultInstantiation(ex);
} catch (InstantiationException ex) {
throw Exceptions.resultInstantiation(ex);
} catch (NoSuchMethodException ex) {
throw Exceptions.resultInstantiation(ex);
} catch (XMLStreamException ex) {
throw Exceptions.resultInstantiation(ex);
}
return (T) result;
}
use of javax.xml.stream.XMLOutputFactory in project Activiti by Activiti.
the class BpmnXMLConverter method convertToXML.
public byte[] convertToXML(BpmnModel model, String encoding) {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
XMLOutputFactory xof = XMLOutputFactory.newInstance();
OutputStreamWriter out = new OutputStreamWriter(outputStream, encoding);
XMLStreamWriter writer = xof.createXMLStreamWriter(out);
XMLStreamWriter xtw = new IndentingXMLStreamWriter(writer);
DefinitionsRootExport.writeRootElement(model, xtw, encoding);
CollaborationExport.writePools(model, xtw);
DataStoreExport.writeDataStores(model, xtw);
SignalAndMessageDefinitionExport.writeSignalsAndMessages(model, xtw);
for (Process process : model.getProcesses()) {
if (process.getFlowElements().isEmpty() && process.getLanes().isEmpty()) {
// empty process, ignore it
continue;
}
ProcessExport.writeProcess(process, xtw);
for (FlowElement flowElement : process.getFlowElements()) {
createXML(flowElement, model, xtw);
}
for (Artifact artifact : process.getArtifacts()) {
createXML(artifact, model, xtw);
}
// end process element
xtw.writeEndElement();
}
BPMNDIExport.writeBPMNDI(model, xtw);
// end definitions root element
xtw.writeEndElement();
xtw.writeEndDocument();
xtw.flush();
outputStream.close();
xtw.close();
return outputStream.toByteArray();
} catch (Exception e) {
LOGGER.error("Error writing BPMN XML", e);
throw new XMLException("Error writing BPMN XML", e);
}
}
Aggregations