Esempio n. 1
0
		/// <summary>Flatten an object's value into an XmlSerializer.</summary>
		/// <remarks>
		/// Flatten an object's value into an XmlSerializer.  The value can later
		/// be read back with readThisValueXml().
		/// Currently supported value types are: null, String, Integer, Long,
		/// Float, Double Boolean, Map, List.
		/// </remarks>
		/// <param name="v">The object to be flattened.</param>
		/// <param name="name">
		/// Name attribute to include with this value's tag, or null
		/// for none.
		/// </param>
		/// <param name="out">XmlSerializer to write the object into.</param>
		/// <seealso cref="writeMapXml(java.util.Map{K, V}, java.io.OutputStream)">writeMapXml(java.util.Map&lt;K, V&gt;, java.io.OutputStream)
		/// 	</seealso>
		/// <seealso cref="writeListXml(java.util.List{E}, java.io.OutputStream)">writeListXml(java.util.List&lt;E&gt;, java.io.OutputStream)
		/// 	</seealso>
		/// <seealso cref="readValueXml(org.xmlpull.v1.XmlPullParser, string[])">readValueXml(org.xmlpull.v1.XmlPullParser, string[])
		/// 	</seealso>
		/// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		public static void writeValueXml(object v, string name, org.xmlpull.v1.XmlSerializer
			 @out)
		{
			string typeStr;
			if (v == null)
			{
				@out.startTag(null, "null");
				if (name != null)
				{
					@out.attribute(null, "name", name);
				}
				@out.endTag(null, "null");
				return;
			}
			else
			{
				if (v is string)
				{
					@out.startTag(null, "string");
					if (name != null)
					{
						@out.attribute(null, "name", name);
					}
					@out.text(v.ToString());
					@out.endTag(null, "string");
					return;
				}
				else
				{
					if (v is int)
					{
						typeStr = "int";
					}
					else
					{
						if (v is long)
						{
							typeStr = "long";
						}
						else
						{
							if (v is float)
							{
								typeStr = "float";
							}
							else
							{
								if (v is double)
								{
									typeStr = "double";
								}
								else
								{
									if (v is bool)
									{
										typeStr = "boolean";
									}
									else
									{
										if (v is byte[])
										{
											writeByteArrayXml((byte[])v, name, @out);
											return;
										}
										else
										{
											if (v is int[])
											{
												writeIntArrayXml((int[])v, name, @out);
												return;
											}
											else
											{
												if (v is java.util.Map<object, object>)
												{
													writeMapXml((java.util.Map<object, object>)v, name, @out);
													return;
												}
												else
												{
													if (v is java.util.List<object>)
													{
														writeListXml((java.util.List<object>)v, name, @out);
														return;
													}
													else
													{
														if (v is java.util.Set<object>)
														{
															writeSetXml((java.util.Set<object>)v, name, @out);
															return;
														}
														else
														{
															if (v is java.lang.CharSequence)
															{
																// XXX This is to allow us to at least write something if
																// we encounter styled text...  but it means we will drop all
																// of the styling information. :(
																@out.startTag(null, "string");
																if (name != null)
																{
																	@out.attribute(null, "name", name);
																}
																@out.text(v.ToString());
																@out.endTag(null, "string");
																return;
															}
															else
															{
																throw new java.lang.RuntimeException("writeValueXml: unable to write value " + v);
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
			@out.startTag(null, typeStr);
			if (name != null)
			{
				@out.attribute(null, "name", name);
			}
			@out.attribute(null, "value", v.ToString());
			@out.endTag(null, typeStr);
		}
Esempio n. 2
0
		/// <summary>Flatten an int[] into an XmlSerializer.</summary>
		/// <remarks>
		/// Flatten an int[] into an XmlSerializer.  The list can later be read back
		/// with readThisIntArrayXml().
		/// </remarks>
		/// <param name="val">The int array to be flattened.</param>
		/// <param name="name">
		/// Name attribute to include with this array's tag, or null for
		/// none.
		/// </param>
		/// <param name="out">XmlSerializer to write the array into.</param>
		/// <seealso cref="writeMapXml(java.util.Map{K, V}, java.io.OutputStream)">writeMapXml(java.util.Map&lt;K, V&gt;, java.io.OutputStream)
		/// 	</seealso>
		/// <seealso cref="writeValueXml(object, string, org.xmlpull.v1.XmlSerializer)">writeValueXml(object, string, org.xmlpull.v1.XmlSerializer)
		/// 	</seealso>
		/// <seealso cref="readThisIntArrayXml(org.xmlpull.v1.XmlPullParser, string, string[])
		/// 	">readThisIntArrayXml(org.xmlpull.v1.XmlPullParser, string, string[])</seealso>
		/// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		public static void writeIntArrayXml(int[] val, string name, org.xmlpull.v1.XmlSerializer
			 @out)
		{
			if (val == null)
			{
				@out.startTag(null, "null");
				@out.endTag(null, "null");
				return;
			}
			@out.startTag(null, "int-array");
			if (name != null)
			{
				@out.attribute(null, "name", name);
			}
			int N = val.Length;
			@out.attribute(null, "num", System.Convert.ToString(N));
			{
				for (int i = 0; i < N; i++)
				{
					@out.startTag(null, "item");
					@out.attribute(null, "value", System.Convert.ToString(val[i]));
					@out.endTag(null, "item");
				}
			}
			@out.endTag(null, "int-array");
		}
Esempio n. 3
0
		/// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		public static void writeSetXml(java.util.Set<object> val, string name, org.xmlpull.v1.XmlSerializer
			 @out)
		{
			if (val == null)
			{
				@out.startTag(null, "null");
				@out.endTag(null, "null");
				return;
			}
			@out.startTag(null, "set");
			if (name != null)
			{
				@out.attribute(null, "name", name);
			}
			foreach (object v in Sharpen.IterableProxy.Create(val))
			{
				writeValueXml(v, null, @out);
			}
			@out.endTag(null, "set");
		}
Esempio n. 4
0
		/// <summary>Flatten a byte[] into an XmlSerializer.</summary>
		/// <remarks>
		/// Flatten a byte[] into an XmlSerializer.  The list can later be read back
		/// with readThisByteArrayXml().
		/// </remarks>
		/// <param name="val">The byte array to be flattened.</param>
		/// <param name="name">
		/// Name attribute to include with this array's tag, or null for
		/// none.
		/// </param>
		/// <param name="out">XmlSerializer to write the array into.</param>
		/// <seealso cref="writeMapXml(java.util.Map{K, V}, java.io.OutputStream)">writeMapXml(java.util.Map&lt;K, V&gt;, java.io.OutputStream)
		/// 	</seealso>
		/// <seealso cref="writeValueXml(object, string, org.xmlpull.v1.XmlSerializer)">writeValueXml(object, string, org.xmlpull.v1.XmlSerializer)
		/// 	</seealso>
		/// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		public static void writeByteArrayXml(byte[] val, string name, org.xmlpull.v1.XmlSerializer
			 @out)
		{
			if (val == null)
			{
				@out.startTag(null, "null");
				@out.endTag(null, "null");
				return;
			}
			@out.startTag(null, "byte-array");
			if (name != null)
			{
				@out.attribute(null, "name", name);
			}
			int N = val.Length;
			@out.attribute(null, "num", System.Convert.ToString(N));
			java.lang.StringBuilder sb = new java.lang.StringBuilder(val.Length * 2);
			{
				for (int i = 0; i < N; i++)
				{
					int b = val[i];
					int h = b >> 4;
					sb.append(h >= 10 ? ('a' + h - 10) : ('0' + h));
					h = b & unchecked((int)(0xff));
					sb.append(h >= 10 ? ('a' + h - 10) : ('0' + h));
				}
			}
			@out.text(sb.ToString());
			@out.endTag(null, "byte-array");
		}
Esempio n. 5
0
		/// <summary>Flatten a List into an XmlSerializer.</summary>
		/// <remarks>
		/// Flatten a List into an XmlSerializer.  The list can later be read back
		/// with readThisListXml().
		/// </remarks>
		/// <param name="val">The list to be flattened.</param>
		/// <param name="name">
		/// Name attribute to include with this list's tag, or null for
		/// none.
		/// </param>
		/// <param name="out">XmlSerializer to write the list into.</param>
		/// <seealso cref="writeListXml(java.util.List{E}, java.io.OutputStream)">writeListXml(java.util.List&lt;E&gt;, java.io.OutputStream)
		/// 	</seealso>
		/// <seealso cref="writeMapXml(java.util.Map{K, V}, java.io.OutputStream)">writeMapXml(java.util.Map&lt;K, V&gt;, java.io.OutputStream)
		/// 	</seealso>
		/// <seealso cref="writeValueXml(object, string, org.xmlpull.v1.XmlSerializer)">writeValueXml(object, string, org.xmlpull.v1.XmlSerializer)
		/// 	</seealso>
		/// <seealso cref="readListXml(java.io.InputStream)">readListXml(java.io.InputStream)
		/// 	</seealso>
		/// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		public static void writeListXml(java.util.List<object> val, string name, org.xmlpull.v1.XmlSerializer
			 @out)
		{
			if (val == null)
			{
				@out.startTag(null, "null");
				@out.endTag(null, "null");
				return;
			}
			@out.startTag(null, "list");
			if (name != null)
			{
				@out.attribute(null, "name", name);
			}
			int N = val.size();
			int i = 0;
			while (i < N)
			{
				writeValueXml(val.get(i), null, @out);
				i++;
			}
			@out.endTag(null, "list");
		}