Android Open Source - Tvdb-Api-Android Series Parser






From Project

Back to project page Tvdb-Api-Android.

License

The source code is released under:

Apache License

If you think the Android project Tvdb-Api-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.sburba.tvdbapi.parser;
/*from  www . j  a  v a  2  s .  c  o  m*/
import com.sburba.tvdbapi.model.Series;
import com.sburba.tvdbapi.xml.XmlException;
import com.sburba.tvdbapi.xml.XmlObjectListParser;
import com.sburba.tvdbapi.xml.XmlObjectParser;
import com.sburba.tvdbapi.xml.XmlUtil;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

public class SeriesParser implements XmlObjectListParser<Series>, XmlObjectParser<Series> {

    @Override
    public Collection<Series> parseListFromXmlString(String xml) throws XmlException {
        try {
            return readSeriesList(XmlUtil.getXmlPullParser(xml));
        } catch (IOException e) {
            throw new XmlException("Error reading XML String", e);
        } catch (XmlPullParserException e) {
            throw new XmlException("Error parsing XML", e);
        }
    }

    @Override
    public Collection<Series> parseListFromXmlStrings(Map<String, String> xmlStrings)
            throws XmlException {
        throw new IllegalStateException("Can't parse series list from a set of xmlStrings");
    }

    @Override
    public Series parseXmlString(String xmlString) throws XmlException {
        try {
            return readSeries(XmlUtil.getXmlPullParser(xmlString));
        } catch (XmlPullParserException e) {
            throw new XmlException("Error parsing XML");
        } catch (IOException e) {
            throw new XmlException("Error reading XML String");
        }
    }

    private Series readSeries(XmlPullParser parser)
            throws XmlPullParserException, IOException, XmlException {
        parser.require(XmlPullParser.START_TAG, null, "Data");
        parser.next();
        return Series.fromXml(parser);
    }

    private Collection<Series> readSeriesList(XmlPullParser parser)
            throws IOException, XmlPullParserException, XmlException {

        List<Series> SeriesList = new ArrayList<Series>();
        parser.require(XmlPullParser.START_TAG, null, "Data");
        while (parser.next() != XmlPullParser.END_TAG) {
            if (parser.getEventType() != XmlPullParser.START_TAG) continue;
            if (parser.getName().equals("Series")) {
                Series series = Series.fromXml(parser);
                SeriesList.add(series);
            } else {
                XmlUtil.skip(parser);
            }
        }
        return SeriesList;
    }
}




Java Source Code List

com.sburba.tvdbapi.TvdbApi.java
com.sburba.tvdbapi.TvdbItemAdapter.java
com.sburba.tvdbapi.example.App.java
com.sburba.tvdbapi.example.EpisodeListActivity.java
com.sburba.tvdbapi.example.LruBitmapCache.java
com.sburba.tvdbapi.example.SeasonListActivity.java
com.sburba.tvdbapi.example.SeriesListActivity.java
com.sburba.tvdbapi.model.Actor.java
com.sburba.tvdbapi.model.Banner.java
com.sburba.tvdbapi.model.Episode.java
com.sburba.tvdbapi.model.Season.java
com.sburba.tvdbapi.model.Series.java
com.sburba.tvdbapi.model.TvdbItem.java
com.sburba.tvdbapi.parser.ActorListParser.java
com.sburba.tvdbapi.parser.BannerListParser.java
com.sburba.tvdbapi.parser.EpisodeParser.java
com.sburba.tvdbapi.parser.SeasonListParser.java
com.sburba.tvdbapi.parser.SeriesParser.java
com.sburba.tvdbapi.util.ThreadPreconditions.java
com.sburba.tvdbapi.xml.XmlException.java
com.sburba.tvdbapi.xml.XmlObjectListParser.java
com.sburba.tvdbapi.xml.XmlObjectListRequest.java
com.sburba.tvdbapi.xml.XmlObjectParser.java
com.sburba.tvdbapi.xml.XmlObjectRequest.java
com.sburba.tvdbapi.xml.XmlRequest.java
com.sburba.tvdbapi.xml.XmlUtil.java
com.sburba.tvdbapi.xml.ZippedXmlObjectListRequest.java