/[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 862 by torben, Wed Jun 16 10:03:13 2010 UTC revision 978 by torben, Sat Jul 10 10:53:44 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    
7  import javax.servlet.ServletException;  import javax.servlet.ServletException;
8    import javax.servlet.annotation.WebServlet;
9  import javax.servlet.http.HttpServlet;  import javax.servlet.http.HttpServlet;
10  import javax.servlet.http.HttpServletRequest;  import javax.servlet.http.HttpServletRequest;
11  import javax.servlet.http.HttpServletResponse;  import javax.servlet.http.HttpServletResponse;
# Line 28  import dk.thoerup.traininfoservice.Stati Line 28  import dk.thoerup.traininfoservice.Stati
28  /**  /**
29   * Servlet implementation class DepartureServlet   * Servlet implementation class DepartureServlet
30   */   */
31    @WebServlet(urlPatterns={"/DepartureServlet"})
32  public class DepartureServlet extends HttpServlet {  public class DepartureServlet extends HttpServlet {
33          private static final long serialVersionUID = 1L;          private static final long serialVersionUID = 1L;
34                    
# Line 65  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;
70    
71                  String stationName = StationDAO.getStationName(station);                  String stationName = StationDAO.getStationName(station);
72    
# Line 93  public class DepartureServlet extends Ht Line 94  public class DepartureServlet extends Ht
94                                    
95                  if (format.equalsIgnoreCase("xml")) {                  if (format.equalsIgnoreCase("xml")) {
96                          resp.setContentType("text/xml");                          resp.setContentType("text/xml");
97                          resp.getWriter().print( formatXml(beans, stationName) );                          resp.getWriter().print( formatXml(beans, stationName, arrival) );
98                  } else if (format.equalsIgnoreCase("html")) {                  } else if (format.equalsIgnoreCase("html")) {
99                                                    
100                          String advStr = req.getParameter("advanced");                          String advStr = req.getParameter("advanced");
# Line 110  public class DepartureServlet extends Ht Line 111  public class DepartureServlet extends Ht
111    
112          }          }
113    
114          protected String formatXml(List<DepartureBean> beans, String stationName) throws ServletException{          protected String formatXml(DepartureBean beans, String stationName, boolean arrival) throws ServletException{
115                  String xml = "";                  String xml = "";
116                  try {                  try {
117                          DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();                          DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
# Line 120  public class DepartureServlet extends Ht Line 121  public class DepartureServlet extends Ht
121                          Document doc = impl.createDocument(null,null,null);                          Document doc = impl.createDocument(null,null,null);
122                  Element root = doc.createElement("departureinfo");                  Element root = doc.createElement("departureinfo");
123                  root.setAttribute("station", stationName);                  root.setAttribute("station", stationName);
124                  for (DepartureBean departure : beans) {                  root.setAttribute("arrival", Boolean.toString(arrival) );
125                    
126                    for (String notif : beans.notifications) {
127                            Element notElem = doc.createElement("notification");
128                            notElem.setTextContent(notif);
129                            root.appendChild(notElem);
130                    }
131                    
132                    for (DepartureEntry departure : beans.departureEntries) {
133                          Element train = doc.createElement("train");                          Element train = doc.createElement("train");
134                                                    
135                          Element time = doc.createElement("time");                          Element time = doc.createElement("time");

Legend:
Removed from v.862  
changed lines
  Added in v.978

  ViewVC Help
Powered by ViewVC 1.1.20