List of usage examples for javax.servlet.jsp.jstl.fmt LocalizationContext getResourceBundle
public ResourceBundle getResourceBundle()
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 ava2s .c o 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.displaytag.localization.I18nJstlAdapter.java
/** * @see I18nResourceProvider#getResource(String, String, Tag, PageContext) *//*from w w w .ja v a 2 s .c o m*/ public String getResource(String resourceKey, String defaultValue, Tag tag, PageContext pageContext) { // if titleKey isn't defined either, use property String key = (resourceKey != null) ? resourceKey : defaultValue; String title = null; ResourceBundle bundle = null; // jakarta jstl implementation, there is no other way to get the bundle from the parent fmt:bundle tag Tag bundleTag = TagSupport.findAncestorWithClass(tag, BundleSupport.class); if (bundleTag != null) { BundleSupport parent = (BundleSupport) bundleTag; if (key != null) { String prefix = parent.getPrefix(); if (prefix != null) { key = prefix + key; } } bundle = parent.getLocalizationContext().getResourceBundle(); } // resin jstl implementation, more versatile (we don't need to look up resin classes) if (bundle == null) { Object cauchoBundle = pageContext.getAttribute("caucho.bundle"); //$NON-NLS-1$ if (cauchoBundle != null && cauchoBundle instanceof LocalizationContext) { bundle = ((LocalizationContext) cauchoBundle).getResourceBundle(); // handle prefix just like resin does String prefix = (String) pageContext.getAttribute("caucho.bundle.prefix"); //$NON-NLS-1$ if (prefix != null) { key = prefix + key; } } } // standard jstl localizationContest if (bundle == null) { // check for the localizationContext in applicationScope, set in web.xml LocalizationContext localization = BundleSupport.getLocalizationContext(pageContext); if (localization != null) { bundle = localization.getResourceBundle(); } } if (bundle != null) { try { title = bundle.getString(key); } catch (MissingResourceException e) { log.debug(Messages.getString("Localization.missingkey", key)); //$NON-NLS-1$ // if user explicitely added a titleKey we guess this is an error if (resourceKey != null) { title = UNDEFINED_KEY + resourceKey + UNDEFINED_KEY; } } } return title; }
From source file:org.wso2.carbon.ui.taglibs.TooltipsGenerator.java
/** * This method is used to get the resource bundle define in a jsp page. * @return return the resource bundle// w w w . ja v a2 s . com */ public ResourceBundle getCommonResourceBundleForJspPage() { Tag t = findAncestorWithClass(this, BundleSupport.class); LocalizationContext localizationContext; if (t != null) { // use resource bundle from parent <bundle> tag BundleSupport parent = (BundleSupport) t; localizationContext = parent.getLocalizationContext(); } else { localizationContext = BundleSupport.getLocalizationContext(pageContext); } return localizationContext.getResourceBundle(); }