Ejemplo n.º 1
0
         public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context) {

            string validatorUri = arguments[0].AsAtomicValues().Single().ToString();
            XPathNavigator source = arguments[1].AsNodes().Single().ToXPathNavigator();
            
            XPathNavigator report;

            if (arguments.Length == 2) {
               report = ValidationModule.ValidateWithSchematron(validatorUri, source);
            
            } else {

               string phase = arguments[2].AsAtomicValues().Select(x => x.ToString()).SingleOrDefault();

               if (arguments.Length == 3) {
                  report = ValidationModule.ValidateWithSchematron(validatorUri, source, phase);
               } else {

                  IEnumerable<XPathNavigator> parameters = arguments[3].AsNodes()
                     .Select(n => n.ToXPathNavigator());

                  report = ValidationModule.ValidateWithSchematron(validatorUri, source, phase, parameters);
               }
            }

            XdmNode result = report.ToXdmNode(this.itemFactory);

            return result.GetXdmEnumerator();
         }
Ejemplo n.º 2
0
         public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context) {

            XPathHttpClient client = new XPathHttpClient { 
               ItemFactory = this.itemFactory
            };

            XPathItem[] result;

            XPathNavigator request = arguments[0].AsNodes().Select(x => x.ToXPathNavigator()).SingleOrDefault();

            if (arguments.Length == 1) {
               result = client.SendRequest(request);
            
            } else {

               string href = arguments[1].AsAtomicValues().Select(x => x.ToString()).SingleOrDefault();

               if (arguments.Length == 2) {
                  result = client.SendRequest(request, href);
               
               } else {
                  IEnumerable<XPathItem> bodies = arguments[2].AsItems()
                     .ToXPathItems();

                  result = client.SendRequest(request, href, bodies);
               }
            }

            return result.ToXdmValue(itemFactory).GetXdmEnumerator();
         }
Ejemplo n.º 3
0
         public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context) {

            string value = arguments[0].AsAtomicValues().Single().ToString();

            ResponseModule.SetContentType(value);

            return XdmEmptySequence.INSTANCE.GetXdmEnumerator();
         }
Ejemplo n.º 4
0
         public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context) {

            string refUrl = RequestModule.ReferrerUrl();

            XdmValue result = refUrl.ToXdmValue();

            return result.GetXdmEnumerator();
         }
Ejemplo n.º 5
0
         public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context) {

            long code = (long)arguments[0].AsAtomicValues().Single().Value;
            string description = arguments[1].AsAtomicValues().Single().ToString();

            ResponseModule.SetStatus(code, description);

            return XdmEmptySequence.INSTANCE.GetXdmEnumerator();
         }
Ejemplo n.º 6
0
         public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context) {

            string name = arguments[0].AsAtomicValues().Single().ToString();

            string[] values = RequestModule.QueryString(name);

            XdmValue result = values.ToXdmValue();

            return result.GetXdmEnumerator();
         }
Ejemplo n.º 7
0
      public static IEnumerable<XdmNode> AsNodes(this IXdmEnumerator enumerator) {

         if (enumerator == null) {
            yield break;
         }

         while (enumerator.MoveNext()) {
            yield return (XdmNode)enumerator.Current;
         }
      }
Ejemplo n.º 8
0
            public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context)
            {
                XdmAtomicValue p1 = arguments[0].AsAtomicValues().SingleOrDefault();

                if (p1 == null) {
                   return EmptyEnumerator.INSTANCE;
                }

                return Math.Acos((double)p1.Value).ToXdmAtomicValue().GetXdmEnumerator();
            }
Ejemplo n.º 9
0
         public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context) {

            string relativePath = arguments[0].AsAtomicValues().Single().ToString();

            string absolutePath = UtilModule.AbsolutePath(relativePath);

            XdmValue result = absolutePath.ToXdmValue();

            return result.GetXdmEnumerator();
         }
Ejemplo n.º 10
0
         public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context) {

            IXdmEnumerator result;

            if (arguments != null || arguments.Length > 0) 
               result = arguments[0];
            else 
               result = XdmEmptySequence.INSTANCE.GetXdmEnumerator();

            return result;
         }
Ejemplo n.º 11
0
        public override JSequence call(JXPathContext context, JSequence [] argument)
        {
            SequenceEnumerator[] na = new SequenceEnumerator[argument.Length];
            for (int i = 0; i < na.Length; i++)
            {
                na[i] = new SequenceEnumerator(argument[i].iterate());
            }
            DynamicContext dc     = new DynamicContext(context);
            IXdmEnumerator result = functionCall.Call(na, dc);

            return(new net.sf.saxon.om.LazySequence(new DotNetSequenceIterator(result)));
        }
