14 |
import javax.servlet.http.HttpServletResponse; |
import javax.servlet.http.HttpServletResponse; |
15 |
|
|
16 |
import javax.xml.transform.Source; |
import javax.xml.transform.Source; |
17 |
|
import javax.xml.transform.Templates; |
18 |
import javax.xml.transform.Transformer; |
import javax.xml.transform.Transformer; |
19 |
import javax.xml.transform.TransformerFactory; |
import javax.xml.transform.TransformerFactory; |
20 |
import javax.xml.transform.stream.StreamResult; |
import javax.xml.transform.stream.StreamResult; |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
String xslPath; |
TransformerFactory xslTransFact; |
44 |
|
Templates xslTemplate; |
45 |
|
|
46 |
|
|
47 |
@Override |
@Override |
54 |
logger.info( "DepartureServlet, use azure site=" + useAzureSite + ", cache=" + cacheTimeout); |
logger.info( "DepartureServlet, use azure site=" + useAzureSite + ", cache=" + cacheTimeout); |
55 |
fetcher = new DepartureFetcher(useAzureSite, cacheTimeout, replyTimeout); |
fetcher = new DepartureFetcher(useAzureSite, cacheTimeout, replyTimeout); |
56 |
|
|
57 |
xslPath = getServletContext().getRealPath("/departures.xsl"); |
xslTransFact = TransformerFactory.newInstance(); |
58 |
|
|
59 |
|
String xslPath = getServletContext().getRealPath("/departures.xsl"); |
60 |
|
Source stylesheet = new StreamSource( new File(xslPath) ); |
61 |
|
|
62 |
|
try { |
63 |
|
xslTemplate = xslTransFact.newTemplates(stylesheet); |
64 |
|
} catch (Exception e) { |
65 |
|
throw new ServletException(e); |
66 |
|
} |
67 |
} |
} |
68 |
|
|
69 |
@Override |
@Override |
143 |
return out.toString(); |
return out.toString(); |
144 |
} |
} |
145 |
|
|
146 |
protected String xmlToHtml(String input) { |
protected String xmlToHtml(String input) throws ServletException { |
147 |
|
|
148 |
try { |
try { |
149 |
Source stylesheet = new StreamSource( new File(xslPath) ); |
Transformer trans = xslTemplate.newTransformer(); |
|
|
|
|
|
|
|
TransformerFactory transFact = TransformerFactory.newInstance(); |
|
|
|
|
|
Transformer trans = transFact.newTransformer(stylesheet); |
|
150 |
|
|
151 |
Source xml = new StreamSource( new ByteArrayInputStream(input.getBytes() )); |
Source xml = new StreamSource( new ByteArrayInputStream(input.getBytes() )); |
152 |
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
154 |
|
|
155 |
return out.toString(); |
return out.toString(); |
156 |
} catch (Exception e) { |
} catch (Exception e) { |
157 |
return e.toString(); |
throw new ServletException(e); |
158 |
} |
} |
159 |
} |
} |
160 |
|
|