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

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

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

revision 1048 by torben, Tue Sep 14 06:10:30 2010 UTC revision 1061 by torben, Thu Sep 16 14:04:28 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;
   
 import java.util.ArrayList;  
 import java.util.List;  
5  import java.util.Map;  import java.util.Map;
6  import java.util.logging.Logger;  import java.util.logging.Logger;
7    
   
8  import org.jsoup.nodes.Document;  import org.jsoup.nodes.Document;
9  import org.jsoup.nodes.Element;  import org.jsoup.nodes.Element;
10  import org.jsoup.select.Elements;  import org.jsoup.select.Elements;
11    
12    import dk.thoerup.android.traininfo.common.MetroBean;
13    import dk.thoerup.android.traininfo.common.MetroBean.MetroEntry;
14    import dk.thoerup.android.traininfo.common.StationBean.StationEntry;
15  import dk.thoerup.circuitbreaker.CircuitBreaker;  import dk.thoerup.circuitbreaker.CircuitBreaker;
16  import dk.thoerup.circuitbreaker.CircuitBreakerManager;  import dk.thoerup.circuitbreaker.CircuitBreakerManager;
 import dk.thoerup.traininfoservice.StationBean;  
17  import dk.thoerup.traininfoservice.StationDAO;  import dk.thoerup.traininfoservice.StationDAO;
18  import dk.thoerup.traininfoservice.Statistics;  import dk.thoerup.traininfoservice.Statistics;
19    
20    
21    
22  public class MetroFetcher {  public class MetroFetcher {
         public static class MetroEntry {  
                 String metro;  
                 String destination;  
                 String minutes;          
         }  
           
         public static class MetroBean {  
                 String head;  
                 String operationInfo; //driftsinfo  
                 String plan; // koereplan  
                   
                 List<MetroEntry> entries = new ArrayList<MetroEntry>();  
         }  
23                    
24          Logger logger = Logger.getLogger(MetroFetcher.class.getName());          Logger logger = Logger.getLogger(MetroFetcher.class.getName());
25          StationDAO stationDAO = new StationDAO();          StationDAO stationDAO = new StationDAO();
# Line 58  public class MetroFetcher { Line 43  public class MetroFetcher {
43    
44          public MetroBean lookupMetroDepartures(int stationID) throws Exception {          public MetroBean lookupMetroDepartures(int stationID) throws Exception {
45                                    
46                  StationBean station = stationDAO.getById(stationID) ;                  StationEntry station = stationDAO.getById(stationID) ;
47                                                    
48                                    
49                  URL url = new URL("http://www.m.dk/layouts/Metro/Widgets/MetroWidget.ashx?StationId=" + station.getMetro() + "&Congestion=true&Application=MyMetro&Expiration=true");                  URL url = new URL("http://www.m.dk/layouts/Metro/Widgets/MetroWidget.ashx?StationId=" + station.getMetro() + "&Congestion=true&Application=MyMetro&Expiration=true");
# Line 83  public class MetroFetcher { Line 68  public class MetroFetcher {
68                  for (int i=1; i<rows.size(); i++) {                  for (int i=1; i<rows.size(); i++) {
69                          Element row = rows.get(i);                                Element row = rows.get(i);      
70                          Elements fields = row.children();                          Elements fields = row.children();
71    
72                            
73                            
74                            Elements metroFields = fields.get(0).children();                        
75                            String metro ="";                      
76                            for (Element elm : metroFields) {
77                                    metro = metro + elm.text() + " ";
78                            }
79                            
80                            
81                                                    
                         String metro = fields.get(0).text();  
82                          String destination = fields.get(1).text();                          String destination = fields.get(1).text();
                         Elements minuteFields = fields.get(2).children();  
                         String minutes ="";  
83                                                    
84                            Elements minuteFields = fields.get(2).children();                      
85                            String minutes ="";                    
86                          for (Element elm : minuteFields) {                          for (Element elm : minuteFields) {
87                                  minutes = minutes + elm.text() + " ";                                  minutes = minutes + elm.text() + " ";
88                          }                          }
89                                                    
90                          MetroEntry entry = new MetroEntry();                          MetroEntry entry = new MetroEntry();
91                          entry.metro = metro;                          entry.metro = metro.trim();
92                          entry.destination = destination;                          entry.destination = destination.trim();
93                          entry.minutes = minutes;                          entry.minutes = minutes.trim();
94                                                    
95                          bean.entries.add(entry);                                                  bean.entries.add(entry);                        
96                  }                  }
97                                                                    
98                  bean.operationInfo = contentElems.get(3).text();                  bean.operationInfo = contentElems.get(3).text();
99                                    
100                  int planIndex;                  for (int i=4; i<contentElems.size(); i++) {
101                  if (contentElems.get(4).text().trim().equalsIgnoreCase("stationsinformation")) {                          if (contentElems.get(i).text().trim().equalsIgnoreCase("køreplan")) {                          
102                          planIndex = 7;                                  bean.plan = contentElems.get(i+1).text();
103                  } else {                          }
                         planIndex = 5;  
104                  }                  }
105                            
                 bean.plan = contentElems.get(planIndex).text();  
                   
106                  return bean;                  return bean;
107          }          }
108                    

Legend:
Removed from v.1048  
changed lines
  Added in v.1061

  ViewVC Help
Powered by ViewVC 1.1.20