public void setLocale(String localeName) { localeName_ = localeName; locale_ = predefinedLocaleMap_.get(localeName); if (locale_ == null) { String[] localeParams = localeName.split("_"); if (localeParams.length > 1) { locale_ = new Locale(localeParams[0], localeParams[1]); } else { locale_ = new Locale(localeName); } tagIdentifier_ = I18N.toTagIdentifier(locale_); } }
@Override public boolean execute(ControllerContext context) throws Exception { String resourceParam = context.getParameter(RESOURCE_QN); String scopeParam = context.getParameter(SCOPE_QN); // if (scopeParam != null && resourceParam != null) { String compressParam = context.getParameter(COMPRESS_QN); String lang = context.getParameter(LANG_QN); String moduleParam = context.getParameter(MODULE_QN); // Locale locale = null; if (lang != null && lang.length() > 0) { locale = I18N.parseTagIdentifier(lang); } // ResourceScope scope; try { scope = ResourceScope.valueOf(ResourceScope.class, scopeParam); } catch (IllegalArgumentException e) { HttpServletResponse response = context.getResponse(); String msg = "Unrecognized scope " + scopeParam; log.error(msg); response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg); return true; } // ResourceId resource = new ResourceId(scope, resourceParam); ScriptKey key = new ScriptKey(resource, moduleParam, "min".equals(compressParam), locale); // ScriptResult result = cache.get(context, key); HttpServletResponse response = context.getResponse(); HttpServletRequest request = context.getRequest(); // if (result instanceof ScriptResult.Resolved) { ScriptResult.Resolved resolved = (ScriptResult.Resolved) result; // Content type + charset response.setContentType("text/javascript"); response.setCharacterEncoding("UTF-8"); // One hour caching // make this configurable later response.setHeader("Cache-Control", "max-age:3600"); response.setDateHeader("Expires", System.currentTimeMillis() + 3600 * 1000); // Set content length response.setContentLength(resolved.bytes.length); long ifModifiedSince = request.getDateHeader(IF_MODIFIED_SINCE); if (resolved.isModified(ifModifiedSince)) { response.setDateHeader(ResourceRequestFilter.LAST_MODIFIED, resolved.lastModified); // Send bytes ServletOutputStream out = response.getOutputStream(); try { out.write(resolved.bytes); } finally { Safe.close(out); } } else { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); } } else if (result instanceof ScriptResult.Error) { ScriptResult.Error error = (ScriptResult.Error) result; log.error("Could not render script " + key + "\n:" + error.message); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } else { String msg = "Resource " + key + " cannot be found"; log.error(msg); response.sendError(HttpServletResponse.SC_NOT_FOUND, msg); } } else { HttpServletResponse response = context.getResponse(); String msg = "Missing scope or resource param"; log.error(msg); response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg); } // return true; }