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

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

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

revision 958 by torben, Mon Jul 5 09:48:06 2010 UTC revision 1026 by torben, Thu Sep 2 18:37:49 2010 UTC
# Line 1  Line 1 
1  package dk.thoerup.traininfoservice.banedk;  package dk.thoerup.traininfoservice.banedk;
2    
3  import java.io.IOException;  import java.io.IOException;
 import java.util.List;  
4  import java.util.logging.Level;  import java.util.logging.Level;
5  import java.util.logging.Logger;  import java.util.logging.Logger;
6    
# Line 23  import org.w3c.dom.Document; Line 22  import org.w3c.dom.Document;
22  import org.w3c.dom.Element;  import org.w3c.dom.Element;
23    
24  import dk.thoerup.circuitbreaker.CircuitBreakerException;  import dk.thoerup.circuitbreaker.CircuitBreakerException;
 import dk.thoerup.traininfoservice.StationDAO;  
25  import dk.thoerup.traininfoservice.Statistics;  import dk.thoerup.traininfoservice.Statistics;
26    
27  /**  /**
# Line 46  public class DepartureServlet extends Ht Line 44  public class DepartureServlet extends Ht
44    
45                  boolean useTempSite =  Boolean.parseBoolean( getServletContext().getInitParameter("usetempsite") );                  boolean useTempSite =  Boolean.parseBoolean( getServletContext().getInitParameter("usetempsite") );
46                  int cacheTimeout =  Integer.parseInt( getServletContext().getInitParameter("cache_timeout") );                  int cacheTimeout =  Integer.parseInt( getServletContext().getInitParameter("cache_timeout") );
47                    int replyTimeout =  Integer.parseInt( getServletContext().getInitParameter("reply_timeout") );
48                  logger.info( "DepartureServlet, use temp site=" + useTempSite + ", cache=" + cacheTimeout);                  logger.info( "DepartureServlet, use temp site=" + useTempSite + ", cache=" + cacheTimeout);
49                  fetcher = new DepartureFetcher(useTempSite, cacheTimeout);                  fetcher = new DepartureFetcher(useTempSite, cacheTimeout, replyTimeout);
50          }          }
51    
52          @Override          @Override
# Line 67  public class DepartureServlet extends Ht Line 66  public class DepartureServlet extends Ht
66                  int station = Integer.parseInt( req.getParameter("station") );                  int station = Integer.parseInt( req.getParameter("station") );
67                  String format = req.getParameter("format");                  String format = req.getParameter("format");
68    
69                  List<DepartureBean> beans;                  DepartureBean beans;            
   
                 String stationName = StationDAO.getStationName(station);  
70    
71                  try {                  try {
72                          beans = fetcher.cachedLookupDepartures(station, arrival);                          beans = fetcher.cachedLookupDepartures(station, arrival);
# Line 95  public class DepartureServlet extends Ht Line 92  public class DepartureServlet extends Ht
92                                    
93                  if (format.equalsIgnoreCase("xml")) {                  if (format.equalsIgnoreCase("xml")) {
94                          resp.setContentType("text/xml");                          resp.setContentType("text/xml");
95                          resp.getWriter().print( formatXml(beans, stationName) );                          resp.getWriter().print( formatXml(beans, arrival) );
96                  } else if (format.equalsIgnoreCase("html")) {                  } else if (format.equalsIgnoreCase("html")) {
97                                                    
98                          String advStr = req.getParameter("advanced");                          String advStr = req.getParameter("advanced");
99                          boolean advanced = advStr != null ? Boolean.parseBoolean(advStr) : false;                          boolean advanced = advStr != null ? Boolean.parseBoolean(advStr) : false;
100                                                    
101                          req.setAttribute("advanced", advanced);                          req.setAttribute("advanced", advanced);
                         req.setAttribute("stationname", stationName );  
102                          req.setAttribute("departurebeans", beans);                          req.setAttribute("departurebeans", beans);
103                          req.setAttribute("stationID", station );                          req.setAttribute("stationID", station );
104                          getServletContext().getRequestDispatcher("/ViewDepartures.jsp").forward(req,resp);                          getServletContext().getRequestDispatcher("/ViewDepartures.jsp").forward(req,resp);
# Line 112  public class DepartureServlet extends Ht Line 108  public class DepartureServlet extends Ht
108    
109          }          }
110    
111          protected String formatXml(List<DepartureBean> beans, String stationName) throws ServletException{          protected String formatXml(DepartureBean beans, boolean arrival) throws ServletException{
112                  String xml = "";                  String xml = "";
113                  try {                  try {
114                          DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();                          DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
# Line 121  public class DepartureServlet extends Ht Line 117  public class DepartureServlet extends Ht
117                                                    
118                          Document doc = impl.createDocument(null,null,null);                          Document doc = impl.createDocument(null,null,null);
119                  Element root = doc.createElement("departureinfo");                  Element root = doc.createElement("departureinfo");
120                  root.setAttribute("station", stationName);                  root.setAttribute("station", beans.getStationName());
121                  for (DepartureBean departure : beans) {                  root.setAttribute("arrival", Boolean.toString(arrival) );
122                    
123                    for (String notif : beans.notifications) {
124                            Element notElem = doc.createElement("notification");
125                            notElem.setTextContent(notif);
126                            root.appendChild(notElem);
127                    }
128                    
129                    for (DepartureEntry departure : beans.departureEntries) {
130                          Element train = doc.createElement("train");                          Element train = doc.createElement("train");
131                                                    
132                          Element time = doc.createElement("time");                          Element time = doc.createElement("time");

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

  ViewVC Help
Powered by ViewVC 1.1.20