FileDocCategorySizeDatePackage
XmlUtils.javaAPI DocAndroid 5.1 API60812Thu Mar 12 22:22:10 GMT 2015com.android.internal.util

XmlUtils

public class XmlUtils extends Object
{@hide}

Fields Summary
Constructors Summary
Methods Summary
public static final voidbeginDocument(org.xmlpull.v1.XmlPullParser parser, java.lang.String firstElementName)

        int type;
        while ((type=parser.next()) != parser.START_TAG
                   && type != parser.END_DOCUMENT) {
            ;
        }

        if (type != parser.START_TAG) {
            throw new XmlPullParserException("No start tag found");
        }

        if (!parser.getName().equals(firstElementName)) {
            throw new XmlPullParserException("Unexpected start tag: found " + parser.getName() +
                    ", expected " + firstElementName);
        }
    
public static final booleanconvertValueToBoolean(java.lang.CharSequence value, boolean defaultValue)

        boolean result = false;

        if (null == value)
            return defaultValue;

        if (value.equals("1")
        ||  value.equals("true")
        ||  value.equals("TRUE"))
            result = true;

        return result;
    
public static final intconvertValueToInt(java.lang.CharSequence charSeq, int defaultValue)

        if (null == charSeq)
            return defaultValue;

        String nm = charSeq.toString();

        // XXX This code is copied from Integer.decode() so we don't
        // have to instantiate an Integer!

        int value;
        int sign = 1;
        int index = 0;
        int len = nm.length();
        int base = 10;

        if ('-" == nm.charAt(0)) {
            sign = -1;
            index++;
        }

        if ('0" == nm.charAt(index)) {
            //  Quick check for a zero by itself
            if (index == (len - 1))
                return 0;

            char    c = nm.charAt(index + 1);

            if ('x" == c || 'X" == c) {
                index += 2;
                base = 16;
            } else {
                index++;
                base = 8;
            }
        }
        else if ('#" == nm.charAt(index))
        {
            index++;
            base = 16;
        }

        return Integer.parseInt(nm.substring(index), base) * sign;
    
public static final intconvertValueToList(java.lang.CharSequence value, java.lang.String[] options, int defaultValue)

        if (null != value) {
            for (int i = 0; i < options.length; i++) {
                if (value.equals(options[i]))
                    return i;
            }
        }

        return defaultValue;
    
public static intconvertValueToUnsignedInt(java.lang.String value, int defaultValue)

        if (null == value) {
            return defaultValue;
        }

        return parseUnsignedIntAttribute(value);
    
public static final voidnextElement(org.xmlpull.v1.XmlPullParser parser)

        int type;
        while ((type=parser.next()) != parser.START_TAG
                   && type != parser.END_DOCUMENT) {
            ;
        }
    
public static booleannextElementWithin(org.xmlpull.v1.XmlPullParser parser, int outerDepth)

        for (;;) {
            int type = parser.next();
            if (type == XmlPullParser.END_DOCUMENT
                    || (type == XmlPullParser.END_TAG && parser.getDepth() == outerDepth)) {
                return false;
            }
            if (type == XmlPullParser.START_TAG
                    && parser.getDepth() == outerDepth + 1) {
                return true;
            }
        }
    
public static intparseUnsignedIntAttribute(java.lang.CharSequence charSeq)

        String  value = charSeq.toString();

        long    bits;
        int     index = 0;
        int     len = value.length();
        int     base = 10;

        if ('0" == value.charAt(index)) {
            //  Quick check for zero by itself
            if (index == (len - 1))
                return 0;

            char    c = value.charAt(index + 1);

            if ('x" == c || 'X" == c) {     //  check for hex
                index += 2;
                base = 16;
            } else {                        //  check for octal
                index++;
                base = 8;
            }
        } else if ('#" == value.charAt(index)) {
            index++;
            base = 16;
        }

        return (int) Long.parseLong(value.substring(index), base);
    
public static android.graphics.BitmapreadBitmapAttribute(org.xmlpull.v1.XmlPullParser in, java.lang.String name)

        final byte[] value = readByteArrayAttribute(in, name);
        if (value != null) {
            return BitmapFactory.decodeByteArray(value, 0, value.length);
        } else {
            return null;
        }
    
public static booleanreadBooleanAttribute(org.xmlpull.v1.XmlPullParser in, java.lang.String name)

        final String value = in.getAttributeValue(null, name);
        return Boolean.parseBoolean(value);
    
public static booleanreadBooleanAttribute(org.xmlpull.v1.XmlPullParser in, java.lang.String name, boolean defaultValue)

        final String value = in.getAttributeValue(null, name);
        if (value == null) {
            return defaultValue;
        } else {
            return Boolean.parseBoolean(value);
        }
    
public static byte[]readByteArrayAttribute(org.xmlpull.v1.XmlPullParser in, java.lang.String name)

        final String value = in.getAttributeValue(null, name);
        if (value != null) {
            return Base64.decode(value, Base64.DEFAULT);
        } else {
            return null;
        }
    
public static floatreadFloatAttribute(org.xmlpull.v1.XmlPullParser in, java.lang.String name)

        final String value = in.getAttributeValue(null, name);
        try {
            return Float.parseFloat(value);
        } catch (NumberFormatException e) {
            throw new ProtocolException("problem parsing " + name + "=" + value + " as long");
        }
    
public static intreadIntAttribute(org.xmlpull.v1.XmlPullParser in, java.lang.String name, int defaultValue)

        final String value = in.getAttributeValue(null, name);
        try {
            return Integer.parseInt(value);
        } catch (NumberFormatException e) {
            return defaultValue;
        }
    
public static intreadIntAttribute(org.xmlpull.v1.XmlPullParser in, java.lang.String name)

        final String value = in.getAttributeValue(null, name);
        try {
            return Integer.parseInt(value);
        } catch (NumberFormatException e) {
            throw new ProtocolException("problem parsing " + name + "=" + value + " as int");
        }
    
public static final java.util.ArrayListreadListXml(java.io.InputStream in)
Read an ArrayList from an InputStream containing XML. The stream can previously have been written by writeListXml().

param
in The InputStream from which to read.
return
ArrayList The resulting list.
see
#readMapXml
see
#readValueXml
see
#readThisListXml
see
#writeListXml

        XmlPullParser   parser = Xml.newPullParser();
        parser.setInput(in, null);
        return (ArrayList)readValueXml(parser, new String[1]);
    
public static longreadLongAttribute(org.xmlpull.v1.XmlPullParser in, java.lang.String name, long defaultValue)

        final String value = in.getAttributeValue(null, name);
        try {
            return Long.parseLong(value);
        } catch (NumberFormatException e) {
            return defaultValue;
        }
    
public static longreadLongAttribute(org.xmlpull.v1.XmlPullParser in, java.lang.String name)

        final String value = in.getAttributeValue(null, name);
        try {
            return Long.parseLong(value);
        } catch (NumberFormatException e) {
            throw new ProtocolException("problem parsing " + name + "=" + value + " as long");
        }
    
public static final java.util.HashMapreadMapXml(java.io.InputStream in)
Read a HashMap from an InputStream containing XML. The stream can previously have been written by writeMapXml().

param
in The InputStream from which to read.
return
HashMap The resulting map.
see
#readListXml
see
#readValueXml
see
#readThisMapXml #see #writeMapXml

        XmlPullParser   parser = Xml.newPullParser();
        parser.setInput(in, null);
        return (HashMap<String, ?>) readValueXml(parser, new String[1]);
    
public static final java.util.HashSetreadSetXml(java.io.InputStream in)
Read a HashSet from an InputStream containing XML. The stream can previously have been written by writeSetXml().

param
in The InputStream from which to read.
return
HashSet The resulting set.
throws
XmlPullParserException
throws
java.io.IOException
see
#readValueXml
see
#readThisSetXml
see
#writeSetXml

        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(in, null);
        return (HashSet) readValueXml(parser, new String[1]);
    
public static java.lang.StringreadStringAttribute(org.xmlpull.v1.XmlPullParser in, java.lang.String name)

        return in.getAttributeValue(null, name);
    
public static final boolean[]readThisBooleanArrayXml(org.xmlpull.v1.XmlPullParser parser, java.lang.String endTag, java.lang.String[] name)
Read a boolean[] object from an XmlPullParser. The XML data could previously have been generated by writeBooleanArrayXml(). The XmlPullParser must be positioned after the tag that begins the list.

param
parser The XmlPullParser from which to read the list data.
param
endTag Name of the tag that will end the list, usually "string-array".
param
name An array of one string, used to return the name attribute of the list's tag.
return
Returns a newly generated boolean[].
see
#readListXml


        int num;
        try {
            num = Integer.parseInt(parser.getAttributeValue(null, "num"));
        } catch (NullPointerException e) {
            throw new XmlPullParserException("Need num attribute in string-array");
        } catch (NumberFormatException e) {
            throw new XmlPullParserException("Not a number in num attribute in string-array");
        }
        parser.next();

        boolean[] array = new boolean[num];
        int i = 0;

        int eventType = parser.getEventType();
        do {
            if (eventType == parser.START_TAG) {
                if (parser.getName().equals("item")) {
                    try {
                        array[i] = Boolean.valueOf(parser.getAttributeValue(null, "value"));
                    } catch (NullPointerException e) {
                        throw new XmlPullParserException("Need value attribute in item");
                    } catch (NumberFormatException e) {
                        throw new XmlPullParserException("Not a number in value attribute in item");
                    }
                } else {
                    throw new XmlPullParserException("Expected item tag at: " + parser.getName());
                }
            } else if (eventType == parser.END_TAG) {
                if (parser.getName().equals(endTag)) {
                    return array;
                } else if (parser.getName().equals("item")) {
                    i++;
                } else {
                    throw new XmlPullParserException("Expected " + endTag + " end tag at: " +
                            parser.getName());
                }
            }
            eventType = parser.next();
        } while (eventType != parser.END_DOCUMENT);

        throw new XmlPullParserException("Document ended before " + endTag + " end tag");
    
public static final double[]readThisDoubleArrayXml(org.xmlpull.v1.XmlPullParser parser, java.lang.String endTag, java.lang.String[] name)
Read a double[] object from an XmlPullParser. The XML data could previously have been generated by writeDoubleArrayXml(). The XmlPullParser must be positioned after the tag that begins the list.

param
parser The XmlPullParser from which to read the list data.
param
endTag Name of the tag that will end the list, usually "double-array".
param
name An array of one string, used to return the name attribute of the list's tag.
return
Returns a newly generated double[].
see
#readListXml


        int num;
        try {
            num = Integer.parseInt(parser.getAttributeValue(null, "num"));
        } catch (NullPointerException e) {
            throw new XmlPullParserException("Need num attribute in double-array");
        } catch (NumberFormatException e) {
            throw new XmlPullParserException("Not a number in num attribute in double-array");
        }
        parser.next();

        double[] array = new double[num];
        int i = 0;

        int eventType = parser.getEventType();
        do {
            if (eventType == parser.START_TAG) {
                if (parser.getName().equals("item")) {
                    try {
                        array[i] = Double.parseDouble(parser.getAttributeValue(null, "value"));
                    } catch (NullPointerException e) {
                        throw new XmlPullParserException("Need value attribute in item");
                    } catch (NumberFormatException e) {
                        throw new XmlPullParserException("Not a number in value attribute in item");
                    }
                } else {
                    throw new XmlPullParserException("Expected item tag at: " + parser.getName());
                }
            } else if (eventType == parser.END_TAG) {
                if (parser.getName().equals(endTag)) {
                    return array;
                } else if (parser.getName().equals("item")) {
                    i++;
                } else {
                    throw new XmlPullParserException("Expected " + endTag + " end tag at: " +
                            parser.getName());
                }
            }
            eventType = parser.next();
        } while (eventType != parser.END_DOCUMENT);

        throw new XmlPullParserException("Document ended before " + endTag + " end tag");
    
public static final int[]readThisIntArrayXml(org.xmlpull.v1.XmlPullParser parser, java.lang.String endTag, java.lang.String[] name)
Read an int[] object from an XmlPullParser. The XML data could previously have been generated by writeIntArrayXml(). The XmlPullParser must be positioned after the tag that begins the list.

param
parser The XmlPullParser from which to read the list data.
param
endTag Name of the tag that will end the list, usually "list".
param
name An array of one string, used to return the name attribute of the list's tag.
return
Returns a newly generated int[].
see
#readListXml


        int num;
        try {
            num = Integer.parseInt(parser.getAttributeValue(null, "num"));
        } catch (NullPointerException e) {
            throw new XmlPullParserException(
                    "Need num attribute in byte-array");
        } catch (NumberFormatException e) {
            throw new XmlPullParserException(
                    "Not a number in num attribute in byte-array");
        }
        parser.next();

        int[] array = new int[num];
        int i = 0;

        int eventType = parser.getEventType();
        do {
            if (eventType == parser.START_TAG) {
                if (parser.getName().equals("item")) {
                    try {
                        array[i] = Integer.parseInt(
                                parser.getAttributeValue(null, "value"));
                    } catch (NullPointerException e) {
                        throw new XmlPullParserException(
                                "Need value attribute in item");
                    } catch (NumberFormatException e) {
                        throw new XmlPullParserException(
                                "Not a number in value attribute in item");
                    }
                } else {
                    throw new XmlPullParserException(
                            "Expected item tag at: " + parser.getName());
                }
            } else if (eventType == parser.END_TAG) {
                if (parser.getName().equals(endTag)) {
                    return array;
                } else if (parser.getName().equals("item")) {
                    i++;
                } else {
                    throw new XmlPullParserException(
                        "Expected " + endTag + " end tag at: "
                        + parser.getName());
                }
            }
            eventType = parser.next();
        } while (eventType != parser.END_DOCUMENT);

        throw new XmlPullParserException(
            "Document ended before " + endTag + " end tag");
    
public static final java.util.ArrayListreadThisListXml(org.xmlpull.v1.XmlPullParser parser, java.lang.String endTag, java.lang.String[] name)
Read an ArrayList object from an XmlPullParser. The XML data could previously have been generated by writeListXml(). The XmlPullParser must be positioned after the tag that begins the list.

param
parser The XmlPullParser from which to read the list data.
param
endTag Name of the tag that will end the list, usually "list".
param
name An array of one string, used to return the name attribute of the list's tag.
return
HashMap The newly generated list.
see
#readListXml

        return readThisListXml(parser, endTag, name, null);
    
private static final java.util.ArrayListreadThisListXml(org.xmlpull.v1.XmlPullParser parser, java.lang.String endTag, java.lang.String[] name, com.android.internal.util.XmlUtils$ReadMapCallback callback)
Read an ArrayList object from an XmlPullParser. The XML data could previously have been generated by writeListXml(). The XmlPullParser must be positioned after the tag that begins the list.

param
parser The XmlPullParser from which to read the list data.
param
endTag Name of the tag that will end the list, usually "list".
param
name An array of one string, used to return the name attribute of the list's tag.
return
HashMap The newly generated list.
see
#readListXml

        ArrayList list = new ArrayList();

        int eventType = parser.getEventType();
        do {
            if (eventType == parser.START_TAG) {
                Object val = readThisValueXml(parser, name, callback);
                list.add(val);
                //System.out.println("Adding to list: " + val);
            } else if (eventType == parser.END_TAG) {
                if (parser.getName().equals(endTag)) {
                    return list;
                }
                throw new XmlPullParserException(
                    "Expected " + endTag + " end tag at: " + parser.getName());
            }
            eventType = parser.next();
        } while (eventType != parser.END_DOCUMENT);

        throw new XmlPullParserException(
            "Document ended before " + endTag + " end tag");
    
public static final long[]readThisLongArrayXml(org.xmlpull.v1.XmlPullParser parser, java.lang.String endTag, java.lang.String[] name)
Read a long[] object from an XmlPullParser. The XML data could previously have been generated by writeLongArrayXml(). The XmlPullParser must be positioned after the tag that begins the list.

param
parser The XmlPullParser from which to read the list data.
param
endTag Name of the tag that will end the list, usually "list".
param
name An array of one string, used to return the name attribute of the list's tag.
return
Returns a newly generated long[].
see
#readListXml


        int num;
        try {
            num = Integer.parseInt(parser.getAttributeValue(null, "num"));
        } catch (NullPointerException e) {
            throw new XmlPullParserException("Need num attribute in long-array");
        } catch (NumberFormatException e) {
            throw new XmlPullParserException("Not a number in num attribute in long-array");
        }
        parser.next();

        long[] array = new long[num];
        int i = 0;

        int eventType = parser.getEventType();
        do {
            if (eventType == parser.START_TAG) {
                if (parser.getName().equals("item")) {
                    try {
                        array[i] = Long.parseLong(parser.getAttributeValue(null, "value"));
                    } catch (NullPointerException e) {
                        throw new XmlPullParserException("Need value attribute in item");
                    } catch (NumberFormatException e) {
                        throw new XmlPullParserException("Not a number in value attribute in item");
                    }
                } else {
                    throw new XmlPullParserException("Expected item tag at: " + parser.getName());
                }
            } else if (eventType == parser.END_TAG) {
                if (parser.getName().equals(endTag)) {
                    return array;
                } else if (parser.getName().equals("item")) {
                    i++;
                } else {
                    throw new XmlPullParserException("Expected " + endTag + " end tag at: " +
                            parser.getName());
                }
            }
            eventType = parser.next();
        } while (eventType != parser.END_DOCUMENT);

        throw new XmlPullParserException("Document ended before " + endTag + " end tag");
    
public static final java.util.HashMapreadThisMapXml(org.xmlpull.v1.XmlPullParser parser, java.lang.String endTag, java.lang.String[] name)
Read a HashMap object from an XmlPullParser. The XML data could previously have been generated by writeMapXml(). The XmlPullParser must be positioned after the tag that begins the map.

param
parser The XmlPullParser from which to read the map data.
param
endTag Name of the tag that will end the map, usually "map".
param
name An array of one string, used to return the name attribute of the map's tag.
return
HashMap The newly generated map.
see
#readMapXml

        return readThisMapXml(parser, endTag, name, null);
    
public static final java.util.HashMapreadThisMapXml(org.xmlpull.v1.XmlPullParser parser, java.lang.String endTag, java.lang.String[] name, com.android.internal.util.XmlUtils$ReadMapCallback callback)
Read a HashMap object from an XmlPullParser. The XML data could previously have been generated by writeMapXml(). The XmlPullParser must be positioned after the tag that begins the map.

param
parser The XmlPullParser from which to read the map data.
param
endTag Name of the tag that will end the map, usually "map".
param
name An array of one string, used to return the name attribute of the map's tag.
return
HashMap The newly generated map.
see
#readMapXml
hide

        HashMap<String, Object> map = new HashMap<String, Object>();

        int eventType = parser.getEventType();
        do {
            if (eventType == parser.START_TAG) {
                Object val = readThisValueXml(parser, name, callback);
                map.put(name[0], val);
            } else if (eventType == parser.END_TAG) {
                if (parser.getName().equals(endTag)) {
                    return map;
                }
                throw new XmlPullParserException(
                    "Expected " + endTag + " end tag at: " + parser.getName());
            }
            eventType = parser.next();
        } while (eventType != parser.END_DOCUMENT);

        throw new XmlPullParserException(
            "Document ended before " + endTag + " end tag");
    
private static final java.lang.ObjectreadThisPrimitiveValueXml(org.xmlpull.v1.XmlPullParser parser, java.lang.String tagName)

        try {
            if (tagName.equals("int")) {
                return Integer.parseInt(parser.getAttributeValue(null, "value"));
            } else if (tagName.equals("long")) {
                return Long.valueOf(parser.getAttributeValue(null, "value"));
            } else if (tagName.equals("float")) {
                return new Float(parser.getAttributeValue(null, "value"));
            } else if (tagName.equals("double")) {
                return new Double(parser.getAttributeValue(null, "value"));
            } else if (tagName.equals("boolean")) {
                return Boolean.valueOf(parser.getAttributeValue(null, "value"));
            } else {
                return null;
            }
        } catch (NullPointerException e) {
            throw new XmlPullParserException("Need value attribute in <" + tagName + ">");
        } catch (NumberFormatException e) {
            throw new XmlPullParserException(
                    "Not a number in value attribute in <" + tagName + ">");
        }
    
public static final java.util.HashSetreadThisSetXml(org.xmlpull.v1.XmlPullParser parser, java.lang.String endTag, java.lang.String[] name)
Read a HashSet object from an XmlPullParser. The XML data could previously have been generated by writeSetXml(). The XmlPullParser must be positioned after the tag that begins the set.

param
parser The XmlPullParser from which to read the set data.
param
endTag Name of the tag that will end the set, usually "set".
param
name An array of one string, used to return the name attribute of the set's tag.
return
HashSet The newly generated set.
throws
XmlPullParserException
throws
java.io.IOException
see
#readSetXml

        return readThisSetXml(parser, endTag, name, null);
    
private static final java.util.HashSetreadThisSetXml(org.xmlpull.v1.XmlPullParser parser, java.lang.String endTag, java.lang.String[] name, com.android.internal.util.XmlUtils$ReadMapCallback callback)
Read a HashSet object from an XmlPullParser. The XML data could previously have been generated by writeSetXml(). The XmlPullParser must be positioned after the tag that begins the set.

param
parser The XmlPullParser from which to read the set data.
param
endTag Name of the tag that will end the set, usually "set".
param
name An array of one string, used to return the name attribute of the set's tag.
return
HashSet The newly generated set.
throws
XmlPullParserException
throws
java.io.IOException
see
#readSetXml
hide

        HashSet set = new HashSet();
        
        int eventType = parser.getEventType();
        do {
            if (eventType == parser.START_TAG) {
                Object val = readThisValueXml(parser, name, callback);
                set.add(val);
                //System.out.println("Adding to set: " + val);
            } else if (eventType == parser.END_TAG) {
                if (parser.getName().equals(endTag)) {
                    return set;
                }
                throw new XmlPullParserException(
                        "Expected " + endTag + " end tag at: " + parser.getName());
            }
            eventType = parser.next();
        } while (eventType != parser.END_DOCUMENT);
        
        throw new XmlPullParserException(
                "Document ended before " + endTag + " end tag");
    
public static final java.lang.String[]readThisStringArrayXml(org.xmlpull.v1.XmlPullParser parser, java.lang.String endTag, java.lang.String[] name)
Read a String[] object from an XmlPullParser. The XML data could previously have been generated by writeStringArrayXml(). The XmlPullParser must be positioned after the tag that begins the list.

param
parser The XmlPullParser from which to read the list data.
param
endTag Name of the tag that will end the list, usually "string-array".
param
name An array of one string, used to return the name attribute of the list's tag.
return
Returns a newly generated String[].
see
#readListXml


        int num;
        try {
            num = Integer.parseInt(parser.getAttributeValue(null, "num"));
        } catch (NullPointerException e) {
            throw new XmlPullParserException("Need num attribute in string-array");
        } catch (NumberFormatException e) {
            throw new XmlPullParserException("Not a number in num attribute in string-array");
        }
        parser.next();

        String[] array = new String[num];
        int i = 0;

        int eventType = parser.getEventType();
        do {
            if (eventType == parser.START_TAG) {
                if (parser.getName().equals("item")) {
                    try {
                        array[i] = parser.getAttributeValue(null, "value");
                    } catch (NullPointerException e) {
                        throw new XmlPullParserException("Need value attribute in item");
                    } catch (NumberFormatException e) {
                        throw new XmlPullParserException("Not a number in value attribute in item");
                    }
                } else {
                    throw new XmlPullParserException("Expected item tag at: " + parser.getName());
                }
            } else if (eventType == parser.END_TAG) {
                if (parser.getName().equals(endTag)) {
                    return array;
                } else if (parser.getName().equals("item")) {
                    i++;
                } else {
                    throw new XmlPullParserException("Expected " + endTag + " end tag at: " +
                            parser.getName());
                }
            }
            eventType = parser.next();
        } while (eventType != parser.END_DOCUMENT);

        throw new XmlPullParserException("Document ended before " + endTag + " end tag");
    
private static final java.lang.ObjectreadThisValueXml(org.xmlpull.v1.XmlPullParser parser, java.lang.String[] name, com.android.internal.util.XmlUtils$ReadMapCallback callback)

        final String valueName = parser.getAttributeValue(null, "name");
        final String tagName = parser.getName();

        //System.out.println("Reading this value tag: " + tagName + ", name=" + valueName);

        Object res;

        if (tagName.equals("null")) {
            res = null;
        } else if (tagName.equals("string")) {
            String value = "";
            int eventType;
            while ((eventType = parser.next()) != parser.END_DOCUMENT) {
                if (eventType == parser.END_TAG) {
                    if (parser.getName().equals("string")) {
                        name[0] = valueName;
                        //System.out.println("Returning value for " + valueName + ": " + value);
                        return value;
                    }
                    throw new XmlPullParserException(
                        "Unexpected end tag in <string>: " + parser.getName());
                } else if (eventType == parser.TEXT) {
                    value += parser.getText();
                } else if (eventType == parser.START_TAG) {
                    throw new XmlPullParserException(
                        "Unexpected start tag in <string>: " + parser.getName());
                }
            }
            throw new XmlPullParserException(
                "Unexpected end of document in <string>");
        } else if ((res = readThisPrimitiveValueXml(parser, tagName)) != null) {
            // all work already done by readThisPrimitiveValueXml
        } else if (tagName.equals("int-array")) {
            res = readThisIntArrayXml(parser, "int-array", name);
            name[0] = valueName;
            //System.out.println("Returning value for " + valueName + ": " + res);
            return res;
        } else if (tagName.equals("long-array")) {
            res = readThisLongArrayXml(parser, "long-array", name);
            name[0] = valueName;
            //System.out.println("Returning value for " + valueName + ": " + res);
            return res;
        } else if (tagName.equals("double-array")) {
            res = readThisDoubleArrayXml(parser, "double-array", name);
            name[0] = valueName;
            //System.out.println("Returning value for " + valueName + ": " + res);
            return res;
        } else if (tagName.equals("string-array")) {
            res = readThisStringArrayXml(parser, "string-array", name);
            name[0] = valueName;
            //System.out.println("Returning value for " + valueName + ": " + res);
            return res;
        } else if (tagName.equals("boolean-array")) {
            res = readThisBooleanArrayXml(parser, "boolean-array", name);
            name[0] = valueName;
            //System.out.println("Returning value for " + valueName + ": " + res);
            return res;
        } else if (tagName.equals("map")) {
            parser.next();
            res = readThisMapXml(parser, "map", name);
            name[0] = valueName;
            //System.out.println("Returning value for " + valueName + ": " + res);
            return res;
        } else if (tagName.equals("list")) {
            parser.next();
            res = readThisListXml(parser, "list", name);
            name[0] = valueName;
            //System.out.println("Returning value for " + valueName + ": " + res);
            return res;
        } else if (tagName.equals("set")) {
            parser.next();
            res = readThisSetXml(parser, "set", name);
            name[0] = valueName;
            //System.out.println("Returning value for " + valueName + ": " + res);
            return res;
        } else if (callback != null) {
            res = callback.readThisUnknownObjectXml(parser, tagName);
            name[0] = valueName;
            return res;
        } else {
            throw new XmlPullParserException("Unknown tag: " + tagName);
        }

        // Skip through to end tag.
        int eventType;
        while ((eventType = parser.next()) != parser.END_DOCUMENT) {
            if (eventType == parser.END_TAG) {
                if (parser.getName().equals(tagName)) {
                    name[0] = valueName;
                    //System.out.println("Returning value for " + valueName + ": " + res);
                    return res;
                }
                throw new XmlPullParserException(
                    "Unexpected end tag in <" + tagName + ">: " + parser.getName());
            } else if (eventType == parser.TEXT) {
                throw new XmlPullParserException(
                "Unexpected text in <" + tagName + ">: " + parser.getName());
            } else if (eventType == parser.START_TAG) {
                throw new XmlPullParserException(
                    "Unexpected start tag in <" + tagName + ">: " + parser.getName());
            }
        }
        throw new XmlPullParserException(
            "Unexpected end of document in <" + tagName + ">");
    
public static android.net.UrireadUriAttribute(org.xmlpull.v1.XmlPullParser in, java.lang.String name)

        final String value = in.getAttributeValue(null, name);
        return (value != null) ? Uri.parse(value) : null;
    
public static final java.lang.ObjectreadValueXml(org.xmlpull.v1.XmlPullParser parser, java.lang.String[] name)
Read a flattened object from an XmlPullParser. The XML data could previously have been written with writeMapXml(), writeListXml(), or writeValueXml(). The XmlPullParser must be positioned at the tag that defines the value.

param
parser The XmlPullParser from which to read the object.
param
name An array of one string, used to return the name attribute of the value's tag.
return
Object The newly generated value object.
see
#readMapXml
see
#readListXml
see
#writeValueXml

        int eventType = parser.getEventType();
        do {
            if (eventType == parser.START_TAG) {
                return readThisValueXml(parser, name, null);
            } else if (eventType == parser.END_TAG) {
                throw new XmlPullParserException(
                    "Unexpected end tag at: " + parser.getName());
            } else if (eventType == parser.TEXT) {
                throw new XmlPullParserException(
                    "Unexpected text: " + parser.getText());
            }
            eventType = parser.next();
        } while (eventType != parser.END_DOCUMENT);

        throw new XmlPullParserException(
            "Unexpected end of document");
    
public static voidskipCurrentTag(org.xmlpull.v1.XmlPullParser parser)

        int outerDepth = parser.getDepth();
        int type;
        while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
               && (type != XmlPullParser.END_TAG
                       || parser.getDepth() > outerDepth)) {
        }
    
