try {
// use the ServletContext to locate the XML file
ServletContext ctx = getServletContext();
String xmlFileName = ctx.getRealPath("/WEB-INF/xml"
+ req.getPathInfo());
// verify that the file exists
if (!new File(xmlFileName).exists()) {
res.sendError(HttpServletResponse.SC_NOT_FOUND, xmlFileName);
} else {
res.setContentType("text/html");
// load the XML file
Source xmlSource = new StreamSource(new BufferedReader(
new FileReader(xmlFileName)));
// use a cached version of the XSLT
Transformer trans =
StylesheetCache.newTransformer(xsltFileName);
trans.transform(xmlSource, new StreamResult(res.getWriter()));
}
} catch (TransformerConfigurationException tce) {
throw new ServletException(tce);
} catch (TransformerException te) {
throw new ServletException(te);
}