1 package de.dhbwloe.campusapp.search;
3 import android.util.Xml;
5 import com.loopj.android.http.AsyncHttpClient;
6 import com.loopj.android.http.AsyncHttpResponseHandler;
8 import org.jsoup.nodes.Document;
10 import java.io.ByteArrayInputStream;
11 import java.io.UnsupportedEncodingException;
12 import java.net.URLEncoder;
13 import java.util.ArrayList;
14 import java.util.List;
16 import de.dhbwloe.campusapp.fragments.AppSearchListItem;
17 import de.dhbwloe.campusapp.network.XmlEntry;
18 import de.dhbwloe.campusapp.network.XmlRequestHelper;
21 * Created by pk910 on 25.01.2016.
23 public class StuvSearchHelper extends SearchHelper {
25 public StuvSearchHelper() {
31 protected void processWebRequest(AsyncHttpResponseHandler handler, String keywords) {
32 AsyncHttpClient client = new AsyncHttpClient();
35 url = "http://stuv-loerrach.de/feed/?s="+ URLEncoder.encode(keywords, "UTF-8");
36 } catch (UnsupportedEncodingException e) {
38 client.get(url, null, handler);
42 protected List<AppSearchListItem> onHtmlDocumentReceived(Document document) {
48 protected List<AppSearchListItem> onPlainTextReceived(byte[] data) {
49 ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
50 List<XmlEntry> entries = XmlRequestHelper.parseXml(inputStream, "channel", "item");
51 ArrayList<AppSearchListItem> results = new ArrayList<>();
53 for(XmlEntry entry : entries) {
56 SearchTarget target = new SearchTarget();
57 target.setInAppTarget(true);
58 target.setTargetUrl("WebBrowser");
60 element = XmlEntry.FindXmlEntryByName(entry, "title");
61 String title = (element == null ? null : element.getValue());
63 element = XmlEntry.FindXmlEntryByName(entry, "link");
64 String link = (element == null ? null : element.getValue());
66 element = XmlEntry.FindXmlEntryByName(entry, "description");
67 String description = (element == null ? null : element.getValue());
69 target.setArgument("url", link);
71 AppSearchListItem result = new AppSearchListItem("STUV: "+title, description, target);