Java Code Examples for org.xmlpull.v1.XmlSerializer#text()
The following examples show how to use
org.xmlpull.v1.XmlSerializer#text() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResPluralsValue.java From ratel with Apache License 2.0 | 6 votes |
@Override public void serializeToResValuesXml(XmlSerializer serializer, ResResource res) throws IOException, AndrolibException { serializer.startTag(null, "plurals"); serializer.attribute(null, "name", res.getResSpec().getName()); for (int i = 0; i < mItems.length; i++) { ResScalarValue item = mItems[i]; if (item == null) { continue; } serializer.startTag(null, "item"); serializer.attribute(null, "quantity", QUANTITY_MAP[i]); serializer.text(ResXmlEncoders.enumerateNonPositionalSubstitutionsIfRequired(item.encodeAsResXmlNonEscapedItemValue())); serializer.endTag(null, "item"); } serializer.endTag(null, "plurals"); }
Example 2
Source File: XmlUtils.java From a with GNU General Public License v3.0 | 5 votes |
/** * Flatten a byte[] into an XmlSerializer. The list can later be read back * with readThisByteArrayXml(). * * @param val The byte array to be flattened. * @param name Name attribute to include with this array's tag, or null for * none. * @param out XmlSerializer to write the array into. * @see #writeMapXml * @see #writeValueXml */ public static void writeByteArrayXml(byte[] val, String name, XmlSerializer out) throws XmlPullParserException, java.io.IOException { 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); } final int N = val.length; out.attribute(null, "num", Integer.toString(N)); StringBuilder sb = new StringBuilder(val.length * 2); for (int b : val) { int h = b >> 4; sb.append(h >= 10 ? ('a' + h - 10) : ('0' + h)); h = b & 0xff; sb.append(h >= 10 ? ('a' + h - 10) : ('0' + h)); } out.text(sb.toString()); out.endTag(null, "byte-array"); }
Example 3
Source File: XmlUtils.java From HeadsUp with GNU General Public License v2.0 | 5 votes |
/** * Flatten a byte[] into an XmlSerializer. The list can later be read back * with readThisByteArrayXml(). * * @param val The byte array to be flattened. * @param name Name attribute to include with this array's tag, or null for * none. * @param out XmlSerializer to write the array into. * @see #writeMapXml * @see #writeValueXml */ public static void writeByteArrayXml(byte[] val, String name, XmlSerializer out) throws java.io.IOException { 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); } final int N = val.length; out.attribute(null, "num", Integer.toString(N)); StringBuilder sb = new StringBuilder(val.length * 2); for (byte b : val) { int h = b >> 4; sb.append(h >= 10 ? ('a' + h - 10) : ('0' + h)); h = b & 0xff; sb.append(h >= 10 ? ('a' + h - 10) : ('0' + h)); } out.text(sb.toString()); out.endTag(null, "byte-array"); }
Example 4
Source File: XmlUtils.java From MyBookshelf with GNU General Public License v3.0 | 5 votes |
/** * Flatten a byte[] into an XmlSerializer. The list can later be read back * with readThisByteArrayXml(). * * @param val The byte array to be flattened. * @param name Name attribute to include with this array's tag, or null for * none. * @param out XmlSerializer to write the array into. * @see #writeMapXml * @see #writeValueXml */ public static void writeByteArrayXml(byte[] val, String name, XmlSerializer out) throws XmlPullParserException, java.io.IOException { 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); } final int N = val.length; out.attribute(null, "num", Integer.toString(N)); StringBuilder sb = new StringBuilder(val.length * 2); for (int b : val) { int h = b >> 4; sb.append(h >= 10 ? ('a' + h - 10) : ('0' + h)); h = b & 0xff; sb.append(h >= 10 ? ('a' + h - 10) : ('0' + h)); } out.text(sb.toString()); out.endTag(null, "byte-array"); }
Example 5
Source File: XmlMapsGDataSerializer.java From mytracks with Apache License 2.0 | 5 votes |
private static void serializeSummary(XmlSerializer serializer, String summary) throws IOException { if (StringUtils.isEmpty(summary)) { return; } serializer.startTag(null /* ns */, "summary"); serializer.text(summary); serializer.endTag(null /* ns */, "summary"); }
Example 6
Source File: SliceClientPermissions.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public synchronized void writeTo(XmlSerializer out) throws IOException { final int N = mPaths.size(); for (int i = 0; i < N; i++) { final String[] segments = mPaths.valueAt(i); if (segments != null) { out.startTag(NAMESPACE, TAG_PATH); out.text(encodeSegments(segments)); out.endTag(NAMESPACE, TAG_PATH); } } }
Example 7
Source File: XmlUtils.java From JobSchedulerCompat with Apache License 2.0 | 5 votes |
/** * Flatten a byte[] into an XmlSerializer. The list can later be read back * with readThisByteArrayXml(). * * @param val The byte array to be flattened. * @param name Name attribute to include with this array's tag, or null for * none. * @param out XmlSerializer to write the array into. * * @see #writeMapXml * @see #writeValueXml */ public static final void writeByteArrayXml(byte[] val, String name, XmlSerializer out) throws XmlPullParserException, java.io.IOException { 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); } final int N = val.length; out.attribute(null, "num", Integer.toString(N)); StringBuilder sb = new 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&0xff; sb.append(h >= 10 ? ('a'+h-10) : ('0'+h)); } out.text(sb.toString()); out.endTag(null, "byte-array"); }
Example 8
Source File: KeyChainSnapshotSerializer.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private static void writePropertyTag( XmlSerializer xmlSerializer, String propertyName, byte[] propertyValue) throws IOException { xmlSerializer.startTag(NAMESPACE, propertyName); xmlSerializer.text(Base64.encodeToString(propertyValue, /*flags=*/ Base64.DEFAULT)); xmlSerializer.endTag(NAMESPACE, propertyName); }
Example 9
Source File: KeyChainSnapshotSerializer.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private static void writePropertyTag( XmlSerializer xmlSerializer, String propertyName, String propertyValue) throws IOException { xmlSerializer.startTag(NAMESPACE, propertyName); xmlSerializer.text(propertyValue); xmlSerializer.endTag(NAMESPACE, propertyName); }
Example 10
Source File: XmlUtils.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * Flatten a byte[] into an XmlSerializer. The list can later be read back * with readThisByteArrayXml(). * * @param val The byte array to be flattened. * @param name Name attribute to include with this array's tag, or null for * none. * @param out XmlSerializer to write the array into. * @see #writeMapXml * @see #writeValueXml */ public static final void writeByteArrayXml(byte[] val, String name, XmlSerializer out) throws XmlPullParserException, java.io.IOException { 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); } final int N = val.length; out.attribute(null, "num", Integer.toString(N)); StringBuilder sb = new StringBuilder(val.length * 2); for (int i = 0; i < N; i++) { int b = val[i]; int h = (b >> 4) & 0x0f; sb.append((char) (h >= 10 ? ('a' + h - 10) : ('0' + h))); h = b & 0x0f; sb.append((char) (h >= 10 ? ('a' + h - 10) : ('0' + h))); } out.text(sb.toString()); out.endTag(null, "byte-array"); }
Example 11
Source File: XmlMapsGDataSerializer.java From mytracks with Apache License 2.0 | 5 votes |
private static void serializeUpdateDate(XmlSerializer serializer, String updateDate) throws IOException { if (StringUtils.isEmpty(updateDate)) { return; } serializer.startTag(null /* ns */, "updated"); serializer.text(updateDate); serializer.endTag(null /* ns */, "updated"); }
Example 12
Source File: XmlUtils.java From HtmlCompat with Apache License 2.0 | 4 votes |
/** * 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. * * @param v The object to be flattened. * @param name Name attribute to include with this value's tag, or null * for none. * @param out XmlSerializer to write the object into. * * @see #writeMapXml * @see #writeListXml * @see #readValueXml */ public static final void writeValueXml(Object v, String name, XmlSerializer out) throws XmlPullParserException, java.io.IOException { 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 instanceof 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 instanceof Integer) { typeStr = "int"; } else if (v instanceof Long) { typeStr = "long"; } else if (v instanceof Float) { typeStr = "float"; } else if (v instanceof Double) { typeStr = "double"; } else if (v instanceof Boolean) { typeStr = "boolean"; } else if (v instanceof byte[]) { writeByteArrayXml((byte[])v, name, out); return; } else if (v instanceof int[]) { writeIntArrayXml((int[])v, name, out); return; } else if (v instanceof Map) { writeMapXml((Map)v, name, out); return; } else if (v instanceof List) { writeListXml((List)v, name, out); return; } else if (v instanceof Set) { writeSetXml((Set)v, name, out); return; } else if (v instanceof 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 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); }
Example 13
Source File: XmlUtils.java From WeexOne with MIT License | 4 votes |
/** * 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. * * @param v The object to be flattened. * @param name Name attribute to include with this value's tag, or null * for none. * @param out XmlSerializer to write the object into. * @param callback Handler for Object types not recognized. * * @see #writeMapXml * @see #writeListXml * @see #readValueXml */ private static final void writeValueXml(Object v, String name, XmlSerializer out, WriteMapCallback callback) throws XmlPullParserException, java.io.IOException { 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 instanceof 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 instanceof Integer) { typeStr = "int"; } else if (v instanceof Long) { typeStr = "long"; } else if (v instanceof Float) { typeStr = "float"; } else if (v instanceof Double) { typeStr = "double"; } else if (v instanceof Boolean) { typeStr = "boolean"; } else if (v instanceof byte[]) { writeByteArrayXml((byte[])v, name, out); return; } else if (v instanceof int[]) { writeIntArrayXml((int[])v, name, out); return; } else if (v instanceof long[]) { writeLongArrayXml((long[])v, name, out); return; } else if (v instanceof double[]) { writeDoubleArrayXml((double[])v, name, out); return; } else if (v instanceof String[]) { writeStringArrayXml((String[])v, name, out); return; } else if (v instanceof boolean[]) { writeBooleanArrayXml((boolean[])v, name, out); return; } else if (v instanceof Map) { writeMapXml((Map)v, name, out); return; } else if (v instanceof List) { writeListXml((List) v, name, out); return; } else if (v instanceof Set) { writeSetXml((Set) v, name, out); return; } else if (v instanceof 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 if (callback != null) { callback.writeUnknownObject(v, name, out); return; } else { throw new 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); }
Example 14
Source File: GpxFiles.java From Androzic with GNU General Public License v3.0 | 4 votes |
/** * Saves track to file. * * @param file valid <code>File</code> * @param track <code>Track</code> object containing the list of track points to save * @throws IOException */ public static void saveTrackToFile(final File file, final Track track) throws IOException { XmlSerializer serializer = Xml.newSerializer(); serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false))); serializer.setOutput(writer); serializer.startDocument("UTF-8", null); serializer.setPrefix("", GPX_NAMESPACE); serializer.startTag(GPX_NAMESPACE, GpxParser.GPX); serializer.attribute("", "creator", "Androzic http://androzic.com"); serializer.startTag(GPX_NAMESPACE, GpxParser.TRK); serializer.startTag(GPX_NAMESPACE, GpxParser.NAME); serializer.text(track.name); serializer.endTag(GPX_NAMESPACE, GpxParser.NAME); serializer.startTag(GPX_NAMESPACE, GpxParser.SRC); serializer.text(Androzic.getDeviceName()); serializer.endTag(GPX_NAMESPACE, GpxParser.SRC); boolean first = true; serializer.startTag(GPX_NAMESPACE, GpxParser.TRKSEG); List<TrackPoint> trackPoints = track.getAllPoints(); for (TrackPoint tp : trackPoints) { if (!tp.continous && !first) { serializer.endTag(GPX_NAMESPACE, GpxParser.TRKSEG); serializer.startTag(GPX_NAMESPACE, GpxParser.TRKSEG); } serializer.startTag(GPX_NAMESPACE, GpxParser.TRKPT); serializer.attribute("", GpxParser.LAT, String.valueOf(tp.latitude)); serializer.attribute("", GpxParser.LON, String.valueOf(tp.longitude)); serializer.startTag(GPX_NAMESPACE, GpxParser.ELE); serializer.text(String.valueOf(tp.elevation)); serializer.endTag(GPX_NAMESPACE, GpxParser.ELE); serializer.startTag(GPX_NAMESPACE, GpxParser.TIME); serializer.text(GpxParser.trktime.format(new Date(tp.time))); serializer.endTag(GPX_NAMESPACE, GpxParser.TIME); serializer.endTag(GPX_NAMESPACE, GpxParser.TRKPT); first = false; } serializer.endTag(GPX_NAMESPACE, GpxParser.TRKSEG); serializer.endTag(GPX_NAMESPACE, GpxParser.TRK); serializer.endTag(GPX_NAMESPACE, GpxParser.GPX); serializer.endDocument(); serializer.flush(); writer.close(); }
Example 15
Source File: XmlUtils.java From MyBookshelf with GNU General Public License v3.0 | 4 votes |
/** * Flatten an object's value into an XmlSerializer. The value can later * be read back with readThisValueXml(). * <p> * Currently supported value types are: null, String, Integer, Long, * Float, Double Boolean, Map, List. * * @param v The object to be flattened. * @param name Name attribute to include with this value's tag, or null * for none. * @param out XmlSerializer to write the object into. * @param callback Handler for Object types not recognized. * @see #writeMapXml * @see #writeListXml * @see #readValueXml */ private static void writeValueXml(Object v, String name, XmlSerializer out, WriteMapCallback callback) throws XmlPullParserException, java.io.IOException { 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 instanceof 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 instanceof Integer) { typeStr = "int"; } else if (v instanceof Long) { typeStr = "long"; } else if (v instanceof Float) { typeStr = "float"; } else if (v instanceof Double) { typeStr = "double"; } else if (v instanceof Boolean) { typeStr = "boolean"; } else if (v instanceof byte[]) { writeByteArrayXml((byte[]) v, name, out); return; } else if (v instanceof int[]) { writeIntArrayXml((int[]) v, name, out); return; } else if (v instanceof long[]) { writeLongArrayXml((long[]) v, name, out); return; } else if (v instanceof double[]) { writeDoubleArrayXml((double[]) v, name, out); return; } else if (v instanceof String[]) { writeStringArrayXml((String[]) v, name, out); return; } else if (v instanceof Map) { writeMapXml((Map) v, name, out); return; } else if (v instanceof List) { writeListXml((List) v, name, out); return; } else if (v instanceof Set) { writeSetXml((Set) v, name, out); return; } else if (v instanceof 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 if (callback != null) { callback.writeUnknownObject(v, name, out); return; } else { throw new 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); }
Example 16
Source File: DashManifestParser.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
/** * Parses an event object. * * @param xpp The current xml parser. * @param scratchOutputStream A {@link ByteArrayOutputStream} that's used when parsing the object. * @return The serialized byte array. * @throws XmlPullParserException If there is any error parsing this node. * @throws IOException If there is any error reading from the underlying input stream. */ protected byte[] parseEventObject(XmlPullParser xpp, ByteArrayOutputStream scratchOutputStream) throws XmlPullParserException, IOException { scratchOutputStream.reset(); XmlSerializer xmlSerializer = Xml.newSerializer(); xmlSerializer.setOutput(scratchOutputStream, null); // Start reading everything between <Event> and </Event>, and serialize them into an Xml // byte array. xpp.nextToken(); while (!XmlPullParserUtil.isEndTag(xpp, "Event")) { switch (xpp.getEventType()) { case (XmlPullParser.START_DOCUMENT): xmlSerializer.startDocument(null, false); break; case (XmlPullParser.END_DOCUMENT): xmlSerializer.endDocument(); break; case (XmlPullParser.START_TAG): xmlSerializer.startTag(xpp.getNamespace(), xpp.getName()); for (int i = 0; i < xpp.getAttributeCount(); i++) { xmlSerializer.attribute(xpp.getAttributeNamespace(i), xpp.getAttributeName(i), xpp.getAttributeValue(i)); } break; case (XmlPullParser.END_TAG): xmlSerializer.endTag(xpp.getNamespace(), xpp.getName()); break; case (XmlPullParser.TEXT): xmlSerializer.text(xpp.getText()); break; case (XmlPullParser.CDSECT): xmlSerializer.cdsect(xpp.getText()); break; case (XmlPullParser.ENTITY_REF): xmlSerializer.entityRef(xpp.getText()); break; case (XmlPullParser.IGNORABLE_WHITESPACE): xmlSerializer.ignorableWhitespace(xpp.getText()); break; case (XmlPullParser.PROCESSING_INSTRUCTION): xmlSerializer.processingInstruction(xpp.getText()); break; case (XmlPullParser.COMMENT): xmlSerializer.comment(xpp.getText()); break; case (XmlPullParser.DOCDECL): xmlSerializer.docdecl(xpp.getText()); break; default: // fall out } xpp.nextToken(); } xmlSerializer.flush(); return scratchOutputStream.toByteArray(); }
Example 17
Source File: Opus.java From LecteurOPUS with GNU General Public License v3.0 | 4 votes |
public String serialize(){ XmlSerializer xmlSerializer = Xml.newSerializer(); StringWriter writer = new StringWriter(); try { xmlSerializer.setOutput(writer); //Start Document xmlSerializer.startDocument("UTF-8", true); //Open Tag <file> xmlSerializer.startTag("", "Opus"); xmlSerializer.startTag("", "ID"); xmlSerializer.text(bytesToHex(m_dataID)); xmlSerializer.endTag("", "ID"); xmlSerializer.startTag("", "Expiration"); xmlSerializer.text(bytesToHex(m_dataExp)); xmlSerializer.endTag("", "Expiration"); xmlSerializer.startTag("", "Transit"); for (int i = 0; i < 3; i++) { xmlSerializer.startTag("", "List"); xmlSerializer.attribute("", "index", Integer.toString(i)); xmlSerializer.text(bytesToHex(m_dataTransit[i])); xmlSerializer.endTag("", "List"); } xmlSerializer.endTag("", "Transit"); xmlSerializer.startTag("", "Subscription"); for (int i = 0; i < 4; i++) { xmlSerializer.startTag("", "List"); xmlSerializer.attribute("", "index", Integer.toString(i)); xmlSerializer.text(bytesToHex(m_dataSubscription[i])); xmlSerializer.endTag("", "List"); } xmlSerializer.endTag("", "Subscription"); xmlSerializer.startTag("", "Ticket"); for (int i = 0; i < 4; i++) { xmlSerializer.startTag("", "List"); xmlSerializer.attribute("", "index", Integer.toString(i)); xmlSerializer.text(bytesToHex(m_dataTicket[i])); xmlSerializer.endTag("", "List"); } xmlSerializer.endTag("", "Ticket"); xmlSerializer.endTag("", "Opus"); xmlSerializer.endDocument(); return writer.toString(); } catch (IOException e){ Log.e("Opus", "Error serialize"); return ""; } }
Example 18
Source File: XmlUtils.java From tysq-android with GNU General Public License v3.0 | 4 votes |
/** * 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. * * @param v The object to be flattened. * @param name Name attribute to include with this value's tag, or null * for none. * @param out XmlSerializer to write the object into. * * @see #writeMapXml * @see #writeListXml */ public static final void writeValueXml(Object v, String name, XmlSerializer out) throws XmlPullParserException, java.io.IOException { 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 instanceof 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 instanceof Integer) { typeStr = "int"; } else if (v instanceof Long) { typeStr = "long"; } else if (v instanceof Float) { typeStr = "float"; } else if (v instanceof Double) { typeStr = "double"; } else if (v instanceof Boolean) { typeStr = "boolean"; } else if (v instanceof byte[]) { writeByteArrayXml((byte[])v, name, out); return; } else if (v instanceof int[]) { writeIntArrayXml((int[])v, name, out); return; } else if (v instanceof Map) { writeMapXml((Map)v, name, out); return; } else if (v instanceof List) { writeListXml((List)v, name, out); return; } else if (v instanceof Set) { writeSetXml((Set)v, name, out); return; } else if (v instanceof 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 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); }
Example 19
Source File: XmlUtils.java From AcDisplay with GNU General Public License v2.0 | 4 votes |
/** * Flatten an object's value into an XmlSerializer. The value can later * be read back with readThisValueXml(). * <p/> * Currently supported value types are: null, String, Integer, Long, * Float, Double Boolean, Map, List. * * @param v The object to be flattened. * @param name Name attribute to include with this value's tag, or null * for none. * @param out XmlSerializer to write the object into. * @param callback Handler for Object types not recognized. * @see #writeMapXml * @see #writeListXml * @see #readValueXml */ private static void writeValueXml(Object v, String name, XmlSerializer out, WriteMapCallback callback) throws XmlPullParserException, java.io.IOException { 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 instanceof 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 instanceof Integer) { typeStr = "int"; } else if (v instanceof Long) { typeStr = "long"; } else if (v instanceof Float) { typeStr = "float"; } else if (v instanceof Double) { typeStr = "double"; } else if (v instanceof Boolean) { typeStr = "boolean"; } else if (v instanceof byte[]) { writeByteArrayXml((byte[]) v, name, out); return; } else if (v instanceof int[]) { writeIntArrayXml((int[]) v, name, out); return; } else if (v instanceof long[]) { writeLongArrayXml((long[]) v, name, out); return; } else if (v instanceof double[]) { writeDoubleArrayXml((double[]) v, name, out); return; } else if (v instanceof String[]) { writeStringArrayXml((String[]) v, name, out); return; } else if (v instanceof Map) { writeMapXml((Map) v, name, out); return; } else if (v instanceof List) { writeListXml((List) v, name, out); return; } else if (v instanceof Set) { writeSetXml((Set) v, name, out); return; } else if (v instanceof 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 if (callback != null) { callback.writeUnknownObject(v, name, out); return; } else { throw new 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); }
Example 20
Source File: XmlUtils.java From XPrivacy with GNU General Public License v3.0 | 4 votes |
/** * 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. * * @param v The object to be flattened. * @param name Name attribute to include with this value's tag, or null * for none. * @param out XmlSerializer to write the object into. * * @see #writeMapXml * @see #writeListXml * @see #readValueXml */ public static final void writeValueXml(Object v, String name, XmlSerializer out) throws XmlPullParserException, java.io.IOException { 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 instanceof 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 instanceof Integer) { typeStr = "int"; } else if (v instanceof Long) { typeStr = "long"; } else if (v instanceof Float) { typeStr = "float"; } else if (v instanceof Double) { typeStr = "double"; } else if (v instanceof Boolean) { typeStr = "boolean"; } else if (v instanceof byte[]) { writeByteArrayXml((byte[])v, name, out); return; } else if (v instanceof int[]) { writeIntArrayXml((int[])v, name, out); return; } else if (v instanceof Map) { writeMapXml((Map)v, name, out); return; } else if (v instanceof List) { writeListXml((List)v, name, out); return; } else if (v instanceof Set) { writeSetXml((Set)v, name, out); return; } else if (v instanceof 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 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); }