Package client.net.sf.saxon.ce

Examples of client.net.sf.saxon.ce.Controller


            case UNDECIDED:
            case ITERATE_AND_MATERIALIZE:
                return SequenceExtent.makeSequenceExtent(exp.iterate(context));

            case PROCESS:
                Controller controller = context.getController();
                XPathContext c2 = context.newMinorContext();
                SequenceOutputter seq = controller.allocateSequenceOutputter(20);
                PipelineConfiguration pipe = controller.makePipelineConfiguration();
                seq.setPipelineConfiguration(pipe);
                c2.setTemporaryReceiver(seq);
                seq.open();
                exp.process(c2);
                seq.close();
View Full Code Here


    * Enumerate the results of the expression
    */

    public SequenceIterator iterate(XPathContext context) throws XPathException {

        Controller controller = context.getController();

        Item arg2;
        try {
            arg2 = argument[2].evaluateItem(context);
        } catch (XPathException e) {
            String code = e.getErrorCodeLocalPart();
            if ("XPDY0002".equals(code)) {
                dynamicError("Cannot call the key() function when there is no context item", "XTDE1270", context);
                return null;
            } else if ("XPDY0050".equals(code)) {
                dynamicError("In the key() function," +
                            " the node supplied in the third argument (or the context node if absent)" +
                            " must be in a tree whose root is a document node", "XTDE1270", context);
                return null;
            } else if ("XPTY0020".equals(code)) {
                dynamicError("Cannot call the key() function when the context item is an atomic value",
                        "XTDE1270", context);
                return null;
            }
            throw e;
        }

        NodeInfo origin = (NodeInfo)arg2;
        NodeInfo root = origin.getRoot();
        if (root.getNodeKind() != Type.DOCUMENT) {
            dynamicError("In the key() function," +
                            " the node supplied in the third argument (or the context node if absent)" +
                            " must be in a tree whose root is a document node", "XTDE1270", context);
            return null;
        }
        DocumentInfo doc = (DocumentInfo)root;

        final KeyManager keyManager = controller.getExecutable().getKeyManager();
        KeyDefinitionSet selectedKeySet = staticKeySet;
        if (selectedKeySet == null) {
            String givenkeyname = argument[0].evaluateItem(context).getStringValue();
            StructuredQName qName = null;
            try {
View Full Code Here

            return BooleanValue.FALSE;
        }
        String href = hrefVal.getStringValue();

        // suppress all error messages while attempting to fetch the document
        Controller controller = context.getController();
        ErrorListener old = controller.getErrorListener();
        controller.setErrorListener(ErrorDiscarder.THE_INSTANCE);
        boolean b = docAvailable(href, context);
        controller.setErrorListener(old);
        return BooleanValue.get(b);
    }
View Full Code Here

     * Evaluate as an expression.
     */

    public Item evaluateItem(XPathContext context) throws XPathException {

        Controller controller = context.getController();
        DocumentInfo root;
        if (textOnly) {
            CharSequence textValue;
            if (constantText != null) {
                textValue = constantText;
            } else {
                FastStringBuffer sb = new FastStringBuffer(FastStringBuffer.SMALL);
                SequenceIterator iter = content.iterate(context);
                while (true) {
                    Item item = iter.next();
                    if (item==null) break;
                    sb.append(item.getStringValueCS());
                }
                textValue = sb.condense();
            }
            root = new TextFragmentValue(textValue, getBaseURI());
            ((TextFragmentValue)root).setConfiguration(controller.getConfiguration());
        } else {
            try {
                XPathContext c2 = context.newMinorContext();

                Builder builder = controller.makeBuilder();

                //receiver.setSystemId(getBaseURI());
                builder.setBaseURI(getBaseURI());

                PipelineConfiguration pipe = controller.makePipelineConfiguration();
                builder.setPipelineConfiguration(pipe);

                c2.changeOutputDestination(builder, false);
                Receiver out = c2.getReceiver();
                out.open();
View Full Code Here

        String prefix = evaluatePrefix(context);
        return context.getNamePool().allocate("", "", prefix);
    }

    public void processValue(CharSequence value, XPathContext context) throws XPathException {
        Controller controller = context.getController();
        String prefix = evaluatePrefix(context);
        String uri = value.toString();
        checkPrefixAndUri(prefix, uri, context);

        SequenceReceiver out = context.getReceiver();
View Full Code Here

    }


    public TailCall processLeavingTail(XPathContext context) throws XPathException {

        Controller controller = context.getController();

        // handle parameters if any

        ParameterSet params = assembleParams(context, actualParams);
        ParameterSet tunnels = assembleTunnelParams(context, tunnelParams);

        Rule currentRule = context.getCurrentTemplateRule();
        if (currentRule==null) {
            XPathException e = new XPathException("There is no current template rule");
            e.setXPathContext(context);
            e.setErrorCode("XTDE0560");
            throw e;
        }
        Mode mode = context.getCurrentMode();
        if (mode == null) {
            mode = controller.getRuleManager().getUnnamedMode();
        }
        if (context.getCurrentIterator()==null) {
            XPathException e = new XPathException("There is no context item");
            e.setXPathContext(context);
            e.setErrorCode("XTDE0565");
            throw e;
        }
        Item currentItem = context.getCurrentIterator().current();
        if (!(currentItem instanceof NodeInfo)) {
            XPathException e = new XPathException("Cannot call xsl:next-match when context item is not a node");
            e.setXPathContext(context);
            e.setErrorCode("XTDE0565");
            throw e;
        }
        NodeInfo node = (NodeInfo)currentItem;
        Rule rule = controller.getRuleManager().getNextMatchHandler(node, mode, currentRule, context);

    if (rule==null) {             // use the default action for the node
            mode.getBuiltInRuleSet().process(node, params, tunnels, context, getSourceLocator());
        } else if (useTailRecursion) {
            //Template nh = (Template)rule.getAction();
View Full Code Here

         throw new XPathException(ue.getMessage());
       }
    }

    public TailCall processLeavingTail(XPathContext context) throws XPathException {
        final Controller controller = context.getController();
        final APIcommand command = controller.getApiCommand();
        XPathContext c2 = context.newMinorContext();
       
        int action = APPEND_CONTENT;
        if (methodExpression != null) {
            String method = methodExpression.evaluateAsString(context).toString();
            StructuredQName methodQ;
            if (method.indexOf(':') >= 0)  {
                methodQ = StructuredQName.fromLexicalQName(method, false, nsResolver);
            } else {
                methodQ = new StructuredQName("", "", method);
            }
            if ("replace-content".equals(methodQ.getLocalName())) {
                // TODO: check the namespace URI is NamespaceConstant.IXSL
                action = REPLACE_CONTENT;
            }
        }

        String hrefValue = null;
        if (href != null) {
          hrefValue = href.evaluateAsString(context).toString();
        } else if (command == APIcommand.UPDATE_HTML) {
          throw new XPathException("html update - no href value for result-document instruction");         
        } else {
          hrefValue = "result" + (controller.getResultDocumentCount() + 1);
        }
        NodeInfo target = null;
        Node targetNode = null;
        String contextNodeName = "";
        String absURI = "";
        if (command == APIcommand.TRANSFORM_TO_DOCUMENT) {
          absURI = getValidAbsoluteURI(controller, hrefValue);
          targetNode = XMLDOM.createDocument(absURI);
        } else if (command == APIcommand.TRANSFORM_TO_FRAGMENT || command == APIcommand.TRANSFORM_TO_HTML_FRAGMENT){
          absURI = getValidAbsoluteURI(controller, hrefValue);
          targetNode = HTMLDocumentWrapper.createDocumentFragment((Document)controller.getTargetNode());
        } else if (hrefValue.startsWith("#")) {
            hrefValue = hrefValue.substring(1);
            targetNode = ((Document)controller.getTargetNode()).getElementById(hrefValue); // com.google.gwt.dom.client.Document.get().getElementById(hrefValue);
        } else if (hrefValue.startsWith("?select=")) {
            String select = hrefValue.substring(8);
            AbstractStaticContext env = new AbstractStaticContext() {
                public String getURIForPrefix(String prefix) throws XPathException {
                    return null;
                }

                public Expression bindVariable(StructuredQName qName) throws XPathException {
                    return null;
                }

                public NamespaceResolver getNamespaceResolver() {
                    return null;
                }
                //override getFunctionLibrary to return that loaded for the prepared stylesheet
                public FunctionLibrary getFunctionLibrary() {
                  return controller.getPreparedStylesheet().getFunctionLibrary();
                }

            };
            ExpressionVisitor visitor = new ExpressionVisitor();
            visitor.setConfiguration(context.getConfiguration());
            visitor.setExecutable(new Executable(context.getConfiguration()));
            visitor.setStaticContext(env);
            env.setConfiguration(context.getConfiguration());
            Container container = (StyleElement)getSourceLocator();
            Expression expr = null;
            try {
            expr = ExpressionTool.make(select, env, container, 0, Token.EOF, getSourceLocator());
            } catch (Exception e) {
              // occurs if expression contains references to variables etc. within the dynamic context
              throw new XPathException("Error on evaluating (in static context) result-document href: " + hrefValue);
            }
            expr = visitor.typeCheck(expr, NodeKindTest.DOCUMENT);
            XPathContext c3 = context.newCleanContext();
            //context for ?select expression is the html page if an external node is the context
            Document page = (Document)controller.getTargetNode(); //com.google.gwt.dom.client.Document.get();
            Item cItem = context.getContextItem();
           
            NodeInfo currentContextItem;
            if (cItem instanceof JSObjectValue){
              currentContextItem = null;
            } else {
              currentContextItem = (NodeInfo)cItem;
            }
           
            boolean useCurrentContext;
            if (currentContextItem == null) {
              useCurrentContext = false;
            } else {
              useCurrentContext = (currentContextItem.getBaseURI().equals(page.getURL()));
            }
           
            NodeInfo contextItem;

            if (useCurrentContext) {
              contextItem = currentContextItem;
              if (LogConfiguration.loggingIsEnabled() && contextItem.getNodeKind() == Type.ELEMENT) {
                contextNodeName = controller.getNamePool().getLocalName(contextItem.getNameCode());
              }
            } else {
              contextItem = new HTMLDocumentWrapper(page, page.getURL(), context.getConfiguration(), DocType.UNKNOWN);
            }
            if (LogConfiguration.loggingIsEnabled()) {
              contextNodeName = (contextNodeName.equals("")? "" : " context node: " + contextNodeName);
            }

            AxisIterator iterator = SingleNodeIterator.makeIterator(contextItem);
            iterator.next(); // position on the single item
            c3.setCurrentIterator(iterator);
            SequenceIterator iter = expr.iterate(c3);
            Item resultItem = iter.next();
           
            if (resultItem == null) {} // do nothing
            else if (!(resultItem instanceof NodeInfo)) {
              throw new XPathException("non-node returned by result-document href: " + hrefValue);
            } else {
              target = (NodeInfo)resultItem;
              targetNode = (com.google.gwt.dom.client.Node)((HTMLNodeWrapper)target).getUnderlyingNode();
            }
        }
        else if (command == APIcommand.UPDATE_HTML) {
          throw new XPathException("expected '?select=' or '#' at start of result-document href, found: " + hrefValue);
        }
        if (targetNode == null) {
          logger.warning("result-document target not found for href: " + hrefValue + contextNodeName);
          return null;
        } else {
          logger.fine("processing result-document for href: " + hrefValue + contextNodeName);
        }

        //checkAcceptableUri(context, absoluteResultURI.toString());
        //IFrameElement container = Document.get().createIFrameElement();
       
        Node container = null;
        if (command == APIcommand.UPDATE_HTML) {
            container = HTMLDocumentWrapper.createDocumentFragment((Document)controller.getTargetNode());
        } else {
            addResultDocument(context, new DocumentURI(absURI), (Document)targetNode);
          container = targetNode;
        }

        PipelineConfiguration pipe = controller.makePipelineConfiguration();
       
        Receiver out = controller.openResult(pipe, c2, container, action);

        try {
            content.process(c2);
            out.endDocument();
        } catch (XPathException err) {
            err.setXPathContext(context);
            err.maybeSetLocation(getSourceLocator());
            throw err;
        }
        controller.closeResult(out, c2);
       
        if (command == APIcommand.UPDATE_HTML){
          PendingUpdateList list = controller.getPendingUpdateList();
          if (action == REPLACE_CONTENT && command == APIcommand.UPDATE_HTML) {
            int existingChildren = targetNode.getChildCount();
              for (int i=0; i<existingChildren; i++) {
                  Node child = targetNode.getChild(i);
                  list.add(new DeleteAction(child));
View Full Code Here

        //controller.setResultTree(absoluteResultURI.toString(), root);
        return null;
    }

    private void addResultDocument(XPathContext context, DocumentURI documentKey, Document doc) throws XPathException {
        Controller controller = context.getController();

            if (controller.getDocumentPool().find(documentKey.toString()) != null) {
                dynamicError("Cannot write to a URI that has already been read: " + documentKey.toString(), "XTRE1500", context);
            }
           
            if (!controller.checkUniqueOutputDestination(documentKey)) {
                dynamicError("Cannot write more than one result document to the same URI: " + documentKey.toString(),"XTDE1490" ,context);
            } else {
              controller.addToResultDocumentPool(documentKey, doc);
                //controller.addUnavailableOutputDestination(documentKey);
            }
        //controller.setThereHasBeenAnExplicitResultDocument();
    }
View Full Code Here

TOP

Related Classes of client.net.sf.saxon.ce.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.