/** * Creates new instances of {@link Serializer}. * @return the new instance */ public Serializer createSerializer() { Processor processor = processorFactory.createProcessor(); Serializer serializer = processor.newSerializer(); return serializer; }
/** * Creates new instances of {@link Serializer} using a {@link ByteArrayOutputStream}. * @param baos the {@link ByteArrayOutputStream} used to create a serializer * @return the new instance */ public Serializer createSerializer(final ByteArrayOutputStream baos) { Processor processor = processorFactory.createProcessor(); Serializer serializer = processor.newSerializer(baos); return serializer; } }
public String transformToString(XdmNode xml, Map<String, Object> parameters) throws SaxonApiException { Serializer dest = processor.newSerializer(); StringWriter sw = new StringWriter(); dest.setOutputWriter(sw); genericTransform(xml, parameters, dest); return sw.toString(); }
private Serializer serializeToFile(File file) throws FileNotFoundException { Serializer serializer = processor.newSerializer(); serializer.setOutputStream(new FileOutputStream(file)); serializer.setCloseOnCompletion(true); return serializer; }
public static InputSource xdmToInputSource(XProcRuntime runtime, XdmNode node) throws SaxonApiException { ByteArrayOutputStream out = new ByteArrayOutputStream(); Serializer serializer = runtime.getProcessor().newSerializer(); serializer.setOutputStream(out); serialize(runtime, node, serializer); InputSource isource = new InputSource(new ByteArrayInputStream(out.toByteArray())); if (node.getBaseURI() != null) { isource.setSystemId(node.getBaseURI().toASCIIString()); } return isource; }
public static InputSource xdmToInputSource(XProcRuntime runtime, XdmNode node) throws SaxonApiException { ByteArrayOutputStream out = new ByteArrayOutputStream(); Serializer serializer = runtime.getProcessor().newSerializer(); serializer.setOutputStream(out); serialize(runtime, node, serializer); InputSource isource = new InputSource(new ByteArrayInputStream(out.toByteArray())); if (node.getBaseURI() != null) { isource.setSystemId(node.getBaseURI().toASCIIString()); } return isource; }
/** * Create a serializer initialised to use the default output parameters defined in the stylesheet. * These serialization parameters can be overridden by use of * {@link Serializer#setOutputProperty(Serializer.Property, String)}. * * @param file the output file to which the serializer will write its output. As well as initializing * the serializer to write to this output file, this method sets the base output URI of this * Xslt30Transformer to be the URI of this file. * @since 9.7.0.1 */ public Serializer newSerializer(File file) { Serializer serializer = processor.newSerializer(file); serializer.setOutputProperties(controller.getExecutable().getPrimarySerializationProperties()); setBaseOutputURI(file.toURI().toString()); return serializer; }
/** * Create a serializer initialised to use the default output parameters defined in the stylesheet. * These serialization parameters can be overridden by use of * {@link Serializer#setOutputProperty(Serializer.Property, String)}. * * @since 9.7.0.1 */ public Serializer newSerializer() { Serializer serializer = processor.newSerializer(); serializer.setOutputProperties(controller.getExecutable().getPrimarySerializationProperties()); return serializer; }
/** * Create a serializer initialised to use the default output parameters defined in the stylesheet. * These serialization parameters can be overridden by use of * {@link Serializer#setOutputProperty(Serializer.Property, String)}. * * @since 9.7.0.1 */ public Serializer newSerializer() { Serializer serializer = processor.newSerializer(); serializer.setOutputProperties(controller.getExecutable().getPrimarySerializationProperties()); return serializer; }
/** * Create a serializer initialised to use the default output parameters defined in the stylesheet. * These serialization parameters can be overridden by use of * {@link Serializer#setOutputProperty(Serializer.Property, String)}. * * @param file the output file to which the serializer will write its output. As well as initializing * the serializer to write to this output file, this method sets the base output URI of this * Xslt30Transformer to be the URI of this file. * @since 9.7.0.1 */ public Serializer newSerializer(File file) { Serializer serializer = processor.newSerializer(file); serializer.setOutputProperties(controller.getExecutable().getPrimarySerializationProperties()); setBaseOutputURI(file.toURI().toString()); return serializer; }
/** * 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; } }
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(); }
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 ""; } }
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 ""; } } }
Processor p = new net.sf.saxon.s9api.Processor(); Serializer s = p.newSerializer(); s.setOutputProperty(Property.METHOD, "xml"); s.setOutputProperty(Property.INDENT, "yes"); s.setOutputStream(....); XMLStreamWriter writer = s.getXMLStreamWriter();
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(); }
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); } }
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); } }