本文整理汇总了Java中net.sf.saxon.s9api.XsltExecutable类的典型用法代码示例。如果您正苦于以下问题:Java XsltExecutable类的具体用法?Java XsltExecutable怎么用?Java XsltExecutable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XsltExecutable类属于net.sf.saxon.s9api包,在下文中一共展示了XsltExecutable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setCustomParameters
import net.sf.saxon.s9api.XsltExecutable; //导入依赖的package包/类
private void setCustomParameters(XsltTransformer xsltTransformer) throws XPathException {
//logger.info("setCustomParameters()");
final URL scriptUrl = getScriptUrl();
final XsltExecutable xsltExecutable = xsltConrefCache.getTransformerCache().getExecutable(scriptUrl, xsltConrefCache.getUriResolver());
final List<String> attrNameList = node.getAttributeNamesOfNamespace(NAMESPACE_PARAMETER_URI);
for (String attrName : attrNameList) {
//logger.info("attribute: " + attrName);
final QName paramName = new QName(attrName.replaceAll("(^[^\\{\\}]*:)|(^\\{.*\\})", ""));
final String paramValue = node.getAttribute(attrName, NAMESPACE_PARAMETER_URI);
//logger.info("set custom parameter: " + paramName + " = '" + paramValue + "'");
if (paramValue != null) {
if (xsltExecutable.getGlobalParameters().containsKey(paramName)) {
try {
xsltTransformer.setParameter(paramName, new XdmAtomicValue(EmbeddedXPathResolver.resolve(paramValue, node), ItemType.UNTYPED_ATOMIC));
//logger.info("parameters set. ");
} catch (SaxonApiException e) {
logger.error(e, e);
}
} else {
//logger.error("Parameter '" + paramName + "' not defined in script.");
}
}
}
}
示例2: extractString
import net.sf.saxon.s9api.XsltExecutable; //导入依赖的package包/类
private String extractString(SaxonNodeWrapper node, String xslUrl) {
try {
final XsltExecutable executable = bookCache.getExtractTransformerCache().getExecutable(new URL(bookCache.getDitaOtUrl(), xslUrl));
final XsltTransformer xsltTransformer = executable.load();
xsltTransformer.setInitialContextNode(new XdmNode(node.getNodeInfo()));
final XdmDestination destination = new XdmDestination();
xsltTransformer.setDestination(destination);
xsltTransformer.transform();
return destination.getXdmNode().getStringValue();
} catch (Exception e) {
logger.error(e, e);
return "<ERR>";
}
}
示例3: tryXsltExecutableCache
import net.sf.saxon.s9api.XsltExecutable; //导入依赖的package包/类
public XsltExecutable tryXsltExecutableCache(String transformationPath,
ErrorListener errorListener, boolean tracing) throws Exception {
String key = FilenameUtils.normalize(transformationPath);
XsltExecutable xsltExecutable = xsltExecutableCache.get(key);
if (xsltExecutable == null) {
logger.info("Compiling and caching XSLT stylesheet \"" + transformationPath + "\" ...");
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setXIncludeAware(true);
spf.setValidating(false);
SAXParser parser = spf.newSAXParser();
XMLReader reader = parser.getXMLReader();
Source source = new SAXSource(reader, new InputSource(transformationPath));
XsltCompiler comp = processor.newXsltCompiler();
comp.setCompileWithTracing(tracing);
comp.setErrorListener(errorListener);
xsltExecutable = comp.compile(source);
} catch (Exception e) {
logger.error("Could not compile XSLT stylesheet \"" + transformationPath + "\"", e);
throw e;
}
if (!developmentMode) {
xsltExecutableCache.put(key, xsltExecutable);
}
}
return xsltExecutable;
}
示例4: compileXsl
import net.sf.saxon.s9api.XsltExecutable; //导入依赖的package包/类
/**
* Compiles an xsl file.
* @param inputStream the xsl file as {@link InputStream}
* @param processor the {@link Processor} that provides the compiler
* @return an {@link XsltExecutable} that will be used further in the xsl transformation process
* @throws SaxonApiException it is thrown if an exception occurs during the compilation
*/
public XsltExecutable compileXsl(final InputStream inputStream, final Processor processor) throws SaxonApiException {
XsltCompiler xsltCompiler = processor.newXsltCompiler();
Source xslSource = streamSourceFactory.createStreamSource(inputStream);
xsltCompiler.setErrorListener(errorListener);
XsltExecutable xsltExecutable = xsltCompiler.compile(xslSource);
return xsltExecutable;
}
示例5: transform
import net.sf.saxon.s9api.XsltExecutable; //导入依赖的package包/类
/**
* Transforms an inputstream based on a template and an xsl.
* @param xslInputStream the xsl as an {@link InputStream}
* @param requestInputStream the request as an {@link InputStream}
* @param templateInputStream the template as an {@link InputStream}
* @param nameToXml the names identifying a request or response and their bodies
* @return the result of the transformation
* @throws SaxonApiException it is thrown if an exception occurs during the xsl transformation
* @throws SAXException it is thrown if an exception occurs during the xsl transformation
*/
public byte[] transform(final InputStream xslInputStream, final InputStream requestInputStream, final InputStream templateInputStream,
final Map<String, String> nameToXml) throws SaxonApiException, SAXException {
Processor processor = processorFactory.createProcessor();
XMLReader xmlReader = createXMLReader();
//xsl compilation
XsltExecutable xsltExecutable = xslCompiler.compileXsl(xslInputStream, processor);
XsltTransformer xsltTransformer = xsltExecutable.load();
//set the output
ByteArrayOutputStream output = xslOutputProvider.getOutput(xsltTransformer);
//set the request
setRequest(requestInputStream, processor, xsltTransformer);
setSessionEntities(nameToXml, processor, xsltTransformer);
//set the template
setTemplate(templateInputStream, processor, xmlReader, xsltTransformer);
xsltTransformer.transform();
return output.toByteArray();
}
示例6: newValidator
import net.sf.saxon.s9api.XsltExecutable; //导入依赖的package包/类
/**
* Compiles the (Schematron-derived) XSLT stylesheet that implements additional validation checks.
*/
private XsltExecutable newValidator(String validatorPath) {
// This method should only be called once in the constructor, and the
// stylesheet is only compiled once, so we
// don't cache any of these objects like we normally would.
final URL resource = getClass().getResource(validatorPath);
if (resource == null) {
throw new RuntimeException("Deployment error: can't find additional TAXII validator (" + validatorPath + ")");
}
try {
final boolean useLicensedEdition = false;
return new Processor(useLicensedEdition).newXsltCompiler()
.compile(new StreamSource(resource.toString()));
}
catch (SaxonApiException e) {
throw new RuntimeException("Deployment error: The validator stylesheet contains static errors or it cannot be read. See the standard error output for details.",
e);
}
}
示例7: getExecutable
import net.sf.saxon.s9api.XsltExecutable; //导入依赖的package包/类
public XsltExecutable getExecutable() {
return executable;
}
示例8: getCachedExecutable
import net.sf.saxon.s9api.XsltExecutable; //导入依赖的package包/类
/**
* Returns an existing XsltExecutable for the specified URL.
* Does not create a new one if there is no existing XsltExecutable.
*
* @param url URL of the XSLT script
* @return the XsltExecutable for this URL or null if there is none.
*/
public XsltExecutable getCachedExecutable(URL url) {
final ExecutableWithTimestamp exWithTime = executableMap.get(url);
if (exWithTime != null) {
// logger.info("getCachedExecutable: " + exWithTime.getXsltExecutable() + ", url: " + url);
return exWithTime.getXsltExecutable();
} else {
// logger.info("getCachedExecutable: " + null + ", url: " + url);
return null;
}
}
示例9: isXslParameterUndefined
import net.sf.saxon.s9api.XsltExecutable; //导入依赖的package包/类
/**
* Checks whether the specified script expects the specified parameter.
*
* @param scriptUrl URL of the script
* @param paramName Name of the parameter
* @return true if the parameter is defined, false if it is undefined or if the script is invalid.
*/
public static boolean isXslParameterUndefined(URL scriptUrl, String paramName) {
//logger.info("isXslParameterUndefined(" + scriptUrl + ", " + paramName + ")");
final XsltExecutable xsltExecutable = XsltConrefResolver.getInstance().getTransformerCache().getCachedExecutable(scriptUrl);
final QName paramQName = new QName(paramName);
//logger.info(xsltExecutable);
if ((xsltExecutable != null) && (!xsltExecutable.getGlobalParameters().containsKey(paramQName))) {
return true;
} else {
return false;
}
}
示例10: getOutputProperties
import net.sf.saxon.s9api.XsltExecutable; //导入依赖的package包/类
private Properties getOutputProperties(WebApp webApp, ErrorListener errorListener, List<PipelineStep> steps) throws Exception {
for (int i=steps.size()-1; i>=0; i--) {
PipelineStep step = steps.get(i);
if (step instanceof TransformerStep) {
String xslPath = ((TransformerStep) step).getXslPath();
XsltExecutable executable = webApp.getXsltExecutable(xslPath, errorListener, false);
return executable.getUnderlyingCompiledStylesheet().getOutputProperties();
}
}
return null;
}
示例11: trySchematronCache
import net.sf.saxon.s9api.XsltExecutable; //导入依赖的package包/类
public XsltExecutable trySchematronCache(String schematronPath, String phase,
ErrorListener errorListener) throws Exception {
String key = FilenameUtils.normalize(schematronPath) + (phase != null ? phase : "");
XsltExecutable templates = xsltExecutableCache.get(key);
if (templates == null) {
logger.info("Compiling and caching schematron schema \"" + schematronPath + "\" ...");
try {
Source source = new StreamSource(new File(schematronPath));
File schematronDir = new File(Context.getInstance().getHomeDir(), "common/xsl/system/schematron");
ErrorListener listener = new TransformationErrorListener(null, developmentMode);
MessageWarner messageWarner = new MessageWarner();
Xslt30Transformer stage1 = tryXsltExecutableCache(new File(schematronDir, "iso_dsdl_include.xsl").getAbsolutePath(), errorListener, false).load30();
stage1.setErrorListener(listener);
stage1.getUnderlyingController().setMessageEmitter(messageWarner);
Xslt30Transformer stage2 = tryXsltExecutableCache(new File(schematronDir, "iso_abstract_expand.xsl").getAbsolutePath(), errorListener, false).load30();
stage2.setErrorListener(listener);
stage2.getUnderlyingController().setMessageEmitter(messageWarner);
Xslt30Transformer stage3 = tryXsltExecutableCache(new File(schematronDir, "iso_svrl_for_xslt2.xsl").getAbsolutePath(), errorListener, false).load30();
stage3.setErrorListener(listener);
stage3.getUnderlyingController().setMessageEmitter(messageWarner);
XdmDestination destStage1 = new XdmDestination();
XdmDestination destStage2 = new XdmDestination();
XdmDestination destStage3 = new XdmDestination();
stage1.applyTemplates(source, destStage1);
stage2.applyTemplates(destStage1.getXdmNode().asSource(), destStage2);
stage3.applyTemplates(destStage2.getXdmNode().asSource(), destStage3);
Source generatedXsltSource = destStage3.getXdmNode().asSource();
if (this.developmentMode) {
TransformerFactory factory = new TransformerFactoryImpl();
Transformer transformer = factory.newTransformer();
Properties props = new Properties();
props.put(OutputKeys.INDENT, "yes");
transformer.setOutputProperties(props);
StringWriter sw = new StringWriter();
transformer.transform(generatedXsltSource, new StreamResult(sw));
logger.info("Generated Schematron XSLT for \"" + schematronPath + "\", phase \"" + (phase != null ? phase : "") + "\" [" + sw.toString() + "]");
}
XsltCompiler comp = processor.newXsltCompiler();
comp.setErrorListener(errorListener);
templates = comp.compile(generatedXsltSource);
} catch (Exception e) {
logger.error("Could not compile schematron schema \"" + schematronPath + "\"", e);
throw e;
}
if (!developmentMode) {
xsltExecutableCache.put(key, templates);
}
}
return templates;
}
示例12: getStyleSheet
import net.sf.saxon.s9api.XsltExecutable; //导入依赖的package包/类
@Override
public PreparedStylesheet getStyleSheet() throws XPathException {
try {
if (this.stylesheet == null) {
XsltExecutable executable = webApp.tryXsltExecutableCache(
new File(Context.getInstance().getHomeDir(), "common/xsl/system/trace/timing.xsl").getAbsolutePath(), null, false);
this.stylesheet = executable.getUnderlyingCompiledStylesheet();
}
return this.stylesheet;
} catch (Exception e) {
throw new XPathException(e);
}
}
示例13: transform
import net.sf.saxon.s9api.XsltExecutable; //导入依赖的package包/类
/**
* Transforms an inputstream based on a template and an xsl.
* @param xslInputStream the xsl as an {@link InputStream}
* @param requestInputStream the request as an {@link InputStream}
* @param templateInputStream the template as an {@link InputStream}
* @return the result of the transformation
* @throws SaxonApiException it is thrown if an exception occurs during the xsl transformation
* @throws SAXException it is thrown if an exception occurs during the xsl transformation
*/
public byte[] transform(final InputStream xslInputStream, final InputStream requestInputStream, final InputStream templateInputStream)
throws SaxonApiException, SAXException {
Processor processor = processorFactory.createProcessor();
XMLReader xmlReader = createXMLReader();
//xsl compilation
XsltExecutable xsltExecutable = xslCompiler.compileXsl(xslInputStream, processor);
XsltTransformer xsltTransformer = xsltExecutable.load();
//set the output
ByteArrayOutputStream output = xslOutputProvider.getOutput(xsltTransformer);
//set the request
setRequest(requestInputStream, processor, xsltTransformer);
//set the template
setTemplate(templateInputStream, processor, xmlReader, xsltTransformer);
xsltTransformer.transform();
return output.toByteArray();
}
示例14: testCompileXslShouldReturnXsltExecutable
import net.sf.saxon.s9api.XsltExecutable; //导入依赖的package包/类
@Test
public void testCompileXslShouldReturnXsltExecutable() throws SaxonApiException {
//GIVEN
given(processor.newXsltCompiler()).willReturn(xsltCompiler);
given(streamSourceFactory.createStreamSource(inputStream)).willReturn(source);
given(xsltCompiler.compile(source)).willReturn(xsltExecutable);
//WHEN
XsltExecutable actual = underTest.compileXsl(inputStream, processor);
//THEN
assertEquals(actual, xsltExecutable);
}
示例15: transform
import net.sf.saxon.s9api.XsltExecutable; //导入依赖的package包/类
/**
* Transforms the content of a DOM Node using a specified XSLT stylesheet.
*
* @param xslt
* A Source object representing a stylesheet (XSLT 1.0 or 2.0).
* @param source
* A Node representing the XML source. If it is an Element node
* it will be imported into a new DOM Document.
* @return A DOM Document containing the result of the transformation.
*/
public static Document transform(Source xslt, Node source) {
Document sourceDoc = null;
Document resultDoc = null;
try {
resultDoc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().newDocument();
if (source.getNodeType() == Node.DOCUMENT_NODE) {
sourceDoc = (Document) source;
} else {
sourceDoc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().newDocument();
sourceDoc.appendChild(sourceDoc.importNode(source, true));
}
} catch (ParserConfigurationException pce) {
throw new RuntimeException(pce);
}
Processor processor = new Processor(false);
XsltCompiler compiler = processor.newXsltCompiler();
try {
XsltExecutable exec = compiler.compile(xslt);
XsltTransformer transformer = exec.load();
transformer.setSource(new DOMSource(sourceDoc));
transformer.setDestination(new DOMDestination(resultDoc));
transformer.transform();
} catch (SaxonApiException e) {
throw new RuntimeException(e);
}
return resultDoc;
}