/[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 1303 by torben, Tue Apr 19 11:52:39 2011 UTC revision 1367 by torben, Wed Apr 20 20:33:22 2011 UTC
# Line 16  import dk.thoerup.android.traininfo.comm Line 16  import dk.thoerup.android.traininfo.comm
16  import dk.thoerup.android.traininfo.common.TimetableEntry;  import dk.thoerup.android.traininfo.common.TimetableEntry;
17  import dk.thoerup.circuitbreaker.CircuitBreaker;  import dk.thoerup.circuitbreaker.CircuitBreaker;
18  import dk.thoerup.circuitbreaker.CircuitBreakerManager;  import dk.thoerup.circuitbreaker.CircuitBreakerManager;
19    import dk.thoerup.genericjavautils.TimeoutMap;
20  import dk.thoerup.traininfoservice.Statistics;  import dk.thoerup.traininfoservice.Statistics;
21  import dk.thoerup.traininfoservice.TraininfoSettings;  import dk.thoerup.traininfoservice.TraininfoSettings;
22  import dk.thoerup.traininfoservice.db.StationDAO;  import dk.thoerup.traininfoservice.db.StationDAO;
# Line 44  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 60  public class TimetableFetcher { Line 62  public class TimetableFetcher {
62                          return lookupTimetableAzureSite(trainID, type);                          return lookupTimetableAzureSite(trainID, type);
63                                                    
64                  } else {                  } else {
65                          return lookupTimetableWwwSite(trainID, type);                          return lookupTimetableMobileSite(trainID, type);
66                  }                  }
67          }          }
68                    
# Line 170  public class TimetableFetcher { Line 172  public class TimetableFetcher {
172                  return timetableBean;                  return timetableBean;
173          }          }
174    
175            TimetableBean lookupTimetableMobileSite(String trainID, String type) throws Exception {
176                    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.info( 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
226          TimetableBean lookupTimetableWwwSite(String trainID, String type) throws Exception {                      TimetableBean lookupTimetableWwwSite(String trainID, String type) throws Exception {            
227                  TimetableBean timetableBean = new TimetableBean();                  TimetableBean timetableBean = new TimetableBean();
228                                    

Legend:
Removed from v.1303  
changed lines
  Added in v.1367

  ViewVC Help
Powered by ViewVC 1.1.20