1 /* StuvSearchHelper.java
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 package de.dhbwloe.campusapp.search;
18 import android.util.Xml;
20 import com.loopj.android.http.AsyncHttpClient;
21 import com.loopj.android.http.AsyncHttpResponseHandler;
23 import org.jsoup.nodes.Document;
25 import java.io.ByteArrayInputStream;
26 import java.io.UnsupportedEncodingException;
27 import java.net.URLEncoder;
28 import java.util.ArrayList;
29 import java.util.List;
31 import de.dhbwloe.campusapp.fragments.AppSearchListItem;
32 import de.dhbwloe.campusapp.network.XmlEntry;
33 import de.dhbwloe.campusapp.network.XmlRequestHelper;
36 * Created by pk910 on 25.01.2016.
38 public class StuvSearchHelper extends SearchHelper {
40 public StuvSearchHelper() {
46 protected void processWebRequest(AsyncHttpResponseHandler handler, String keywords) {
47 AsyncHttpClient client = new AsyncHttpClient();
50 url = "http://stuv-loerrach.de/feed/?s="+ URLEncoder.encode(keywords, "UTF-8");
51 } catch (UnsupportedEncodingException e) {
53 client.get(url, null, handler);
57 protected List<AppSearchListItem> onHtmlDocumentReceived(Document document) {
63 protected List<AppSearchListItem> onPlainTextReceived(byte[] data) {
64 ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
65 List<XmlEntry> entries = XmlRequestHelper.parseXml(inputStream, "channel", "item");
66 ArrayList<AppSearchListItem> results = new ArrayList<>();
68 for(XmlEntry entry : entries) {
71 SearchTarget target = new SearchTarget();
72 target.setInAppTarget(true);
73 target.setTargetUrl("WebBrowser");
75 element = XmlEntry.FindXmlEntryByName(entry, "title");
76 String title = (element == null ? null : element.getValue());
78 element = XmlEntry.FindXmlEntryByName(entry, "link");
79 String link = (element == null ? null : element.getValue());
81 element = XmlEntry.FindXmlEntryByName(entry, "description");
82 String description = (element == null ? null : element.getValue());
84 target.setArgument("url", link);
86 AppSearchListItem result = new AppSearchListItem("STUV: "+title, description, target);