public static voidwriteBitmapAttribute(org.xmlpull.v1.XmlSerializer out, java.lang.String name, android.graphics.Bitmap value)

        if (value != null) {
            final ByteArrayOutputStream os = new ByteArrayOutputStream();
            value.compress(CompressFormat.PNG, 90, os);
            writeByteArrayAttribute(out, name, os.toByteArray());
        }
    
public static final voidwriteBooleanArrayXml(boolean[] val, java.lang.String name, org.xmlpull.v1.XmlSerializer out)
Flatten a boolean[] into an XmlSerializer. The list can later be read back with readThisBooleanArrayXml().

param
val The boolean 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
see
#readThisIntArrayXml


        if (val == null) {
            out.startTag(null, "null");
            out.endTag(null, "null");
            return;
        }

        out.startTag(null, "boolean-array");
        if (name != null) {
            out.attribute(null, "name", name);
        }

        final int N = val.length;
        out.attribute(null, "num", Integer.toString(N));

        for (int i=0; i<N; i++) {
            out.startTag(null, "item");
            out.attribute(null, "value", Boolean.toString(val[i]));
            out.endTag(null, "item");
        }

        out.endTag(null, "boolean-array");
    
public static voidwriteBooleanAttribute(org.xmlpull.v1.XmlSerializer out, java.lang.String name, boolean value)

        out.attribute(null, name, Boolean.toString(value));
    
