List of usage examples for javax.servlet.jsp.jstl.fmt LocalizationContext LocalizationContext
public LocalizationContext(ResourceBundle bundle, Locale locale)
From source file:com.steeleforge.aem.ironsites.i18n.taglib.I18nHelperTag.java
public int doEndTag() throws JspException { try {/*w w w. j a v a2 s . co m*/ init(); ValueMap valueMap = request.getResource().adaptTo(ValueMap.class); I18nResourceBundle bundle = new I18nResourceBundle(valueMap, getResourceBundle(getBaseName(), request)); // make this resource bundle & i18n available as ValueMap for TEI pageContext.setAttribute(getMessagesName(), bundle.adaptTo(ValueMap.class), PageContext.PAGE_SCOPE); pageContext.setAttribute(getI18nName(), new I18n(bundle), PageContext.PAGE_SCOPE); // make this resource bundle available for fmt functions Config.set(pageContext, "javax.servlet.jsp.jstl.fmt.localizationContext", new LocalizationContext(bundle, getLocale(request)), 1); } catch (Exception e) { LOG.error(e.getMessage()); throw new JspException(e); } return EVAL_PAGE; }
From source file:de.micromata.genome.gwiki.page.impl.i18n.GWikiI18NServletFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest hreq = (HttpServletRequest) request; HttpServletResponse hresp = (HttpServletResponse) response; HTTPCTX.set(Pair.make(hreq, hresp)); initWiki(hreq, hresp);//from w w w.ja va2 s .c o m Locale loc = hreq.getLocale(); Object ploc = request.getAttribute(LOC_KEY); if (ploc instanceof Locale) { loc = (Locale) ploc; } LocalizationContext prevLocContext = null; Object plc = hreq.getAttribute(LOCALIZATION_KEY); if (plc instanceof LocalizationContext) { prevLocContext = (LocalizationContext) plc; } Object prevfml = hreq.getAttribute(LOC_KEY); Object prevlocaiz = hreq.getAttribute(LOCALIZATION_KEY); try { hreq.setAttribute(LOC_KEY, loc); hreq.setAttribute(LOCALIZATION_KEY, new LocalizationContext( new GWikiI18NCombinedResourceBundle(loc, prevLocContext, modules), loc)); chain.doFilter(request, response); } finally { hreq.setAttribute(LOC_KEY, prevfml); hreq.setAttribute(LOCALIZATION_KEY, prevlocaiz); HTTPCTX.set(null); } }
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 ww w . j a va 2 s .co m*/ 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./* w w w . j av a 2 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 w w w. ja va 2 s . co m 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; }