/** 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; }
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; }
@Override public Destination getPrimaryDestination(MapItem serializationParamsMap) throws XPathException { Serializer serializer = makeSerializer(serializationParamsMap); primaryWriter = new StringWriter(); serializer.setOutputWriter(primaryWriter); return serializer; }
/** * Create a Serializer initialized to write to a given File. * * @param file The File to which the Serializer will write * @return a new Serializer * @since 9.3 */ /*@NotNull*/ public Serializer newSerializer(File file) { Serializer s = new Serializer(this); s.setOutputFile(file); return s; }
/** * Create a Serializer initialized to write to a given OutputStream. * <p>Closing the output stream after use is the responsibility of the caller.</p> * * @param stream The OutputStream to which the Serializer will write * @return a new Serializer * @since 9.3 */ /*@NotNull*/ public Serializer newSerializer(OutputStream stream) { Serializer s = new Serializer(this); s.setOutputStream(stream); return s; }
/** * Create a Serializer initialized to write to a given Writer. * <p>Closing the writer after use is the responsibility of the caller.</p> * * @param writer The Writer to which the Serializer will write * @return a new Serializer * @since 9.3 */ /*@NotNull*/ public Serializer newSerializer(Writer writer) { Serializer s = new Serializer(this); s.setOutputWriter(writer); return s; }
/** * Transforms a standard SVRL report to a plain text representation that * only includes rule violations (positive or negative assertion failures). * * @param svrlSource * The source for reading the SVRL report. * @return A StreamResult holding the plain text output (as a byte stream), * or null if the transformation failed. */ StreamResult generateTextResult(Source svrlSource) { XsltCompiler compiler = processor.newXsltCompiler(); StreamResult result = null; try { XsltExecutable exec = compiler.compile(new StreamSource(getClass().getResourceAsStream("svrl2text.xsl"))); XsltTransformer transformer = exec.load(); transformer.setSource(svrlSource); Serializer serializer = new Serializer(); serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); serializer.setOutputStream(bos); transformer.setDestination(serializer); transformer.transform(); result = new StreamResult(bos); } catch (SaxonApiException e) { LOGR.warning(e.getMessage()); } return result; }
/** * Set the output method (the default is xml). * @param method */ public void setOutputMethod(String method) { serializer.setOutputProperty(Serializer.Property.METHOD, method); }
public void store(OutputStream ostream) throws IOException { logger.trace("Attempt to write file: " + uri); serializer.setOutputStream(ostream); try { S9apiUtils.serialize(runtime, doc, serializer); } catch (SaxonApiException e) { throw new IOException(e); } } });
serializer.setOutputStream(baos); serializer.setOutputProperty(Serializer.Property.METHOD, "xml"); serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION,"yes"); serializer.setProcessor(proc);
getTestServletURL())); StringWriter sw = new StringWriter(); Serializer serializer = new Serializer(); serializer.setOutputWriter(sw); serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes"); formTransformer.setDestination(serializer);
CharacterMapIndex charMapIndex = new CharacterMapIndex(); charMapIndex.putCharacterMap(charMap.getName(), charMap); serializer.setCharacterMap(charMapIndex); String existing = serializer.getOutputProperty(Serializer.Property.USE_CHARACTER_MAPS); if (existing == null) { serializer.setOutputProperty(Serializer.Property.USE_CHARACTER_MAPS, charMap.getName().getClarkName()); } else { serializer.setOutputProperty(Serializer.Property.USE_CHARACTER_MAPS, existing + " " + charMap.getName().getClarkName()); Serializer.Property prop = Serializer.getProperty(paramName); if (paramName.getClarkName().equals(OutputKeys.CDATA_SECTION_ELEMENTS) || paramName.getClarkName().equals(SaxonOutputKeys.SUPPRESS_INDENTATION)) { String existing = serializer.getOutputProperty(paramName); if (existing == null) { serializer.setOutputProperty(prop, paramValue); } else { serializer.setOutputProperty(prop, existing + paramValue); serializer.setOutputProperty(prop, paramValue);
if (xproc.getHtmlSerializer() && "html".equals(serializer.getOutputProperty(Serializer.Property.METHOD))) { ContentHandler ch = null; Object outputDest = serializer.getOutputDestination(); xqeval.run(); serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes");
if (serializer.getOutputProperty(Serializer.Property.METHOD) == null) { serializer.setOutputProperty(Serializer.Property.METHOD, "xml");
((Serializer) destination).setCloseOnCompletion(true); } else { throw new IllegalArgumentException("StreamResult supplies neither an OutputStream nor a Writer"); QName propertyName = QName.fromClarkName(key); if (!(propertyName.getNamespaceURI().equals(NamespaceConstant.SAXON) && propertyName.getLocalName().equals("next-in-chain"))) { ((Serializer) destination).setOutputProperty(QName.fromClarkName(key), localOutputProperties.getProperty(key));
serializer.setOutputStream(s); serializer.setCloseOnCompletion(true); serializer.serializeNode(source.read()); serializer.close(); InputStream obflStream = new ByteArrayInputStream(s.toByteArray()); s.close();
if (result instanceof StreamResult) { StreamResult streamResult = (StreamResult) result; serializer.setOutputStream(streamResult.getOutputStream()); } else { URI uri = null; serializer.setOutputFile(new File(uri)); } else { URL url; final URLConnection conn = url.openConnection(); conn.setDoOutput(true); serializer.setOutputStream(conn.getOutputStream()); } catch (MalformedURLException e) { throw new RuntimeException(String.format("Malformed url while writing results: %s",uri),e); serializer.serializeNode(rpipe.read()); } catch (SaxonApiException e) { throw new RuntimeException("Error caught when writing results",e);
private List<File> convertFiles(List<File> filesToLoad) throws ServletException { List<File> rdfxmlFiles = new ArrayList<File>(filesToLoad.size()); for( File file: filesToLoad){ try { //look for an example of this in S9APIExamples.java from saxon he 9 XsltTransformer t = xsltExec.load(); //this is how to set parameters: //t.setParameter(new QName("someparametername"), new XdmAtomicValue(10)); Serializer out = new Processor(false).newSerializer(); out.setOutputProperty(Serializer.Property.METHOD, "xml"); out.setOutputProperty(Serializer.Property.INDENT, "yes"); File outFile = new File(file.getAbsolutePath() + ".rdfxml"); rdfxmlFiles.add(outFile); out.setOutputFile(outFile); t.setSource(new StreamSource(file)); t.setDestination(out); t.transform(); } catch (SaxonApiException e) { log.error("could not convert " + file.getAbsolutePath() + " to RDF/XML: " + e.getMessage()); throw new ServletException("could not convert " + file.getAbsolutePath() + " to RDF/XML: " + e.getMessage()); } } return rdfxmlFiles; }
Processor p = new Processor(); Serializer s = p.newSerializer(System.out); s.setOutputProperty(Property.INDENT, "yes"); XMLStreamWriter w = s.getXMLStreamWriter();
private Serializer serializeToFile(File file) throws FileNotFoundException { Serializer serializer = processor.newSerializer(); serializer.setOutputStream(new FileOutputStream(file)); serializer.setCloseOnCompletion(true); return serializer; }