public static voidwriteByteArrayAttribute(org.xmlpull.v1.XmlSerializer out, java.lang.String name, byte[] value)

        if (value != null) {
            out.attribute(null, name, Base64.encodeToString(value, Base64.DEFAULT));
        }
    
public static final voidwriteByteArrayXml(byte[] val, java.lang.String name, org.xmlpull.v1.XmlSerializer out)
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


        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");
    
public static final voidwriteDoubleArrayXml(double[] val, java.lang.String name, org.xmlpull.v1.XmlSerializer out)
Flatten a double[] into an XmlSerializer. The list can later be read back with readThisDoubleArrayXml().

param
val The double 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
see
#readThisIntArrayXml


        if (val == null) {
            out.startTag(null, "null");
            out.endTag(null, "null");
            return;
        }

        out.startTag(null, "double-array");
        if (name != null) {
            out.attribute(null, "name", name);
        }

        final int N = val.length;
        out.attribute(null, "num", Integer.toString(N));

        for (int i=0; i<N; i++) {
            out.startTag(null, "item");
            out.attribute(null, "value", Double.toString(val[i]));
            out.endTag(null, "item");
        }

        out.endTag(null, "double-array");
    
public static voidwriteFloatAttribute(org.xmlpull.v1.XmlSerializer out, java.lang.String name, float value)

        out.attribute(null, name, Float.toString(value));
    
