/[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 1060 by torben, Thu Sep 16 13:32:10 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.util.ArrayList;  import java.util.ArrayList;
6  import java.util.List;  import java.util.List;
7  import java.util.Map;  import java.util.Map;
8  import java.util.logging.Logger;  import java.util.logging.Logger;
9    
   
10  import org.jsoup.nodes.Document;  import org.jsoup.nodes.Document;
11  import org.jsoup.nodes.Element;  import org.jsoup.nodes.Element;
12  import org.jsoup.select.Elements;  import org.jsoup.select.Elements;
13    import org.simpleframework.xml.ElementList;
14    import org.simpleframework.xml.Root;
15    
16  import dk.thoerup.circuitbreaker.CircuitBreaker;  import dk.thoerup.circuitbreaker.CircuitBreaker;
17  import dk.thoerup.circuitbreaker.CircuitBreakerManager;  import dk.thoerup.circuitbreaker.CircuitBreakerManager;
 import dk.thoerup.traininfoservice.StationBean;  
18  import dk.thoerup.traininfoservice.StationDAO;  import dk.thoerup.traininfoservice.StationDAO;
19  import dk.thoerup.traininfoservice.Statistics;  import dk.thoerup.traininfoservice.Statistics;
20    import dk.thoerup.traininfoservice.StationBean.StationEntry;
21    
22    
23    
24  public class MetroFetcher {  public class MetroFetcher {
25            @Root(name="entry")
26          public static class MetroEntry {          public static class MetroEntry {
27                    
28                    @org.simpleframework.xml.Element
29                  String metro;                  String metro;
30                    
31                    @org.simpleframework.xml.Element
32                  String destination;                  String destination;
33                    
34                    @org.simpleframework.xml.Element
35                  String minutes;                          String minutes;        
36          }          }
37                    
38            @Root(name="metrodepatures")
39          public static class MetroBean {          public static class MetroBean {
40                    
41                    @org.simpleframework.xml.Element
42                  String head;                  String head;
                 String operationInfo; //driftsinfo  
                 String plan; // koereplan  
43                                    
44                    
45                    @org.simpleframework.xml.Element(name="operations")
46                    String operationInfo; //driftsinfo      
47                    
48                    @ElementList
49                  List<MetroEntry> entries = new ArrayList<MetroEntry>();                  List<MetroEntry> entries = new ArrayList<MetroEntry>();
50                    
51                    @org.simpleframework.xml.Element
52                    String plan; // koereplan
53          }          }
54                    
55          Logger logger = Logger.getLogger(MetroFetcher.class.getName());          Logger logger = Logger.getLogger(MetroFetcher.class.getName());
# Line 58  public class MetroFetcher { Line 74  public class MetroFetcher {
74    
75          public MetroBean lookupMetroDepartures(int stationID) throws Exception {          public MetroBean lookupMetroDepartures(int stationID) throws Exception {
76                                    
77                  StationBean station = stationDAO.getById(stationID) ;                  StationEntry station = stationDAO.getById(stationID) ;
78                                                    
79                                    
80                  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 99  public class MetroFetcher {
99                  for (int i=1; i<rows.size(); i++) {                  for (int i=1; i<rows.size(); i++) {
100                          Element row = rows.get(i);                                Element row = rows.get(i);      
101                          Elements fields = row.children();                          Elements fields = row.children();
102    
103                            
104                            
105                            Elements metroFields = fields.get(0).children();                        
106                            String metro ="";                      
107                            for (Element elm : metroFields) {
108                                    metro = metro + elm.text() + " ";
109                            }
110                            
111                            
112                                                    
                         String metro = fields.get(0).text();  
113                          String destination = fields.get(1).text();                          String destination = fields.get(1).text();
                         Elements minuteFields = fields.get(2).children();  
                         String minutes ="";  
114                                                    
115                            Elements minuteFields = fields.get(2).children();                      
116                            String minutes ="";                    
117                          for (Element elm : minuteFields) {                          for (Element elm : minuteFields) {
118                                  minutes = minutes + elm.text() + " ";                                  minutes = minutes + elm.text() + " ";
119                          }                          }
120                                                    
121                          MetroEntry entry = new MetroEntry();                          MetroEntry entry = new MetroEntry();
122                          entry.metro = metro;                          entry.metro = metro.trim();
123                          entry.destination = destination;                          entry.destination = destination.trim();
124                          entry.minutes = minutes;                          entry.minutes = minutes.trim();
125                                                    
126                          bean.entries.add(entry);                                                  bean.entries.add(entry);                        
127                  }                  }
128                                                                    
129                  bean.operationInfo = contentElems.get(3).text();                  bean.operationInfo = contentElems.get(3).text();
130                                    
131                  int planIndex;                  for (int i=4; i<contentElems.size(); i++) {
132                  if (contentElems.get(4).text().trim().equalsIgnoreCase("stationsinformation")) {                          if (contentElems.get(i).text().trim().equalsIgnoreCase("køreplan")) {                          
133                          planIndex = 7;                                  bean.plan = contentElems.get(i+1).text();
134                  } else {                          }
                         planIndex = 5;  
135                  }                  }
136                            
                 bean.plan = contentElems.get(planIndex).text();  
                   
137                  return bean;                  return bean;
138          }          }
139                    

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

  ViewVC Help
Powered by ViewVC 1.1.20