Example #1
0
        /// <summary>
        /// Insert-Before operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:insert-before operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence id(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext context) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence id(ICollection args, EvaluationContext context)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            ResultBuffer rs = new ResultBuffer();

            IEnumerator argIt = cargs.GetEnumerator();

            argIt.MoveNext();
            ResultSequence idrefRS = (ResultSequence)argIt.Current;

            string[] idrefst = idrefRS.first().StringValue.Split(" ", true);

            ArrayList      idrefs   = createIDRefs(idrefst);
            ResultSequence nodeArg  = null;
            NodeType       nodeType = null;

            if (argIt.MoveNext())
            {
                nodeArg  = (ResultSequence)argIt.Current;
                nodeType = (NodeType)nodeArg.first();
            }
            else
            {
                if (context.ContextItem == null)
                {
                    throw DynamicError.contextUndefined();
                }
                if (!(context.ContextItem is NodeType))
                {
                    throw new DynamicError(TypeError.invalid_type(null));
                }
                nodeType = (NodeType)context.ContextItem;
                if (nodeType.node_value().OwnerDocument == null)
                {
                    throw DynamicError.contextUndefined();
                }
            }

            Node node = nodeType.node_value();

            if (node.OwnerDocument == null)
            {
                // W3C Test suite seems to want XPDY0002
                throw DynamicError.contextUndefined();
                //throw DynamicError.noContextDoc();
            }

            if (hasIDREF(idrefs, node))
            {
                ElementType element = new ElementType((Element)node, context.StaticContext.TypeModel);
                rs.add(element);
            }

            processAttributes(node, idrefs, rs, context);
            processChildNodes(node, idrefs, rs, context);

            return(rs.Sequence);
        }
Example #2
0
        /// <summary>
        /// Position operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <param name="dc">
        ///            Result of dynamic context operation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:position operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence position(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence position(ICollection args, EvaluationContext ec)
        {
            Debug.Assert(args.Count == 0);

            if (ec.ContextItem == null)
            {
                throw DynamicError.contextUndefined();
            }

            return(ResultSequenceFactory.create_new(new XSInteger(new System.Numerics.BigInteger(ec.ContextPosition))));
        }
Example #3
0
        protected internal static ResultSequence getResultSetForArityZero(EvaluationContext ec)
        {
            ResultSequence rs = ResultSequenceFactory.create_new();

            Item contextItem = ec.ContextItem;

            if (contextItem != null)
            {
                // if context item is defined, then that is the default argument
                // to fn:string function
                rs.add(new XSString(contextItem.StringValue));
            }
            else
            {
                throw DynamicError.contextUndefined();
            }
            return(rs);
        }
Example #4
0
        /// <summary>
        /// Local-Name operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:local-name operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence local_name(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext context) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence local_name(ICollection args, EvaluationContext context)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            // get arg
            ResultSequence arg1 = null;

            if (cargs.Count == 0)
            {
                if (context.ContextItem == null)
                {
                    throw DynamicError.contextUndefined();
                }
                else
                {
                    arg1 = (AnyType)context.ContextItem;
                }
            }
            else
            {
                var i = cargs.GetEnumerator();
                i.MoveNext();
                arg1 = (ResultSequence)i.Current;
            }

            if (arg1.empty())
            {
                return(new XSString(""));
            }

            NodeType an = (NodeType)arg1.first();


            QName name = an.node_name();

            string sname = "";

            if (name != null)
            {
                sname = name.local();
            }

            return(new XSString(sname));
        }
Example #5
0
        /// <summary>
        /// Language operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:lang operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence lang(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence lang(ICollection args, EvaluationContext ec)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            // get arg
            IEnumerator citer = cargs.GetEnumerator();

            citer.MoveNext();
            ResultSequence arg1 = (ResultSequence)citer.Current;
            ResultSequence arg2 = null;

            if (cargs.Count == 1)
            {
                if (ec.ContextItem == null)
                {
                    throw DynamicError.contextUndefined();
                }
                arg2 = (AnyType)ec.ContextItem;
            }
            else
            {
                citer.MoveNext();
                arg2 = (ResultSequence)citer.Current;
            }

            string lang = "";

            if (!(arg1 == null || arg1.empty()))
            {
                lang = ((XSString)arg1.first()).value();
            }


            if (!(arg2.first() is NodeType))
            {
                throw DynamicError.invalidType();
            }

            NodeType an = (NodeType)arg2.first();

            return(new XSBoolean(test_lang(an.node_value(), lang)));
        }
Example #6
0
        /// <summary>
        /// Base-Uri operation.
        /// </summary>
        /// <param name="args">
        ///            Result from the expressions evaluation. </param>
        /// <param name="d_context">
        ///               Dynamic context </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:base-uri operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence base_uri(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence base_uri(ICollection args, EvaluationContext ec)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            ResultSequence rs = null;

            if (cargs.Count == 0)
            {
                // support for arity 0
                // get base-uri from the context item.
                Item contextItem = ec.ContextItem;
                if (contextItem != null)
                {
                    rs = getBaseUri(contextItem);
                }
                else
                {
                    throw DynamicError.contextUndefined();
                }
            }
            else if (cargs.Count == 1)
            {
                // support for arity 1
                var i = cargs.GetEnumerator();
                i.MoveNext();
                ResultSequence arg1 = (ResultSequence)i.Current;
                Item           att  = arg1 == null || arg1.empty() ? null : arg1.first();

                rs = getBaseUri(att);
            }
            else
            {
                // arity other than 0 or 1 is not allowed
                throw DynamicError.throw_type_error();
            }

            return(rs);
        }
Example #7
0
        /// <summary>
        /// Root operation.
        /// </summary>
        /// <param name="arg">
        ///            Result from the expressions evaluation. </param>
        /// <param name="dc">
        ///            Result of dynamic context operation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:root operation. </returns>
        public static ResultSequence fn_root(ICollection args, EvaluationContext ec)
        {
            ICollection cargs = Function.convert_arguments(args, expected_args());

            if (cargs.Count > 1)
            {
                throw new DynamicError(TypeError.invalid_type(null));
            }

            ResultSequence arg = null;

            if (cargs.Count == 0)
            {
                if (ec.ContextItem == null)
                {
                    throw DynamicError.contextUndefined();
                }
                arg = ResultBuffer.wrap(ec.ContextItem);
            }
            else
            {
                var i = cargs.GetEnumerator();
                i.MoveNext();
                arg = (ResultSequence)i.Current;
            }

            if (arg.empty())
            {
                return(ResultBuffer.EMPTY);
            }

            Item aa = arg.item(0);

            if (!(aa is NodeType))
            {
                throw new DynamicError(TypeError.invalid_type(null));
            }

            NodeType nt = (NodeType)aa;

            // ok we got a sane argument... own it.
            Node root = nt.node_value();

            while (root != null && !(root is Document))
            {
                Node newroot = root.ParentNode;
                if (newroot == null && root is Attr)
                {
                    newroot = ((Attr)root).OwnerElement;
                }

                // found it
                if (newroot == null)
                {
                    break;
                }

                root = newroot;
            }

            return(NodeType.dom_to_xpath(root, ec.StaticContext.TypeModel));
        }