public static final voidwriteIntArrayXml(int[] val, java.lang.String name, org.xmlpull.v1.XmlSerializer out)
Flatten an int[] into an XmlSerializer. The list can later be read back with readThisIntArrayXml().

param
val The int 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
see
#readThisIntArrayXml


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

        final int N = val.length;
        out.attribute(null, "num", Integer.toString(N));

        for (int i=0; i<N; i++) {
            out.startTag(null, "item");
            out.attribute(null, "value", Integer.toString(val[i]));
            out.endTag(null, "item");
        }

        out.endTag(null, "int-array");
    
public static voidwriteIntAttribute(org.xmlpull.v1.XmlSerializer out, java.lang.String name, int value)

        out.attribute(null, name, Integer.toString(value));
    
public static final voidwriteListXml(java.util.List val, java.lang.String name, org.xmlpull.v1.XmlSerializer out)
Flatten a List into an XmlSerializer. The list can later be read back with readThisListXml().

param
val The list to be flattened.
param
name Name attribute to include with this list's tag, or null for none.
param
out XmlSerializer to write the list into.
see
#writeListXml(List, OutputStream)
see
#writeMapXml
see
#writeValueXml
see
#readListXml

        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");
    
public static final voidwriteListXml(java.util.List val, java.io.OutputStream out)
Flatten a List into an output stream as XML. The list can later be read back with readListXml().

