/** * Set the output method (the default is xml). * @param method */ public void setOutputMethod(String method) { serializer.setOutputProperty(Serializer.Property.METHOD, method); }
/** * Set the output method (the default is xml). * @param method */ public void setOutputMethod(String method) { serializer.setOutputProperty(Serializer.Property.METHOD, method); }
/** * Set the output method (the default is xml). * @param method */ public void setOutputMethod(String method) { serializer.setOutputProperty(Serializer.Property.METHOD, method); }
public Serializer checkoutSerializer() { Serializer serializer = serializerPool.poll(); if (serializer == null) { serializer = new Serializer(); serializer.setOutputProperty(Serializer.Property.ENCODING, "utf-8"); serializer.setOutputProperty(Serializer.Property.BYTE_ORDER_MARK, "no"); serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes"); } return serializer; }
/** * Set any output properties appearing on the command line in the form {@code !indent=yes} * as properties of the supplied {@code Serializer} * @param serializer the supplied {@code Serializer}, whose serialization properties * are to be modified. */ public void setSerializationProperties(Serializer serializer) { for (Enumeration e = serializationParams.propertyNames(); e.hasMoreElements(); ) { String name = (String) e.nextElement(); String value = serializationParams.getProperty(name); // parameters starting with "!" are taken as output properties // Allow the prefix "!saxon:" instead of "!{http://saxon.sf.net}" if (name.startsWith("saxon:")) { name = "{" + NamespaceConstant.SAXON + "}" + name.substring(6); } serializer.setOutputProperty(QName.fromClarkName(name), value); } }
public String serializeAsXML(XdmNode node) { try { Serializer serializer = runtime.getProcessor().newSerializer(); serializer.setOutputProperty(Serializer.Property.BYTE_ORDER_MARK, "no"); serializer.setOutputProperty(Serializer.Property.ENCODING, "utf-8"); serializer.setOutputProperty(Serializer.Property.INDENT, "yes"); serializer.setOutputProperty(Serializer.Property.METHOD, "xml"); serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes"); ByteArrayOutputStream os = new ByteArrayOutputStream(); serializer.setOutputStream(os); S9apiUtils.serialize(runtime, node, serializer); String result = os.toString(); return result; } catch (SaxonApiException sae) { logger.warn("Failed to serialize node: " + node); logger.debug(sae.getMessage(), sae); return ""; } }
/** * Set any output properties appearing on the command line in the form {@code !indent=yes} * as properties of the supplied {@code Serializer} * @param serializer the supplied {@code Serializer}, whose serialization properties * are to be modified. */ public void setSerializationProperties(Serializer serializer) { for (Enumeration e = serializationParams.propertyNames(); e.hasMoreElements(); ) { String name = (String) e.nextElement(); String value = serializationParams.getProperty(name); // parameters starting with "!" are taken as output properties // Allow the prefix "!saxon:" instead of "!{http://saxon.sf.net}" if (name.startsWith("saxon:")) { name = "{" + NamespaceConstant.SAXON + "}" + name.substring(6); } serializer.setOutputProperty(QName.fromClarkName(name), value); } }
public String serializeAsXML(XdmNode node) { try { Serializer serializer = runtime.getProcessor().newSerializer(); serializer.setOutputProperty(Serializer.Property.BYTE_ORDER_MARK, "no"); serializer.setOutputProperty(Serializer.Property.ENCODING, "utf-8"); serializer.setOutputProperty(Serializer.Property.INDENT, "yes"); serializer.setOutputProperty(Serializer.Property.METHOD, "xml"); serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes"); ByteArrayOutputStream os = new ByteArrayOutputStream(); serializer.setOutputStream(os); S9apiUtils.serialize(runtime, node, serializer); String result = os.toString(); return result; } catch (SaxonApiException sae) { logger.warn("Failed to serialize node: " + node); logger.debug(sae.getMessage(), sae); return ""; } } }
public String serializeAsXML(XdmNode node) { try { Serializer serializer = runtime.getProcessor().newSerializer(); serializer.setOutputProperty(Serializer.Property.BYTE_ORDER_MARK, "no"); serializer.setOutputProperty(Serializer.Property.ENCODING, "utf-8"); serializer.setOutputProperty(Serializer.Property.INDENT, "yes"); serializer.setOutputProperty(Serializer.Property.METHOD, "xml"); serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes"); ByteArrayOutputStream os = new ByteArrayOutputStream(); serializer.setOutputStream(os); S9apiUtils.serialize(runtime, node, serializer); String result = os.toString(); return result; } catch (SaxonApiException sae) { logger.warn("Failed to serialize node: " + node); logger.debug(sae.getMessage(), sae); return ""; } }
private static void storeXML(XProcRuntime runtime, XdmNode doc, OutputStream stream) { try { try { Serializer serializer = runtime.getProcessor().newSerializer(); serializer.setOutputProperty(Serializer.Property.ENCODING, "utf-8"); serializer.setOutputProperty(Serializer.Property.INDENT, "no"); serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes"); serializer.setOutputProperty(Serializer.Property.METHOD, "xml"); serializer.setOutputStream(stream); S9apiUtils.serialize(runtime, doc, serializer); } finally { stream.close(); } } catch (IOException ioe) { throw new XProcException("Failed to serialize as XML: " + doc, ioe); } catch (SaxonApiException sae) { throw new XProcException("Failed to serialize as XML: " + doc, sae); } }
private static void storeXML(XProcRuntime runtime, XdmNode doc, OutputStream stream) { try { try { Serializer serializer = runtime.getProcessor().newSerializer(); serializer.setOutputProperty(Serializer.Property.ENCODING, "utf-8"); serializer.setOutputProperty(Serializer.Property.INDENT, "no"); serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes"); serializer.setOutputProperty(Serializer.Property.METHOD, "xml"); serializer.setOutputStream(stream); S9apiUtils.serialize(runtime, doc, serializer); } finally { stream.close(); } } catch (IOException ioe) { throw new XProcException("Failed to serialize as XML: " + doc, ioe); } catch (SaxonApiException sae) { throw new XProcException("Failed to serialize as XML: " + doc, sae); } }
/** Retrieves the output for a given xslt transformer. * @param xsltTransformer the {@link XsltTransformer} that will receive the output * @return the output as a {@link ByteArrayOutputStream} */ public ByteArrayOutputStream getOutput(final XsltTransformer xsltTransformer) { Serializer serializer = serializerFactory.createSerializer(); serializer.setOutputProperty(Serializer.Property.METHOD, "xml"); serializer.setOutputProperty(Serializer.Property.INDENT, "no"); ByteArrayOutputStream output = byteArrayOutputStreamFactory.createByteArrayOutputStream(); serializer.setOutputStream(output); xsltTransformer.setDestination(serializer); return output; }
private byte[] textContent(final XdmNode doc) { Serializer serializer = makeSerializer(); serializer.setOutputProperty(Serializer.Property.METHOD, "text"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); serializer.setOutputStream(baos); try { S9apiUtils.serialize(runtime, doc, serializer); } catch (SaxonApiException e) { throw new XProcException(e); } return baos.toByteArray(); }
private void generateAggregatedHtmlReport(File xmlFile, File outputDir) throws SaxonApiException { Processor proc = new Processor(false); XsltCompiler comp = proc.newXsltCompiler(); InputStream xsl = getClass().getClassLoader().getResourceAsStream("spotbugs/html-aggregated.xsl"); XsltExecutable exp = comp.compile(new StreamSource(xsl)); XdmNode source = proc.newDocumentBuilder().build(new StreamSource(xmlFile)); Serializer out = proc.newSerializer(new File(outputDir, "SpotBugsAggregated.html")); out.setOutputProperty(Serializer.Property.METHOD, "html"); out.setOutputProperty(Serializer.Property.INDENT, "yes"); XsltTransformer trans = exp.load(); trans.setInitialContextNode(source); trans.setDestination(out); trans.transform(); }
Processor p = new Processor(); Serializer s = p.newSerializer(System.out); s.setOutputProperty(Property.INDENT, "yes"); XMLStreamWriter w = s.getXMLStreamWriter();
Processor p = new Processor(); Serializer s = p.newSerializer(); s.setOutputProperty(Property.INDENT, "yes"); XMLStreamWriter w = s.getXMLStreamWriter();
public void run() throws SaxonApiException { super.run(); XsltCompiler compiler = runtime.getProcessor().newXsltCompiler(); XsltExecutable exec = compiler.compile(prettyPrint.asSource()); XsltTransformer transformer = exec.load(); transformer.setInitialContextNode(source.read()); ByteArrayOutputStream stream = new ByteArrayOutputStream(); Serializer serializer = runtime.getProcessor().newSerializer(); serializer.setOutputProperty(Serializer.Property.ENCODING, "utf-8"); serializer.setOutputProperty(Serializer.Property.INDENT, "yes"); serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes"); serializer.setOutputProperty(Serializer.Property.METHOD, "xml"); serializer.setOutputStream(stream); transformer.setDestination(serializer); transformer.transform(); XdmNode output = runtime.parse(new InputSource(new ByteArrayInputStream(stream.toByteArray()))); result.write(output); } }
public void run() throws SaxonApiException { super.run(); XsltCompiler compiler = runtime.getProcessor().newXsltCompiler(); XsltExecutable exec = compiler.compile(prettyPrint.asSource()); XsltTransformer transformer = exec.load(); transformer.setInitialContextNode(source.read()); ByteArrayOutputStream stream = new ByteArrayOutputStream(); Serializer serializer = runtime.getProcessor().newSerializer(); serializer.setOutputProperty(Serializer.Property.ENCODING, "utf-8"); serializer.setOutputProperty(Serializer.Property.INDENT, "yes"); serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes"); serializer.setOutputProperty(Serializer.Property.METHOD, "xml"); serializer.setOutputStream(stream); transformer.setDestination(serializer); transformer.transform(); XdmNode output = runtime.parse(new InputSource(new ByteArrayInputStream(stream.toByteArray()))); result.write(output); } }
/** * New serializer. * * @param serialization the serialization * @param config the config * @return the serializer */ public static Serializer newSerializer(Serialization serialization, XProcConfiguration config) { Serializer serializer = config.getProcessor().newSerializer(); for (SerializationOptions so : EnumSet .allOf(SerializationOptions.class)) { serializer.setOutputProperty(so.asSaxonProp(), so.getValue(serialization, config)); } return serializer; } }
public void aggregateSpotBugsFiles(File rootDir, int level, File outputDir) throws FileNotFoundException, IOException, SaxonApiException { List<File> spotBugsFiles = getSpotBugsFiles(rootDir, level); Processor proc = new Processor(false); XsltCompiler comp = proc.newXsltCompiler(); InputStream xsl = getClass().getClassLoader().getResourceAsStream("spotbugs/xml-aggregated.xsl"); XsltExecutable exp = comp.compile(new StreamSource(xsl)); Serializer out = proc.newSerializer(new File(outputDir, "SpotBugsAggregated.xml")); out.setOutputProperty(Serializer.Property.METHOD, "xml"); out.setOutputProperty(Serializer.Property.INDENT, "yes"); XsltTransformer trans = exp.load(); List<XdmNode> sources = createXdmNodes(spotBugsFiles, proc.newDocumentBuilder()); QName xmlFiles = new QName("xmlFiles"); XdmValue filesXdm = XdmValue.makeSequence(sources); trans.setParameter(xmlFiles, filesXdm); trans.setInitialTemplate(new QName("test")); trans.setDestination(out); trans.transform(); }