/[projects]/android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/CompareStations.java
ViewVC logotype

Diff of /android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/CompareStations.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1451 by torben, Thu May 5 11:21:11 2011 UTC revision 1693 by torben, Fri Feb 24 19:10:18 2012 UTC
# Line 38  public class CompareStations extends Htt Line 38  public class CompareStations extends Htt
38                  Map<String,String> banedkStations = new TreeMap<String,String>();                  Map<String,String> banedkStations = new TreeMap<String,String>();
39                  Set<String> dbStations = new TreeSet<String>();                  Set<String> dbStations = new TreeSet<String>();
40                                    
41                    StationDAO dao = new StationDAO();
42                                    
43                  try {                  try {
44                          Document doc = (Document) cb.invoke(jsoup);                          Document doc = (Document) cb.invoke(jsoup);
# Line 53  public class CompareStations extends Htt Line 54  public class CompareStations extends Htt
54                                  }                                  }
55                          }                          }
56    
                         StationDAO dao = new StationDAO();  
57                          StationBean bean = dao.dumpAll();                          StationBean bean = dao.dumpAll();
58                          for (StationEntry station : bean.entries) {                          for (StationEntry station : bean.entries) {
59                                  if (station.isRegional() || station.isStrain()) {                                  if (station.isRegional() || station.isStrain()) {
# Line 74  public class CompareStations extends Htt Line 74  public class CompareStations extends Htt
74                  Set<String> tmpDbStations = new TreeSet<String>( dbStations );                  Set<String> tmpDbStations = new TreeSet<String>( dbStations );
75                  Set<String> tmpBanedkStations = new TreeSet<String>( banedkStations.keySet()) ;                  Set<String> tmpBanedkStations = new TreeSet<String>( banedkStations.keySet()) ;
76                  tmpBanedkStations.removeAll(tmpDbStations);                  tmpBanedkStations.removeAll(tmpDbStations);
77    
78                    
79    
80                  for(String s : tmpBanedkStations) {                  for(String s : tmpBanedkStations) {
81                          String uri = banedkStations.get(s);                          String uri = banedkStations.get(s);
82                          sb.append( "<li><a href='http://trafikinfo.bane.dk" + uri + "'>"+ s + "</a></li>" );                          String disabled = "";
83                            String data = hasData(uri);
84                            
85                            try {
86                                    boolean tmpdisabled = dao.hasDisabledStation(s);
87                                    if (tmpdisabled == true)
88                                            disabled = "disabled";
89                            } catch (Exception e) {
90                                    throw new ServletException(e);
91                            }
92                            
93                            sb.append( "<li><a href='http://trafikinfo.bane.dk" + uri + "'>" + s + "</a>&nbsp;&nbsp;" + data + " - " + disabled + "</li>" );
94                  }                                                }                              
95                  sb.append("</ul>");                  sb.append("</ul>");
96    
# Line 95  public class CompareStations extends Htt Line 109  public class CompareStations extends Htt
109                  PrintWriter out = response.getWriter();                  PrintWriter out = response.getWriter();
110                  out.print(sb.toString());                  out.print(sb.toString());
111                                    
112            }
113            
114            String hasData(String uri) {
115                    String returnVal = "unknown";
116                                    
117                    try {
118                            CircuitBreaker cb = CircuitBreakerManager.getManager().getCircuitBreaker("banedk");
119                            
120                            JsoupInvocation jsoup = new JsoupInvocation(new URL("http://trafikinfo.bane.dk" + uri), 5000);
121                            
122                            Document doc = (Document) cb.invoke(jsoup);
123                            
124                            Element tabel = doc.getElementById("afgangtabel");
125                            if ( tabel != null) {
126                                    returnVal = "<font color='red'>Data!</font>";
127                            } else {
128                                    returnVal =  "";
129                            }
130                            
131                    } catch (Exception e) {
132                            System.out.println( e.getMessage() );
133                    }
134                                    
135                    return returnVal;
136          }          }
137    
138    
139  }  }

Legend:
Removed from v.1451  
changed lines
  Added in v.1693

  ViewVC Help
Powered by ViewVC 1.1.20