Ejemplo n.º 12
0
         public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context) {

            XPathSmtpClient client = new XPathSmtpClient { 
               ItemFactory = this.itemFactory
            };

            XPathNavigator message = arguments[0].AsNodes().Select(x => x.ToXPathNavigator()).Single();

            XPathNavigator result = client.Send(message);

            return result.ToXdmValue(this.itemFactory).GetXdmEnumerator();
         }
Ejemplo n.º 13
0
        public static IEnumerable <XdmAtomicValue> AsAtomicValues(this IXdmEnumerator enumerator)
        {
            if (enumerator == null)
            {
                yield break;
            }

            while (enumerator.MoveNext())
            {
                yield return((XdmAtomicValue)enumerator.Current);
            }
        }
Ejemplo n.º 14
0
        public static IEnumerable <XdmItem> AsItems(this IXdmEnumerator enumerator)
        {
            if (enumerator == null)
            {
                yield break;
            }

            while (enumerator.MoveNext())
            {
                yield return((XdmItem)enumerator.Current);
            }
        }
Ejemplo n.º 15
0
        public override JSequenceIterator call(JSequenceIterator[] arguments, JXPathContext context)
        {
            SequenceEnumerator[] na = new SequenceEnumerator[arguments.Length];
            for (int i = 0; i < na.Length; i++)
            {
                na[i] = new SequenceEnumerator(arguments[i]);
            }
            DynamicContext dc     = new DynamicContext(context);
            IXdmEnumerator result = functionCall.Call(na, dc);

            return(new DotNetSequenceIterator(result));
        }
Ejemplo n.º 16
0
         public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context) {

            string name = arguments[0].AsAtomicValues().Single().ToString();
            XdmItem value = arguments[1].AsItems().Single();

            object sessionVal = value.IsAtomic() ? 
               (object)value.ToString() : 
               (object)((XdmNode)value).ToXPathNavigator();

            SessionModule.Set(name, sessionVal);

            return XdmEmptySequence.INSTANCE.GetXdmEnumerator();
         }
         public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context) {

            IXdmEnumerator first = arguments[0];
            IXdmEnumerator second = arguments[1];

            first.MoveNext();
            second.MoveNext();

            Uri firstUri = (Uri)((XdmAtomicValue)first.Current).Value;
            Uri secondUri = (Uri)((XdmAtomicValue)second.Current).Value;

            return (IXdmEnumerator)new XdmAtomicValue(
               firstUri.MakeRelativeUri(secondUri)
            ).GetEnumerator();
         }
Ejemplo n.º 18
0
         public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context) {

            string components = arguments[0].AsAtomicValues().Single().ToString();

            string result;

            if (arguments.Length == 1) {
               result = RequestModule.ReferrerUrlComponents(components);
            } else {
               string format = arguments[1].AsAtomicValues().Single().ToString();

               result = RequestModule.ReferrerUrlComponents(components, format);
            }

            return result.ToXdmValue().GetXdmEnumerator();
         }
Ejemplo n.º 19
0
            public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context)
            {
                XdmItem[] items = arguments[0].AsItems().ToArray();
                XdmItem item;

                if (items.Length != 1
                   || (item = items[0]) is XdmNode) {

                   return Result("node-set");
                }

                if (item.IsAtomic()) {

                   XdmAtomicValue atomicVal = (XdmAtomicValue)item;

                   object typedVal = atomicVal.Value;

                   if (typedVal is string) {
                  return Result("string");
                   }

                   switch (Type.GetTypeCode(typedVal.GetType())) {
                  case TypeCode.Boolean:
                     return Result("boolean");

                  case TypeCode.Byte:
                  case TypeCode.Decimal:
                  case TypeCode.Double:
                  case TypeCode.Int16:
                  case TypeCode.Int32:
                  case TypeCode.Int64:
                  case TypeCode.SByte:
                  case TypeCode.Single:
                  case TypeCode.UInt16:
                  case TypeCode.UInt32:
                  case TypeCode.UInt64:
                     return Result("number");
                   }
                }

                return Result("external");
            }
Ejemplo n.º 20
0
 public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context)
 {
     return Math.PI.ToXdmAtomicValue().GetXdmEnumerator();
 }
