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

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

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

revision 1562 by torben, Fri Jul 8 16:26:09 2011 UTC revision 2033 by torben, Wed Jul 24 14:50:04 2013 UTC
# Line 134  public class DepartureFetcher { Line 134  public class DepartureFetcher {
134                  if (type == FetchTrainType.BOTH) { //if we have both S-tog and regional order by departure/arrival time                  if (type == FetchTrainType.BOTH) { //if we have both S-tog and regional order by departure/arrival time
135                          Collections.sort( departureBean.entries, departureTimeComparator);                          Collections.sort( departureBean.entries, departureTimeComparator);
136                  }                  }
137                    
138                    //System.out.println("Trit: " + settings.isTritinfoEnabled()  + " " +  station.getTritStation() );
139                    if ( settings.isTritinfoEnabled()  && station.getTritStation() != -1) {
140                            try {
141                                    injectTritinfoData(departureBean, station);
142                            } catch (Exception ex) { //det er ikke kritisk at vi får perron numre med
143                                    logger.warning("tritinfo failed with " + ex.getClass().getName() + ": " + ex.getMessage() );
144                            }
145                    }
146    
147                                    
148                  return departureBean;                  return departureBean;
# Line 509  http://mobil.bane.dk/mobilStation.asp?ar Line 518  http://mobil.bane.dk/mobilStation.asp?ar
518                  Element anchorElement = trainTd.getElementsByTag("a").get(0);                  Element anchorElement = trainTd.getElementsByTag("a").get(0);
519                  String href = anchorElement.attr("href");                  String href = anchorElement.attr("href");
520                                    
521                  int pos = href.lastIndexOf('/');                  int pos = href.lastIndexOf('=');
522                  String number = href.substring(pos+1);                  String number = href.substring(pos+1);
523                                    
524                  return number;                  return number;
# Line 543  http://mobil.bane.dk/mobilStation.asp?ar Line 552  http://mobil.bane.dk/mobilStation.asp?ar
552                                    
553                  return number;                  return number;
554          }          }
555            
556            
557            private void injectTritinfoData(DepartureBean departureBean, StationEntry station) throws Exception {
558                String uri = "http://tritinfo.pallas.dk/webtavle?page=stationcontent&staid=" + station.getTritStation();
559                logger.fine("URI:" + uri);
560                
561    
562                JsoupInvocation wrapper = new JsoupInvocation( new URL(uri), settings.getReplyTimeout() );
563                CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("tritinfo");
564                
565                Element page = (Element) breaker.invoke(wrapper);          
566                
567                Element table = page.getElementsByClass("passages").get(0);
568                
569                Elements trains = table.getElementsByClass("train");
570                
571                for (int i=0; i<trains.size(); i++) {
572                    Element train = trains.get(i);
573                    
574                    //String trainType = train.getElementsByClass("trainType").get(0).text();
575                    String trainNumber = train.getElementsByClass("trainNumber").get(0).text();            
576                    
577                    Elements trackElems = train.getElementsByClass("plannedTrack");
578                    if (trackElems.size() == 0) {
579                            trackElems = train.getElementsByClass("expectedTrack");
580                    }
581                    String track = trackElems.get(0).text().trim();
582                    String trackType = train.getElementsByClass("trackType").get(0).text().trim();
583                    
584            
585                    String platform = track;
586                            if ( !trackType.equals("")) {
587                                    platform += trackType;
588                            }
589                    
590                    for (DepartureEntry entry : departureBean.entries) {
591                            String entryTrainId = entry.getTrainNumber().split(" ")[1];
592                            if ( entryTrainId.equals(trainNumber)) {
593                                    
594                                    entry.setPlatform(platform);
595                                    break;
596                            }
597                    }
598                }
599            }
600    
601                    
602          //test          //test

Legend:
Removed from v.1562  
changed lines
  Added in v.2033

  ViewVC Help
Powered by ViewVC 1.1.20