List of usage examples for javax.xml.stream XMLOutputFactory IS_REPAIRING_NAMESPACES
String IS_REPAIRING_NAMESPACES
To view the source code for javax.xml.stream XMLOutputFactory IS_REPAIRING_NAMESPACES.
Click Source Link
From source file:org.deegree.geometry.wkbadapter.WKBReaderTest.java
@Test public void testWKBToGML() throws Exception { ICRS crs = CRSManager.lookup("EPSG:4326"); InputStream is = WKBReaderTest.class.getResourceAsStream(BASE_DIR + "Polygon.wkb"); byte[] wkb = IOUtils.toByteArray(is); Polygon geom = (Polygon) WKBReader.read(wkb, crs); assertTrue(geom.getGeometryType() == GeometryType.PRIMITIVE_GEOMETRY); StringWriter sw = new StringWriter(); XMLOutputFactory outFactory = XMLOutputFactory.newInstance(); outFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true); XMLStreamWriter writer = outFactory.createXMLStreamWriter(sw); writer.setDefaultNamespace(CommonNamespaces.GML3_2_NS); GMLStreamWriter gmlSw = GMLOutputFactory.createGMLStreamWriter(GMLVersion.GML_32, writer); gmlSw.write(geom);//from w w w .ja va2 s.c o m writer.close(); String s = "<gml:posList>5.148530 59.951879 5.134692 59.736522 5.561175 59.728897 5.577771 59.944188 5.148530 59.951879</gml:posList>"; assertTrue(sw.toString().contains(s)); }
From source file:org.deegree.protocol.wps.client.wps100.ExecuteResponse100Reader.java
/** * <ul>// w w w . j a va2 s .com * <li>Precondition: cursor must point at the <code>START_ELEMENT</code> event (<wps:ComplexData>)</li> * <li>Postcondition: cursor points at the corresponding <code>END_ELEMENT</code> event (</wps:ComplexData>)</li> * </ul> * * @return * @throws XMLStreamException * @throws IOException */ private ExecutionOutput parseComplexOutput(CodeType id) throws XMLStreamException { ComplexFormat attribs = parseComplexAttributes(); StreamBufferStore tmpSink = new StreamBufferStore(); try { if (attribs.getMimeType().startsWith("text/xml") || attribs.getMimeType().startsWith("application/xml")) { XMLOutputFactory fac = XMLOutputFactory.newInstance(); fac.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true); XMLStreamWriter xmlWriter = fac.createXMLStreamWriter(tmpSink, "UTF-8"); XMLStreamUtils.nextElement(reader); xmlWriter.writeStartDocument("UTF-8", "1.0"); if (reader.getEventType() == START_ELEMENT) { XMLAdapter.writeElement(xmlWriter, reader); XMLStreamUtils.nextElement(reader); } else { LOG.debug("Response document contains empty complex data output '" + id + "'"); } xmlWriter.writeEndDocument(); xmlWriter.close(); } else { if ("base64".equals(attribs.getEncoding())) { String base64String = reader.getElementText(); byte[] bytes = Base64.decodeBase64(base64String); tmpSink.write(bytes); } else { LOG.warn("The encoding of binary data (found at response location " + reader.getLocation() + ") is not base64. Currently only for this format the decoding can be performed. Skipping the data."); } } tmpSink.close(); } catch (IOException e) { LOG.error(e.getMessage()); } return new ComplexOutput(id, tmpSink, attribs.getMimeType(), attribs.getEncoding(), attribs.getEncoding()); }
From source file:org.rhq.enterprise.server.sync.ExportingInputStream.java
private void exporterMain() { XMLStreamWriter wrt = null;/*from w w w. ja v a 2s. c o m*/ OutputStream out = null; try { XMLOutputFactory ofactory = XMLOutputFactory.newInstance(); ofactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true); try { out = exportOutput; if (zipOutput) { out = new GZIPOutputStream(out); } wrt = new IndentingXMLStreamWriter(ofactory.createXMLStreamWriter(out, "UTF-8")); //wrt = ofactory.createXMLStreamWriter(out, "UTF-8"); } catch (XMLStreamException e) { LOG.error("Failed to create the XML stream writer to output the export file to.", e); return; } exportPrologue(wrt); for (Synchronizer<?, ?> exp : synchronizers) { exportSingle(wrt, exp); } exportEpilogue(wrt); wrt.flush(); } catch (Exception e) { LOG.error("Error while exporting.", e); unexpectedExporterException = e; } finally { if (wrt != null) { try { wrt.close(); } catch (XMLStreamException e) { LOG.warn("Failed to close the exporter XML stream.", e); } } safeClose(out); } }