/[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 992 by torben, Wed Jul 14 08:05:31 2010 UTC revision 1026 by torben, Thu Sep 2 18:37:49 2010 UTC
# Line 2  package dk.thoerup.traininfoservice.bane Line 2  package dk.thoerup.traininfoservice.bane
2    
3    
4  import java.net.URL;  import java.net.URL;
5    import java.net.URLEncoder;
6  import java.util.Collections;  import java.util.Collections;
7  import java.util.Map;  import java.util.Map;
8  import java.util.logging.Logger;  import java.util.logging.Logger;
# Line 30  public class DepartureFetcher { Line 31  public class DepartureFetcher {
31          StationDAO stationDao = new StationDAO();          StationDAO stationDao = new StationDAO();
32                    
33          private boolean useTempSite;          private boolean useTempSite;
34            private int replyTimeout;
35                    
36          public DepartureFetcher(boolean tempSite, int cacheTimeout) {          public DepartureFetcher(boolean tempSite, int cacheTimeout, int replyTimeout) {
37                    this.replyTimeout = replyTimeout;
38                  useTempSite = tempSite;                  useTempSite = tempSite;
39                  cache = new TimeoutMap<String,DepartureBean>(cacheTimeout);                  cache = new TimeoutMap<String,DepartureBean>(cacheTimeout);
40          }          }
# Line 62  public class DepartureFetcher { Line 65  public class DepartureFetcher {
65                                    
66                  StationBean station = stationDao.getById(stationID);                  StationBean station = stationDao.getById(stationID);
67                                    
68                    departureBean.stationName = station.getName();
69                    
70                  if (station.getRegional() != null) {                  if (station.getRegional() != null) {
71                          DepartureBean tempBean = lookupDepartures(station.getRegional(), TrainType.REGIONAL, arrival);                          DepartureBean tempBean = lookupDepartures(station.getRegional(), TrainType.REGIONAL, arrival);
72                          departureBean.departureEntries.addAll( tempBean.departureEntries );                          departureBean.departureEntries.addAll( tempBean.departureEntries );
# Line 108  public class DepartureFetcher { Line 113  public class DepartureFetcher {
113                            
114              String typeString = getTypeString(type);              String typeString = getTypeString(type);
115              String arrivalDeparture = (arrival==false) ? "Afgang" : "Ankomst";              String arrivalDeparture = (arrival==false) ? "Afgang" : "Ankomst";
116                                            
117                stationcode = URLEncoder.encode(stationcode,"ISO-8859-1");
118              //String uri = "http://www.bane.dk/visStation.asp?ArtikelID=4275&W=" + type + "&S=" + stationcode;              //String uri = "http://www.bane.dk/visStation.asp?ArtikelID=4275&W=" + type + "&S=" + stationcode;
119              String uri = "http://trafikinfo.bane.dk/Trafikinformation/AfgangAnkomst/" + arrivalDeparture + "/" + stationcode + "/" + typeString + "/UdvidetVisning";              String uri = "http://trafikinfo.bane.dk/Trafikinformation/AfgangAnkomst/" + arrivalDeparture + "/" + stationcode + "/" + typeString + "/UdvidetVisning";
120    
121                
122                
123              //logger.info("URI: " + uri);                        //logger.info("URI: " + uri);          
124              JsoupInvocation wrapper = new JsoupInvocation( new URL(uri), 2500);              JsoupInvocation wrapper = new JsoupInvocation( new URL(uri), replyTimeout);
125              CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk");              CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk");
126                            
127              Document page = (Document) breaker.invoke(wrapper);              Document page = (Document) breaker.invoke(wrapper);
# Line 124  public class DepartureFetcher { Line 132  public class DepartureFetcher {
132              if (table != null) {              if (table != null) {
133                      Elements tableRows =  table.getElementsByTag("tr");                      Elements tableRows =  table.getElementsByTag("tr");
134                                            
135                        boolean tidsstregExists = (table.getElementsByAttributeValue("class", "Tidsstreg").size() > 0);
136                        boolean passedTidsstreg = false;
137                        
138                      for (Element currentRow : tableRows) {                      for (Element currentRow : tableRows) {
139                          String rowClass = currentRow.attr("class");                          String rowClass = currentRow.attr("class");
140                            
141                            if (tidsstregExists == true && passedTidsstreg == false) {
142                                    if (currentRow.getElementsByAttributeValue("class", "Tidsstreg").size() > 0) {
143                                            passedTidsstreg = true;
144                                    } else {
145                                            continue;
146                                    }
147                            }
148                            
149                          if (rowClass != null && rowClass.toLowerCase().contains("station") ) {                          if (rowClass != null && rowClass.toLowerCase().contains("station") ) {
150                                    
151                                  Elements fields = currentRow.getElementsByTag("td");                                  Elements fields = currentRow.getElementsByTag("td");
152                    
153                                  DepartureEntry departure = new DepartureEntry();                                  DepartureEntry departure = new DepartureEntry();

Legend:
Removed from v.992  
changed lines
  Added in v.1026

  ViewVC Help
Powered by ViewVC 1.1.20