default:
throw new HttpErrorException(500, "Invalid path type to dispatch a css/js request: " + path.getPathType(), path.getDatabaseKey());
}
WGCSSJSModule lib = database.getScriptModule(path.getCssjsKey(), codeType);
if (lib == null) {
throw new HttpErrorException(404, "No css/js resource of name " + path.getCssjsKey(), path.getDatabaseKey());
}
// determine mime type and encoding
String mimeType;
String libType = lib.getCodeType();
if (libType.equals(WGCSSJSModule.CODETYPE_CSS)) {
mimeType = "text/css";
}
else if (libType.equals(WGCSSJSModule.CODETYPE_JS)) {
mimeType = "text/javascript";
}
else if (libType.equals(WGCSSJSModule.CODETYPE_VBS)) {
mimeType = "text/vbscript";
}
else {
mimeType = "text/" + libType;
}
response.setContentType(mimeType);
// Set expiration time
int fileExpirationMinutes = ((Integer) _core.readPublisherOptionOrDefault(database, WGACore.DBATTRIB_FILEEXPIRATION_MINUTES)).intValue();
if (fileExpirationMinutes > 0) {
int fileExpirationSeconds = fileExpirationMinutes * 60;
response.setHeader("Cache-Control", "max-age=" + fileExpirationSeconds + ", must-revalidate");
}
// 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
long lastModified;
if (isBinary(response)) {
lastModified = lib.getLastModified().getTime();
}
else {
lastModified = Math.max(lib.getLastModified().getTime(), _core.getCharacterEncodingLastModified());
lastModified = Math.max(lastModified, _core.getDesignEncodingLastModified(database.getDbReference()));
}
if (browserCacheIsValid(request, lastModified)) {
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
else {
response.setDateHeader("Last-Modified", lastModified);
response.setHeader("ETag", '"' + String.valueOf(lastModified) + '"');
}
// If this is a head request we are finished now
if ("HEAD".equalsIgnoreCase(request.getMethod())) {
return;
}
String code = lib.getCode();
// response.setContentLength(code.length());
try {
java.io.Writer out = response.getWriter();
out.write(code);