本文整理了Java中net.sf.saxon.s9api.Processor.newSerializer()
方法的一些代码示例,展示了Processor.newSerializer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Processor.newSerializer()
方法的具体详情如下:
包路径:net.sf.saxon.s9api.Processor
类名称:Processor
方法名:newSerializer
[英]Create a Serializer
[中]
代码示例来源:origin: epam/Wilma
/**
* Creates new instances of {@link Serializer}.
* @return the new instance
*/
public Serializer createSerializer() {
Processor processor = processorFactory.createProcessor();
Serializer serializer = processor.newSerializer();
return serializer;
}
代码示例来源:origin: epam/Wilma
/**
* 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;
}
}
代码示例来源:origin: org.daisy.pipeline/common-utils
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();
}
代码示例来源:origin: org.daisy.maven/xspec-runner
private Serializer serializeToFile(File file) throws FileNotFoundException {
Serializer serializer = processor.newSerializer();
serializer.setOutputStream(new FileOutputStream(file));
serializer.setCloseOnCompletion(true);
return serializer;
}
代码示例来源:origin: org.daisy.libs/com.xmlcalabash
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;
}
代码示例来源:origin: com.xmlcalabash/xmlcalabash
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;
}
代码示例来源:origin: net.sf.saxon/Saxon-HE
/**
* 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;
}
代码示例来源:origin: net.sf.saxon/Saxon-HE
/**
* 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;
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.saxon
/**
* 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;
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.saxon
/**
* 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;
}
代码示例来源:origin: org.daisy.pipeline/calabash-adapter
/**
* 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;
}
}
代码示例来源:origin: gradle.plugin.com.simonscholz/report-aggregator-gradle
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();
}
代码示例来源:origin: com.xmlcalabash/xmlcalabash
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 "";
}
}
代码示例来源:origin: org.daisy.libs/com.xmlcalabash
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 "";
}
}
代码示例来源:origin: org.daisy.libs/com.xmlcalabash
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 "";
}
}
}
代码示例来源:origin: stackoverflow.com
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();
代码示例来源:origin: gradle.plugin.com.simonscholz/report-aggregator-gradle
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();
}
代码示例来源:origin: org.daisy.libs/com.xmlcalabash
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);
}
}
代码示例来源:origin: com.xmlcalabash/xmlcalabash
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);
}
}
代码示例来源:origin: org.daisy.libs/com.xmlcalabash
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);
}
}
内容来源于网络,如有侵权,请联系作者删除!