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;
}
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.
}
}
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.
}
}
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.
}
}
Aggregations