Search in sources :

Example 1 with Receiver

use of net.sf.saxon.event.Receiver in project intellij-community by JetBrains.

the class Saxon9Support method init.

public static boolean init(Transformer transformer, final LocalDebugger dbg) {
    if (transformer instanceof Controller) {
        System.out.println("SAXON 9");
        final Controller controller = (Controller) transformer;
        ((Saxon9TraceListener) controller.getConfiguration().getTraceListener()).setDebugger(dbg);
        controller.getConfiguration().setLineNumbering(true);
        controller.getConfiguration().setCompileWithTracing(true);
        controller.getConfiguration().setMultiThreading(false);
        controller.getConfiguration().setSerializerFactory(new SerializerFactory(controller.getConfiguration()) {

            @Override
            protected Receiver createXMLSerializer(Emitter emitter, Properties props, PipelineConfiguration pipe, CharacterMapExpander characterMapExpander, ProxyReceiver normalizer) throws XPathException {
                return super.createXMLSerializer(emitter, props, pipe, characterMapExpander, normalizer);
            }

            @Override
            protected Emitter newXMLEmitter() {
                return new TracingOutputter(dbg.getEventQueue(), super.newXMLEmitter());
            }
        });
        controller.getConfiguration().setDebugger(new Debugger() {

            public SlotManager makeSlotManager() {
                return new SlotManager() {

                    @Override
                    public int allocateSlotNumber(StructuredQName qName) {
                        System.out.println("qName = " + qName);
                        return super.allocateSlotNumber(qName);
                    }
                };
            }
        });
        return true;
    }
    return false;
}
Also used : Debugger(net.sf.saxon.expr.instruct.Debugger) LocalDebugger(org.intellij.plugins.xsltDebugger.rt.engine.local.LocalDebugger) SerializerFactory(net.sf.saxon.lib.SerializerFactory) Emitter(net.sf.saxon.serialize.Emitter) CharacterMapExpander(net.sf.saxon.serialize.CharacterMapExpander) XPathException(net.sf.saxon.trans.XPathException) ProxyReceiver(net.sf.saxon.event.ProxyReceiver) Receiver(net.sf.saxon.event.Receiver) PipelineConfiguration(net.sf.saxon.event.PipelineConfiguration) Controller(net.sf.saxon.Controller) Properties(java.util.Properties) StructuredQName(net.sf.saxon.om.StructuredQName) SlotManager(net.sf.saxon.expr.instruct.SlotManager) ProxyReceiver(net.sf.saxon.event.ProxyReceiver)

Example 2 with Receiver

use of net.sf.saxon.event.Receiver in project teiid by teiid.

the class ContentHandlerProxyReceiver method parse.

@Override
public void parse(InputSource input) throws IOException, SAXException {
    final ContentHandlerProxy chp = new ContentHandlerProxy();
    chp.setLexicalHandler(lexicalHandler);
    chp.setUnderlyingContentHandler(handler);
    this.source.addFilter(new FilterFactory() {

        @Override
        public ProxyReceiver makeFilter(Receiver arg0) {
            return new ContentHandlerProxyReceiver(chp, arg0);
        }
    });
    try {
        config.buildDocumentTree(source);
    } catch (XPathException e) {
        throw new SAXException(e);
    }
}
Also used : ContentHandlerProxy(net.sf.saxon.event.ContentHandlerProxy) XPathException(net.sf.saxon.trans.XPathException) ProxyReceiver(net.sf.saxon.event.ProxyReceiver) Receiver(net.sf.saxon.event.Receiver) FilterFactory(net.sf.saxon.event.FilterFactory) ProxyReceiver(net.sf.saxon.event.ProxyReceiver) SAXException(org.xml.sax.SAXException)

Example 3 with Receiver

use of net.sf.saxon.event.Receiver in project teiid by teiid.

the class XQueryEvaluator method evaluateXQuery.