param
val The list to be flattened.
param
out Where to write the XML data.
see
#writeListXml(List, String, XmlSerializer)
see
#writeMapXml
see
#writeValueXml
see
#readListXml

        XmlSerializer serializer = Xml.newSerializer();
        serializer.setOutput(out, "utf-8");
        serializer.startDocument(null, true);
        serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        writeListXml(val, null, serializer);
        serializer.endDocument();
    
public static final voidwriteLongArrayXml(long[] val, java.lang.String name, org.xmlpull.v1.XmlSerializer out)
Flatten a long[] into an XmlSerializer. The list can later be read back with readThisLongArrayXml().

param
val The long 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
see
#readThisIntArrayXml


        if (val == null) {
            out.startTag(null, "null");
            out.endTag(null, "null");
            return;
        }

        out.startTag(null, "long-array");
        if (name != null) {
            out.attribute(null, "name", name);
        }

        final int N = val.length;
        out.attribute(null, "num", Integer.toString(N));

        for (int i=0; i<N; i++) {
            out.startTag(null, "item");
            out.attribute(null, "value", Long.toString(val[i]));
            out.endTag(null, "item");
        }

        out.endTag(null, "long-array");
    
public static voidwriteLongAttribute(org.xmlpull.v1.XmlSerializer out, java.lang.String name, long value)

        out.attribute(null, name, Long.toString(value));
    
