/[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 861 by torben, Wed Jun 16 09:58:15 2010 UTC revision 969 by torben, Fri Jul 9 21:02:13 2010 UTC
# Line 6  import java.util.logging.Level; Line 6  import java.util.logging.Level;
6  import java.util.logging.Logger;  import java.util.logging.Logger;
7    
8  import javax.servlet.ServletException;  import javax.servlet.ServletException;
9    import javax.servlet.annotation.WebServlet;
10  import javax.servlet.http.HttpServlet;  import javax.servlet.http.HttpServlet;
11  import javax.servlet.http.HttpServletRequest;  import javax.servlet.http.HttpServletRequest;
12  import javax.servlet.http.HttpServletResponse;  import javax.servlet.http.HttpServletResponse;
# Line 28  import dk.thoerup.traininfoservice.Stati Line 29  import dk.thoerup.traininfoservice.Stati
29  /**  /**
30   * Servlet implementation class DepartureServlet   * Servlet implementation class DepartureServlet
31   */   */
32    @WebServlet(urlPatterns={"/DepartureServlet"})
33  public class DepartureServlet extends HttpServlet {  public class DepartureServlet extends HttpServlet {
34          private static final long serialVersionUID = 1L;          private static final long serialVersionUID = 1L;
35                    
# Line 93  public class DepartureServlet extends Ht Line 95  public class DepartureServlet extends Ht
95                                    
96                  if (format.equalsIgnoreCase("xml")) {                  if (format.equalsIgnoreCase("xml")) {
97                          resp.setContentType("text/xml");                          resp.setContentType("text/xml");
98                          resp.getWriter().print( formatXml(beans, stationName) );                          resp.getWriter().print( formatXml(beans, stationName, arrival) );
99                  } else if (format.equalsIgnoreCase("html")) {                  } else if (format.equalsIgnoreCase("html")) {
100                                                    
101                          String advStr = req.getParameter("advanced");                          String advStr = req.getParameter("advanced");
# Line 105  public class DepartureServlet extends Ht Line 107  public class DepartureServlet extends Ht
107                          req.setAttribute("stationID", station );                          req.setAttribute("stationID", station );
108                          getServletContext().getRequestDispatcher("/ViewDepartures.jsp").forward(req,resp);                          getServletContext().getRequestDispatcher("/ViewDepartures.jsp").forward(req,resp);
109                  } else {                  } else {
110                          throw new ServletException("Unknown format");                          resp.sendError(400, "Unknown format");                  
111                  }                  }
112    
113          }          }
114    
115          protected String formatXml(List<DepartureBean> beans, String stationName) throws ServletException{          protected String formatXml(List<DepartureBean> beans, String stationName, boolean arrival) throws ServletException{
116                  String xml = "";                  String xml = "";
117                  try {                  try {
118                          DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();                          DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
# Line 120  public class DepartureServlet extends Ht Line 122  public class DepartureServlet extends Ht
122                          Document doc = impl.createDocument(null,null,null);                          Document doc = impl.createDocument(null,null,null);
123                  Element root = doc.createElement("departureinfo");                  Element root = doc.createElement("departureinfo");
124                  root.setAttribute("station", stationName);                  root.setAttribute("station", stationName);
125                    root.setAttribute("arrival", Boolean.toString(arrival) );
126                  for (DepartureBean departure : beans) {                  for (DepartureBean departure : beans) {
127                          Element train = doc.createElement("train");                          Element train = doc.createElement("train");
128                                                    

Legend:
Removed from v.861  
changed lines
  Added in v.969

  ViewVC Help
Powered by ViewVC 1.1.20