// ensure that we are running in a servlet environment
if (servletResponse == null || servletRequest == null || servletContext == null) {
throw new ProcessingException("JSPReader can only be used from within a Servlet environment.");
}
JSPEngine engine = null;
SAXParser parser = null;
try {
// TODO (KP): Should we exclude not supported protocols, say 'context'?
String url = super.source;
// absolute path is processed as is
if (!url.startsWith("/")) {
// get current request path
String servletPath = servletRequest.getServletPath();
// remove sitemap URI part
String sitemapURI = ObjectModelHelper.getRequest(objectModel).getSitemapURI();
if (sitemapURI != null) {
servletPath = servletPath.substring(0, servletPath.indexOf(sitemapURI));
} else {
// for example when using cocoon:/ pseudo protocol
servletPath = servletPath.substring(0, servletPath.lastIndexOf("/") + 1);
}
url = servletPath + url;
}
engine = (JSPEngine) super.manager.lookup(JSPEngine.ROLE);
if (getLogger().isDebugEnabled()) {
getLogger().debug("JSPGenerator executing:" + url);
}
byte[] bytes = engine.executeJSP(url, servletRequest, servletResponse, servletContext);
InputSource input = new InputSource(new ByteArrayInputStream(bytes));
// utf-8 is default encoding; specified explicitely here as a reminder.
input.setEncoding("utf-8");