PageRenderTime 28ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/android/generated/android/util/internal/XmlUtils.cs

https://bitbucket.org/festevezga/xobotos
C# | 1090 lines | 802 code | 25 blank | 263 comment | 160 complexity | c3120f24cfcf30b138c9e94fc1c9759b MD5 | raw file
  1. using Sharpen;
  2. namespace android.util.@internal
  3. {
  4. /// <summary>
  5. /// <hide></hide>
  6. ///
  7. /// </summary>
  8. [Sharpen.Sharpened]
  9. public class XmlUtils
  10. {
  11. /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
  12. /// <exception cref="System.IO.IOException"></exception>
  13. public static void skipCurrentTag(org.xmlpull.v1.XmlPullParser parser)
  14. {
  15. int outerDepth = parser.getDepth();
  16. int type;
  17. while ((type = parser.next()) != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT &&
  18. (type != org.xmlpull.v1.XmlPullParserClass.END_TAG || parser.getDepth() > outerDepth
  19. ))
  20. {
  21. }
  22. }
  23. public static int convertValueToList(java.lang.CharSequence value, string[] options
  24. , int defaultValue)
  25. {
  26. if (null != value)
  27. {
  28. {
  29. for (int i = 0; i < options.Length; i++)
  30. {
  31. if (value.Equals(options[i]))
  32. {
  33. return i;
  34. }
  35. }
  36. }
  37. }
  38. return defaultValue;
  39. }
  40. public static bool convertValueToBoolean(java.lang.CharSequence value, bool defaultValue
  41. )
  42. {
  43. bool result = false;
  44. if (null == value)
  45. {
  46. return defaultValue;
  47. }
  48. if (value.Equals("1") || value.Equals("true") || value.Equals("TRUE"))
  49. {
  50. result = true;
  51. }
  52. return result;
  53. }
  54. public static int convertValueToInt(java.lang.CharSequence charSeq, int defaultValue
  55. )
  56. {
  57. if (null == charSeq)
  58. {
  59. return defaultValue;
  60. }
  61. string nm = charSeq.ToString();
  62. // XXX This code is copied from Integer.decode() so we don't
  63. // have to instantiate an Integer!
  64. int value;
  65. int sign = 1;
  66. int index = 0;
  67. int len = nm.Length;
  68. int @base = 10;
  69. if ('-' == nm[0])
  70. {
  71. sign = -1;
  72. index++;
  73. }
  74. if ('0' == nm[index])
  75. {
  76. // Quick check for a zero by itself
  77. if (index == (len - 1))
  78. {
  79. return 0;
  80. }
  81. char c = nm[index + 1];
  82. if ('x' == c || 'X' == c)
  83. {
  84. index += 2;
  85. @base = 16;
  86. }
  87. else
  88. {
  89. index++;
  90. @base = 8;
  91. }
  92. }
  93. else
  94. {
  95. if ('#' == nm[index])
  96. {
  97. index++;
  98. @base = 16;
  99. }
  100. }
  101. return System.Convert.ToInt32(Sharpen.StringHelper.Substring(nm, index), @base) *
  102. sign;
  103. }
  104. public static int convertValueToUnsignedInt(string value, int defaultValue)
  105. {
  106. if (null == value)
  107. {
  108. return defaultValue;
  109. }
  110. return parseUnsignedIntAttribute(java.lang.CharSequenceProxy.Wrap(value));
  111. }
  112. public static int parseUnsignedIntAttribute(java.lang.CharSequence charSeq)
  113. {
  114. string value = charSeq.ToString();
  115. long bits;
  116. int index = 0;
  117. int len = value.Length;
  118. int @base = 10;
  119. if ('0' == value[index])
  120. {
  121. // Quick check for zero by itself
  122. if (index == (len - 1))
  123. {
  124. return 0;
  125. }
  126. char c = value[index + 1];
  127. if ('x' == c || 'X' == c)
  128. {
  129. // check for hex
  130. index += 2;
  131. @base = 16;
  132. }
  133. else
  134. {
  135. // check for octal
  136. index++;
  137. @base = 8;
  138. }
  139. }
  140. else
  141. {
  142. if ('#' == value[index])
  143. {
  144. index++;
  145. @base = 16;
  146. }
  147. }
  148. return (int)Sharpen.Util.ParseLong(Sharpen.StringHelper.Substring(value, index),
  149. @base);
  150. }
  151. [Sharpen.Stub]
  152. public static void writeMapXml(java.util.Map<object, object> val, java.io.OutputStream
  153. @out)
  154. {
  155. throw new System.NotImplementedException();
  156. }
  157. /// <summary>Flatten a List into an output stream as XML.</summary>
  158. /// <remarks>
  159. /// Flatten a List into an output stream as XML. The list can later be
  160. /// read back with readListXml().
  161. /// </remarks>
  162. /// <param name="val">The list to be flattened.</param>
  163. /// <param name="out">Where to write the XML data.</param>
  164. /// <seealso cref="writeListXml(java.util.List{E}, string, org.xmlpull.v1.XmlSerializer)
  165. /// ">writeListXml(java.util.List&lt;E&gt;, string, org.xmlpull.v1.XmlSerializer)</seealso>
  166. /// <seealso cref="writeMapXml(java.util.Map{K, V}, java.io.OutputStream)">writeMapXml(java.util.Map&lt;K, V&gt;, java.io.OutputStream)
  167. /// </seealso>
  168. /// <seealso cref="writeValueXml(object, string, org.xmlpull.v1.XmlSerializer)">writeValueXml(object, string, org.xmlpull.v1.XmlSerializer)
  169. /// </seealso>
  170. /// <seealso cref="readListXml(java.io.InputStream)">readListXml(java.io.InputStream)
  171. /// </seealso>
  172. /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
  173. /// <exception cref="System.IO.IOException"></exception>
  174. public static void writeListXml(java.util.List<object> val, java.io.OutputStream
  175. @out)
  176. {
  177. org.xmlpull.v1.XmlSerializer serializer = android.util.Xml.newSerializer();
  178. serializer.setOutput(@out, "utf-8");
  179. serializer.startDocument(null, true);
  180. serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true
  181. );
  182. writeListXml(val, null, serializer);
  183. serializer.endDocument();
  184. }
  185. [Sharpen.Stub]
  186. public static void writeMapXml(java.util.Map<object, object> val, string name, org.xmlpull.v1.XmlSerializer
  187. @out)
  188. {
  189. throw new System.NotImplementedException();
  190. }
  191. /// <summary>Flatten a List into an XmlSerializer.</summary>
  192. /// <remarks>
  193. /// Flatten a List into an XmlSerializer. The list can later be read back
  194. /// with readThisListXml().
  195. /// </remarks>
  196. /// <param name="val">The list to be flattened.</param>
  197. /// <param name="name">
  198. /// Name attribute to include with this list's tag, or null for
  199. /// none.
  200. /// </param>
  201. /// <param name="out">XmlSerializer to write the list into.</param>
  202. /// <seealso cref="writeListXml(java.util.List{E}, java.io.OutputStream)">writeListXml(java.util.List&lt;E&gt;, java.io.OutputStream)
  203. /// </seealso>
  204. /// <seealso cref="writeMapXml(java.util.Map{K, V}, java.io.OutputStream)">writeMapXml(java.util.Map&lt;K, V&gt;, java.io.OutputStream)
  205. /// </seealso>
  206. /// <seealso cref="writeValueXml(object, string, org.xmlpull.v1.XmlSerializer)">writeValueXml(object, string, org.xmlpull.v1.XmlSerializer)
  207. /// </seealso>
  208. /// <seealso cref="readListXml(java.io.InputStream)">readListXml(java.io.InputStream)
  209. /// </seealso>
  210. /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
  211. /// <exception cref="System.IO.IOException"></exception>
  212. public static void writeListXml(java.util.List<object> val, string name, org.xmlpull.v1.XmlSerializer
  213. @out)
  214. {
  215. if (val == null)
  216. {
  217. @out.startTag(null, "null");
  218. @out.endTag(null, "null");
  219. return;
  220. }
  221. @out.startTag(null, "list");
  222. if (name != null)
  223. {
  224. @out.attribute(null, "name", name);
  225. }
  226. int N = val.size();
  227. int i = 0;
  228. while (i < N)
  229. {
  230. writeValueXml(val.get(i), null, @out);
  231. i++;
  232. }
  233. @out.endTag(null, "list");
  234. }
  235. /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
  236. /// <exception cref="System.IO.IOException"></exception>
  237. public static void writeSetXml(java.util.Set<object> val, string name, org.xmlpull.v1.XmlSerializer
  238. @out)
  239. {
  240. if (val == null)
  241. {
  242. @out.startTag(null, "null");
  243. @out.endTag(null, "null");
  244. return;
  245. }
  246. @out.startTag(null, "set");
  247. if (name != null)
  248. {
  249. @out.attribute(null, "name", name);
  250. }
  251. foreach (object v in Sharpen.IterableProxy.Create(val))
  252. {
  253. writeValueXml(v, null, @out);
  254. }
  255. @out.endTag(null, "set");
  256. }
  257. /// <summary>Flatten a byte[] into an XmlSerializer.</summary>
  258. /// <remarks>
  259. /// Flatten a byte[] into an XmlSerializer. The list can later be read back
  260. /// with readThisByteArrayXml().
  261. /// </remarks>
  262. /// <param name="val">The byte array to be flattened.</param>
  263. /// <param name="name">
  264. /// Name attribute to include with this array's tag, or null for
  265. /// none.
  266. /// </param>
  267. /// <param name="out">XmlSerializer to write the array into.</param>
  268. /// <seealso cref="writeMapXml(java.util.Map{K, V}, java.io.OutputStream)">writeMapXml(java.util.Map&lt;K, V&gt;, java.io.OutputStream)
  269. /// </seealso>
  270. /// <seealso cref="writeValueXml(object, string, org.xmlpull.v1.XmlSerializer)">writeValueXml(object, string, org.xmlpull.v1.XmlSerializer)
  271. /// </seealso>
  272. /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
  273. /// <exception cref="System.IO.IOException"></exception>
  274. public static void writeByteArrayXml(byte[] val, string name, org.xmlpull.v1.XmlSerializer
  275. @out)
  276. {
  277. if (val == null)
  278. {
  279. @out.startTag(null, "null");
  280. @out.endTag(null, "null");
  281. return;
  282. }
  283. @out.startTag(null, "byte-array");
  284. if (name != null)
  285. {
  286. @out.attribute(null, "name", name);
  287. }
  288. int N = val.Length;
  289. @out.attribute(null, "num", System.Convert.ToString(N));
  290. java.lang.StringBuilder sb = new java.lang.StringBuilder(val.Length * 2);
  291. {
  292. for (int i = 0; i < N; i++)
  293. {
  294. int b = val[i];
  295. int h = b >> 4;
  296. sb.append(h >= 10 ? ('a' + h - 10) : ('0' + h));
  297. h = b & unchecked((int)(0xff));
  298. sb.append(h >= 10 ? ('a' + h - 10) : ('0' + h));
  299. }
  300. }
  301. @out.text(sb.ToString());
  302. @out.endTag(null, "byte-array");
  303. }
  304. /// <summary>Flatten an int[] into an XmlSerializer.</summary>
  305. /// <remarks>
  306. /// Flatten an int[] into an XmlSerializer. The list can later be read back
  307. /// with readThisIntArrayXml().
  308. /// </remarks>
  309. /// <param name="val">The int array to be flattened.</param>
  310. /// <param name="name">
  311. /// Name attribute to include with this array's tag, or null for
  312. /// none.
  313. /// </param>
  314. /// <param name="out">XmlSerializer to write the array into.</param>
  315. /// <seealso cref="writeMapXml(java.util.Map{K, V}, java.io.OutputStream)">writeMapXml(java.util.Map&lt;K, V&gt;, java.io.OutputStream)
  316. /// </seealso>
  317. /// <seealso cref="writeValueXml(object, string, org.xmlpull.v1.XmlSerializer)">writeValueXml(object, string, org.xmlpull.v1.XmlSerializer)
  318. /// </seealso>
  319. /// <seealso cref="readThisIntArrayXml(org.xmlpull.v1.XmlPullParser, string, string[])
  320. /// ">readThisIntArrayXml(org.xmlpull.v1.XmlPullParser, string, string[])</seealso>
  321. /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
  322. /// <exception cref="System.IO.IOException"></exception>
  323. public static void writeIntArrayXml(int[] val, string name, org.xmlpull.v1.XmlSerializer
  324. @out)
  325. {
  326. if (val == null)
  327. {
  328. @out.startTag(null, "null");
  329. @out.endTag(null, "null");
  330. return;
  331. }
  332. @out.startTag(null, "int-array");
  333. if (name != null)
  334. {
  335. @out.attribute(null, "name", name);
  336. }
  337. int N = val.Length;
  338. @out.attribute(null, "num", System.Convert.ToString(N));
  339. {
  340. for (int i = 0; i < N; i++)
  341. {
  342. @out.startTag(null, "item");
  343. @out.attribute(null, "value", System.Convert.ToString(val[i]));
  344. @out.endTag(null, "item");
  345. }
  346. }
  347. @out.endTag(null, "int-array");
  348. }
  349. /// <summary>Flatten an object's value into an XmlSerializer.</summary>
  350. /// <remarks>
  351. /// Flatten an object's value into an XmlSerializer. The value can later
  352. /// be read back with readThisValueXml().
  353. /// Currently supported value types are: null, String, Integer, Long,
  354. /// Float, Double Boolean, Map, List.
  355. /// </remarks>
  356. /// <param name="v">The object to be flattened.</param>
  357. /// <param name="name">
  358. /// Name attribute to include with this value's tag, or null
  359. /// for none.
  360. /// </param>
  361. /// <param name="out">XmlSerializer to write the object into.</param>
  362. /// <seealso cref="writeMapXml(java.util.Map{K, V}, java.io.OutputStream)">writeMapXml(java.util.Map&lt;K, V&gt;, java.io.OutputStream)
  363. /// </seealso>
  364. /// <seealso cref="writeListXml(java.util.List{E}, java.io.OutputStream)">writeListXml(java.util.List&lt;E&gt;, java.io.OutputStream)
  365. /// </seealso>
  366. /// <seealso cref="readValueXml(org.xmlpull.v1.XmlPullParser, string[])">readValueXml(org.xmlpull.v1.XmlPullParser, string[])
  367. /// </seealso>
  368. /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
  369. /// <exception cref="System.IO.IOException"></exception>
  370. public static void writeValueXml(object v, string name, org.xmlpull.v1.XmlSerializer
  371. @out)
  372. {
  373. string typeStr;
  374. if (v == null)
  375. {
  376. @out.startTag(null, "null");
  377. if (name != null)
  378. {
  379. @out.attribute(null, "name", name);
  380. }
  381. @out.endTag(null, "null");
  382. return;
  383. }
  384. else
  385. {
  386. if (v is string)
  387. {
  388. @out.startTag(null, "string");
  389. if (name != null)
  390. {
  391. @out.attribute(null, "name", name);
  392. }
  393. @out.text(v.ToString());
  394. @out.endTag(null, "string");
  395. return;
  396. }
  397. else
  398. {
  399. if (v is int)
  400. {
  401. typeStr = "int";
  402. }
  403. else
  404. {
  405. if (v is long)
  406. {
  407. typeStr = "long";
  408. }
  409. else
  410. {
  411. if (v is float)
  412. {
  413. typeStr = "float";
  414. }
  415. else
  416. {
  417. if (v is double)
  418. {
  419. typeStr = "double";
  420. }
  421. else
  422. {
  423. if (v is bool)
  424. {
  425. typeStr = "boolean";
  426. }
  427. else
  428. {
  429. if (v is byte[])
  430. {
  431. writeByteArrayXml((byte[])v, name, @out);
  432. return;
  433. }
  434. else
  435. {
  436. if (v is int[])
  437. {
  438. writeIntArrayXml((int[])v, name, @out);
  439. return;
  440. }
  441. else
  442. {
  443. if (v is java.util.Map<object, object>)
  444. {
  445. writeMapXml((java.util.Map<object, object>)v, name, @out);
  446. return;
  447. }
  448. else
  449. {
  450. if (v is java.util.List<object>)
  451. {
  452. writeListXml((java.util.List<object>)v, name, @out);
  453. return;
  454. }
  455. else
  456. {
  457. if (v is java.util.Set<object>)
  458. {
  459. writeSetXml((java.util.Set<object>)v, name, @out);
  460. return;
  461. }
  462. else
  463. {
  464. if (v is java.lang.CharSequence)
  465. {
  466. // XXX This is to allow us to at least write something if
  467. // we encounter styled text... but it means we will drop all
  468. // of the styling information. :(
  469. @out.startTag(null, "string");
  470. if (name != null)
  471. {
  472. @out.attribute(null, "name", name);
  473. }
  474. @out.text(v.ToString());
  475. @out.endTag(null, "string");
  476. return;
  477. }
  478. else
  479. {
  480. throw new java.lang.RuntimeException("writeValueXml: unable to write value " + v);
  481. }
  482. }
  483. }
  484. }
  485. }
  486. }
  487. }
  488. }
  489. }
  490. }
  491. }
  492. }
  493. }
  494. @out.startTag(null, typeStr);
  495. if (name != null)
  496. {
  497. @out.attribute(null, "name", name);
  498. }
  499. @out.attribute(null, "value", v.ToString());
  500. @out.endTag(null, typeStr);
  501. }
  502. /// <summary>Read a HashMap from an InputStream containing XML.</summary>
  503. /// <remarks>
  504. /// Read a HashMap from an InputStream containing XML. The stream can
  505. /// previously have been written by writeMapXml().
  506. /// </remarks>
  507. /// <param name="in">The InputStream from which to read.</param>
  508. /// <returns>HashMap The resulting map.</returns>
  509. /// <seealso cref="readListXml(java.io.InputStream)">readListXml(java.io.InputStream)
  510. /// </seealso>
  511. /// <seealso cref="readValueXml(org.xmlpull.v1.XmlPullParser, string[])">readValueXml(org.xmlpull.v1.XmlPullParser, string[])
  512. /// </seealso>
  513. /// <seealso cref="readThisMapXml(org.xmlpull.v1.XmlPullParser, string, string[])">#see #writeMapXml
  514. /// </seealso>
  515. /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
  516. /// <exception cref="System.IO.IOException"></exception>
  517. public static java.util.HashMap<object, object> readMapXml(java.io.InputStream @in
  518. )
  519. {
  520. org.xmlpull.v1.XmlPullParser parser = android.util.Xml.newPullParser();
  521. parser.setInput(@in, null);
  522. return (java.util.HashMap<object, object>)readValueXml(parser, new string[1]);
  523. }
  524. /// <summary>Read an ArrayList from an InputStream containing XML.</summary>
  525. /// <remarks>
  526. /// Read an ArrayList from an InputStream containing XML. The stream can
  527. /// previously have been written by writeListXml().
  528. /// </remarks>
  529. /// <param name="in">The InputStream from which to read.</param>
  530. /// <returns>ArrayList The resulting list.</returns>
  531. /// <seealso cref="readMapXml(java.io.InputStream)">readMapXml(java.io.InputStream)</seealso>
  532. /// <seealso cref="readValueXml(org.xmlpull.v1.XmlPullParser, string[])">readValueXml(org.xmlpull.v1.XmlPullParser, string[])
  533. /// </seealso>
  534. /// <seealso cref="readThisListXml(org.xmlpull.v1.XmlPullParser, string, string[])">readThisListXml(org.xmlpull.v1.XmlPullParser, string, string[])
  535. /// </seealso>
  536. /// <seealso cref="writeListXml(java.util.List{E}, java.io.OutputStream)">writeListXml(java.util.List&lt;E&gt;, java.io.OutputStream)
  537. /// </seealso>
  538. /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
  539. /// <exception cref="System.IO.IOException"></exception>
  540. public static java.util.ArrayList<object> readListXml(java.io.InputStream @in)
  541. {
  542. org.xmlpull.v1.XmlPullParser parser = android.util.Xml.newPullParser();
  543. parser.setInput(@in, null);
  544. return (java.util.ArrayList<object>)readValueXml(parser, new string[1]);
  545. }
  546. /// <summary>Read a HashSet from an InputStream containing XML.</summary>
  547. /// <remarks>
  548. /// Read a HashSet from an InputStream containing XML. The stream can
  549. /// previously have been written by writeSetXml().
  550. /// </remarks>
  551. /// <param name="in">The InputStream from which to read.</param>
  552. /// <returns>HashSet The resulting set.</returns>
  553. /// <exception cref="org.xmlpull.v1.XmlPullParserException">org.xmlpull.v1.XmlPullParserException
  554. /// </exception>
  555. /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
  556. /// <seealso cref="readValueXml(org.xmlpull.v1.XmlPullParser, string[])">readValueXml(org.xmlpull.v1.XmlPullParser, string[])
  557. /// </seealso>
  558. /// <seealso cref="readThisSetXml(org.xmlpull.v1.XmlPullParser, string, string[])">readThisSetXml(org.xmlpull.v1.XmlPullParser, string, string[])
  559. /// </seealso>
  560. /// <seealso cref="writeSetXml(java.util.Set{E}, string, org.xmlpull.v1.XmlSerializer)
  561. /// ">writeSetXml(java.util.Set&lt;E&gt;, string, org.xmlpull.v1.XmlSerializer)</seealso>
  562. public static java.util.HashSet<object> readSetXml(java.io.InputStream @in)
  563. {
  564. org.xmlpull.v1.XmlPullParser parser = android.util.Xml.newPullParser();
  565. parser.setInput(@in, null);
  566. return (java.util.HashSet<object>)readValueXml(parser, new string[1]);
  567. }
  568. /// <summary>Read a HashMap object from an XmlPullParser.</summary>
  569. /// <remarks>
  570. /// Read a HashMap object from an XmlPullParser. The XML data could
  571. /// previously have been generated by writeMapXml(). The XmlPullParser
  572. /// must be positioned <em>after</em> the tag that begins the map.
  573. /// </remarks>
  574. /// <param name="parser">The XmlPullParser from which to read the map data.</param>
  575. /// <param name="endTag">Name of the tag that will end the map, usually "map".</param>
  576. /// <param name="name">
  577. /// An array of one string, used to return the name attribute
  578. /// of the map's tag.
  579. /// </param>
  580. /// <returns>HashMap The newly generated map.</returns>
  581. /// <seealso cref="readMapXml(java.io.InputStream)">readMapXml(java.io.InputStream)</seealso>
  582. /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
  583. /// <exception cref="System.IO.IOException"></exception>
  584. public static java.util.HashMap<object, object> readThisMapXml(org.xmlpull.v1.XmlPullParser
  585. parser, string endTag, string[] name)
  586. {
  587. java.util.HashMap<object, object> map = new java.util.HashMap<object, object>();
  588. int eventType = parser.getEventType();
  589. do
  590. {
  591. if (eventType == org.xmlpull.v1.XmlPullParserClass.START_TAG)
  592. {
  593. object val = readThisValueXml(parser, name);
  594. if (name[0] != null)
  595. {
  596. //System.out.println("Adding to map: " + name + " -> " + val);
  597. map.put(name[0], val);
  598. }
  599. else
  600. {
  601. throw new org.xmlpull.v1.XmlPullParserException("Map value without name attribute: "
  602. + parser.getName());
  603. }
  604. }
  605. else
  606. {
  607. if (eventType == org.xmlpull.v1.XmlPullParserClass.END_TAG)
  608. {
  609. if (parser.getName().Equals(endTag))
  610. {
  611. return map;
  612. }
  613. throw new org.xmlpull.v1.XmlPullParserException("Expected " + endTag + " end tag at: "
  614. + parser.getName());
  615. }
  616. }
  617. eventType = parser.next();
  618. }
  619. while (eventType != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT);
  620. throw new org.xmlpull.v1.XmlPullParserException("Document ended before " + endTag
  621. + " end tag");
  622. }
  623. /// <summary>Read an ArrayList object from an XmlPullParser.</summary>
  624. /// <remarks>
  625. /// Read an ArrayList object from an XmlPullParser. The XML data could
  626. /// previously have been generated by writeListXml(). The XmlPullParser
  627. /// must be positioned <em>after</em> the tag that begins the list.
  628. /// </remarks>
  629. /// <param name="parser">The XmlPullParser from which to read the list data.</param>
  630. /// <param name="endTag">Name of the tag that will end the list, usually "list".</param>
  631. /// <param name="name">
  632. /// An array of one string, used to return the name attribute
  633. /// of the list's tag.
  634. /// </param>
  635. /// <returns>HashMap The newly generated list.</returns>
  636. /// <seealso cref="readListXml(java.io.InputStream)">readListXml(java.io.InputStream)
  637. /// </seealso>
  638. /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
  639. /// <exception cref="System.IO.IOException"></exception>
  640. public static java.util.ArrayList<object> readThisListXml(org.xmlpull.v1.XmlPullParser
  641. parser, string endTag, string[] name)
  642. {
  643. java.util.ArrayList<object> list = new java.util.ArrayList<object>();
  644. int eventType = parser.getEventType();
  645. do
  646. {
  647. if (eventType == org.xmlpull.v1.XmlPullParserClass.START_TAG)
  648. {
  649. object val = readThisValueXml(parser, name);
  650. list.add(val);
  651. }
  652. else
  653. {
  654. //System.out.println("Adding to list: " + val);
  655. if (eventType == org.xmlpull.v1.XmlPullParserClass.END_TAG)
  656. {
  657. if (parser.getName().Equals(endTag))
  658. {
  659. return list;
  660. }
  661. throw new org.xmlpull.v1.XmlPullParserException("Expected " + endTag + " end tag at: "
  662. + parser.getName());
  663. }
  664. }
  665. eventType = parser.next();
  666. }
  667. while (eventType != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT);
  668. throw new org.xmlpull.v1.XmlPullParserException("Document ended before " + endTag
  669. + " end tag");
  670. }
  671. /// <summary>Read a HashSet object from an XmlPullParser.</summary>
  672. /// <remarks>
  673. /// Read a HashSet object from an XmlPullParser. The XML data could previously
  674. /// have been generated by writeSetXml(). The XmlPullParser must be positioned
  675. /// <em>after</em> the tag that begins the set.
  676. /// </remarks>
  677. /// <param name="parser">The XmlPullParser from which to read the set data.</param>
  678. /// <param name="endTag">Name of the tag that will end the set, usually "set".</param>
  679. /// <param name="name">
  680. /// An array of one string, used to return the name attribute
  681. /// of the set's tag.
  682. /// </param>
  683. /// <returns>HashSet The newly generated set.</returns>
  684. /// <exception cref="org.xmlpull.v1.XmlPullParserException">org.xmlpull.v1.XmlPullParserException
  685. /// </exception>
  686. /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
  687. /// <seealso cref="readSetXml(java.io.InputStream)">readSetXml(java.io.InputStream)</seealso>
  688. public static java.util.HashSet<object> readThisSetXml(org.xmlpull.v1.XmlPullParser
  689. parser, string endTag, string[] name)
  690. {
  691. java.util.HashSet<object> set = new java.util.HashSet<object>();
  692. int eventType = parser.getEventType();
  693. do
  694. {
  695. if (eventType == org.xmlpull.v1.XmlPullParserClass.START_TAG)
  696. {
  697. object val = readThisValueXml(parser, name);
  698. set.add(val);
  699. }
  700. else
  701. {
  702. //System.out.println("Adding to set: " + val);
  703. if (eventType == org.xmlpull.v1.XmlPullParserClass.END_TAG)
  704. {
  705. if (parser.getName().Equals(endTag))
  706. {
  707. return set;
  708. }
  709. throw new org.xmlpull.v1.XmlPullParserException("Expected " + endTag + " end tag at: "
  710. + parser.getName());
  711. }
  712. }
  713. eventType = parser.next();
  714. }
  715. while (eventType != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT);
  716. throw new org.xmlpull.v1.XmlPullParserException("Document ended before " + endTag
  717. + " end tag");
  718. }
  719. /// <summary>Read an int[] object from an XmlPullParser.</summary>
  720. /// <remarks>
  721. /// Read an int[] object from an XmlPullParser. The XML data could
  722. /// previously have been generated by writeIntArrayXml(). The XmlPullParser
  723. /// must be positioned <em>after</em> the tag that begins the list.
  724. /// </remarks>
  725. /// <param name="parser">The XmlPullParser from which to read the list data.</param>
  726. /// <param name="endTag">Name of the tag that will end the list, usually "list".</param>
  727. /// <param name="name">
  728. /// An array of one string, used to return the name attribute
  729. /// of the list's tag.
  730. /// </param>
  731. /// <returns>Returns a newly generated int[].</returns>
  732. /// <seealso cref="readListXml(java.io.InputStream)">readListXml(java.io.InputStream)
  733. /// </seealso>
  734. /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
  735. /// <exception cref="System.IO.IOException"></exception>
  736. public static int[] readThisIntArrayXml(org.xmlpull.v1.XmlPullParser parser, string
  737. endTag, string[] name)
  738. {
  739. int num;
  740. try
  741. {
  742. num = System.Convert.ToInt32(parser.getAttributeValue(null, "num"));
  743. }
  744. catch (System.ArgumentNullException)
  745. {
  746. throw new org.xmlpull.v1.XmlPullParserException("Need num attribute in byte-array"
  747. );
  748. }
  749. catch (System.ArgumentException)
  750. {
  751. throw new org.xmlpull.v1.XmlPullParserException("Not a number in num attribute in byte-array"
  752. );
  753. }
  754. int[] array = new int[num];
  755. int i = 0;
  756. int eventType = parser.getEventType();
  757. do
  758. {
  759. if (eventType == org.xmlpull.v1.XmlPullParserClass.START_TAG)
  760. {
  761. if (parser.getName().Equals("item"))
  762. {
  763. try
  764. {
  765. array[i] = System.Convert.ToInt32(parser.getAttributeValue(null, "value"));
  766. }
  767. catch (System.ArgumentNullException)
  768. {
  769. throw new org.xmlpull.v1.XmlPullParserException("Need value attribute in item");
  770. }
  771. catch (System.ArgumentException)
  772. {
  773. throw new org.xmlpull.v1.XmlPullParserException("Not a number in value attribute in item"
  774. );
  775. }
  776. }
  777. else
  778. {
  779. throw new org.xmlpull.v1.XmlPullParserException("Expected item tag at: " + parser
  780. .getName());
  781. }
  782. }
  783. else
  784. {
  785. if (eventType == org.xmlpull.v1.XmlPullParserClass.END_TAG)
  786. {
  787. if (parser.getName().Equals(endTag))
  788. {
  789. return array;
  790. }
  791. else
  792. {
  793. if (parser.getName().Equals("item"))
  794. {
  795. i++;
  796. }
  797. else
  798. {
  799. throw new org.xmlpull.v1.XmlPullParserException("Expected " + endTag + " end tag at: "
  800. + parser.getName());
  801. }
  802. }
  803. }
  804. }
  805. eventType = parser.next();
  806. }
  807. while (eventType != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT);
  808. throw new org.xmlpull.v1.XmlPullParserException("Document ended before " + endTag
  809. + " end tag");
  810. }
  811. /// <summary>Read a flattened object from an XmlPullParser.</summary>
  812. /// <remarks>
  813. /// Read a flattened object from an XmlPullParser. The XML data could
  814. /// previously have been written with writeMapXml(), writeListXml(), or
  815. /// writeValueXml(). The XmlPullParser must be positioned <em>at</em> the
  816. /// tag that defines the value.
  817. /// </remarks>
  818. /// <param name="parser">The XmlPullParser from which to read the object.</param>
  819. /// <param name="name">
  820. /// An array of one string, used to return the name attribute
  821. /// of the value's tag.
  822. /// </param>
  823. /// <returns>Object The newly generated value object.</returns>
  824. /// <seealso cref="readMapXml(java.io.InputStream)">readMapXml(java.io.InputStream)</seealso>
  825. /// <seealso cref="readListXml(java.io.InputStream)">readListXml(java.io.InputStream)
  826. /// </seealso>
  827. /// <seealso cref="writeValueXml(object, string, org.xmlpull.v1.XmlSerializer)">writeValueXml(object, string, org.xmlpull.v1.XmlSerializer)
  828. /// </seealso>
  829. /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
  830. /// <exception cref="System.IO.IOException"></exception>
  831. public static object readValueXml(org.xmlpull.v1.XmlPullParser parser, string[] name
  832. )
  833. {
  834. int eventType = parser.getEventType();
  835. do
  836. {
  837. if (eventType == org.xmlpull.v1.XmlPullParserClass.START_TAG)
  838. {
  839. return readThisValueXml(parser, name);
  840. }
  841. else
  842. {
  843. if (eventType == org.xmlpull.v1.XmlPullParserClass.END_TAG)
  844. {
  845. throw new org.xmlpull.v1.XmlPullParserException("Unexpected end tag at: " + parser
  846. .getName());
  847. }
  848. else
  849. {
  850. if (eventType == org.xmlpull.v1.XmlPullParserClass.TEXT)
  851. {
  852. throw new org.xmlpull.v1.XmlPullParserException("Unexpected text: " + parser.getText
  853. ());
  854. }
  855. }
  856. }
  857. eventType = parser.next();
  858. }
  859. while (eventType != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT);
  860. throw new org.xmlpull.v1.XmlPullParserException("Unexpected end of document");
  861. }
  862. /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
  863. /// <exception cref="System.IO.IOException"></exception>
  864. private static object readThisValueXml(org.xmlpull.v1.XmlPullParser parser, string
  865. [] name)
  866. {
  867. string valueName = parser.getAttributeValue(null, "name");
  868. string tagName = parser.getName();
  869. //System.out.println("Reading this value tag: " + tagName + ", name=" + valueName);
  870. object res;
  871. if (tagName.Equals("null"))
  872. {
  873. res = null;
  874. }
  875. else
  876. {
  877. if (tagName.Equals("string"))
  878. {
  879. string value = string.Empty;
  880. int eventType;
  881. while ((eventType = parser.next()) != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT
  882. )
  883. {
  884. if (eventType == org.xmlpull.v1.XmlPullParserClass.END_TAG)
  885. {
  886. if (parser.getName().Equals("string"))
  887. {
  888. name[0] = valueName;
  889. //System.out.println("Returning value for " + valueName + ": " + value);
  890. return value;
  891. }
  892. throw new org.xmlpull.v1.XmlPullParserException("Unexpected end tag in <string>: "
  893. + parser.getName());
  894. }
  895. else
  896. {
  897. if (eventType == org.xmlpull.v1.XmlPullParserClass.TEXT)
  898. {
  899. value += parser.getText();
  900. }
  901. else
  902. {
  903. if (eventType == org.xmlpull.v1.XmlPullParserClass.START_TAG)
  904. {
  905. throw new org.xmlpull.v1.XmlPullParserException("Unexpected start tag in <string>: "
  906. + parser.getName());
  907. }
  908. }
  909. }
  910. }
  911. throw new org.xmlpull.v1.XmlPullParserException("Unexpected end of document in <string>"
  912. );
  913. }
  914. else
  915. {
  916. if (tagName.Equals("int"))
  917. {
  918. res = System.Convert.ToInt32(parser.getAttributeValue(null, "value"));
  919. }
  920. else
  921. {
  922. if (tagName.Equals("long"))
  923. {
  924. res = long.Parse(parser.getAttributeValue(null, "value"));
  925. }
  926. else
  927. {
  928. if (tagName.Equals("float"))
  929. {
  930. res = System.Convert.ToSingle(parser.getAttributeValue(null, "value"));
  931. }
  932. else
  933. {
  934. if (tagName.Equals("double"))
  935. {
  936. res = System.Convert.ToDouble(parser.getAttributeValue(null, "value"));
  937. }
  938. else
  939. {
  940. if (tagName.Equals("boolean"))
  941. {
  942. res = bool.Parse(parser.getAttributeValue(null, "value"));
  943. }
  944. else
  945. {
  946. if (tagName.Equals("int-array"))
  947. {
  948. parser.next();
  949. res = readThisIntArrayXml(parser, "int-array", name);
  950. name[0] = valueName;
  951. //System.out.println("Returning value for " + valueName + ": " + res);
  952. return res;
  953. }
  954. else
  955. {
  956. if (tagName.Equals("map"))
  957. {
  958. parser.next();
  959. res = readThisMapXml(parser, "map", name);
  960. name[0] = valueName;
  961. //System.out.println("Returning value for " + valueName + ": " + res);
  962. return res;
  963. }
  964. else
  965. {
  966. if (tagName.Equals("list"))
  967. {
  968. parser.next();
  969. res = readThisListXml(parser, "list", name);
  970. name[0] = valueName;
  971. //System.out.println("Returning value for " + valueName + ": " + res);
  972. return res;
  973. }
  974. else
  975. {
  976. if (tagName.Equals("set"))
  977. {
  978. parser.next();
  979. res = readThisSetXml(parser, "set", name);
  980. name[0] = valueName;
  981. //System.out.println("Returning value for " + valueName + ": " + res);
  982. return res;
  983. }
  984. else
  985. {
  986. throw new org.xmlpull.v1.XmlPullParserException("Unknown tag: " + tagName);
  987. }
  988. }
  989. }
  990. }
  991. }
  992. }
  993. }
  994. }
  995. }
  996. }
  997. }
  998. // Skip through to end tag.
  999. int eventType_1;
  1000. while ((eventType_1 = parser.next()) != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT
  1001. )
  1002. {
  1003. if (eventType_1 == org.xmlpull.v1.XmlPullParserClass.END_TAG)
  1004. {
  1005. if (parser.getName().Equals(tagName))
  1006. {
  1007. name[0] = valueName;
  1008. //System.out.println("Returning value for " + valueName + ": " + res);
  1009. return res;
  1010. }
  1011. throw new org.xmlpull.v1.XmlPullParserException("Unexpected end tag in <" + tagName
  1012. + ">: " + parser.getName());
  1013. }
  1014. else
  1015. {
  1016. if (eventType_1 == org.xmlpull.v1.XmlPullParserClass.TEXT)
  1017. {
  1018. throw new org.xmlpull.v1.XmlPullParserException("Unexpected text in <" + tagName
  1019. + ">: " + parser.getName());
  1020. }
  1021. else
  1022. {
  1023. if (eventType_1 == org.xmlpull.v1.XmlPullParserClass.START_TAG)
  1024. {
  1025. throw new org.xmlpull.v1.XmlPullParserException("Unexpected start tag in <" + tagName
  1026. + ">: " + parser.getName());
  1027. }
  1028. }
  1029. }
  1030. }
  1031. throw new org.xmlpull.v1.XmlPullParserException("Unexpected end of document in <"
  1032. + tagName + ">");
  1033. }
  1034. /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
  1035. /// <exception cref="System.IO.IOException"></exception>
  1036. public static void beginDocument(org.xmlpull.v1.XmlPullParser parser, string firstElementName
  1037. )
  1038. {
  1039. int type;
  1040. while ((type = parser.next()) != org.xmlpull.v1.XmlPullParserClass.START_TAG && type
  1041. != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT)
  1042. {
  1043. }
  1044. if (type != org.xmlpull.v1.XmlPullParserClass.START_TAG)
  1045. {
  1046. throw new org.xmlpull.v1.XmlPullParserException("No start tag found");
  1047. }
  1048. if (!parser.getName().Equals(firstElementName))
  1049. {
  1050. throw new org.xmlpull.v1.XmlPullParserException("Unexpected start tag: found " +
  1051. parser.getName() + ", expected " + firstElementName);
  1052. }
  1053. }
  1054. /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
  1055. /// <exception cref="System.IO.IOException"></exception>
  1056. public static void nextElement(org.xmlpull.v1.XmlPullParser parser)
  1057. {
  1058. int type;
  1059. while ((type = parser.next()) != org.xmlpull.v1.XmlPullParserClass.START_TAG && type
  1060. != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT)
  1061. {
  1062. }
  1063. }
  1064. }
  1065. }