XQueryFunctionCliImpl.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. //
  2. // XQueryFunctionCliImple.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. //
  8. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. //
  30. // Runtime-level (native) implementation of XQuery 1.0 and XPath 2.0
  31. // Functions implementation. XQueryCliFunction
  32. // See XQuery 1.0 and XPath 2.0 Functions and Operators.
  33. //
  34. #if NET_2_0
  35. using System;
  36. using System.Collections;
  37. using System.Globalization;
  38. using System.IO;
  39. using System.Text.RegularExpressions;
  40. using System.Xml;
  41. using System.Xml.Query;
  42. using System.Xml.Schema;
  43. using System.Xml.XPath;
  44. namespace Mono.Xml.XPath2
  45. {
  46. public class XQueryFunctionCliImpl
  47. {
  48. internal static XmlSchemaType XmlTypeFromCliType (Type cliType)
  49. {
  50. switch (Type.GetTypeCode (cliType)) {
  51. case TypeCode.Int32:
  52. return XmlSchemaSimpleType.XsInt;
  53. case TypeCode.Decimal:
  54. return XmlSchemaSimpleType.XsDecimal;
  55. case TypeCode.Double:
  56. return XmlSchemaSimpleType.XsDouble;
  57. case TypeCode.Single:
  58. return XmlSchemaSimpleType.XsFloat;
  59. case TypeCode.Int64:
  60. return XmlSchemaSimpleType.XsLong;
  61. case TypeCode.Int16:
  62. return XmlSchemaSimpleType.XsShort;
  63. case TypeCode.UInt16:
  64. return XmlSchemaSimpleType.XsUnsignedShort;
  65. case TypeCode.UInt32:
  66. return XmlSchemaSimpleType.XsUnsignedInt;
  67. case TypeCode.String:
  68. return XmlSchemaSimpleType.XsString;
  69. case TypeCode.DateTime:
  70. return XmlSchemaSimpleType.XsDateTime;
  71. case TypeCode.Boolean:
  72. return XmlSchemaSimpleType.XsBoolean;
  73. }
  74. if (cliType == typeof (XmlQualifiedName))
  75. return XmlSchemaSimpleType.XsQName;
  76. return null;
  77. }
  78. private static XPathItem ToItem (object arg)
  79. {
  80. if (arg == null)
  81. return null;
  82. XPathItem item = arg as XPathItem;
  83. if (item != null)
  84. return item;
  85. XPathSequence seq = arg as XPathSequence;
  86. if (seq != null)
  87. return seq.MoveNext () ? seq.Current : null;
  88. return new XPathAtomicValue (arg, XmlTypeFromCliType (arg.GetType ()));
  89. }
  90. // Accessors
  91. public static XmlQualifiedName FnNodeName (XPathNavigator arg)
  92. {
  93. if (arg == null)
  94. return null;
  95. return arg.LocalName == String.Empty ?
  96. XmlQualifiedName.Empty :
  97. new XmlQualifiedName (arg.LocalName, arg.NamespaceURI);
  98. }
  99. public static bool FnNilled (XPathNavigator arg)
  100. {
  101. if (arg == null)
  102. throw new XmlQueryException ("Function nilled() does not allow empty sequence parameter.");
  103. IXmlSchemaInfo info = arg.NodeType == XPathNodeType.Element ? arg.SchemaInfo : null;
  104. return info != null && info.IsNil;
  105. }
  106. public static string FnString (XQueryContext context)
  107. {
  108. XPathItem item = context.CurrentItem;
  109. if (item == null)
  110. throw new ArgumentException ("FONC0001: undefined context item");
  111. return FnString (item);
  112. }
  113. [MonoTODO]
  114. public static string FnString (object arg)
  115. {
  116. if (arg == null)
  117. return String.Empty;
  118. XPathNavigator nav = arg as XPathNavigator;
  119. if (nav != null)
  120. return nav.Value;
  121. // FIXME: it should be exactly the same as "arg cast as xs:string"
  122. XPathItem item = ToItem (arg);
  123. return item != null ? XQueryConvert.ItemToString (item) : null;
  124. }
  125. [MonoTODO]
  126. public static XPathAtomicValue FnData (object arg)
  127. {
  128. // FIXME: parameter should be object []
  129. XPathNavigator nav = arg as XPathNavigator;
  130. if (nav != null) {
  131. XmlSchemaType st = nav.SchemaInfo != null ? nav.SchemaInfo.SchemaType : null;
  132. return new XPathAtomicValue (nav.TypedValue, st != null ? st : XmlSchemaComplexType.AnyType);
  133. }
  134. else
  135. return (XPathAtomicValue) arg;
  136. }
  137. public static string FnBaseUri (XPathNavigator nav)
  138. {
  139. return nav != null ? nav.BaseURI : null;
  140. }
  141. public static string FnDocumentUri (XPathNavigator nav)
  142. {
  143. if (nav == null)
  144. return null;
  145. XPathNavigator root = nav.Clone ();
  146. root.MoveToRoot ();
  147. return root.BaseURI;
  148. }
  149. // Error
  150. [MonoTODO]
  151. public static void FnError (object arg)
  152. {
  153. throw new NotImplementedException ();
  154. }
  155. // Trace
  156. [MonoTODO]
  157. public static object FnTrace (XQueryContext ctx, object value, string label)
  158. {
  159. if (value == null)
  160. return new XPathEmptySequence (ctx);
  161. XPathSequence seq = value as XPathSequence;
  162. if (seq == null) {
  163. XPathAtomicValue av = value as XPathAtomicValue;
  164. if (av == null)
  165. av = new XPathAtomicValue (value,
  166. XmlSchemaType.GetBuiltInType (
  167. XPathAtomicValue.XmlTypeCodeFromRuntimeType (
  168. value.GetType (), true)));
  169. seq = new SingleItemIterator (av, ctx);
  170. }
  171. return new TracingIterator (seq, label);
  172. }
  173. // Numeric Operation
  174. [MonoTODO]
  175. public static object FnAbs (object arg)
  176. {
  177. if (arg is int)
  178. return System.Math.Abs ((int) arg);
  179. if (arg is long)
  180. return System.Math.Abs ((long) arg);
  181. else if (arg is decimal)
  182. return System.Math.Abs ((decimal) arg);
  183. else if (arg is double)
  184. return System.Math.Abs ((double) arg);
  185. else if (arg is float)
  186. return System.Math.Abs ((float) arg);
  187. else if (arg is short)
  188. return System.Math.Abs ((short) arg);
  189. else if (arg is uint || arg is ulong || arg is ushort)
  190. return arg;
  191. return null;
  192. }
  193. [MonoTODO]
  194. public static object FnCeiling (object arg)
  195. {
  196. if (arg is decimal) {
  197. decimal d = (decimal) arg;
  198. decimal d2 = Decimal.Floor (d);
  199. return d2 != d ? d2 + 1 : d2;
  200. }
  201. else if (arg is double || arg is float)
  202. return System.Math.Ceiling ((double) arg);
  203. else if (arg is int || arg is long || arg is short || arg is uint || arg is ulong || arg is ushort)
  204. return arg;
  205. return null;
  206. }
  207. [MonoTODO]
  208. public static object FnFloor (object arg)
  209. {
  210. if (arg is decimal)
  211. return Decimal.Floor ((decimal) arg);
  212. else if (arg is double || arg is float)
  213. return System.Math.Floor ((double) arg);
  214. else if (arg is int || arg is long || arg is short || arg is uint || arg is ulong || arg is ushort)
  215. return arg;
  216. return null;
  217. }
  218. [MonoTODO]
  219. public static object FnRound (object arg)
  220. {
  221. if (arg is decimal)
  222. return Decimal.Round ((decimal) arg, 0);
  223. else if (arg is double || arg is float)
  224. return System.Math.Round ((double) arg);
  225. else if (arg is int || arg is long || arg is short || arg is uint || arg is ulong || arg is ushort)
  226. return arg;
  227. return null;
  228. }
  229. [MonoTODO]
  230. public static object FnRoundHalfToEven (object arg)
  231. {
  232. throw new NotImplementedException ();
  233. }
  234. [MonoTODO]
  235. public static string FnCodepointsToString (int [] arg)
  236. {
  237. throw new NotImplementedException ();
  238. }
  239. [MonoTODO]
  240. public static int [] FnStringToCodepoints (string arg)
  241. {
  242. throw new NotImplementedException ();
  243. }
  244. public static int FnCompare (XQueryContext ctx, string s1, string s2)
  245. {
  246. return FnCompare (s1, s2, ctx.DefaultCollation);
  247. }
  248. public static int FnCompare (XQueryContext ctx, string s1, string s2, string collation)
  249. {
  250. return FnCompare (s1, s2, ctx.GetCulture (collation));
  251. }
  252. private static int FnCompare (string s1, string s2, CultureInfo ci)
  253. {
  254. return ci.CompareInfo.Compare (s1, s2);
  255. }
  256. public static string FnConcat (object o1, object o2)
  257. {
  258. return String.Concat (o1, o2);
  259. }
  260. public static string FnStringJoin (string [] strings, string separator)
  261. {
  262. return String.Join (separator, strings);
  263. }
  264. public static string FnSubstring (string src, double loc)
  265. {
  266. return src.Substring ((int) loc);
  267. }
  268. public static string FnSubstring (string src, double loc, double length)
  269. {
  270. return src.Substring ((int) loc, (int) length);
  271. }
  272. public static int FnStringLength (XQueryContext ctx)
  273. {
  274. return FnString (ctx).Length;
  275. }
  276. public static int FnStringLength (string s)
  277. {
  278. return s.Length;
  279. }
  280. public static string FnNormalizeSpace (XQueryContext ctx)
  281. {
  282. return FnNormalizeSpace (FnString (ctx));
  283. }
  284. [MonoTODO]
  285. public static string FnNormalizeSpace (string s)
  286. {
  287. throw new NotImplementedException ();
  288. }
  289. public static string FnNormalizeUnicode (string arg)
  290. {
  291. return FnNormalizeUnicode (arg, "NFC");
  292. }
  293. [MonoTODO]
  294. public static string FnNormalizeUnicode (string arg, string normalizationForm)
  295. {
  296. throw new NotImplementedException ();
  297. }
  298. public static string FnUpperCase (string arg)
  299. {
  300. // FIXME: supply culture
  301. return arg.ToUpper ();
  302. }
  303. public static string FnLowerCase (string arg)
  304. {
  305. // FIXME: supply culture
  306. return arg.ToLower ();
  307. }
  308. public static string FnTranslate (string arg, string mapString, string transString)
  309. {
  310. return arg == null ? null : arg.Replace (mapString, transString);
  311. }
  312. [MonoTODO]
  313. public static string FnEscapeUri (string uriPart, bool escapeReserved)
  314. {
  315. throw new NotImplementedException ();
  316. }
  317. public static bool FnContains (XQueryContext ctx, string arg1, string arg2)
  318. {
  319. return FnContains (arg1, arg2, ctx.DefaultCollation);
  320. }
  321. public static bool FnContains (XQueryContext ctx, string arg1, string arg2, string collation)
  322. {
  323. return FnContains (arg1, arg2, ctx.GetCulture (collation));
  324. }
  325. private static bool FnContains (string arg1, string arg2, CultureInfo ci)
  326. {
  327. if (arg1 == null)
  328. arg1 = String.Empty;
  329. if (arg2 == null)
  330. arg2 = String.Empty;
  331. if (arg2 == String.Empty)
  332. return true;
  333. return ci.CompareInfo.IndexOf (arg1, arg2) >= 0;
  334. }
  335. public static bool FnStartsWith (XQueryContext ctx, string arg1, string arg2)
  336. {
  337. return FnStartsWith (arg1, arg2, ctx.DefaultCollation);
  338. }
  339. public static bool FnStartsWith (XQueryContext ctx, string arg1, string arg2, string collation)
  340. {
  341. return FnStartsWith (arg1, arg2, ctx.GetCulture (collation));
  342. }
  343. private static bool FnStartsWith (string arg1, string arg2, CultureInfo ci)
  344. {
  345. return ci.CompareInfo.IsPrefix (arg1, arg2);
  346. }
  347. public static bool FnEndsWith (XQueryContext ctx, string arg1, string arg2)
  348. {
  349. return FnEndsWith (arg1, arg2, ctx.DefaultCollation);
  350. }
  351. public static bool FnEndsWith (XQueryContext ctx, string arg1, string arg2, string collation)
  352. {
  353. return FnEndsWith (arg1, arg2, ctx.GetCulture (collation));
  354. }
  355. private static bool FnEndsWith (string arg1, string arg2, CultureInfo ci)
  356. {
  357. return ci.CompareInfo.IsSuffix (arg1, arg2);
  358. }
  359. public static string FnSubstringBefore (XQueryContext ctx, string arg1, string arg2)
  360. {
  361. return FnSubstringBefore (arg1, arg2, ctx.DefaultCollation);
  362. }
  363. public static string FnSubstringBefore (XQueryContext ctx, string arg1, string arg2, string collation)
  364. {
  365. return FnSubstringBefore (arg1, arg2, ctx.GetCulture (collation));
  366. }
  367. private static string FnSubstringBefore (string arg1, string arg2, CultureInfo ci)
  368. {
  369. int index = ci.CompareInfo.IndexOf (arg1, arg2);
  370. return arg1.Substring (0, index);
  371. }
  372. public static string FnSubstringAfter (XQueryContext ctx, string arg1, string arg2)
  373. {
  374. return FnSubstringAfter (arg1, arg2, ctx.DefaultCollation);
  375. }
  376. public static string FnSubstringAfter (XQueryContext ctx, string arg1, string arg2, string collation)
  377. {
  378. return FnSubstringAfter (arg1, arg2, ctx.GetCulture (collation));
  379. }
  380. private static string FnSubstringAfter (string arg1, string arg2, CultureInfo ci)
  381. {
  382. int index = ci.CompareInfo.IndexOf (arg1, arg2);
  383. return arg1.Substring (index);
  384. }
  385. public static bool FnMatches (string input, string pattern)
  386. {
  387. return new Regex (pattern).IsMatch (input);
  388. }
  389. [MonoTODO]
  390. public static bool FnMatches (string input, string pattern, string flags)
  391. {
  392. throw new NotImplementedException ();
  393. }
  394. public static string FnReplace (string input, string pattern, string replace)
  395. {
  396. return new Regex (pattern).Replace (input, replace);
  397. }
  398. [MonoTODO]
  399. public static string FnReplace (string input, string pattern, string replace, string flags)
  400. {
  401. throw new NotImplementedException ();
  402. }
  403. public static string [] FnTokenize (string input, string pattern)
  404. {
  405. return new Regex (pattern).Split (input);
  406. }
  407. [MonoTODO]
  408. public static string [] FnTokenize (string input, string pattern, string flags)
  409. {
  410. throw new NotImplementedException ();
  411. }
  412. public static string FnResolveUri (XQueryContext ctx, string relUri)
  413. {
  414. return new Uri (new Uri (ctx.StaticContext.BaseUri), relUri).ToString ();
  415. }
  416. public static string FnResolveUri (string relUri, string baseUri)
  417. {
  418. return new Uri (new Uri (baseUri), relUri).ToString ();
  419. }
  420. public static object FnTrue ()
  421. {
  422. return true;
  423. }
  424. public static object FnFalse ()
  425. {
  426. return false;
  427. }
  428. public static object FnNot (bool value)
  429. {
  430. return !value;
  431. }
  432. // FIXME: add a bunch of annoying datetime functions
  433. [MonoTODO]
  434. public static object FnResolveQName ()
  435. {
  436. throw new NotImplementedException ();
  437. }
  438. [MonoTODO]
  439. public static object FnExpandQName ()
  440. {
  441. throw new NotImplementedException ();
  442. }
  443. public static string FnLocalNameFromQName (XmlQualifiedName name)
  444. {
  445. return name != null ? name.Name : null;
  446. }
  447. public static object FnNamespaceUriFromQName (XmlQualifiedName name)
  448. {
  449. return name != null ? name.Namespace : null;
  450. }
  451. public static object FnNamespaceUriForPrefix (XQueryContext context, string prefix)
  452. {
  453. return prefix != null ? context.LookupNamespace (prefix) : null;
  454. }
  455. public static string [] FnInScopePrefixes (XQueryContext context)
  456. {
  457. IDictionary dict = context.GetNamespacesInScope (XmlNamespaceScope.ExcludeXml);
  458. ArrayList keys = new ArrayList (dict.Keys);
  459. return keys.ToArray (typeof (string)) as string [];
  460. }
  461. public static string FnName (XPathNavigator nav)
  462. {
  463. return nav != null ? nav.Name : null;
  464. }
  465. public static string FnLocalName (XPathNavigator nav)
  466. {
  467. return nav != null ? nav.LocalName : null;
  468. }
  469. public static string FnNamespaceUri (XPathNavigator nav)
  470. {
  471. return nav != null ? nav.NamespaceURI : null;
  472. }
  473. public static double FnNumber (XQueryContext ctx)
  474. {
  475. return FnNumber (ctx.CurrentItem);
  476. }
  477. public static double FnNumber (object arg)
  478. {
  479. if (arg == null)
  480. throw new XmlQueryException ("Context item could not be ndetermined during number() evaluation.");
  481. XPathItem item = ToItem (arg);
  482. return XQueryConvert.ItemToDouble (item);
  483. }
  484. public static bool FnLang (XQueryContext ctx, string testLang)
  485. {
  486. return FnLang (testLang, ctx.CurrentNode);
  487. }
  488. public static bool FnLang (string testLang, XPathNavigator node)
  489. {
  490. return testLang == node.XmlLang;
  491. }
  492. public static XPathNavigator FnRoot (XQueryContext ctx)
  493. {
  494. if (ctx.CurrentItem == null)
  495. throw new XmlQueryException ("FONC0001: Undefined context item.");
  496. if (ctx.CurrentNode == null)
  497. throw new XmlQueryException ("FOTY0011: Context item is not a node.");
  498. return FnRoot (ctx.CurrentNode);
  499. }
  500. public static XPathNavigator FnRoot (XPathNavigator node)
  501. {
  502. if (node == null)
  503. return null;
  504. XPathNavigator root = node.Clone ();
  505. root.MoveToRoot ();
  506. return root;
  507. }
  508. public static bool FnBoolean (IEnumerator e)
  509. {
  510. if (!e.MoveNext ())
  511. return false;
  512. XPathItem item = e.Current as XPathItem;
  513. if (e.MoveNext ())
  514. return true;
  515. return XQueryConvert.ItemToBoolean (item);
  516. }
  517. public static XPathSequence FnIndexOf (XQueryContext ctx, XPathSequence items, XPathItem item)
  518. {
  519. return FnIndexOf (ctx, items, item, ctx.DefaultCollation);
  520. }
  521. public static XPathSequence FnIndexOf (XQueryContext ctx, XPathSequence items, XPathItem item, CultureInfo ci)
  522. {
  523. ArrayList al = new ArrayList ();
  524. IEnumerator e = items.GetEnumerator ();
  525. for (int i = 0; e.MoveNext (); i++) {
  526. XPathItem iter = e.Current as XPathItem;
  527. if (iter.XmlType.TypeCode == XmlTypeCode.String) {
  528. if (ci.CompareInfo.Compare (iter.Value, item.Value) == 0)
  529. al.Add (i);
  530. }
  531. else {
  532. IComparable ic = (IComparable) iter.TypedValue;
  533. if (ic.CompareTo ((IComparable) item.TypedValue) == 0)
  534. al.Add (i);
  535. }
  536. }
  537. return new ListIterator (ctx, al);
  538. }
  539. public static bool FnEmpty (XPathSequence e)
  540. {
  541. if (e is XPathEmptySequence)
  542. return true;
  543. return !e.GetEnumerator ().MoveNext ();
  544. }
  545. public static object FnExists (XPathSequence e)
  546. {
  547. if (e is XPathEmptySequence)
  548. return false;
  549. return e.GetEnumerator ().MoveNext ();
  550. }
  551. [MonoTODO]
  552. public static object FnDistinctValues (XQueryContext ctx, XPathSequence items)
  553. {
  554. throw new NotImplementedException ();
  555. }
  556. [MonoTODO]
  557. public static object FnDistinctValues (XQueryContext ctx, XPathSequence items, string collation)
  558. {
  559. throw new NotImplementedException ();
  560. }
  561. [MonoTODO]
  562. public static XPathSequence FnInsertBefore (XPathSequence target, int position, XPathSequence inserts)
  563. {
  564. throw new NotImplementedException ();
  565. }
  566. [MonoTODO]
  567. public static XPathSequence FnRemove (XPathSequence target, int position)
  568. {
  569. throw new NotImplementedException ();
  570. }
  571. [MonoTODO]
  572. public static XPathSequence FnReverse (XPathSequence arg)
  573. {
  574. throw new NotImplementedException ();
  575. }
  576. [MonoTODO]
  577. public static object FnSubsequence (XPathSequence sourceSeq, double startingLoc)
  578. {
  579. throw new NotImplementedException ();
  580. }
  581. [MonoTODO]
  582. public static object FnSubsequence (XPathSequence sourceSeq, double startingLoc, double length)
  583. {
  584. throw new NotImplementedException ();
  585. }
  586. [MonoTODO]
  587. // Basically it should be optimized by XQueryASTCompiler
  588. public static XPathSequence FnUnordered (XPathSequence e)
  589. {
  590. return e;
  591. }
  592. [MonoTODO]
  593. public static object FnZeroOrMore (XPathSequence e)
  594. {
  595. throw new NotImplementedException ();
  596. }
  597. [MonoTODO]
  598. public static object FnOneOrMore (XPathSequence e)
  599. {
  600. throw new NotImplementedException ();
  601. }
  602. [MonoTODO]
  603. public static object FnExactlyOne (XPathSequence e)
  604. {
  605. throw new NotImplementedException ();
  606. }
  607. [MonoTODO]
  608. public static object FnDeepEqual (XQueryContext ctx, XPathSequence p1, XPathSequence p2)
  609. {
  610. throw new NotImplementedException ();
  611. }
  612. [MonoTODO]
  613. public static object FnDeepEqual (XQueryContext ctx, XPathSequence p1, XPathSequence p2, string collation)
  614. {
  615. throw new NotImplementedException ();
  616. }
  617. public static int FnCount (XPathSequence e)
  618. {
  619. if (e == null)
  620. return 0;
  621. return e.Count;
  622. }
  623. [MonoTODO]
  624. public static object FnAvg (XPathSequence e)
  625. {
  626. throw new NotImplementedException ();
  627. }
  628. [MonoTODO]
  629. public static object FnMax (XQueryContext ctx, XPathSequence e)
  630. {
  631. throw new NotImplementedException ();
  632. }
  633. [MonoTODO]
  634. public static object FnMax (XQueryContext ctx, XPathSequence e, string collation)
  635. {
  636. throw new NotImplementedException ();
  637. }
  638. [MonoTODO]
  639. public static object FnMin (XQueryContext ctx, XPathSequence e)
  640. {
  641. throw new NotImplementedException ();
  642. }
  643. [MonoTODO]
  644. public static object FnMin (XQueryContext ctx, XPathSequence e, string collation)
  645. {
  646. throw new NotImplementedException ();
  647. }
  648. [MonoTODO]
  649. public static object FnSum (XPathSequence e)
  650. {
  651. throw new NotImplementedException ();
  652. }
  653. [MonoTODO]
  654. public static object FnSum (XPathSequence e, XPathItem zero)
  655. {
  656. throw new NotImplementedException ();
  657. }
  658. public static XPathNavigator FnId (XQueryContext ctx, string id)
  659. {
  660. return FnId (id, ctx.CurrentNode);
  661. }
  662. public static XPathNavigator FnId (string id, XPathNavigator nav)
  663. {
  664. XPathNavigator node = nav.Clone ();
  665. return node.MoveToId (id) ? node : null;
  666. }
  667. [MonoTODO]
  668. public static object FnIdRef (XQueryContext ctx, string arg)
  669. {
  670. return FnIdRef (arg, ctx.CurrentNode);
  671. }
  672. [MonoTODO]
  673. public static object FnIdRef (string arg, XPathNavigator node)
  674. {
  675. throw new NotImplementedException ();
  676. }
  677. public static XPathNavigator FnDoc (XQueryContext ctx, string uri)
  678. {
  679. XmlResolver res = ctx.ContextManager.ExtDocResolver;
  680. string baseUriString = ctx.StaticContext.BaseUri;
  681. Uri baseUri = null;
  682. if (baseUriString != null && baseUriString != String.Empty)
  683. baseUri = new Uri (baseUriString);
  684. Uri relUri = res.ResolveUri (baseUri, uri);
  685. Stream s = res.GetEntity (relUri, null, typeof (Stream)) as Stream;
  686. try {
  687. XPathDocument doc = new XPathDocument (new XmlValidatingReader (new XmlTextReader (s)), XmlSpace.Preserve);
  688. return doc.CreateNavigator ();
  689. } finally {
  690. s.Close ();
  691. }
  692. }
  693. public static XPathSequence FnCollection (XQueryContext ctx, string name)
  694. {
  695. return ctx.ResolveCollection (name);
  696. }
  697. [XQueryFunctionContext]
  698. public static int FnPosition (XPathSequence current)
  699. {
  700. return current.Position;
  701. }
  702. [XQueryFunctionContext]
  703. public static int FnLast (XPathSequence current)
  704. {
  705. return current.Count;
  706. }
  707. public static DateTime FnCurrentDateTime ()
  708. {
  709. return DateTime.Now;
  710. }
  711. public static DateTime FnCurrentDate ()
  712. {
  713. return DateTime.Today;
  714. }
  715. public static DateTime FnCurrentTime ()
  716. {
  717. return new DateTime (DateTime.Now.TimeOfDay.Ticks);
  718. }
  719. [MonoTODO]
  720. public static object FnDefaultCollation ()
  721. {
  722. throw new NotImplementedException ();
  723. }
  724. [MonoTODO]
  725. public static object FnImplicitTimeZone ()
  726. {
  727. throw new NotImplementedException ();
  728. }
  729. }
  730. }
  731. #endif