public static final voidwriteMapXml(java.util.Map val, java.lang.String name, org.xmlpull.v1.XmlSerializer out, com.android.internal.util.XmlUtils$WriteMapCallback callback)
Flatten a Map into an XmlSerializer. The map can later be read back with readThisMapXml().

param
val The map to be flattened.
param
name Name attribute to include with this list's tag, or null for none.
param
out XmlSerializer to write the map into.
param
callback Method to call when an Object type is not recognized.
see
#writeMapXml(Map, OutputStream)
see
#writeListXml
see
#writeValueXml
see
#readMapXml
hide


        if (val == null) {
            out.startTag(null, "null");
            out.endTag(null, "null");
            return;
        }

        out.startTag(null, "map");
        if (name != null) {
            out.attribute(null, "name", name);
        }

        writeMapXml(val, out, callback);

        out.endTag(null, "map");
    
public static final voidwriteMapXml(java.util.Map val, org.xmlpull.v1.XmlSerializer out, com.android.internal.util.XmlUtils$WriteMapCallback callback)
Flatten a Map into an XmlSerializer. The map can later be read back with readThisMapXml(). This method presumes that the start tag and name attribute have already been written and does not write an end tag.

param
val The map to be flattened.
param
out XmlSerializer to write the map into.
see
#writeMapXml(Map, OutputStream)
see
#writeListXml
see
#writeValueXml
see
#readMapXml
hide

        if (val == null) {
            return;
        }

        Set s = val.entrySet();
        Iterator i = s.iterator();

        while (i.hasNext()) {
            Map.Entry e = (Map.Entry)i.next();
            writeValueXml(e.getValue(), (String)e.getKey(), out, callback);
        }
    
