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 |
DepartureBean beans; |
DepartureBean beans; |
|
|
|
|
String stationName = StationDAO.getStationName(station); |
|
70 |
|
|
71 |
try { |
try { |
72 |
beans = fetcher.cachedLookupDepartures(station, arrival); |
beans = fetcher.cachedLookupDepartures(station, arrival); |
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, arrival) ); |
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); |
108 |
|
|
109 |
} |
} |
110 |
|
|
111 |
protected String formatXml(DepartureBean beans, String stationName, boolean arrival) 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(); |
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 |
root.setAttribute("arrival", Boolean.toString(arrival) ); |
root.setAttribute("arrival", Boolean.toString(arrival) ); |
122 |
|
|
123 |
for (String notif : beans.notifications) { |
for (String notif : beans.notifications) { |