List of usage examples for javax.xml.stream XMLOutputFactory newInstance
public static XMLOutputFactory newInstance() throws FactoryConfigurationError
From source file:com.pocketsoap.salesforce.soap.SoapRequestEntity.java
public final void writeRequest(OutputStream out) throws IOException { XMLOutputFactory f = XMLOutputFactory.newInstance(); try {/*from w w w . jav a 2 s. c o m*/ XMLStreamWriter w = f.createXMLStreamWriter(new BufferedOutputStream(out, 1024), "UTF-8"); w.writeStartDocument(); w.writeStartElement("s", "Envelope", SOAP_NS); w.writeNamespace("s", SOAP_NS); w.writeNamespace("p", PARTNER_NS); w.setPrefix("p", PARTNER_NS); w.setPrefix("s", SOAP_NS); if (hasHeaders()) { w.writeStartElement(SOAP_NS, "Header"); writeHeaders(w); w.writeEndElement(); } w.writeStartElement(SOAP_NS, "Body"); writeBody(w); w.writeEndElement();//body w.writeEndElement();//envelope w.writeEndDocument(); w.close(); } catch (XMLStreamException e) { throw new IOException("Error generating request xml", e); } }
From source file:de.tudarmstadt.ukp.integration.alignment.xml.AlignmentXmlWriter.java
public AlignmentXmlWriter(OutputStream out) throws IOException { try {/*from ww w . j a va 2s . c om*/ XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance(); xmlEventWriter = xmlOutputFactory.createXMLEventWriter(out); JAXBContext context = JAXBContext.newInstance(XmlMeta.class, Alignments.class); //Source.class marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); // no document level events marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); xmlef = XMLEventFactory.newInstance(); xmlEventWriter.add(xmlef.createStartDocument()); xmlEventWriter.add(xmlef.createStartElement("", "", RESOURCE_ALIGNMENT)); } catch (XMLStreamException e) { throw new IOException(e); } catch (JAXBException e) { throw new IOException(e); } }
From source file:com.microsoft.windowsazure.services.table.client.AtomPubParser.java
/** * Reserved for internal use. A static factory method to construct an <code>XMLStreamWriter</code> instance based on * the specified <code>OutputStream</code>. * /* w ww . ja v a2 s . c om*/ * @param outStream * The <code>OutputStream</code> instance to create an <code>XMLStreamWriter</code> on. * @return * An <code>XMLStreamWriter</code> instance based on the specified <code>OutputStream</code>. * @throws XMLStreamException * if an error occurs while creating the stream. */ protected static XMLStreamWriter generateTableWriter(final OutputStream outStream) throws XMLStreamException { final XMLOutputFactory xmlOutFactoryInst = XMLOutputFactory.newInstance(); return xmlOutFactoryInst.createXMLStreamWriter(outStream, "UTF-8"); }
From source file:edu.vt.middleware.gator.util.StaxIndentationHandler.java
/** * Convenience method for creating a {@link XMLStreamWriter} that emits * indented output using an instance of this class. * // w w w. ja v a 2s . c o m * @param out Output stream that receives written XML. * * @return Proxy to a {@link XMLStreamWriter} that has an instance of this * class as an invocation handler to provided indented output. * * @throws FactoryConfigurationError * On serious errors creating an XMLOutputFactory * @throws XMLStreamException On errors creating a an XMLStreamWriter from * the default factory. */ public static XMLStreamWriter createIndentingStreamWriter(final OutputStream out) throws XMLStreamException, FactoryConfigurationError { final XMLOutputFactory factory = XMLOutputFactory.newInstance(); factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true); final XMLStreamWriter writer = factory.createXMLStreamWriter(out, "UTF-8"); return (XMLStreamWriter) Proxy.newProxyInstance(XMLStreamWriter.class.getClassLoader(), new Class[] { XMLStreamWriter.class }, new StaxIndentationHandler(writer)); }
From source file:eionet.meta.exports.rdf.VocabularyXmlWriter.java
/** * Class constructor./* w ww .j av a 2s .c om*/ * * @param out * output stream * @throws XMLStreamException * if writing fails */ public VocabularyXmlWriter(OutputStream out) throws XMLStreamException { writer = XMLOutputFactory.newInstance().createXMLStreamWriter(out, ENCODING); }
From source file:edu.harvard.hms.dbmi.bd2k.irct.ws.rs.resultconverter.XMLTabularDataConverter.java
@Override public StreamingOutput createStream(final Result result) { StreamingOutput stream = new StreamingOutput() { @Override// ww w . j a v a 2s .c o m public void write(OutputStream outputStream) throws IOException, WebApplicationException { ResultSet rs = null; XMLStreamWriter xtw = null; try { rs = (ResultSet) result.getData(); rs.load(result.getResultSetLocation()); XMLOutputFactory xof = XMLOutputFactory.newInstance(); xtw = xof.createXMLStreamWriter(new OutputStreamWriter(outputStream)); xtw.writeStartDocument("utf-8", "1.0"); xtw.writeStartElement("results"); rs.beforeFirst(); while (rs.next()) { xtw.writeStartElement("result"); for (int i = 0; i < rs.getColumnSize(); i++) { xtw.writeStartElement(rs.getColumn(i).getName().replace(" ", "_")); xtw.writeCharacters(rs.getString(i)); xtw.writeEndElement(); } xtw.writeEndElement(); } xtw.writeEndElement(); xtw.writeEndDocument(); xtw.flush(); } catch (ResultSetException | PersistableException | XMLStreamException e) { log.info("Error creating XML Stream: " + e.getMessage()); } finally { if (xtw != null) { try { xtw.close(); } catch (XMLStreamException e) { e.printStackTrace(); } } if (rs != null && !rs.isClosed()) { try { rs.close(); } catch (ResultSetException e) { e.printStackTrace(); } } if (outputStream != null) { outputStream.close(); } } } }; return stream; }
From source file:StreamSrcStAXRst.java
public static void transform(InputStream xmlIn, InputStream xsltIn, OutputStream out) throws Exception { javax.xml.transform.Source xmlSource = new javax.xml.transform.stream.StreamSource(xmlIn); javax.xml.transform.Result xmlResult = new javax.xml.transform.stax.StAXResult( XMLOutputFactory.newInstance().createXMLStreamWriter(new FileWriter(fileName))); javax.xml.transform.Source xsltSource = new javax.xml.transform.stream.StreamSource(xsltIn); javax.xml.transform.Source source = new javax.xml.transform.stream.StreamSource(xmlIn); // create an instance of TransformerFactory javax.xml.transform.TransformerFactory transFact = javax.xml.transform.TransformerFactory.newInstance(); transFact.setAttribute("debug", new String("true")); transFact.setAttribute("translet-name", new String("suresh")); transFact.setAttribute("generate-translet", new String("true")); transFact.setAttribute("jar-name", new String("transletjar")); javax.xml.transform.Transformer trans = transFact.newTransformer(xsltSource); trans.transform(source, xmlResult);/*from w ww . j a v a2 s . c o m*/ }
From source file:com.predic8.membrane.core.interceptor.xmlprotection.XMLProtector.java
public XMLProtector(OutputStreamWriter osw, boolean removeDTD, int maxElementNameLength, int maxAttibuteCount) throws Exception { this.writer = XMLOutputFactory.newInstance().createXMLEventWriter(osw); this.removeDTD = removeDTD; this.maxElementNameLength = maxElementNameLength; this.maxAttibuteCount = maxAttibuteCount; }
From source file:microsoft.exchange.webservices.data.credential.WSSecurityBasedCredentialsTest.java
@Before public void initTest() throws XMLStreamException { // testObject wsSecurityBasedCredentials = new WSSecurityBasedCredentials() { };/*from w w w . j a va 2 s . c o m*/ // testContext stringWriter = new StringWriter(); xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(stringWriter); }
From source file:eionet.webq.converter.JsonXMLBidirectionalConverter.java
/** * Converts json to xml.//from w ww . j av a 2 s.co m * * @param json json as byte array. * @return xml as byte array. */ public byte[] convertJsonToXml(byte[] json) { JsonXMLConfig config = new JsonXMLConfigBuilder().prettyPrint(true).multiplePI(false).build(); XMLInputFactory reader = new JsonXMLInputFactory(config); XMLOutputFactory writer = XMLOutputFactory.newInstance(); return convert(reader, writer, json); }