Package net.sf.saxon

Examples of net.sf.saxon.Controller


                // XSLT recovery action when the computed name is invalid
                skipElement(context);
                return null;
            }

            Controller controller = context.getController();
            XPathContext c2 = context;
            SequenceReceiver out = context.getReceiver();

            Receiver validator = controller.getConfiguration().getElementValidator(
                    out, nameCode, locationId,
                    schemaType, validation,
                    controller.getNamePool()
            );

            if (validator != out) {
                c2 = context.newMinorContext();
                c2.setOrigin(this);
                out = new TreeReceiver(validator);
                out.setConfiguration(controller.getConfiguration());
                c2.setReceiver(out);
            }
            int properties = (inheritNamespaces ? 0 : ReceiverOptions.DISINHERIT_NAMESPACES);
            out.startElement(nameCode, -1, locationId, properties);
View Full Code Here


     * the content
     */

    public Item evaluateItem(XPathContext context) throws XPathException {
        try {
            Controller controller = context.getController();
            XPathContext c2 = context.newMinorContext();
            c2.setOrigin(this);
            SequenceOutputter seq = new SequenceOutputter();
            seq.setConfiguration(controller.getConfiguration());

            int nameCode = getNameCode(c2);

            Receiver validator = controller.getConfiguration().getElementValidator(
                    seq, nameCode, locationId,
                    schemaType, validation,
                    controller.getNamePool()
            );

            SequenceReceiver ini = seq;
            if (validator == seq) {
                c2.setTemporaryReceiver(seq);
            } else {
                TreeReceiver tr = new TreeReceiver(validator);
                tr.setConfiguration(controller.getConfiguration());
                tr.setDocumentLocator(getExecutable().getLocationMap());
                c2.setReceiver(tr);
                ini = tr;
            }

View Full Code Here

            element.outputNamespaceNodes(receiver, true);
        }
    }

    public TailCall processLeavingTail(XPathContext context) throws XPathException {
        Controller controller = context.getController();
        XPathContext c2 = context.newMinorContext();
        c2.setOrigin(this);
        SequenceReceiver out = c2.getReceiver();
        Item item = context.getContextItem();
        if (!(item instanceof NodeInfo)) {
            out.append(item, locationId);
            return null;
        }
        NodeInfo source = (NodeInfo)item;

        // Processing depends on the node kind.

        switch(source.getNodeKind()) {

        case Type.ELEMENT:
            // use the generic code for creating new elements
            return super.processLeavingTail(c2);

        case Type.ATTRIBUTE:
            try {
                CopyOf.copyAttribute(source, schemaType, validation, locationId, c2);
            } catch (NoOpenStartTagException err) {
                DynamicError e = new DynamicError(err.getMessage());
                e.setXPathContext(context);
                e.setErrorCode(err.getErrorCode());
                context.getController().recoverableError(e);
            }
            break;

        case Type.TEXT:
            out.characters(source.getStringValue(), locationId, 0);
            break;

        case Type.PROCESSING_INSTRUCTION:
            out.processingInstruction(source.getDisplayName(), source.getStringValue(), locationId, 0);
            break;

        case Type.COMMENT:
            out.comment(source.getStringValue(), locationId, 0);
            break;

        case Type.NAMESPACE:
            try {
                source.copy(out, NodeInfo.NO_NAMESPACES, false, locationId);
            } catch (NoOpenStartTagException err) {
                DynamicError e = new DynamicError(err.getMessage());
                e.setXPathContext(context);
                e.setErrorCode(err.getErrorCode());
                context.getController().recoverableError(e);
            }
            break;

        case Type.DOCUMENT:
            Receiver val = controller.getConfiguration().
                    getDocumentValidator(out,
                                         source.getBaseURI(),
                                         controller.getNamePool(),
                                         validation);
            if (val != out) {
                SequenceReceiver sr = new TreeReceiver(val);
                sr.setConfiguration(controller.getConfiguration());
                c2.setReceiver(sr);
                val = sr;
            }
            val.setConfiguration(controller.getConfiguration());
            val.startDocument(0);
            processChildren(c2);
            val.endDocument();
            break;
View Full Code Here

    * Evaluate in a context where a string is wanted
    */

    public String evaluateAsString(XPathContext context) throws XPathException {
        int numArgs = argument.length;
        Controller ctrl = context.getController();
        DecimalFormatManager dfm = ctrl.getDecimalFormatManager();
        DecimalFormatSymbols dfs;

        AtomicValue av0 = (AtomicValue)argument[0].evaluateItem(context);
        NumericValue number = (NumericValue)av0.getPrimitiveValue();
        String format = argument[1].evaluateItem(context).getStringValue();
View Full Code Here

    /**
     * Evaluate as an expression.
     */

    public Item evaluateItem(XPathContext context) throws XPathException {
        Controller controller = context.getController();
        DocumentInfo root = null;
        if (textOnly) {
            CharSequence textValue;
            if (constantText != null) {
                textValue = constantText;
            } else {
                textValue = new StringBuffer();
                Expression[] children = getChildren();
                for (int i=0; i<children.length; i++) {
                    SequenceIterator iter = children[i].iterate(context);
                    if (iter instanceof AtomizableIterator) {
                        ((AtomizableIterator)iter).setIsAtomizing(true);
                    }
                    while (true) {
                        Item item = iter.next();
                        if (item==null) break;
                        ((StringBuffer)textValue).append(item.getStringValue());
                    }
                }
            }
            root = new TextFragmentValue(textValue, baseURI);
            root.setConfiguration(controller.getConfiguration());
        } else {
            XPathContext c2 = context.newMinorContext();
            c2.setOrigin(this);

            // TODO: delayed evaluation of temporary trees, in the same way as
            // node-sets. This requires saving the controller, including values of local variables
            // and any assignable global variables (ouch).

            // TODO: use an Outputter that delayes the decision whether to build a
            // TextFragment or a TinyTree until the first element is encountered, to
            // avoid the overhead of using a TinyTree for text-only trees. This would
            // make the static analysis superfluous.

            TinyBuilder builder = new TinyBuilder();
            //System.err.println("Build doc " + builder);
            builder.setSizeParameters(treeSizeParameters);
            builder.setLineNumbering(controller.getConfiguration().isLineNumbering());

            Receiver receiver = builder;
            receiver.setSystemId(baseURI);
            receiver.setConfiguration(controller.getConfiguration());
            receiver.open();
            receiver.startDocument(0);
            c2.changeOutputDestination(null,
                    receiver,
                    false,
View Full Code Here

        return StandardNames.XSL_NEXT_MATCH;
    }

    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);

        Template currentTemplate = context.getCurrentTemplate();
        if (currentTemplate==null) {
            DynamicError e = new DynamicError("There is no current template rule");
            e.setXPathContext(context);
            e.setErrorCode("XT0560");
            throw e;
        }
        Mode mode = context.getCurrentMode();
        if (context.getCurrentIterator()==null) {
            DynamicError e = new DynamicError("There is no context item");
            e.setXPathContext(context);
            e.setErrorCode("XT0565");
            throw e;
        }
        Item currentItem = context.getCurrentIterator().current();
        if (!(currentItem instanceof NodeInfo)) {
            DynamicError e = new DynamicError("Cannot call xsl:next-match when context item is not a node");
            e.setXPathContext(context);
            e.setErrorCode("XT0565");
            throw e;
        }
        NodeInfo node = (NodeInfo)currentItem;
        Template nh = controller.getRuleManager().getNextMatchHandler(node, mode, currentTemplate, context);

    if (nh==null) {             // use the default action for the node
            ApplyTemplates.defaultAction(node, params, tunnels, context);
        } else {
            XPathContextMajor c2 = context.newContext();
View Full Code Here

        return list.iterator();
    }

    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);

        Template currentTemplate = context.getCurrentTemplate();
        if (currentTemplate==null) {
            DynamicError e = new DynamicError("There is no current template rule");
            e.setXPathContext(context);
            e.setErrorCode("XT0560");
            throw e;
        }

        int min = currentTemplate.getMinImportPrecedence();
        int max = currentTemplate.getPrecedence()-1;
        Mode mode = context.getCurrentMode();
        if (context.getCurrentIterator()==null) {
            DynamicError e = new DynamicError("Cannot call xsl:apply-imports when there is no context item");
            e.setXPathContext(context);
            e.setErrorCode("XT0565");
            throw e;
        }
        Item currentItem = context.getCurrentIterator().current();
        if (!(currentItem instanceof NodeInfo)) {
            DynamicError e = new DynamicError("Cannot call xsl:apply-imports when context item is not a node");
            e.setXPathContext(context);
            e.setErrorCode("XT0565");
            throw e;
        }
        NodeInfo node = (NodeInfo)currentItem;
        Template nh = controller.getRuleManager().getTemplateRule(node, mode, min, max, context);

    if (nh==null) {             // use the default action for the node
            ApplyTemplates.defaultAction(node, params, tunnels, context);
        } else {
            XPathContextMajor c2 = context.newContext();
View Full Code Here

     */

    protected int getNameCode(XPathContext context)
            throws XPathException, XPathException {

        Controller controller = context.getController();
        NamePool pool = controller.getNamePool();

        String prefix;
        String localName;
        String uri;

View Full Code Here

    * Evaluate in a context where a string is wanted
    */

    public String evaluateAsString(XPathContext context) throws XPathException {
        int numArgs = argument.length;
        Controller ctrl = context.getController();

        DecimalFormatSymbols dfs = decimalFormatSymbols;

        AtomicValue av0 = (AtomicValue)argument[0].evaluateItem(context);
        NumericValue number = (NumericValue)av0.getPrimitiveValue();

        if (dfs == null) {
            // the decimal-format name was not resolved statically
            if (requireFixup) {
                // we registered for a fixup, but none came
                dynamicError("Unknown decimal format name", "XT1280", context);
                return null;
            }
            DecimalFormatManager dfm = ctrl.getDecimalFormatManager();
            if (numArgs==2) {
                dfs = dfm.getDefaultDecimalFormat();
            } else {
                // the decimal-format name was given as a run-time expression
                String qname = argument[2].evaluateItem(context).getStringValue();
View Full Code Here

    * @return a TailCall to be executed by the caller, always null for this instruction
    */

    public TailCall processLeavingTail(XPathContext context) throws XPathException
    {
        Controller controller = context.getController();
        SequenceReceiver out = context.getReceiver();
        int opt = options;
        int ann = annotation;

      // we may need to change the namespace prefix if the one we chose is
      // already in use with a different namespace URI: this is done behind the scenes
      // by the Outputter

        String value = expandChildren(context).toString();
        if (schemaType != null) {
            // test whether the value actually conforms to the given type
            try {
                schemaType.validateContent(value, DummyNamespaceResolver.getInstance());
                if (schemaType.isNamespaceSensitive()) {
                    opt |= ReceiverOptions.NEEDS_PREFIX_CHECK;
                }
            } catch (ValidationException err) {
                throw new ValidationException("Attribute value " + Err.wrap(value, Err.VALUE) +
                                               " does not the match the required type " +
                                               schemaType.getDescription() + ". " +
                                               err.getMessage());
            }
        } else if (validationAction==Validation.STRICT ||
                validationAction==Validation.LAX) {
            long res = controller.getConfiguration().validateAttribute(nameCode,
                                                                         value,
                                                                         validationAction);
            ann = (int)(res & 0xffffffff);
            opt |= (int)(res >> 32);
        }
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.