Ejemplo n.º 21
0
         public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context) {

            XdmValue result = RequestModule.HttpMethod().ToXdmValue();

            return result.GetXdmEnumerator();
         }
 public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context)
 {
     arguments[0].MoveNext();
     var arg = (XdmAtomicValue)arguments[0].Current;
     string path = arg.Value.ToString();
     if(string.IsNullOrWhiteSpace(path))
         return EmptyEnumerator.INSTANCE;
     var nodeset = compiler.Evaluate(path, context.ContextItem);
     return (IXdmEnumerator)nodeset.GetEnumerator();
 }
Ejemplo n.º 23
0
         public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context) {

            XdmValue result = RequestModule.UrlAppRelativeFilePath().ToXdmValue();

            return result.GetXdmEnumerator();
         }
Ejemplo n.º 24
0
            public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context)
            {
                string xml = arguments[0].AsAtomicValues().Single().ToString();

                var parseOptions = new XmlParsingOptions {
                  ConformanceLevel = ConformanceLevel.Document,
                  BaseUri = new Uri("", UriKind.Relative) // Saxon requires a base URI
                };

                using (var reader = new StringReader(xml)) {

                   return this.itemFactory.CreateNodeReadOnly(reader, parseOptions)
                  .ToXdmNode(this.itemFactory)
                  .GetXdmEnumerator();
                }
            }
Ejemplo n.º 25
0
 public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context)
 {
     return arguments[0];
 }
Ejemplo n.º 26
0
 public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context)
 {
     if (defaultNamespace != null)
     {
         return (IXdmEnumerator)new XdmAtomicValue(defaultNamespace).GetEnumerator();
     }
     else
     {
         return EmptyEnumerator.INSTANCE;
     }
 }
Ejemplo n.º 27
0
            public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context)
            {
                XdmNode node = arguments[0].AsNodes().Single();

                var options = new XPathSerializationOptions();

                XdmItem arg2 = null;

                if (arguments.Length > 1
                   && (arg2 = arguments[1].AsItems().SingleOrDefault()) != null) {

                   if (arg2.IsAtomic()) {

                  string methodLexical = arg2.ToString();

                  QName method = (context.ContextItem == null || context.ContextItem.IsAtomic()) ?
                     new QName(methodLexical)
                     : new QName(methodLexical, (XdmNode)context.ContextItem);

                  options.Method = method.ToXmlQualifiedName();
                   }
                }

                Serializer serializer = this.itemFactory.CreateSerializer(options);

                if (arg2 != null
                   && !arg2.IsAtomic()) {

                   foreach (XdmNode attr in ((IXdmEnumerator)((XdmNode)arg2).EnumerateAxis(XdmAxis.Attribute)).AsNodes()) {
                  serializer.SetOutputProperty(attr.NodeName, attr.StringValue);
                   }
                }

                using (var writer = new StringWriter()) {

                   serializer.SetOutputWriter(writer);

                   this.itemFactory.processor.WriteXdmValue(node, serializer);

                   return writer.ToString().ToXdmAtomicValue().GetXdmEnumerator();
                }
            }
Ejemplo n.º 28
0
 public DotNetSequenceIterator(IXdmEnumerator iter)
 {
     this.iter = iter;
 }
Ejemplo n.º 29
0
 public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context)
 {
     Boolean exists = arguments[0].MoveNext();
     if (exists)
     {
         XdmAtomicValue arg = (XdmAtomicValue)arguments[0].Current;
         double val = (double)arg.Value;
         double sqrt = System.Math.Sqrt(val);
         XdmAtomicValue result = new XdmAtomicValue(sqrt);
         return (IXdmEnumerator)result.GetEnumerator();
     }
     else
     {
         return EmptyEnumerator.INSTANCE;
     }
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Method called at run time to evaluate the function.
 /// </summary>
 /// <param name="arguments">The values of the arguments to the function, supplied as iterators over XPath
 /// sequence values.</param>
 /// <param name="context">The dynamic context for evaluation of the function. This provides access
 /// to the context item, position, and size, and if required to internal data maintained by the Saxon
 /// engine.</param>
 /// <returns>An iterator over a sequence, representing the result of the extension function.
 /// Note that Saxon does not guarantee to read this sequence to completion, so calls on the iterator
 /// must have no side-effects. In rare circumstances (for example, when <code>last()</code> is
 /// used) Saxon may clone the returned iterator by calling its <c>GetAnother()</c> method, 
 /// allowing the function results to be read more than once.</returns>
 public abstract IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context);
Ejemplo n.º 31
0
         public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context) {

            XdmValue result = RequestModule.IsLocal().ToXdmItem();

            return result.GetXdmEnumerator();
         }