Example #1
0
 public override void SetXsltContext(XsltContext context)
 {
     if (context == null)
     {
         throw XPathException.Create(SR.Xp_NoContext);
     }
     if (this.xsltContext != context)
     {
         xsltContext = context;
         foreach (Query argument in _args)
         {
             argument.SetXsltContext(context);
         }
         XPathResultType[] argTypes = new XPathResultType[_args.Count];
         for (int i = 0; i < _args.Count; i++)
         {
             argTypes[i] = _args[i].StaticType;
         }
         _function = xsltContext.ResolveFunction(prefix, name, argTypes);
         // KB article allows to return null, see http://support.microsoft.com/?kbid=324462#6
         if (_function == null)
         {
             throw XPathException.Create(SR.Xp_UndefFunc, QName);
         }
     }
 }
Example #2
0
		public ExsltContextFunction(MethodInfo mi, XPathResultType[] argTypes,
			object owner)
		{
			_method = mi;
			_argTypes = argTypes;
			_ownerObj = owner;
		}
 public override IXsltContextFunction ResolveFunction(string prefix, string name, XPathResultType[] argTypes)
 {
   XsltFunction function;
   if (functions.TryGetValue(name, out function))
     return function;
   return baseContext.ResolveFunction(prefix, name, argTypes);
 }
            public override IXsltContextFunction ResolveFunction(string prefix, string name, XPathResultType[] argTypes)
            {
                if (string.IsNullOrEmpty(prefix))
                   return base.ResolveFunction(prefix, name, argTypes);

                return mvpContext.ResolveFunction(prefix, name, argTypes);
            }
        /// <summary>
        /// Creates a new extension function definition.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="minArgs"></param>
        /// <param name="maxArgs"></param>
        /// <param name="argTypes"></param>
        /// <param name="returnType"></param>
        /// <param name="fn"></param>
        public TriflesXPathExtensionFunction(XName name, int minArgs, int maxArgs, XPathResultType[] argTypes, XPathResultType returnType, TriflesXPathInvokable fn)
        {
            FunctionName = Checker.NotNull(name, "name");

            Minargs = minArgs;
            Maxargs = maxArgs;

            if (Minargs < 0)
            {
                throw new ArgumentOutOfRangeException("minArgs");
            }
            else if (Maxargs < Minargs)
            {
                throw new ArgumentOutOfRangeException("maxArgs", "maxArgs cannot be less than minArgs");
            }

            if (argTypes == null)
            {
                argTypes = new XPathResultType[0];
            }

            this.argTypes = argTypes.ToImmutableArray();

            ReturnType = Checker.NotNull(returnType, "returnType");

            invokable = Checker.NotNull(fn, "fn");
        }
		protected void Init (int minArgs, int maxArgs, XPathResultType returnType, XPathResultType[] argTypes)
		{
			this.minargs	= minArgs;
			this.maxargs	= maxArgs;
			this.returnType = returnType;
			this.argTypes	= argTypes;
		}
 internal XPathResult(XPathNodeIterator nodeSetResult)
     : this()
 {
     this.nodeSetResult = nodeSetResult;
     this.internalIterator = nodeSetResult as SafeNodeSequenceIterator;
     this.resultType = XPathResultType.NodeSet;
 }
 protected XPathMessageFunction(XPathResultType[] argTypes, int max, int min, XPathResultType retType)
 {
     this.argTypes = argTypes;
     this.maxArgs = max;
     this.minArgs = min;
     this.retType = retType;
 }
 private void CheckNodeSet(XPathResultType t)
 {
     if ((t != XPathResultType.NodeSet) && (t != XPathResultType.Any))
     {
         throw XPathException.Create("Xp_NodeSetExpected", this.scanner.SourceText);
     }
 }
            public override IXsltContextFunction ResolveFunction(string prefix, string name, XPathResultType[] argTypes)
            {
                IXsltContextFunction function = null;
                if (string.IsNullOrEmpty(prefix))
                    functions.TryGetValue(name, out function);

                return function ?? base.ResolveFunction(prefix, name, argTypes);
            }
Example #11
0
 public CustomXsltFunction(string name, XPathResultType[] argTypes, XPathResultType returnType, InvokedFunction function = null)
 {
     Prefix = String.Empty;
     Name = name;
     ArgTypes = argTypes;
     ReturnType = returnType;
     Function = function;
 }
