List of usage examples for javax.servlet.jsp.jstl.core Config FMT_LOCALIZATION_CONTEXT
String FMT_LOCALIZATION_CONTEXT
To view the source code for javax.servlet.jsp.jstl.core Config FMT_LOCALIZATION_CONTEXT.
Click Source Link
From source file:info.magnolia.cms.i18n.MessagesManager.java
/** * Called through the initialization process (startup of the container) * @param context servlet context//from w w w .ja v a 2 s . c o m */ public static void init(ServletContext context) { MessagesManager.context = context; // setting fallback context.setAttribute(Config.FMT_FALLBACK_LOCALE + ".application", FALLBACK_LOCALE); //$NON-NLS-1$ // setting basename context.setAttribute(Config.FMT_LOCALIZATION_CONTEXT + ".application", MessagesManager.DEFAULT_BASENAME); //$NON-NLS-1$ // for Resin and other J2EE Containers context.setAttribute(Config.FMT_LOCALIZATION_CONTEXT, MessagesManager.DEFAULT_BASENAME); // setting default language (en) MessagesManager.setDefaultLocale(FALLBACK_LOCALE); load(); registerEventListener(); }
From source file:opa.filter.LoadResourceBundle.java
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain fc) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpSession session = request.getSession(); DatabaseResourceBundle bundle = null; InitiativeSetup setup = (InitiativeSetup) session.getAttribute("initiativeSetup"); LocalizationContext context = (LocalizationContext) Config.get(session, Config.FMT_LOCALIZATION_CONTEXT); if (context != null) bundle = (DatabaseResourceBundle) context.getResourceBundle(); if (setup == null || setup.getLang_id() == null) { throw new ServletException( "Could not get language from InitiativeSetup object in application context."); }//from w w w . ja v a 2 s . com if (bundle == null || !bundle.getLangId().equals(setup.getLang_id())) { if (bundle != null) { bundle.destroy(); bundle = null; } bundle = new DatabaseResourceBundle(jdbcJndi, setup.getLang_id()); bundle.init(); /* * set the localization context of the session for jsp to process */ Config.set(session, Config.FMT_LOCALIZATION_CONTEXT, new LocalizationContext(bundle, null)); log.info("setting language for current user to: " + bundle.getLangId()); } fc.doFilter(req, res); }
From source file:org.jahia.bin.JahiaAdministration.java
/** * This method is used like a dispatcher for user requests. * * @param request Servlet request.//from w ww . j a v a2 s.c o m * @param response Servlet response. * @param session Servlet session for the current user. */ private void userRequestDispatcher(final HttpServletRequest request, final HttpServletResponse response, final HttpSession session) throws JahiaException, IOException, ServletException { String op = request.getParameter("do"); if (op == null) op = ""; final String operation = op; ParamBean jParams = initAdminJahiaData(request, response, session); final JahiaUser user = jParams.getUser(); final JahiaSite site = jParams.getSite(); try { Boolean accessGranted = (Boolean) session.getAttribute(CLASS_NAME + "accessGranted"); if (accessGranted == null) { accessGranted = Boolean.FALSE; } if (accessGranted) { Locale uiLocale = (Locale) request.getSession().getAttribute(ProcessingContext.SESSION_UI_LOCALE); if (request.getParameter("switchUiLocale") != null) { uiLocale = LanguageCodeConverters.languageCodeToLocale(request.getParameter("switchUiLocale")); request.getSession().setAttribute(ProcessingContext.SESSION_UI_LOCALE, uiLocale); user.setProperty("preferredLanguage", uiLocale.toString()); } Config.set(request, Config.FMT_LOCALIZATION_CONTEXT, new LocalizationContext( new JahiaResourceBundle(uiLocale, site.getTemplatePackageName()), uiLocale)); AdministrationModulesRegistry modulesRegistry = (AdministrationModulesRegistry) SpringContextSingleton .getInstance().getContext().getBean("administrationModulesRegistry"); AdministrationModule currentModule = modulesRegistry.getServerAdministrationModule(operation); if (currentModule != null) { if (hasSitePermission(currentModule.getPermissionName(), site.getSiteKey()) || hasServerPermission(currentModule.getPermissionName())) { session.setAttribute(CLASS_NAME + "configJahia", Boolean.TRUE); /** todo clean up this hardcoded mess. Is it even used anymore ? */ if ("sharecomponents".equals(operation) && user.isRoot()) { request.setAttribute("showAllComponents", Boolean.TRUE); } currentModule.service(request, response); } else if ("sites".equals(operation) && (session.getAttribute(JahiaAdministration.CLASS_NAME + "redirectToJahia") != null)) { session.setAttribute(CLASS_NAME + "configJahia", Boolean.TRUE); currentModule.service(request, response); } } else { currentModule = modulesRegistry.getSiteAdministrationModule(operation); if (currentModule != null) { if (hasSitePermission(currentModule.getPermissionName(), site.getSiteKey())) { session.setAttribute(CLASS_NAME + "configJahia", Boolean.FALSE); if ("search".equals(operation)) { // Use response wrapper to ensure correct handling of Application fields output to the response // @todo is this still necessary with Pluto wrapper in effect ? currentModule.service(new ServletIncludeRequestWrapper(request), new ServletIncludeResponseWrapper(response, true, SettingsBean.getInstance().getCharacterEncoding())); } else { currentModule.service(request, response); } } } } if ("switch".equals(operation)) { // operation : switch management mode (server, sites) switchModeAction(request, response, session); } else if ("change".equals(operation)) { // operation : change site id to manage session.setAttribute(CLASS_NAME + "configJahia", Boolean.FALSE); changeSite(request, response, session); } else { if (currentModule == null) { displayMenu(request, response, session); } } // the user don't currently have a granted access... } else if (isValidLoginSession(session)) { displayMenu(request, response, session); } else { logger.debug("session login not valid."); if (JahiaUserManagerService .isGuest((JahiaUser) session.getAttribute(ProcessingContext.SESSION_USER))) { displayLogin(request, response, session); } else { throw new JahiaForbiddenAccessException(); } } } catch (Exception e) { if (e instanceof JahiaForbiddenAccessException) { throw (JahiaForbiddenAccessException) e; } logger.error("Error during " + operation + " operation", e); if (isValidLoginSession(session)) { displayMenu(request, response, session); } else { if (JahiaUserManagerService .isGuest((JahiaUser) session.getAttribute(ProcessingContext.SESSION_USER))) { displayLogin(request, response, session); } else { throw new JahiaForbiddenAccessException(); } } } }
From source file:org.jahia.services.render.filter.TemplateAttributesFilter.java
public String prepare(RenderContext context, Resource resource, RenderChain chain) throws Exception { final JCRSiteNode site = context.getSite(); final JahiaTemplatesPackage templatePackage = site.getTemplatePackage(); if (templatePackage == null) { throw new ItemNotFoundException("Couldn't find the template associated with site " + site.getName() + ". Please check that all its dependencies are started."); }/*from www .ja v a 2 s . c om*/ JCRNodeWrapper node = resource.getNode(); final HttpServletRequest request = context.getRequest(); // Resolve params Map<String, Object> params = new HashMap<String, Object>(); Map<String, Serializable> moduleParams = resource.getModuleParams(); for (Map.Entry<String, Serializable> entry : moduleParams.entrySet()) { String key = entry.getKey(); params.put(key, entry.getValue()); } /* TODO BACKLOG-6561: we should avoid that, if we remove the AggregateCacheFilter some day this is used to reset cache request attributes that should not be used like request attribute "expiration" that is used to set an expiration on error fragment It's not used anymore with new CacheFilter implementation */ ExtendedNodeType cache = NodeTypeRegistry.getInstance().getNodeType("jmix:cache"); overrideProperties(node, params, moduleParams, cache); for (Map.Entry<String, Object> entry : params.entrySet()) { chain.pushAttribute(request, entry.getKey(), entry.getValue()); } Script script = (Script) request.getAttribute("script"); Locale locale = (Locale) request.getAttribute(FORCED_LOCALE_ATTRIBUTE); locale = (locale != null ? locale : resource.getLocale()); chain.pushAttribute(context.getRequest(), Config.FMT_LOCALIZATION_CONTEXT + ".request", new LocalizationContext(ResourceBundles.get(templatePackage.getResourceBundleName(), script.getView().getModule(), locale), locale)); // get areaResourcePath if defined. String areaResourcePath = (String) request.getAttribute(AreaResourceCacheKeyPartGenerator.SAVED_AREA_PATH); if (areaResourcePath != null && !context.isContributionMode()) { chain.pushAttribute(request, AREA_RESOURCE, resource.getNode().getSession().getNode(areaResourcePath)); } return null; }