@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 SingleCategoryXacmlAttributesParser<Attributes> getInstance() { // create instance of inner class (has access to this.xmlProc) return new FullXacmlJaxbAttributesParser<>(xacmlReqAttributeParser, namedAttrIterConverter, xmlProc.newDocumentBuilder()); } }
private void loadConfigurationFile(XProcConfiguration conf, InputStream config) { SAXSource source = new SAXSource(new InputSource(config)); DocumentBuilder builder = conf.getProcessor().newDocumentBuilder(); XdmNode doc; try { doc = builder.build(source); } catch (SaxonApiException e) { logger.error("Error loading configuration file", e); throw new RuntimeException("error loading configuration file", e); } conf.parse(doc); }
/** * Set the source document for the transformation. This method is equivalent to building * a document from the supplied source object, and then supplying the document node of * the resulting document as the initial context node. * @param source the principal source document for the transformation */ public void setSource(Source source) throws SaxonApiException { setInitialContextNode(processor.newDocumentBuilder().build(source)); }
/** * Set the source document for the query. This method is equivalent to building * a document from the supplied source object, and then supplying the document node of * the resulting document as the initial context node. * @param source the principal source document for the transformation */ public void setSource(Source source) throws SaxonApiException { setContextItem(processor.newDocumentBuilder().build(source)); }
private XdmNode buildXdmNode(Source s, URI baseURI) throws SaxonApiException { DocumentBuilder builder = processor.newDocumentBuilder(); builder.setBaseURI(baseURI); return builder.build(s); }
/** * @param processor the Saxon processor * @throws LuxException if there is an error creating an XMLStreamWriter */ public SaxonDocBuilder (Processor processor) { builder = processor.newDocumentBuilder(); try { writer = builder.newBuildingStreamWriter(); } catch (SaxonApiException e) { throw new LuxException (e); } }
private XdmNode parse(InputStream instream, URI baseURI) throws SaxonApiException { try { XMLReader reader = XMLReaderFactory.createXMLReader(); reader.setEntityResolver(runtime.getResolver()); SAXSource source = new SAXSource(reader, new InputSource(instream)); DocumentBuilder builder = runtime.getProcessor().newDocumentBuilder(); builder.setLineNumbering(true); builder.setDTDValidation(false); builder.setBaseURI(baseURI); return builder.build(source); } catch (SAXException se) { throw new XProcException(se); } }
private Iterable<XdmItem> getIterableXpathResult(String source, LogicalSource logicalSource) { DocumentBuilder documentBuilder = xpathProcessor.newDocumentBuilder(); StringReader reader = new StringReader(source); setNamespaces(logicalSource); try { XdmNode item = documentBuilder.build(new StreamSource(reader)); XPathSelector selector = xpath.compile(logicalSource.getIterator()).load(); selector.setContextItem(item); return selector; } catch (SaxonApiException e) { throw new RuntimeException(e); } }
private void setTemplate(final InputStream templateInputStream, final Processor processor, final XMLReader xmlReader, final XsltTransformer xsltTransformer) throws SaxonApiException { InputSource inputSource = inputSourceFactory.createInputSource(templateInputStream); Source templateSource = saxSourceFactory.createSAXSource(xmlReader, inputSource); XdmNode templateNode = processor.newDocumentBuilder().build(templateSource); xsltTransformer.setInitialContextNode(templateNode); }
@BeforeClass public static void setupClass() throws Exception { String xml = "<document><?foo?><p>A paragraph</p> <p>A paragraph</p> some text "; xml += "<p>Another paragraph</p><!--comment-->"; xml += "<documentation xmlns='http://www.w3.org/ns/xproc'>some doc</documentation></document>"; DocumentBuilder builder = processor.newDocumentBuilder(); root = S9apiUtils.getDocumentElement(builder.build(new SAXSource(new InputSource(new StringReader(xml))))); }
private void setParameter(final InputStream parameterInputStream, final Processor processor, final XsltTransformer xsltTransformer, final String parameterName) throws SaxonApiException { StreamSource requestStreamSource = streamSourceFactory.createStreamSource(parameterInputStream); XdmNode requestDocument = processor.newDocumentBuilder().build(requestStreamSource); QName parameter = qNameFactory.createQName(parameterName); xsltTransformer.setParameter(parameter, requestDocument); }
private void setRequest(final InputStream requestInputStream, final Processor processor, final XsltTransformer xsltTransformer) throws SaxonApiException { StreamSource requestStreamSource = streamSourceFactory.createStreamSource(requestInputStream); XdmNode requestDocument = processor.newDocumentBuilder().build(requestStreamSource); QName requestName = qNameFactory.createQName(REQUEST_PARAMETER_NAME); xsltTransformer.setParameter(requestName, requestDocument); }
private void setTemplate(final InputStream templateInputStream, final Processor processor, final XMLReader xmlReader, final XsltTransformer xsltTransformer) throws SaxonApiException { InputSource inputSource = inputSourceFactory.createInputSource(templateInputStream); Source templateSource = saxSourceFactory.createSAXSource(xmlReader, inputSource); XdmNode templateNode = processor.newDocumentBuilder().build(templateSource); xsltTransformer.setInitialContextNode(templateNode); }
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 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()); } }
private void givenParameter(final String parameterName, final QName qName) throws SaxonApiException { given(streamSourceFactory.createStreamSource(requestInputStream)).willReturn(new StreamSource()); given(processor.newDocumentBuilder().build(any(StreamSource.class))).willReturn(requestDocument); given(qNameFactory.createQName(parameterName)).willReturn(qName); }
private void setTemplateMocks() throws SaxonApiException { given(inputSourceFactory.createInputSource(templateInputStream)).willReturn(inputSource); given(saxSourceFactory.createSAXSource(xmlReader, inputSource)).willReturn(templateSource); given(processor.newDocumentBuilder().build(templateSource)).willReturn(templateNode); } }
private void setTemplateMocks() throws SaxonApiException { given(inputSourceFactory.createInputSource(templateInputStream)).willReturn(inputSource); given(saxSourceFactory.createSAXSource(xmlReader, inputSource)).willReturn(templateSource); given(processor.newDocumentBuilder().build(templateSource)).willReturn(templateNode); } }
private void setRequestMocks() throws SaxonApiException { given(streamSourceFactory.createStreamSource(requestInputStream)).willReturn(requestStreamResource); given(processor.newDocumentBuilder().build(requestStreamResource)).willReturn(requestDocument); given(qNameFactory.createQName("request")).willReturn(requestName); }