Example #12
0
 public override IXsltContextFunction ResolveFunction(string prefix, string name, XPathResultType[] ArgTypes)
 {
     if (name == "upper-case")
     {
         return new UpperCase();
     }
     return null;
 }
        public override IXsltContextFunction ResolveFunction(string prefix, string name, XPathResultType[] ArgTypes)
        {
            var func = _functions.SingleOrDefault(f => f.Name == name && f.Prefix == prefix);

            if(func != null)
                return func;
            else
                throw new InvalidOperationException("Unknown function in XPath: " + name);              
        }
        public override IXsltContextFunction ResolveFunction(string prefix, string name, XPathResultType[] argTypes)
        {
            if (name == "document")
            {
                return new XsltContextFunction("document");
            }

            return null;
        }
        /// <summary>
        /// Creates the variable object.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="isLocal"></param>
        /// <param name="isParam"></param>
        /// <param name="resultType"></param>
        public TriflesXPathExtensionVariable(XName name, object value, bool isLocal = false, bool isParam = false, XPathResultType? resultType = null)
        {
            this.VariableName = name;
            this.Value = value;
            this.IsLocal = isLocal;
            this.IsParam = isParam;

            this.VariableType = resultType.HasValue ? resultType.Value : TriflesXPathData.GuessXPathResultType(value);
        }
            public override IXsltContextFunction ResolveFunction(string prefix, string name, XPathResultType[] argTypes)
            {
                if (string.IsNullOrEmpty(prefix))
                {
                   if (name == "current" && argTypes.Length == 0)
                  return currentFunction;
                }

                return base.ResolveFunction(prefix, name, argTypes);
            }
Example #17
0
 // Constructors
 
 public XsltFunction(string name, XPathResultType[] argTypes, XPathResultType returnType,
   Func<XsltContext, XPathNavigator, object[], object> implementation, int? minArgs = null, int? maxArgs = null)
 {
   this.name = name;
   this.argTypes = argTypes;
   this.returnType = returnType;
   this.minArgs = minArgs ?? argTypes.Length;
   this.maxArgs = maxArgs ?? argTypes.Length;
   this.implementation = implementation;
 }
Example #18
0
        public override IXsltContextFunction ResolveFunction(string prefix, string name, XPathResultType[] ArgTypes) {
            switch (name) {
                case "match":
                    return m_MatchFct;
                case "canCastTo":
                    return m_CanCastTo;
                default:
                    throw new NotSupportedException();
            }
		}
 static XPathParser()
 {
     XPathResultType[] typeArray5 = new XPathResultType[3];
     typeArray5[0] = XPathResultType.String;
     temparray6 = typeArray5;
     temparray7 = new XPathResultType[] { XPathResultType.String, XPathResultType.String, XPathResultType.String };
     temparray8 = new XPathResultType[] { XPathResultType.Boolean };
     temparray9 = new XPathResultType[1];
     functionTable = CreateFunctionTable();
     AxesTable = CreateAxesTable();
 }
        public override IXsltContextFunction ResolveFunction(string prefix, string name,
                                                             XPathResultType[] argTypes)
        {
            IXsltContextFunction function = null;

            if (this.functions.TryGetValue(prefix + ":" + name, out function))
            {
                return function;
            }

            return null;
        }
 public XPathProcessorResult(object value, XPathResultType resultType)
 {
     switch (resultType)
     {
         case XPathResultType.NodeSet:
             XMLNodeList = (XmlNodeList)value;
             break;
         case XPathResultType.Boolean:
         case XPathResultType.Number:
         case XPathResultType.String:
             StringResult = value.ToString();
             break;
         default:
             throw new ArgumentOutOfRangeException("Unexpected XPathResultType");
     }
 }
Example #22
0
        /// <summary>
        /// Resolves the specified function name.
        /// </summary>
        /// <param name="prefix"></param>
        /// <param name="localName"></param>
        /// <param name="argTypes"></param>
        /// <returns></returns>
        public override IXsltContextFunction ResolveFunction(string prefix, string localName, XPathResultType[] argTypes)
        {
            Contract.Assert(prefix != null);
            Contract.Assert(localName != null);
            Contract.Assert(argTypes != null);

            return functionProvider.GetFunctions()
                .SelectMany(i => i.Metadata.ExpandedName
                    .Select((j, k) => new
                    {
                        Name = i.Metadata.ExpandedName[k],
                        Item = i,
                    }))
                .Where(i => ResolveFunctionPredicate(
                    XName.Get(i.Name),
                    prefix,
                    localName))
                .Select(i => i.Item.Value)
                .FirstOrDefault();
        }
Example #23
0
        public override IXsltContextFunction ResolveFunction(string Prefix, string Name, XPathResultType[] ArgTypes)
        {
            if (LookupNamespace(Prefix) == ExtensionsNamespaceUri) {
            switch (Name) {
              case "CountChar":

            return new XPathExtensions(2, 2, XPathResultType.Number, ArgTypes, "CountChar");
              case "FindTaskBy":
            // Implemented but not called.

            return new XPathExtensions(2, 2, XPathResultType.String, ArgTypes, "FindTaskBy");
              case "Right":
            // Implemented but not called.

            return new XPathExtensions(2, 2, XPathResultType.String, ArgTypes, "Right");
              case "Left":
            // Implemented but not called.

            return new XPathExtensions(2, 2, XPathResultType.String, ArgTypes, "Left");
              case "Like":
              case "matches":
            // Implemented but not called.
            return new XPathExtensions(2, 2, XPathResultType.Boolean, ArgTypes, "Like");
              case "verntoenglish":
              case "VernToEnglish":
            return new XPathExtensions(1, 1, XPathResultType.String, ArgTypes, "VernToEnglish");
              case "DepType":
              case "deptype":
            return new XPathExtensions(1, 1, XPathResultType.String, ArgTypes, "DepType");
              case "LabelExtNum":
              case "labelnum":
            return new XPathExtensions(1, 1, XPathResultType.Number, ArgTypes, "LabelExtNum");
              default:

            break;
            }
              }
              // Return Nothing if none of the functions match name.
              return null;
        }
