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

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

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

revision 1355 by torben, Wed Apr 20 19:01:33 2011 UTC revision 1372 by torben, Thu Apr 21 05:51:25 2011 UTC
# Line 45  public class TimetableFetcher { Line 45  public class TimetableFetcher {
45          TimetableBean cachedLookupTimetable(String trainID, String type) throws Exception {          TimetableBean cachedLookupTimetable(String trainID, String type) throws Exception {
46                  String key = trainID+type;                  String key = trainID+type;
47                  TimetableBean list = cache.get(key);                  TimetableBean list = cache.get(key);
48                    list = null; //TODO: DEBUG
49                                    
50                  if (list == null) {                  if (list == null) {
51                          list = lookupTimetable(trainID,type);                          list = lookupTimetable(trainID,type);
# Line 57  public class TimetableFetcher { Line 58  public class TimetableFetcher {
58          }          }
59                    
60          TimetableBean lookupTimetable(String trainID, String type) throws Exception {          TimetableBean lookupTimetable(String trainID, String type) throws Exception {
61                  if (settings.getUseAzureSite() == true ){                  if (settings.getBackend() == TraininfoSettings.Backend.Azure ){
62                          return lookupTimetableAzureSite(trainID, type);                          return lookupTimetableAzureSite(trainID, type);
63                                                    
64                  } else {                  } else {
# Line 172  public class TimetableFetcher { Line 173  public class TimetableFetcher {
173          }          }
174    
175          TimetableBean lookupTimetableMobileSite(String trainID, String type) throws Exception {          TimetableBean lookupTimetableMobileSite(String trainID, String type) throws Exception {
176                  return new TimetableBean(); //dummy skeleton method                  TimetableBean timetableBean = new TimetableBean();
177                    
178                    String url = "http://mobil.bane.dk/mobilStation.asp?artikelID=5332&tognummer=" + trainID + "&webprofil=" + type + "&mode=rute";
179                    logger.fine("URL:" + url);
180    
181                
182                JsoupInvocation wrapper = new JsoupInvocation( new URL(url) , settings.getReplyTimeout() );
183                CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk");
184                
185                Document doc = (Document) breaker.invoke(wrapper);
186    
187                Element content = doc.getElementsByClass("contentDiv").get(1);
188                Element dlist = content.child(0);
189    
190                
191                Elements rows = dlist.getElementsByTag("dt");
192    
193                for (int i=0; i<rows.size(); i++) {
194    
195                    Element row = rows.get(i);
196                    
197                    logger.fine( row.text() );
198                    
199                    String parts[] = row.text().split(",");
200                    
201                    TimetableEntry entry = new TimetableEntry();
202    
203                    String station = DepartureFetcher.cleanText( parts[0] ) ;
204                    if (station.equals("København"))
205                            station = "København H"; //correct inconsistency in naming
206    
207                    String arrival = DepartureFetcher.cleanText( parts[1] );
208                    String departure = DepartureFetcher.cleanText( "" );
209    
210                    entry.setStation( station );
211                    entry.setArrival( arrival );
212                    entry.setDeparture( departure );
213    
214    
215                    entry.setStationId( getStationId( station ));
216    
217                    timetableBean.entries.add(entry);
218                }          
219    
220    
221                return timetableBean;
222    
223          }          }
224                    
225          @Deprecated          @Deprecated

Legend:
Removed from v.1355  
changed lines
  Added in v.1372

  ViewVC Help
Powered by ViewVC 1.1.20