Android Open Source - Tvdb-Api-Android Xml Object Request






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.xml;
//w w  w .j a va  2s.  c o m
import com.android.volley.NetworkResponse;
import com.android.volley.ParseError;
import com.android.volley.Response;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.toolbox.HttpHeaderParser;

import java.io.UnsupportedEncodingException;

/**
 * A request for retrieving a {@link T} XML response body at a given URL
 */
public class XmlObjectRequest<T, S extends XmlObjectParser<T>> extends XmlRequest<T> {
    protected final S mXmlParser;

    /**
     * Creates a new request.
     *
     * @param xmlParser     Parser to create {@link T} from XML at given URL
     * @param url           URL to fetch the XML from
     * @param listener      Listener to receive the XML response
     * @param errorListener Error listener, or null to ignore errors.
     */
    public XmlObjectRequest(S xmlParser, String url, Listener<T> listener,
                            ErrorListener errorListener) {
        super(Method.GET, url, null, listener, errorListener);
        mXmlParser = xmlParser;
    }

    @Override
    protected Response<T> parseNetworkResponse(NetworkResponse response) {
        try {
            String xml =
                    new String(response.data, HttpHeaderParser.parseCharset(response.headers));
            return Response.success(parseXml(xml), HttpHeaderParser.parseCacheHeaders(response));
        } catch (UnsupportedEncodingException e) {
            return Response.error(new ParseError(e));
        } catch (XmlException e) {
            return Response.error(new ParseError(e));
        }
    }

    protected T parseXml(String xml) throws XmlException {
        return mXmlParser.parseXmlString(xml);
    }
}




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