@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); } } });
@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(); } } }
/** * 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(); }
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 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(); }
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");
this.processor = new Processor(isLicensedSaxonEdition); this.documentBuilder = processor.newDocumentBuilder(); processor.setConfigurationProperty(entry.getKey(), entry.getValue()); processor.registerExtensionFunction((ExtensionFunction) function);
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()); } }
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) {
proc = new Processor(false); proc.setConfigurationProperty(entry.getKey(), entry.getValue()); XQueryCompiler xqueryCompiler = proc.newXQueryCompiler(); xqueryCompiler.setEncoding(CharEncoding.UTF_8); serializer = proc.newSerializer(baos);
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); } } }
public XPathResolver(boolean autoNodeTextExtraction) { this.autoNodeTextExtraction = autoNodeTextExtraction; this.xpathProcessor = new Processor(false); this.xpath = xpathProcessor.newXPathCompiler(); this.xpath.setCaching(true); }
/** * Construct a TransformerFactory using an existing Configuration. * * @param config the Saxon configuration */ public SaxonTransformerFactory(Configuration config) { processor = new Processor(config); }
public XsltCompiler getXsltCompiler () { return processor.newXsltCompiler(); }
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(); }
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); } }
public XPathCompiler getXPathCompiler () { XPathCompiler xpathCompiler = processor.newXPathCompiler(); xpathCompiler.declareNamespace("lux", FunCall.LUX_NAMESPACE); return xpathCompiler; }
/** * Creates new instances of {@link Serializer}. * @return the new instance */ public Serializer createSerializer() { Processor processor = processorFactory.createProcessor(); Serializer serializer = processor.newSerializer(); return serializer; }
/** * 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(); }
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));