if (mediaKeyObj.isBinary()) {
request.setAttribute(WGACore.ATTRIB_SERVLETRESPONSE, response);
}
// Determine tml design for this request
WGTMLModule tmlLib = null;
if (path.getLayoutKey() != null) {
tmlLib = (WGTMLModule) database.getDesignObject(WGDocument.TYPE_TML, path.getLayoutKey(), mediaKey);
if (tmlLib != null && tmlLib.isDirectAccessAllowed() == false) {
throw new HttpErrorException(java.net.HttpURLConnection.HTTP_FORBIDDEN, "This design is not allowed for direct access: " + tmlLib.getName() + " (" + tmlLib.getMediaKey() + ")", path
.getDatabaseKey());
}
}
else {
WGStructEntry entry = content.getStructEntry();
if (entry == null) {
throw new HttpErrorException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Content " + content.getContentKey().toString() + " has no struct entry", path.getDatabaseKey());
}
tmlLib = entry.getOuterLayout(mediaKey);
}
if (tmlLib == null || tmlLib.isDummy()) {
if (path.getLayoutKey() != null) {
throw new HttpErrorException(404, "No WebTML layout '" + path.getLayoutKey() + "' for media key '" + mediaKey + "' available in app '" + database.getDbReference() + "'", path.getDatabaseKey());
}
else {
throw new HttpErrorException(500, "Outer layout of struct entry '" + content.getStructEntry().getTitle() + "(" + content.getStructEntry().getStructKey() + ")"
+ "' not available for media key '" + mediaKey + "'", path.getDatabaseKey());
}
}
request.setAttribute(WGACore.ATTRIB_OUTER_DESIGN, tmlLib.getName());
// TML Cache control
if (tmlLib.isCacheable()) {
response.setHeader("Cache-Control", "must-revalidate");
long lastModified;
// determine lastModified
// - last modified of binary response depends only on resource
// change date
// - last change date of textual response additionally depends on
// character encoding change date
if (isBinary(response)) {
lastModified = getCore().getDeployer().getLastChangedOrDeployed(database).getTime();
}
else {
lastModified = Math.max(getCore().getDeployer().getLastChangedOrDeployed(database).getTime(), _core.getCharacterEncodingLastModified());
lastModified = Math.max(lastModified, _core.getDesignEncodingLastModified(database.getDbReference()));
}
// Test modified since
if (browserCacheIsValid(request, lastModified)) {
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
else {
response.setDateHeader("Last-Modified", lastModified);
response.setHeader("ETag", '"' + String.valueOf(lastModified) + '"');
}
}
else {
response.setHeader("Pragma", "No-Cache");
if (mediaKeyObj.isBinary()) {
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
}
else {
response.setHeader("Cache-Control", "No-Cache");
}
}
// check if we have an ajaxcall
String encAjaxInfo = request.getParameter("$ajaxInfo");
if (encAjaxInfo != null) {
tmlLib = processAjaxCall(request, database, encAjaxInfo);
ajax = true;
}
// Update usage statistics
getCore().getUsageStatistics().addRequestStatistic(request, session, database, tmlUserProfile);
// Dispatch to jsp
String targetJSP = _core.getDeployer().locateTmlResource(tmlLib);
try {
if (targetJSP != null) {
if (!"HEAD".equalsIgnoreCase(request.getMethod())) {
if (mediaKeyObj.isBinary()) {
if (request instanceof RenderServletRequestWrapper) {
HttpServletRequestWrapper wrapper = (HttpServletRequestWrapper) request;
wrapper.getRequest().getRequestDispatcher(targetJSP).include(wrapper.getRequest(), new DummyServletResponse(response));
}
else {
this.getServletContext().getRequestDispatcher(targetJSP).include(request, new DummyServletResponse(response));
}
}
else {
if (request instanceof RenderServletRequestWrapper) {
HttpServletRequestWrapper wrapper = (HttpServletRequestWrapper) request;
wrapper.getRequest().getRequestDispatcher(targetJSP).include(wrapper.getRequest(), response);
}
else {
this.getServletContext().getRequestDispatcher(targetJSP).include(request, response);
}
}
}
}
else {
throw new HttpErrorException(500, "tml design not active: " + tmlLib.getName(), path.getDatabaseKey());
}
// Eventually do redirect
if (request.getAttribute(WGACore.ATTRIB_REDIRECT) != null) {