public static SaxonXQueryExpression.Result evaluateXQuery(final SaxonXQueryExpression xquery, Object context, Map<String, Object> parameterValues, final RowProcessor processor, CommandContext commandContext) throws TeiidProcessingException, TeiidComponentException {
    DynamicQueryContext dynamicContext = new DynamicQueryContext(xquery.config);
    SaxonXQueryExpression.Result result = new SaxonXQueryExpression.Result();
    try {
        for (Map.Entry<String, Object> entry : parameterValues.entrySet()) {
            try {
                Object value = entry.getValue();
                Sequence s = null;
                if (value instanceof SQLXML) {
                    value = XMLSystemFunctions.convertToSource(value);
                    result.sources.add((Source) value);
                    Source source = wrapStax((Source) value);
                    s = xquery.config.buildDocumentTree(source).getRootNode();
                } else if (value instanceof java.util.Date) {
                    s = XQueryEvaluator.convertToAtomicValue(value);
                } else if (value instanceof BinaryType) {
                    s = new HexBinaryValue(((BinaryType) value).getBytesDirect());
                }
                dynamicContext.setParameter(StructuredQName.fromClarkName(entry.getKey()), s);
            } catch (TransformerException e) {
                throw new TeiidProcessingException(QueryPlugin.Event.TEIID30148, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30148, entry.getKey()));
            }
        }
        if (context != null) {
            Source source = XMLSystemFunctions.convertToSource(context);
            result.sources.add(source);
            source = wrapStax(source);
            if (xquery.contextRoot != null) {
                // create our own filter as this logic is not provided in the free saxon
                AugmentedSource sourceInput = AugmentedSource.makeAugmentedSource(source);
                sourceInput.addFilter(new FilterFactory() {

                    @Override
                    public ProxyReceiver makeFilter(Receiver arg0) {
                        return new PathMapFilter(xquery.contextRoot, arg0);
                    }
                });
                source = sourceInput;
                // use streamable processing instead
                if (xquery.streamingPath != null && processor != null) {
                    if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
                        // $NON-NLS-1$
                        LogManager.logDetail(LogConstants.CTX_DQP, "Using stream processing for evaluation of", xquery.xQueryString);
                    }
                    // set to non-blocking in case default expression evaluation blocks
                    boolean isNonBlocking = commandContext.isNonBlocking();
                    commandContext.setNonBlocking(true);
                    final StreamingTransform myTransform = new StreamingTransform() {

                        public Nodes transform(Element elem) {
                            processor.processRow(XQueryEvaluator.wrap(elem, xquery.config));
                            return NONE;
                        }
                    };
                    Builder builder = new Builder(new SaxonReader(xquery.config, sourceInput), false, new StreamingPathFilter(xquery.streamingPath, xquery.namespaceMap).createNodeFactory(null, myTransform));
                    try {
                        // the builder is hard wired to parse the source, but the api will throw an exception if the stream is null
                        builder.build(FAKE_IS);
                        return result;
                    } catch (ParsingException e) {
                        if (e.getCause() instanceof TeiidRuntimeException) {
                            RelationalNode.unwrapException((TeiidRuntimeException) e.getCause());
                        }
                        throw new TeiidProcessingException(QueryPlugin.Event.TEIID30151, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30151));
                    } catch (IOException e) {
                        throw new TeiidProcessingException(QueryPlugin.Event.TEIID30151, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30151));
                    } finally {
                        if (!isNonBlocking) {
                            commandContext.setNonBlocking(false);
                        }
                    }
                }
            }
            TreeInfo doc;
            try {
                doc = xquery.config.buildDocumentTree(source);
            } catch (XPathException e) {
                throw new TeiidProcessingException(QueryPlugin.Event.TEIID30151, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30151));
            }
            dynamicContext.setContextItem(doc.getRootNode());
        }
        try {
            result.iter = xquery.xQuery.iterator(dynamicContext);
            return result;
        } catch (TransformerException e) {
            throw new TeiidProcessingException(QueryPlugin.Event.TEIID30152, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30152));
        }
    } finally {
        if (result.iter == null) {
            result.close();
        }
    }
}
Also used : XPathException(net.sf.saxon.trans.XPathException) Element(nu.xom.Element) Builder(nu.xom.Builder) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) StAXSource(javax.xml.transform.stax.StAXSource) AugmentedSource(net.sf.saxon.lib.AugmentedSource) FilterFactory(net.sf.saxon.event.FilterFactory) StreamingPathFilter(nux.xom.xquery.StreamingPathFilter) StreamResult(javax.xml.transform.stream.StreamResult) Result(org.teiid.query.xquery.saxon.SaxonXQueryExpression.Result) QueryResult(net.sf.saxon.query.QueryResult) TeiidProcessingException(org.teiid.core.TeiidProcessingException) DynamicQueryContext(net.sf.saxon.query.DynamicQueryContext) ParsingException(nu.xom.ParsingException) TransformerException(javax.xml.transform.TransformerException) BinaryType(org.teiid.core.types.BinaryType) HexBinaryValue(net.sf.saxon.value.HexBinaryValue) Receiver(net.sf.saxon.event.Receiver) ProxyReceiver(net.sf.saxon.event.ProxyReceiver) Sequence(net.sf.saxon.om.Sequence) IOException(java.io.IOException) SQLXML(java.sql.SQLXML) Result(org.teiid.query.xquery.saxon.SaxonXQueryExpression.Result) StreamingTransform(nux.xom.xquery.StreamingTransform) TreeInfo(net.sf.saxon.om.TreeInfo) Map(java.util.Map) AugmentedSource(net.sf.saxon.lib.AugmentedSource) ProxyReceiver(net.sf.saxon.event.ProxyReceiver)

Aggregations

ProxyReceiver (net.sf.saxon.event.ProxyReceiver)3 Receiver (net.sf.saxon.event.Receiver)3 XPathException (net.sf.saxon.trans.XPathException)3 FilterFactory (net.sf.saxon.event.FilterFactory)2 IOException (java.io.IOException)1 SQLXML (java.sql.SQLXML)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Source (javax.xml.transform.Source)1 TransformerException (javax.xml.transform.TransformerException)1 StAXSource (javax.xml.transform.stax.StAXSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Controller (net.sf.saxon.Controller)1 ContentHandlerProxy (net.sf.saxon.event.ContentHandlerProxy)1 PipelineConfiguration (net.sf.saxon.event.PipelineConfiguration)1 Debugger (net.sf.saxon.expr.instruct.Debugger)1 SlotManager (net.sf.saxon.expr.instruct.SlotManager)1 AugmentedSource (net.sf.saxon.lib.AugmentedSource)1 SerializerFactory (net.sf.saxon.lib.SerializerFactory)1