2 |
|
|
3 |
|
|
4 |
import java.net.URLEncoder; |
import java.net.URLEncoder; |
|
import java.util.ArrayList; |
|
|
import java.util.List; |
|
5 |
|
|
6 |
import org.simpleframework.xml.Serializer; |
import org.simpleframework.xml.Serializer; |
7 |
import org.simpleframework.xml.core.Persister; |
import org.simpleframework.xml.core.Persister; |
8 |
import org.w3c.dom.Document; |
|
|
import org.w3c.dom.Node; |
|
|
import org.w3c.dom.NodeList; |
|
9 |
|
|
10 |
import android.location.Location; |
import android.location.Location; |
11 |
import android.util.Log; |
import android.util.Log; |
12 |
import dk.thoerup.android.traininfo.common.StationBean; |
import dk.thoerup.android.traininfo.common.StationBean; |
|
import dk.thoerup.android.traininfo.common.TimetableBean; |
|
13 |
import dk.thoerup.traininfo.util.AndroidTimeoutCache; |
import dk.thoerup.traininfo.util.AndroidTimeoutCache; |
14 |
import dk.thoerup.traininfo.util.DownloadUtil; |
import dk.thoerup.traininfo.util.DownloadUtil; |
15 |
import dk.thoerup.traininfo.util.XmlUtil; |
import dk.thoerup.traininfo.util.XmlUtil; |
18 |
|
|
19 |
final static int CACHE_TIMEOUT = 300*1000; |
final static int CACHE_TIMEOUT = 300*1000; |
20 |
|
|
21 |
//List<StationBean> stations = new ArrayList<StationBean>(); |
|
22 |
AndroidTimeoutCache<String, StationBean> stationCache = new AndroidTimeoutCache<String, StationBean>(CACHE_TIMEOUT); |
AndroidTimeoutCache<String, StationBean> stationCache = new AndroidTimeoutCache<String, StationBean>(CACHE_TIMEOUT); |
23 |
|
|
24 |
|
|
42 |
@Override |
@Override |
43 |
public StationBean lookupStationsByName(String name) { |
public StationBean lookupStationsByName(String name) { |
44 |
|
|
|
// String url = XmlUtil.SERVICE_BASE + "/LocateStations?name=" + Uri.encode(name); |
|
|
String url = ""; |
|
|
|
|
45 |
try { |
try { |
46 |
url = XmlUtil.SERVICE_BASE + "/LocateStations?name=" + URLEncoder.encode(name, "ISO8859-1"); |
name = URLEncoder.encode(name, "ISO8859-1"); |
47 |
} catch (Exception e) { |
} catch (Exception e) { |
48 |
Log.e("lookupStations", "Encoding failed", e); |
Log.e("lookupStations", "Encoding failed", e);//if encoding fails use original and hope for the best |
49 |
} |
} |
50 |
|
|
51 |
|
String url = XmlUtil.SERVICE_BASE + "/LocateStations?name=" + name; |
52 |
|
|
53 |
|
|
54 |
Log.i("url", url); |
Log.i("url", url); |
55 |
return lookupStationsWorker(url); |
return lookupStationsWorker(url); |
56 |
} |
} |
93 |
|
|
94 |
StationBean stations = serializer.read(StationBean.class, xml); |
StationBean stations = serializer.read(StationBean.class, xml); |
95 |
|
|
|
|
|
96 |
return stations; |
return stations; |
97 |
|
|
|
|
|
98 |
} catch (Exception e) { |
} catch (Exception e) { |
99 |
Log.e("XmlStationProvider", "lookupStations: ", e); |
Log.e("XmlStationProvider", "lookupStations: ", e); |
100 |
return null; |
return null; |
101 |
} |
} |
102 |
} |
} |
103 |
|
|
104 |
|
@Override |
105 |
|
public void purgeOldEntries() { |
106 |
|
stationCache.purgeOldEntries(); |
107 |
|
} |
108 |
} |
} |