net.sf.saxon.s9api.Processor类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(219)

本文整理了Java中net.sf.saxon.s9api.Processor类的一些代码示例,展示了Processor类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Processor类的具体详情如下:
包路径:net.sf.saxon.s9api.Processor
类名称:Processor

Processor介绍

[英]The Processor class serves three purposes: it allows global Saxon configuration options to be set; it acts as a factory for generating XQuery, XPath, and XSLT compilers; and it owns certain shared resources such as the Saxon NamePool and compiled schemas. This is the first object that a Saxon application should create. Once established, a Processor may be used in multiple threads.

It is possible to run more than one Saxon Processor concurrently, but only when running completely independent workloads. Nothing can be shared between Processor instances. Within a query or transformation, all source documents and schemas must be built using the same Processor, which must also be used to compile the query or stylesheet.
[中]Processor类有三个用途:它允许设置全局Saxon配置选项;它充当生成XQuery、XPath和XSLT编译器的工厂;它还拥有某些共享资源,比如Saxon名称池和编译模式。这是Saxon应用程序应该创建的第一个对象。一旦建立,一个处理器可以在多个线程中使用。
可以同时运行多个Saxon处理器,但只有在运行完全独立的工作负载时。处理器实例之间不能共享任何内容。在查询或转换中,所有源文档和模式都必须使用同一处理器构建,该处理器还必须用于编译查询或样式表。

代码示例

代码示例来源:origin: apache/nifi

@Override
  public void process(final InputStream rawIn) throws IOException {
    try (final InputStream in = new BufferedInputStream(rawIn)) {
      XQueryEvaluator qe = slashExpression.load();
      qe.setSource(new SAXSource(xmlReader, new InputSource(in)));
      DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
      dfactory.setNamespaceAware(true);
      Document dom = dfactory.newDocumentBuilder().newDocument();
      qe.run(new DOMDestination(dom));
      XdmNode rootNode = proc.newDocumentBuilder().wrap(dom);
      sourceRef.set(rootNode);
    } catch (final Exception e) {
      error.set(e);
    }
  }
});

代码示例来源:origin: apache/nifi

@Override
  public ValidationResult validate(final String subject, final String input, final ValidationContext validationContext) {
    try {
      final Processor proc = new Processor(false);
      final XQueryCompiler comp = proc.newXQueryCompiler();
      String error = null;
      try {
        comp.compile(input);
      } catch (final Exception e) {
        error = e.toString();
      }
      return new ValidationResult.Builder().input(input).subject(subject).valid(error == null).explanation(error).build();
    } catch (final Exception e) {
      return new ValidationResult.Builder().input(input).subject(subject).valid(false)
          .explanation("Unable to initialize XQuery engine due to " + e.toString()).build();
    }
  }
}

代码示例来源:origin: net.sf.saxon/Saxon-HE

/**
 * Get the configuration. This can also be done using the JAXP method
 * getAttribute, with the attribute name {@link net.sf.saxon.lib.FeatureKeys#CONFIGURATION}
 * This is a trapdoor method that provides access to underlying implementation details that
 * may change in subsequent Saxon releases.
 * @return the Saxon configuration
 */
public Configuration getConfiguration() {
  return processor.getUnderlyingConfiguration();
}

代码示例来源: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: org.opengis.cite.teamengine/teamengine-core

public Engine() throws Exception {
  String s = System.getProperty("te.cacheSize");
  if (s != null) {
    cacheSize = Integer.parseInt(s);
  }
  // Create processor
  processor = new Processor(false);
  // Modify its configuration settings
  Configuration config = processor.getUnderlyingConfiguration();
  config.setVersionWarning(false);
  // Use our custom error listener which reports line numbers in the CTL
  // source file
  errorListener = new TeErrorListener();
  config.setErrorListener(errorListener);
  // Create a compiler and document builder
  compiler = processor.newXsltCompiler();
  builder = processor.newDocumentBuilder();
  // Load an executable for the TECore.form method
  ClassLoader cl = Thread.currentThread().getContextClassLoader();
  InputStream is = cl.getResourceAsStream("com/occamlab/te/formfn.xsl");
  formExecutable = compiler.compile(new StreamSource(is));
  // Fortify Mod: We are done with the InputStream.  Release the resource
  is.close();
}

代码示例来源:origin: elsevierlabs-os/spark-xml-utils

proc = new Processor(false);
    proc.setConfigurationProperty(entry.getKey(), entry.getValue());
XPathCompiler xpathCompiler = proc.newXPathCompiler();
builder = proc.newDocumentBuilder();
serializer = proc.newSerializer(baos);
serializer.setOutputStream(baos);
serializer.setOutputProperty(Serializer.Property.METHOD, "xml");

代码示例来源:origin: kite-sdk/kite

this.processor = new Processor(isLicensedSaxonEdition);
this.documentBuilder = processor.newDocumentBuilder();
 processor.setConfigurationProperty(entry.getKey(), entry.getValue());
  processor.registerExtensionFunction((ExtensionFunction) function);

代码示例来源:origin: com.cloudera.cdk/cdk-morphlines-saxon

