--- android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/CompareStations.java 2011/05/05 10:48:29 1450 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/CompareStations.java 2012/02/24 14:26:53 1692 @@ -3,8 +3,9 @@ import java.io.IOException; import java.io.PrintWriter; import java.net.URL; -import java.util.ArrayList; +import java.util.Map; import java.util.Set; +import java.util.TreeMap; import java.util.TreeSet; import javax.servlet.ServletException; @@ -34,9 +35,11 @@ JsoupInvocation jsoup = new JsoupInvocation(new URL("http://trafikinfo.bane.dk/Trafikinformation/Stationsliste"), 5000); - Set banedkStations = new TreeSet(); + Map banedkStations = new TreeMap(); Set dbStations = new TreeSet(); + StationDAO dao = new StationDAO(); + try { Document doc = (Document) cb.invoke(jsoup); @@ -45,13 +48,12 @@ for(Element e : tables) { if (e.tagName().equals("table") ){ Elements links = e.getElementsByTag("a"); - for (Element link : links) { - banedkStations.add( link.text() ); + for (Element link : links) { + banedkStations.put( link.text(), link.attr("href") ); } } } - StationDAO dao = new StationDAO(); StationBean bean = dao.dumpAll(); for (StationEntry station : bean.entries) { if (station.isRegional() || station.isStrain()) { @@ -70,10 +72,23 @@ sb.append("

stations on website not in db

"); sb.append("
    "); Set tmpDbStations = new TreeSet( dbStations ); - Set tmpBanedkStations = new TreeSet( banedkStations) ; + Set tmpBanedkStations = new TreeSet( banedkStations.keySet()) ; tmpBanedkStations.removeAll(tmpDbStations); + + + for(String s : tmpBanedkStations) { - sb.append( "
  • " + s + "
  • " ); + String uri = banedkStations.get(s); + String disabled = ""; + try { + boolean tmpdisabled = dao.hasDisabledStation(s); + if (tmpdisabled == true) + disabled = "disabled"; + } catch (Exception e) { + throw new ServletException(e); + } + + sb.append( "
  • " + s + "  " + disabled + "
  • " ); } sb.append("
"); @@ -81,7 +96,7 @@ sb.append("

stations in db not on website

"); sb.append("
    "); tmpDbStations = new TreeSet( dbStations ); - tmpBanedkStations = new TreeSet( banedkStations) ; + tmpBanedkStations = new TreeSet( banedkStations.keySet() ) ; tmpDbStations.removeAll(tmpBanedkStations); for(String s : tmpDbStations) { sb.append( "
  • " + s + "
  • " ); @@ -96,4 +111,5 @@ } + }