Example #24
0
        IXsltContextFunction IXPathFunctionLibrary.ResolveFunction( string prefix, string name,
                                                                    XPathResultType[] argTypes )
        {
            BindingFlags flags = BindingFlags.Static | BindingFlags.Public;
            if ( fInstance != null )
            {
                flags |= BindingFlags.Instance;
            }
            MethodInfo[] methods = fType.GetMethods( flags );
            List<MethodInfo> methodList = new List<MethodInfo>();
            foreach ( MethodInfo info in methods )
            {
                if ( info.Name == name )
                {
                    methodList.Add( info );
                }
            }

            if ( methodList.Count > 0 )
            {
                return new CustomFunction( methodList.ToArray(), fInstance );
            }
            return null;
        }
 static Function()
 {
     XPathResultType[] typeArray = new XPathResultType[0x1c];
     typeArray[3] = XPathResultType.NodeSet;
     typeArray[4] = XPathResultType.String;
     typeArray[5] = XPathResultType.String;
     typeArray[6] = XPathResultType.String;
     typeArray[7] = XPathResultType.String;
     typeArray[8] = XPathResultType.Boolean;
     typeArray[10] = XPathResultType.Boolean;
     typeArray[11] = XPathResultType.Boolean;
     typeArray[12] = XPathResultType.Boolean;
     typeArray[13] = XPathResultType.String;
     typeArray[14] = XPathResultType.Boolean;
     typeArray[15] = XPathResultType.Boolean;
     typeArray[0x10] = XPathResultType.String;
     typeArray[0x11] = XPathResultType.String;
     typeArray[0x12] = XPathResultType.String;
     typeArray[20] = XPathResultType.String;
     typeArray[0x15] = XPathResultType.String;
     typeArray[0x16] = XPathResultType.Boolean;
     typeArray[0x1b] = XPathResultType.Any;
     ReturnTypes = typeArray;
 }
 public Operand(bool val)
 {
     this.type = XPathResultType.Boolean;
     this.val = val;
 }
 internal ParamInfo(Function.FunctionType ftype, int minargs, int maxargs, XPathResultType[] argTypes)
 {
     this.ftype = ftype;
     this.minargs = minargs;
     this.maxargs = maxargs;
     this.argTypes = argTypes;
 }
Example #28
0
		public override IXsltContextFunction ResolveFunction(string prefix, string name, XPathResultType[] argTypes)
		{
			Func<IXsltContextFunction> function;
			if (functions.TryGetValue(GetQualifiedName(prefix, name), out function))
				return function();
			return (parent != null) ? parent.ResolveFunction(prefix, name, argTypes) : null;
		}
 public Operand(double val)
 {
     this.type = XPathResultType.Number;
     this.val = val;
 }
 public Operand(string val)
 {
     this.type = XPathResultType.String;
     this.val = val;
 }
Example #31
0
        private MethodInfo FindBestMethod(MethodInfo[] methods, bool ignoreCase, bool publicOnly, string name, XPathResultType[] argTypes)
        {
            int length = methods.Length;
            int free   = 0;

            // restrict search to methods with the same name and requiested protection attribute
            for (int i = 0; i < length; i++)
            {
                if (string.Equals(name, methods[i].Name, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal))
                {
                    if (!publicOnly || methods[i].GetBaseDefinition().IsPublic)
                    {
                        methods[free++] = methods[i];
                    }
                }
            }
            length = free;
            if (length == 0)
            {
                // this is the only place we returning null in this function
                return(null);
            }
            if (argTypes == null)
            {
                // without arg types we can't do more detailed search
                return(methods[0]);
            }
            // restrict search by number of parameters
            free = 0;
            for (int i = 0; i < length; i++)
            {
                if (methods[i].GetParameters().Length == argTypes.Length)
                {
                    methods[free++] = methods[i];
                }
            }
            length = free;
            if (length <= 1)
            {
                // 0 -- not method found. We have to return non-null and let it fail with correct exception on call.
                // 1 -- no reason to continue search anyway.
                return(methods[0]);
            }
            // restrict search by parameters type
            free = 0;
            for (int i = 0; i < length; i++)
            {
                bool            match      = true;
                ParameterInfo[] parameters = methods[i].GetParameters();
                for (int par = 0; par < parameters.Length; par++)
                {
                    XPathResultType required = argTypes[par];
                    if (required == XPathResultType.Any)
                    {
                        continue;                        // Any means we don't know type and can't discriminate by it
                    }
                    XPathResultType actual = GetXPathType(parameters[par].ParameterType);
                    if (
                        actual != required &&
                        actual != XPathResultType.Any   // actual arg is object and we can pass everithing here.
                        )
                    {
                        match = false;
                        break;
                    }
                }
                if (match)
                {
                    methods[free++] = methods[i];
                }
            }
            length = free;
            return(methods[0]);
        }