public static final voidwriteMapXml(java.util.Map val, java.io.OutputStream out)
Flatten a Map into an output stream as XML. The map can later be read back with readMapXml().

param
val The map to be flattened.
param
out Where to write the XML data.
see
#writeMapXml(Map, String, XmlSerializer)
see
#writeListXml
see
#writeValueXml
see
#readMapXml

        XmlSerializer serializer = new FastXmlSerializer();
        serializer.setOutput(out, "utf-8");
        serializer.startDocument(null, true);
        serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        writeMapXml(val, null, serializer);
        serializer.endDocument();
    
public static final voidwriteMapXml(java.util.Map val, java.lang.String name, org.xmlpull.v1.XmlSerializer out)
Flatten a Map into an XmlSerializer. The map can later be read back with readThisMapXml().

param
val The map to be flattened.
param
name Name attribute to include with this list's tag, or null for none.
param
out XmlSerializer to write the map into.
see
#writeMapXml(Map, OutputStream)
see
#writeListXml
see
#writeValueXml
see
#readMapXml

        writeMapXml(val, name, out, null);
    
public static final voidwriteSetXml(java.util.Set val, java.lang.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);
        }
        
        for (Object v : val) {
            writeValueXml(v, null, out);
        }
        
        out.endTag(null, "set");
    
