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 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");
		}