Search in sources :

Example 6 with EndTextElementListener

use of android.sax.EndTextElementListener in project SeriesGuide by UweTrottmann.

the class TvdbTools method searchShow.

/**
     * Search TheTVDB for shows which include a certain keyword in their title.
     *
     * @param language If not provided, will query for results in all languages.
     * @return At most 100 results (limited by TheTVDB API).
     */
@Nonnull
public List<SearchResult> searchShow(@NonNull String query, @Nullable final String language) throws TvdbException {
    final List<SearchResult> series = new ArrayList<>();
    final SearchResult currentShow = new SearchResult();
    RootElement root = new RootElement("Data");
    Element item = root.getChild("Series");
    // set handlers for elements we want to react to
    item.setEndElementListener(new EndElementListener() {

        public void end() {
            // only take results in the selected language
            if (language == null || language.equals(currentShow.language)) {
                series.add(currentShow.copy());
            }
        }
    });
    item.getChild("id").setEndTextElementListener(new EndTextElementListener() {

        public void end(String body) {
            currentShow.tvdbid = Integer.valueOf(body);
        }
    });
    item.getChild("language").setEndTextElementListener(new EndTextElementListener() {

        @Override
        public void end(String body) {
            currentShow.language = body.trim();
        }
    });
    item.getChild("SeriesName").setEndTextElementListener(new EndTextElementListener() {

        public void end(String body) {
            currentShow.title = body.trim();
        }
    });
    item.getChild("Overview").setEndTextElementListener(new EndTextElementListener() {

        public void end(String body) {
            currentShow.overview = body.trim();
        }
    });
    // build search URL: encode query...
    String url;
    try {
        url = TVDB_API_GETSERIES + URLEncoder.encode(query, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new TvdbDataException("searchShow: " + e.getMessage(), e);
    }
    // ...and set language filter
    if (language == null) {
        url += TVDB_PARAM_LANGUAGE + "all";
    } else {
        url += TVDB_PARAM_LANGUAGE + language;
    }
    downloadAndParse(root.getContentHandler(), url, false, "searchShow: ");
    return series;
}
Also used : RootElement(android.sax.RootElement) EndElementListener(android.sax.EndElementListener) Element(android.sax.Element) RootElement(android.sax.RootElement) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SearchResult(com.battlelancer.seriesguide.items.SearchResult) EndTextElementListener(android.sax.EndTextElementListener) Nonnull(javax.annotation.Nonnull)

Example 7 with EndTextElementListener

use of android.sax.EndTextElementListener in project android_frameworks_base by AOSPA.

the class SafeSaxTest method testMixedContent.

@SmallTest
public void testMixedContent() throws Exception {
    String xml = "<feed><entry></entry></feed>";
    RootElement root = new RootElement("feed");
    root.setEndTextElementListener(new EndTextElementListener() {

        public void end(String body) {
        }
    });
    try {
        Xml.parse(xml, root.getContentHandler());
        fail("expected exception not thrown");
    } catch (SAXException e) {
    // Expected.
    }
}
Also used : RootElement(android.sax.RootElement) EndTextElementListener(android.sax.EndTextElementListener) SAXException(org.xml.sax.SAXException) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 8 with EndTextElementListener

use of android.sax.EndTextElementListener in project android_frameworks_base by DirtyUnicorns.

the class SafeSaxTest method testMixedContent.

@SmallTest
public void testMixedContent() throws Exception {
    String xml = "<feed><entry></entry></feed>";
    RootElement root = new RootElement("feed");
    root.setEndTextElementListener(new EndTextElementListener() {

        public void end(String body) {
        }
    });
    try {
        Xml.parse(xml, root.getContentHandler());
        fail("expected exception not thrown");
    } catch (SAXException e) {
    // Expected.
    }
}
Also used : RootElement(android.sax.RootElement) EndTextElementListener(android.sax.EndTextElementListener) SAXException(org.xml.sax.SAXException) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 9 with EndTextElementListener

use of android.sax.EndTextElementListener in project android_frameworks_base by ResurrectionRemix.

the class SafeSaxTest method testMixedContent.

@SmallTest
public void testMixedContent() throws Exception {
    String xml = "<feed><entry></entry></feed>";
    RootElement root = new RootElement("feed");
    root.setEndTextElementListener(new EndTextElementListener() {

        public void end(String body) {
        }
    });
    try {
        Xml.parse(xml, root.getContentHandler());
        fail("expected exception not thrown");
    } catch (SAXException e) {
    // Expected.
    }
}
Also used : RootElement(android.sax.RootElement) EndTextElementListener(android.sax.EndTextElementListener) SAXException(org.xml.sax.SAXException) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

EndTextElementListener (android.sax.EndTextElementListener)9 RootElement (android.sax.RootElement)9 SmallTest (android.test.suitebuilder.annotation.SmallTest)6 SAXException (org.xml.sax.SAXException)6 Element (android.sax.Element)3 EndElementListener (android.sax.EndElementListener)3 ArrayList (java.util.ArrayList)2 ContentValues (android.content.ContentValues)1 Message (android.os.Message)1 StartElementListener (android.sax.StartElementListener)1 SearchResult (com.battlelancer.seriesguide.items.SearchResult)1 FileInputStream (java.io.FileInputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Matcher (java.util.regex.Matcher)1 Nonnull (javax.annotation.Nonnull)1 DateTimeZone (org.joda.time.DateTimeZone)1 LocalTime (org.joda.time.LocalTime)1