public static final voidwriteStringArrayXml(java.lang.String[] val, java.lang.String name, org.xmlpull.v1.XmlSerializer out)
Flatten a String[] into an XmlSerializer. The list can later be read back with readThisStringArrayXml().

param
val The String 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
see
#readThisIntArrayXml


        if (val == null) {
            out.startTag(null, "null");
            out.endTag(null, "null");
            return;
        }

        out.startTag(null, "string-array");
        if (name != null) {
            out.attribute(null, "name", name);
        }

        final int N = val.length;
        out.attribute(null, "num", Integer.toString(N));

        for (int i=0; i<N; i++) {
            out.startTag(null, "item");
            out.attribute(null, "value", val[i]);
            out.endTag(null, "item");
        }

        out.endTag(null, "string-array");
    
public static voidwriteStringAttribute(org.xmlpull.v1.XmlSerializer out, java.lang.String name, java.lang.String value)

        if (value != null) {
            out.attribute(null, name, value);
        }
    
public static voidwriteUriAttribute(org.xmlpull.v1.XmlSerializer out, java.lang.String name, android.net.Uri value)

        if (value != null) {
            out.attribute(null, name, value.toString());
        }
    
public static final voidwriteValueXml(java.lang.Object v, java.lang.String name, org.xmlpull.v1.XmlSerializer out)
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

        writeValueXml(v, name, out, null);
    
private static final voidwriteValueXml(java.lang.Object v, java.lang.String name, org.xmlpull.v1.XmlSerializer out, com.android.internal.util.XmlUtils$WriteMapCallback callback)
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

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