Search in sources :

Example 41 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project HoloEverywhere by Prototik.

the class XmlUtils method readSetXml.

public static final HashSet readSetXml(InputStream in) throws XmlPullParserException, java.io.IOException {
    XmlPullParser parser = Xml.newPullParser();
    parser.setInput(in, null);
    return (HashSet) XmlUtils.readValueXml(parser, new String[1]);
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) HashSet(java.util.HashSet)

Example 42 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project HoloEverywhere by Prototik.

the class XmlUtils method readThisIntArrayXml.

public static final int[] readThisIntArrayXml(XmlPullParser parser, String endTag, String[] name) throws XmlPullParserException, java.io.IOException {
    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");
    }
    int[] array = new int[num];
    int i = 0;
    int eventType = parser.getEventType();
    do {
        if (eventType == XmlPullParser.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 == XmlPullParser.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 != XmlPullParser.END_DOCUMENT);
    throw new XmlPullParserException("Document ended before " + endTag + " end tag");
}
Also used : XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 43 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project DesignLibrary by StylingAndroid.

the class SaRssParser method newInstance.

public static SaRssParser newInstance(InputStream inputStream) {
    XmlPullParserFactory factory;
    XmlPullParser parser = null;
    try {
        factory = XmlPullParserFactory.newInstance();
        parser = factory.newPullParser();
        parser.setInput(inputStream, DEFAULT_CHARSET);
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    }
    return new SaRssParser(parser);
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 44 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project ElasticDownload by Tibolte.

the class AnimatedVectorDrawable method create.

public static AnimatedVectorDrawable create(Context c, Resources resources, int rid) {
    try {
        final XmlPullParser parser = resources.getXml(rid);
        final AttributeSet attrs = Xml.asAttributeSet(parser);
        int type;
        while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
        // Empty loop
        }
        if (type != XmlPullParser.START_TAG) {
            throw new XmlPullParserException("No start tag found");
        } else if (!ANIMATED_VECTOR.equals(parser.getName())) {
            throw new IllegalArgumentException("root node must start with: " + ANIMATED_VECTOR);
        }
        final AnimatedVectorDrawable drawable = new AnimatedVectorDrawable();
        drawable.inflate(c, resources, parser, attrs, null);
        return drawable;
    } catch (XmlPullParserException e) {
        Log.e(LOG_TAG, "parser error", e);
    } catch (IOException e) {
        Log.e(LOG_TAG, "parser error", e);
    }
    return null;
}
Also used : AttributeSet(android.util.AttributeSet) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 45 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project ElasticDownload by Tibolte.

the class VectorDrawable method inflateInternal.

private void inflateInternal(Resources res, XmlPullParser parser, AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException {
    final VectorDrawableState state = mVectorState;
    final VPathRenderer pathRenderer = state.mVPathRenderer;
    boolean noPathTag = true;
    // Use a stack to help to build the group tree.
    // The top of the stack is always the current group.
    final Stack<VGroup> groupStack = new Stack<VGroup>();
    groupStack.push(pathRenderer.mRootGroup);
    int eventType = parser.getEventType();
    while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG) {
            final String tagName = parser.getName();
            final VGroup currentGroup = groupStack.peek();
            if (SHAPE_PATH.equals(tagName)) {
                final VFullPath path = new VFullPath();
                path.inflate(res, attrs, theme);
                currentGroup.mChildren.add(path);
                if (path.getPathName() != null) {
                    pathRenderer.mVGTargetsMap.put(path.getPathName(), path);
                }
                noPathTag = false;
                state.mChangingConfigurations |= path.mChangingConfigurations;
            } else if (SHAPE_CLIP_PATH.equals(tagName)) {
                final VClipPath path = new VClipPath();
                path.inflate(res, attrs, theme);
                currentGroup.mChildren.add(path);
                if (path.getPathName() != null) {
                    pathRenderer.mVGTargetsMap.put(path.getPathName(), path);
                }
                state.mChangingConfigurations |= path.mChangingConfigurations;
            } else if (SHAPE_GROUP.equals(tagName)) {
                VGroup newChildGroup = new VGroup();
                newChildGroup.inflate(res, attrs, theme);
                currentGroup.mChildren.add(newChildGroup);
                groupStack.push(newChildGroup);
                if (newChildGroup.getGroupName() != null) {
                    pathRenderer.mVGTargetsMap.put(newChildGroup.getGroupName(), newChildGroup);
                }
                state.mChangingConfigurations |= newChildGroup.mChangingConfigurations;
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            final String tagName = parser.getName();
            if (SHAPE_GROUP.equals(tagName)) {
                groupStack.pop();
            }
        }
        eventType = parser.next();
    }
    // Print the tree out for debug.
    if (DBG_VECTOR_DRAWABLE) {
        printGroupTree(pathRenderer.mRootGroup, 0);
    }
    if (noPathTag) {
        final StringBuffer tag = new StringBuffer();
        if (tag.length() > 0) {
            tag.append(" or ");
        }
        tag.append(SHAPE_PATH);
        throw new XmlPullParserException("no " + tag + " defined");
    }
}
Also used : XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Paint(android.graphics.Paint) Stack(java.util.Stack)

Aggregations

XmlPullParser (org.xmlpull.v1.XmlPullParser)665 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)614 IOException (java.io.IOException)376 FileNotFoundException (java.io.FileNotFoundException)185 FileInputStream (java.io.FileInputStream)184 File (java.io.File)107 ArrayList (java.util.ArrayList)75 StringReader (java.io.StringReader)65 AttributeSet (android.util.AttributeSet)61 Test (org.junit.Test)57 TypedArray (android.content.res.TypedArray)56 InputStream (java.io.InputStream)48 AtomicFile (android.util.AtomicFile)47 HashMap (java.util.HashMap)42 BridgeXmlBlockParser (com.android.layoutlib.bridge.android.BridgeXmlBlockParser)39 FileReader (java.io.FileReader)36 BufferedInputStream (java.io.BufferedInputStream)30 XmlPullParserFactory (org.xmlpull.v1.XmlPullParserFactory)29 RemoteException (android.os.RemoteException)28 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)28