/[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 1410 by torben, Mon May 2 12:02:54 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 56  public class TimetableFetcher { Line 57  public class TimetableFetcher {
57          }          }
58                    
59          TimetableBean lookupTimetable(String trainID, String type) throws Exception {          TimetableBean lookupTimetable(String trainID, String type) throws Exception {
60                  if (settings.getUseAzureSite() == true ){                  if (settings.getBackend() == TraininfoSettings.Backend.Azure ){
61                          return lookupTimetableAzureSite(trainID, type);                          return lookupTimetableAzureSite(trainID, type);
62                                                    
63                  } else {                  } else {
64                          return lookupTimetableWwwSite(trainID, type);                          return lookupTimetableMobileSite(trainID, type);
65                  }                  }
66          }          }
67                    
# Line 79  public class TimetableFetcher { Line 80  public class TimetableFetcher {
80    
81                  return id;                  return id;
82          }          }
83            
84            String correctStationName(String name) {
85                    if (name.equals("København"))
86                            name = "København H"; //correct inconsistency in naming
87                    
88                    return name;            
89            }
90    
91          TimetableBean lookupTimetableAzureSite(String trainID, String type) throws Exception {                    TimetableBean lookupTimetableAzureSite(String trainID, String type) throws Exception {          
92                  TimetableBean timetableBean = new TimetableBean();                  TimetableBean timetableBean = new TimetableBean();
# Line 118  public class TimetableFetcher { Line 126  public class TimetableFetcher {
126                                                    
127                          TimetableEntry entry = new TimetableEntry();                          TimetableEntry entry = new TimetableEntry();
128                                                    
129                          String station = fields.get(0).text() ;                          String station = correctStationName( fields.get(0).text() );
                         if (station.equals("København"))  
                                 station = "København H"; //correct inconsistency in naming  
130                                                    
131                          entry.setStation( station );                          entry.setStation( station );
132                          entry.setArrival( fields.get(1).text() );                          entry.setArrival( fields.get(1).text() );
# Line 170  public class TimetableFetcher { Line 176  public class TimetableFetcher {
176                  return timetableBean;                  return timetableBean;
177          }          }
178    
179            TimetableBean lookupTimetableMobileSite(String trainID, String type) throws Exception {
180                    TimetableBean timetableBean = new TimetableBean();
181                    
182                    String url = "http://mobil.bane.dk/mobilStation.asp?artikelID=5332&tognummer=" + trainID + "&webprofil=" + type + "&mode=rute";
183                    logger.fine("URL:" + url);
184    
185                
186                JsoupInvocation wrapper = new JsoupInvocation( new URL(url) , settings.getReplyTimeout() );
187                CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk");
188                
189                Document doc = (Document) breaker.invoke(wrapper);
190    
191                Element content = doc.getElementsByClass("contentDiv").get(1);
192                Element dlist = content.child(0);
193    
194                
195                Elements rows = dlist.getElementsByTag("dt");
196    
197                for (int i=0; i<rows.size(); i++) {
198    
199                    Element row = rows.get(i);
200                    
201                    logger.fine( row.text() );
202                    
203                    String parts[] = row.text().split(",");
204                    
205                    TimetableEntry entry = new TimetableEntry();
206    
207                    String station = DepartureFetcher.cleanText( parts[0] ) ;
208                    station = correctStationName(station);
209    
210    
211                    String arrival = DepartureFetcher.cleanText( parts[1] );
212                    String departure = DepartureFetcher.cleanText( "" );
213    
214                    entry.setStation( station );
215                    entry.setArrival( arrival );
216                    entry.setDeparture( departure );
217    
218    
219                    entry.setStationId( getStationId( station ));
220    
221                    timetableBean.entries.add(entry);
222                }          
223    
224    
225                return timetableBean;
226    
227            }
228            
229            @Deprecated
230          TimetableBean lookupTimetableWwwSite(String trainID, String type) throws Exception {                      TimetableBean lookupTimetableWwwSite(String trainID, String type) throws Exception {            
231                  TimetableBean timetableBean = new TimetableBean();                  TimetableBean timetableBean = new TimetableBean();
232                                    
# Line 209  public class TimetableFetcher { Line 266  public class TimetableFetcher {
266                          TimetableEntry entry = new TimetableEntry();                          TimetableEntry entry = new TimetableEntry();
267                                                    
268                          String station = DepartureFetcher.cleanText( fields.get(0).text() ) ;                          String station = DepartureFetcher.cleanText( fields.get(0).text() ) ;
269                          if (station.equals("København"))                          station = correctStationName(station);
270                                  station = "København H"; //correct inconsistency in naming  
271                                                    
272                          String arrival = DepartureFetcher.cleanText( fields.get(1).text() );                          String arrival = DepartureFetcher.cleanText( fields.get(1).text() );
273                          String departure = DepartureFetcher.cleanText( fields.get(2).text() );                          String departure = DepartureFetcher.cleanText( fields.get(2).text() );

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

  ViewVC Help
Powered by ViewVC 1.1.20