--- android/TrainInfo/src/dk/thoerup/traininfo/provider/XmlStationProvider.java 2010/09/08 08:45:18 1031 +++ android/TrainInfo/src/dk/thoerup/traininfo/provider/XmlStationProvider.java 2010/09/18 07:16:40 1077 @@ -2,16 +2,14 @@ import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.List; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; +import org.simpleframework.xml.Serializer; +import org.simpleframework.xml.core.Persister; + import android.location.Location; import android.util.Log; -import dk.thoerup.traininfo.StationBean; +import dk.thoerup.android.traininfo.common.StationBean; import dk.thoerup.traininfo.util.AndroidTimeoutCache; import dk.thoerup.traininfo.util.DownloadUtil; import dk.thoerup.traininfo.util.XmlUtil; @@ -21,7 +19,7 @@ final static int CACHE_TIMEOUT = 300*1000; //List stations = new ArrayList(); - AndroidTimeoutCache> stationCache = new AndroidTimeoutCache>(CACHE_TIMEOUT); + AndroidTimeoutCache stationCache = new AndroidTimeoutCache(CACHE_TIMEOUT); double roundToPlaces(double value, int places) { @@ -32,7 +30,7 @@ } @Override - public List lookupStations(Location location) { + public StationBean lookupStations(Location location) { double lat = roundToPlaces(location.getLatitude(), 4); double lng = roundToPlaces(location.getLongitude(), 4); @@ -42,24 +40,24 @@ } @Override - public List lookupStationsByName(String name) { - - // String url = XmlUtil.SERVICE_BASE + "/LocateStations?name=" + Uri.encode(name); - String url = ""; + public StationBean lookupStationsByName(String name) { try { - url = XmlUtil.SERVICE_BASE + "/LocateStations?name=" + URLEncoder.encode(name, "ISO8859-1"); + name = URLEncoder.encode(name, "ISO8859-1"); } catch (Exception e) { - Log.e("lookupStations", "Encoding failed", e); + Log.e("lookupStations", "Encoding failed", e);//if encoding fails use original and hope for the best } + String url = XmlUtil.SERVICE_BASE + "/LocateStations?name=" + name; + + Log.i("url", url); return lookupStationsWorker(url); } @Override - public List lookupStationsByIds(String ids) { + public StationBean lookupStationsByIds(String ids) { String url = ""; url = XmlUtil.SERVICE_BASE + "/LocateStations?list=" + ids; @@ -67,9 +65,9 @@ return lookupStationsWorker(url); } - public List lookupStationsWorker(String url) { + public StationBean lookupStationsWorker(String url) { - List tmpStations = stationCache.get(url); + StationBean tmpStations = stationCache.get(url); if (tmpStations != null) { Log.i("lookupStations", "cache hit " + url); @@ -85,69 +83,17 @@ } - public List fetchStations(String url) { + public StationBean fetchStations(String url) { try { - List stations = new ArrayList(); String xml = DownloadUtil.getContentString(url, 15000, "ISO-8859-1"); - - Document doc = XmlUtil.parseXML(xml); - Node rootNode = doc.getDocumentElement(); // stations - NodeList stationList = rootNode.getChildNodes(); - - - for (int i=0; i