public SaxonCommand(CommandBuilder builder, Config config, Command parent, Command child, MorphlineContext context) {
 super(builder, config, parent, child, context);
 
 this.isTracing = getConfigs().getBoolean(config, "isTracing", false);
 boolean isLicensedSaxonEdition = getConfigs().getBoolean(config, "isLicensedSaxonEdition", false);
 this.processor = new Processor(isLicensedSaxonEdition);
 this.documentBuilder = processor.newDocumentBuilder();
 
 Config features = getConfigs().getConfig(config, "features", ConfigFactory.empty());
 for (Map.Entry<String, Object> entry : new Configs().getEntrySet(features)) {
  processor.setConfigurationProperty(entry.getKey(), entry.getValue());
 }
}

代码示例来源:origin: org.daisy.libs/com.xmlcalabash

Processor processor = runtime.getProcessor();
String sed = processor.getUnderlyingConfiguration().getEditionCode();
if (!"EE".equals(sed)) {
  throw new XProcException("Importing functions is only supported by Saxon EE.");
    XsltCompiler compiler = processor.newXsltCompiler();
    XsltExecutable exec = compiler.compile(stylesheet);
    PreparedStylesheet ps = exec.getUnderlyingCompiledStylesheet();
    fl = ps.getFunctionLibrary();
  } else {
    XQueryCompiler xqcomp = processor.newXQueryCompiler();
    StaticQueryContext sqc = xqcomp.getUnderlyingStaticContext();
    sqc.compileLibrary(connection.getInputStream(), "utf-8");
  Class<?> fc = Class.forName("net.sf.saxon.functions.FunctionLibrary");
  Method setBinder = pc.getMethod("setExtensionBinder", String.class, fc);
  setBinder.invoke(processor.getUnderlyingConfiguration(), "xmlcalabash" + importCount, fl);
  importCount++;
} catch (Exception e) {

代码示例来源:origin: elsevierlabs-os/spark-xml-utils

proc = new Processor(false);
    proc.setConfigurationProperty(entry.getKey(), entry.getValue());
XQueryCompiler xqueryCompiler = proc.newXQueryCompiler();
xqueryCompiler.setEncoding(CharEncoding.UTF_8);
serializer = proc.newSerializer(baos);

代码示例来源:origin: org.daisy.pipeline/common-utils

private void initCompiler(Configuration config) {
    this.xsltCompiler = new Processor(config).newXsltCompiler();
    if (this.uriResolver != null) {
      //this resolver is used for xsl:include and xsl:import
      this.xsltCompiler.setURIResolver(this.uriResolver);
    }
  }
}

代码示例来源:origin: com.taxonic.carml/carml-logical-source-resolver-xpath

public XPathResolver(boolean autoNodeTextExtraction) {
  this.autoNodeTextExtraction = autoNodeTextExtraction;
  this.xpathProcessor = new Processor(false);
  this.xpath = xpathProcessor.newXPathCompiler();
  this.xpath.setCaching(true);
}

代码示例来源:origin: net.sf.saxon/Saxon-HE

/**
 * Construct a TransformerFactory using an existing Configuration.
 *
 * @param config the Saxon configuration
 */
public SaxonTransformerFactory(Configuration config) {
  processor = new Processor(config);
}

代码示例来源:origin: msokolov/lux

public XsltCompiler getXsltCompiler () {
  return processor.newXsltCompiler();
}

代码示例来源:origin: ndw/xmlcalabash1

public void run() throws SaxonApiException {
  Processor saxon = new Processor(false);
  XProcConfiguration config = new XProcConfiguration(saxon);
  XProcRuntime runtime = new XProcRuntime(config);
  InputStream stream = new ByteArrayInputStream(pipeline_xml.getBytes());
  DocumentBuilder builder = saxon.newDocumentBuilder();
  XdmNode pipeline_doc = builder.build(new SAXSource(new InputSource(stream)));
  XPipeline pipeline = runtime.use(pipeline_doc);
  pipeline.run();
}

代码示例来源: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: msokolov/lux

public XPathCompiler getXPathCompiler () {
  XPathCompiler xpathCompiler = processor.newXPathCompiler();
  xpathCompiler.declareNamespace("lux", FunCall.LUX_NAMESPACE);
  return xpathCompiler;
}

代码示例来源: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: org.opengis.cite/schema-utils

/**
 * Constructs a validator for the given Schematron schema and phase (pattern
 * set).
 *
 * @param schema
 *            The Source that represents the schema.
 * @param phase
 *            The active phase; if null, the default phase is enabled (all
 *            patterns are active if no default is specified).
 * @throws Exception
 *             If any error occurs while attempting to read or preprocess
 *             the schema.
 */
public SchematronValidator(Source schema, String phase) throws Exception {
  if (schema == null) {
    throw new IllegalArgumentException("No schema Source provided.");
  }
  processor = new Processor(false);
  processor.setConfigurationProperty(FeatureKeys.RECOVERY_POLICY, Configuration.RECOVER_SILENTLY);
  XsltExecutable xslt = compileSchema(schema, phase);
  this.transformer = xslt.load();
}

代码示例来源:origin: com.xmlcalabash/xmlcalabash

public static void serialize(XProcRuntime xproc, Vector<XdmNode> nodes, Serializer serializer) throws SaxonApiException {
  Processor qtproc = xproc.getProcessor();
  XQueryCompiler xqcomp = qtproc.newXQueryCompiler();
  xqcomp.setModuleURIResolver(xproc.getResolver());
      xqcomp.getProcessor().getUnderlyingConfiguration().isLicensedFeature(
          Configuration.LicenseFeature.ENTERPRISE_XQUERY));

相关文章