1 |
package dk.thoerup.traininfoservice.banedk; |
package dk.thoerup.traininfoservice.banedk; |
2 |
|
|
3 |
|
|
4 |
import java.io.IOException; |
import java.io.IOException; |
5 |
|
import java.io.StringWriter; |
6 |
import java.util.logging.Level; |
import java.util.logging.Level; |
7 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
8 |
|
|
12 |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletRequest; |
13 |
import javax.servlet.http.HttpServletResponse; |
import javax.servlet.http.HttpServletResponse; |
14 |
|
|
15 |
|
import org.simpleframework.xml.Serializer; |
16 |
|
import org.simpleframework.xml.core.Persister; |
17 |
|
|
18 |
|
import dk.thoerup.android.traininfo.common.MetroBean; |
19 |
import dk.thoerup.circuitbreaker.CircuitBreakerException; |
import dk.thoerup.circuitbreaker.CircuitBreakerException; |
20 |
import dk.thoerup.traininfoservice.Statistics; |
import dk.thoerup.traininfoservice.Statistics; |
21 |
import dk.thoerup.traininfoservice.banedk.MetroFetcher.MetroBean; |
|
|
import dk.thoerup.traininfoservice.banedk.MetroFetcher.MetroEntry; |
|
22 |
|
|
23 |
|
|
24 |
|
|
53 |
|
|
54 |
resp.setDateHeader("Expires", 0); |
resp.setDateHeader("Expires", 0); |
55 |
resp.setHeader("Cache-Control", "no-cache, must-revalidate"); |
resp.setHeader("Cache-Control", "no-cache, must-revalidate"); |
56 |
|
resp.setContentType("text/xml"); |
57 |
resp.getWriter().print(xml); |
resp.getWriter().print(xml); |
58 |
|
|
59 |
} catch (java.io.IOException ioe) { |
} catch (java.io.IOException ioe) { |
76 |
|
|
77 |
} |
} |
78 |
|
|
79 |
String formatXml(MetroBean metro) { |
String formatXml(MetroBean metro) throws ServletException { |
|
StringBuilder sb = new StringBuilder(); |
|
80 |
|
|
81 |
sb.append("<metrodepatures>\n"); |
Serializer serializer = new Persister(); |
82 |
sb.append(" <head>" + metro.head + "</head>\n"); |
|
83 |
sb.append(" <operations>" + metro.operationInfo + "</operations>\n"); |
StringWriter out = new StringWriter(); |
84 |
|
|
85 |
sb.append(" <entries>\n"); |
try { |
86 |
for (MetroEntry entry : metro.entries) { |
serializer.write(metro, out); |
87 |
sb.append(" <entry>\n"); |
} catch (Exception e) { |
88 |
sb.append(" <metro>" + entry.metro + "</metro>\n"); |
throw new ServletException(e); |
|
sb.append(" <destination>" + entry.destination + "</destination>\n"); |
|
|
sb.append(" <minutes>" + entry.minutes.trim() + "</minutes>\n"); |
|
|
sb.append(" </entry>\n"); |
|
89 |
} |
} |
|
sb.append(" </entries>\n"); |
|
|
|
|
|
sb.append(" <plan>" + metro.plan + "</plan>\n"); |
|
|
|
|
|
sb.append("</metrodepatures>\n"); |
|
|
|
|
90 |
|
|
91 |
return sb.toString(); |
return out.toString(); |
92 |
} |
} |
93 |
|
|
94 |
} |
} |