/[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 842 by torben, Fri Jun 11 20:50:40 2010 UTC revision 977 by torben, Sat Jul 10 09:57:04 2010 UTC
# Line 90  public class TimetableFetcher { Line 90  public class TimetableFetcher {
90          List<TimetableBean> lookupTimetableRealSite(String trainID, String type) throws Exception {                      List<TimetableBean> lookupTimetableRealSite(String trainID, String type) throws Exception {            
91                  List<TimetableBean> timetableList = new ArrayList<TimetableBean>();                  List<TimetableBean> timetableList = new ArrayList<TimetableBean>();
92                                    
93                  String url = "http://www.bane.dk/visRute.asp?W=" + type + "&TogNr=" + trainID + "&artikelId=4276";                  //String url = "http://www.bane.dk/visRute.asp?W=" + type + "&TogNr=" + trainID + "&artikelId=4276";
94                                                    String url = "http://trafikinfo.bane.dk/TrafikInformation/Ruteplan/" + trainID;                
95    
96              final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3);              final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3);
97              webClient.setTimeout(2500);              webClient.setTimeout(2500);
# Line 100  public class TimetableFetcher { Line 100  public class TimetableFetcher {
100              webClient.setCssEnabled(false);              webClient.setCssEnabled(false);
101                            
102                            
103              BanedkInvocation wrapper = new BanedkInvocation(webClient, url);              HtmlunitInvocation wrapper = new HtmlunitInvocation(webClient, url);
104              CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk");              CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk");
105                            
106              HtmlPage page = (HtmlPage) breaker.invoke(wrapper);              HtmlPage page = (HtmlPage) breaker.invoke(wrapper);
# Line 137  public class TimetableFetcher { Line 137  public class TimetableFetcher {
137                          bean.setArrival( fields.get(1).asText() );                          bean.setArrival( fields.get(1).asText() );
138                          bean.setDeparture( fields.get(2).asText() );                          bean.setDeparture( fields.get(2).asText() );
139                                                    
140                            boolean cancelled = fields.get(3).asText().equalsIgnoreCase("aflyst");
141                            bean.setCancelled(cancelled);
142                            
143                          if (currentStation == true && currentStationSaved == false ) {                          if (currentStation == true && currentStationSaved == false ) {
144                                  bean.setCurrent(currentStation);                                  bean.setCurrent(currentStation);
145                                  currentStationSaved = true;                                  currentStationSaved = true;
# Line 145  public class TimetableFetcher { Line 148  public class TimetableFetcher {
148                          bean.setStationId( getStationId( station ));                          bean.setStationId( getStationId( station ));
149                                                    
150                          timetableList.add(bean);                          timetableList.add(bean);
151                    }
152                    
153                    //TODO: There is an off-by-one error in this cancelled parser thingie
154                    final String cancelledString = "Aflyst";
155                    for (int i=0;i<timetableList.size(); i++) { //handle cancelled labels
156                            final int lastIdx = (timetableList.size() - 1);
157                            
158                            TimetableBean current = timetableList.get(i);
159                            if (current.isCancelled()) {
160                                    if (i == 0) {
161                                            current.setDeparture(cancelledString);
162                                    } else if (i == lastIdx) {
163                                            current.setArrival(cancelledString);
164                                    } else if (i>0 && i<lastIdx) {
165                                            TimetableBean next = timetableList.get(i+1);
166                                            TimetableBean prev = timetableList.get(i-1);
167                                            
168                                            if (next.isCancelled())
169                                                    current.setDeparture(cancelledString);
170                                            if (prev.isCancelled())
171                                                    current.setArrival(cancelledString);
172                                    }
173                            }
174                  }                  }
175                                    
176              } else {              } else {

Legend:
Removed from v.842  
changed lines
  Added in v.977

  ViewVC Help
Powered by ViewVC 1.1.20