--- android/TrainInfo/src/dk/thoerup/traininfo/provider/XmlStationProvider.java 2009/09/01 20:28:55 294 +++ android/TrainInfo/src/dk/thoerup/traininfo/provider/XmlStationProvider.java 2009/09/29 19:06:34 357 @@ -1,24 +1,17 @@ package dk.thoerup.traininfo.provider; -import java.io.ByteArrayInputStream; -import java.io.IOException; import java.util.ArrayList; import java.util.List; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import org.w3c.dom.Text; -import org.xml.sax.SAXException; import android.location.Location; import android.util.Log; import dk.thoerup.traininfo.StationBean; import dk.thoerup.traininfo.util.DownloadUtil; +import dk.thoerup.traininfo.util.XmlUtil; public class XmlStationProvider implements StationProvider { @@ -31,18 +24,17 @@ } @Override - public void lookupStations(Location location) { - - //String url = "http://pumba.t-hoerup.dk:8080/TrainInfoService/LocateStations?latitude=" + location.getLatitude() + "&longitude=" + location.getLongitude(); - String url = "http://app.t-hoerup.dk/TrainInfoService/LocateStations?latitude=" + location.getLatitude() + "&longitude=" + location.getLongitude(); + public boolean lookupStations(Location location) { + boolean success = false; + String url = XmlUtil.SERVICE_BASE + "/LocateStations?latitude=" + location.getLatitude() + "&longitude=" + location.getLongitude(); Log.i("url", url); try { stations.clear(); - String xml = DownloadUtil.getContentString(url, 15000); + String xml = DownloadUtil.getContentString(url, 15000, "ISO-8859-1"); - Document doc = parseXML(xml); + Document doc = XmlUtil.parseXML(xml); Node rootNode = doc.getDocumentElement(); // stations NodeList stationList = rootNode.getChildNodes(); @@ -65,7 +57,8 @@ String nodeName = current.getNodeName(); - Log.i("XML", "" + nodeName + "=" + content); + if (nodeName.equals("id")) + station.setId( Integer.parseInt(content)); if (nodeName.equals("name")) station.setName(content); @@ -84,17 +77,13 @@ } stations.add(station); - } + } + success = true; } catch (Exception e) { Log.e("XmlStationProvider", "lookupStations: ", e); } - } - - public Document parseXML(String str) throws SAXException, IOException, ParserConfigurationException - { - DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - return builder.parse( new ByteArrayInputStream(str.getBytes()) ); + return success; } }