Package net.sf.saxon

Examples of net.sf.saxon.Controller


     * @throws XPathException if a dynamic error occurs
     */

    public void process(XPathContext context) throws XPathException {

        Controller controller = context.getController();
        Template t = getTargetTemplate(context);
        XPathContextMajor c2 = context.newContext();
        c2.setOrigin(this);
        c2.openStackFrame(t.getStackFrameMap());
        c2.setLocalParameters(assembleParams(context, actualParams));
View Full Code Here


     * or does not reference a known template
     */

    public Template getTargetTemplate(XPathContext context) throws XPathException {
        if (calledTemplateExpression != null) {
            Controller controller = context.getController();
            String qname = calledTemplateExpression.evaluateAsString(context);

            String prefix;
            String localName;
            try {
                String[] parts = Name.getQNameParts(qname);
                prefix = parts[0];
                localName = parts[1];
            } catch (QNameException err) {
                throw dynamicError("Invalid template name. " + err.getMessage(), controller);
            }
            String uri = nsContext.getURIForPrefix(prefix, false);
            if (uri==null) {
              throw dynamicError("Namespace prefix " + prefix + " has not been declared", controller);
          }
            int fprint = controller.getNamePool().getFingerprint(uri, localName);
            Template target = controller.getExecutable().getNamedTemplate(fprint);
            //HashMap templateTable = controller.getExecutable().getNamedTemplateTable();
            //Template target = (Template)templateTable.get(new Integer(fprint));
            if (target==null) {
              throw dynamicError("Template " + qname + " has not been defined", controller);
            }
View Full Code Here

        * a TailCall representing the call from C to D.
         * @throws XPathException if a dynamic error occurs
        */

        public TailCall processLeavingTail(XPathContext context) throws XPathException {
            Controller controller = context.getController();
            XPathContextMajor c2 = evaluationContext.newContext();
            c2.setOrigin(CallTemplate.this);
            c2.setLocalParameters(params);
            c2.setTunnelParameters(tunnelParams);
            c2.openStackFrame(target.getStackFrameMap());
View Full Code Here

     * dynamic errors will not be reported by this method, but will only be reported
     * when the individual items of the result are accessed using the returned iterator.
     */

    public SequenceIterator iterator(DynamicQueryContext env) throws XPathException {
        Controller controller = getController();
        initializeController(env, controller);

        try {
            NodeInfo node = env.getContextNode();
            Bindery bindery = controller.getBindery();
            //bindery.openStackFrame();
            controller.defineGlobalParameters(bindery);
            XPathContextMajor context = controller.newXPathContext();

            // In tracing/debugging mode, evaluate all the global variables first
            if (controller.getConfiguration().getTraceListener() != null) {
                controller.preEvaluateGlobals(context);
            }

            context.openStackFrame(stackFrameMap);
            if (node != null) {
                context.setCurrentIterator(SingletonIterator.makeIterator(node));
                controller.setPrincipalSourceDocument(node.getDocumentRoot());
            }           
            SequenceIterator iterator = expression.iterate(context);
            return new ErrorReportingIterator(iterator, controller.getErrorListener());
        } catch (XPathException err) {
            TransformerException terr = err;
            while (terr.getException() instanceof TransformerException) {
                terr = (TransformerException)terr.getException();
            }
            try {
                controller.getErrorListener().error(terr);
            } catch (TransformerException e) {
                //
            }
            throw XPathException.wrap(terr);
        }
View Full Code Here

    public Iterator iterateSubExpressions() {
        return new PairIterator(select, action);
    }

    public TailCall processLeavingTail(XPathContext context) throws XPathException {
        Controller controller = context.getController();
        SequenceIterator iter = select.iterate(context);

        XPathContextMajor c2 = context.newContext();
        c2.setOrigin(this);
        c2.setCurrentIterator(iter);
        c2.setCurrentTemplate(null);

        if (controller.isTracing()) {
            TraceListener listener = controller.getTraceListener();
            while(true) {
                Item item = iter.next();
                if (item == null) {
                    break;
                }
View Full Code Here

     * @throws XPathException if the query fails.
     */

    public void run(DynamicQueryContext env, Result result, Properties outputProperties) throws XPathException {

        Controller controller = getController();
        initializeController(env, controller);

        // Validate the serialization properties requested

        if (outputProperties == null) {
            outputProperties = new Properties();
        } else {
            Enumeration iter = outputProperties.propertyNames();
            while (iter.hasMoreElements()) {
                String key = (String)iter.nextElement();
                String value = outputProperties.getProperty(key);
                try {
                    SaxonOutputKeys.checkOutputProperty(key, value);
                } catch (DynamicError dynamicError) {
                    try {
                        controller.getErrorListener().error(dynamicError);
                        throw dynamicError;
                        // TODO: could be a warning, but currently all warnings are fatal.
                        //outputProperties.remove(key);
                    } catch (TransformerException err2) {
                        throw DynamicError.wrap(err2);
                    }
                }
            }
        }

        NodeInfo node = env.getContextNode();

        Bindery bindery = controller.getBindery();
        controller.defineGlobalParameters(bindery);
       
        XPathContextMajor context = controller.newXPathContext();

        // In tracing/debugging mode, evaluate all the global variables first
        TraceListener tracer = controller.getConfiguration().getTraceListener();
        if (tracer != null) {
            controller.preEvaluateGlobals(context);
            tracer.open();
        }

        context.openStackFrame(stackFrameMap);
        if (node != null) {
            context.setCurrentIterator(SingletonIterator.makeIterator(node));
            controller.setPrincipalSourceDocument(node.getDocumentRoot());
        }       
       
        boolean mustClose = (result instanceof StreamResult &&
            ((StreamResult)result).getOutputStream() == null);
        context.changeOutputDestination(outputProperties, result, true, Validation.PRESERVE, null);

        // Run the query
        try {
            documentInstruction.process(context);
        } catch (XPathException err) {
            try {
                controller.getErrorListener().fatalError(err);
            } catch (TransformerException e) {
                //
            }
            throw err;
        }
View Full Code Here

     * They can then be called directly from the Java application using {@link net.sf.saxon.instruct.UserFunction#call}
     * The same Controller can be used for a series of function calls.
     */

    public Controller getController() {
        Controller controller = new Controller(executable.getConfiguration());
        controller.setExecutable(executable);
        executable.initialiseBindery(controller.getBindery());
        return controller;
    }
View Full Code Here

            } catch (MalformedURLException err) {
                documentKey = baseURL + "/../" + href;
            }
        }

        Controller controller = c.getController();

        // see if the document is already loaded


        DocumentInfo doc = controller.getDocumentPool().find(documentKey);
        if (doc != null) {
            return getFragment(doc, fragmentId);
        }

        try {
            // Get a Source from the URIResolver

            URIResolver r = controller.getURIResolver();
            Source source = r.resolve(href, baseURL);

            // if a user URI resolver returns null, try the standard one
            // (Note, the standard URI resolver never returns null)
            if (source==null) {
                r = controller.getStandardURIResolver();
                source = r.resolve(href, baseURL);
            }

            DocumentInfo newdoc;
            if (source instanceof NodeInfo || source instanceof DOMSource) {
                NodeInfo startNode = controller.prepareInputTree(source);
                newdoc = startNode.getDocumentRoot();
            } else {
                Builder b = controller.makeBuilder();
                Stripper s = controller.makeStripper(b);
                new Sender(controller.getConfiguration()).send(source, s);
                newdoc = b.getCurrentDocument();
            }
            controller.registerDocument(newdoc, documentKey);
            return getFragment(newdoc, fragmentId);

        } catch (TransformerException err) {
            XPathException xerr = XPathException.wrap(err);
            try {
                controller.recoverableError(xerr);
            } catch (XPathException err2) {
                throw new DynamicError(err);
            }
            return null;
        }
View Full Code Here

    /**
    * Evaluate the variable
    */

    public Value evaluateVariable(XPathContext context) throws XPathException {
        Controller controller = context.getController();
        Bindery b = controller.getBindery();

        Value v = b.getGlobalVariableValue(this);

        if (v != null) {
            return v;
View Full Code Here

            } else {
                return flatten(select.iterate(context), sep);
            }

        } else {
            Controller controller = context.getController();
            XPathContext c2 = context.newMinorContext();
            SequenceOutputter seq = new SequenceOutputter();
            seq.setConfiguration(controller.getConfiguration());
            seq.setDocumentLocator(getExecutable().getLocationMap());
            c2.setTemporaryReceiver(seq);
            // process the child elements in the stylesheet
            processChildren(c2);
            seq.close();
View Full Code Here

TOP

Related Classes of net.sf.saxon.Controller

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.