当前位置: 首页>>代码示例>>Java>>正文


Java Config类代码示例

本文整理汇总了Java中javax.servlet.jsp.jstl.core.Config的典型用法代码示例。如果您正苦于以下问题:Java Config类的具体用法?Java Config怎么用?Java Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Config类属于javax.servlet.jsp.jstl.core包,在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sessionCreated

import javax.servlet.jsp.jstl.core.Config; //导入依赖的package包/类
/** HttpSessionListener interface */
   @Override
   public void sessionCreated(HttpSessionEvent sessionEvent) {
if (sessionEvent == null) {
    return;
}
HttpSession session = sessionEvent.getSession();
session.setMaxInactiveInterval(SessionListener.timeout);

//set server default locale for STURTS and JSTL. This value should be overwrite
//LocaleFilter class. But this part code can cope with login.jsp Locale.
if (session != null) {
    String defaults[] = LanguageUtil.getDefaultLangCountry();
    Locale preferredLocale = new Locale(defaults[0] == null ? "" : defaults[0],
	    defaults[1] == null ? "" : defaults[1]);
    session.setAttribute(LocaleFilter.PREFERRED_LOCALE_KEY, preferredLocale);
    Config.set(session, Config.FMT_LOCALE, preferredLocale);
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:SessionListener.java

示例2: getJstlAwareMessageSource

import javax.servlet.jsp.jstl.core.Config; //导入依赖的package包/类
/**
 * Checks JSTL's "javax.servlet.jsp.jstl.fmt.localizationContext"
 * context-param and creates a corresponding child message source,
 * with the provided Spring-defined MessageSource as parent.
 * @param servletContext the ServletContext we're running in
 * (to check JSTL-related context-params in {@code web.xml})
 * @param messageSource the MessageSource to expose, typically
 * the ApplicationContext of the current DispatcherServlet
 * @return the MessageSource to expose to JSTL; first checking the
 * JSTL-defined bundle, then the Spring-defined MessageSource
 * @see org.springframework.context.ApplicationContext
 */
public static MessageSource getJstlAwareMessageSource(
		ServletContext servletContext, MessageSource messageSource) {

	if (servletContext != null) {
		String jstlInitParam = servletContext.getInitParameter(Config.FMT_LOCALIZATION_CONTEXT);
		if (jstlInitParam != null) {
			// Create a ResourceBundleMessageSource for the specified resource bundle
			// basename in the JSTL context-param in web.xml, wiring it with the given
			// Spring-defined MessageSource as parent.
			ResourceBundleMessageSource jstlBundleWrapper = new ResourceBundleMessageSource();
			jstlBundleWrapper.setBasename(jstlInitParam);
			jstlBundleWrapper.setParentMessageSource(messageSource);
			return jstlBundleWrapper;
		}
	}
	return messageSource;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:JstlUtils.java

示例3: setupTextProvider

import javax.servlet.jsp.jstl.core.Config; //导入依赖的package包/类
public static void setupTextProvider(ServletContext servletContext, ServletRequest request) {
    Locale locale = request.getLocale();
    ResourceBundleManager resourceBundleManager =
            (ResourceBundleManager) servletContext.getAttribute(BaseModule.RESOURCE_BUNDLE_MANAGER);
    ResourceBundle portofinoResourceBundle = resourceBundleManager.getBundle(locale);

    LocalizationContext localizationContext =
            new LocalizationContext(portofinoResourceBundle, locale);
    request.setAttribute(Config.FMT_LOCALIZATION_CONTEXT + ".request", localizationContext);

    //Setup Elements I18n
    ResourceBundle elementsResourceBundle =
            ResourceBundle.getBundle(SimpleTextProvider.DEFAULT_MESSAGE_RESOURCE, locale);

    TextProvider textProvider =
            new MultipleTextProvider(
                    portofinoResourceBundle, elementsResourceBundle);
    ElementsThreadLocals.setTextProvider(textProvider);
}
 
开发者ID:ManyDesigns,项目名称:Portofino,代码行数:20,代码来源:I18nUtils.java

示例4: doFilter

import javax.servlet.jsp.jstl.core.Config; //导入依赖的package包/类
@Override
public void doFilter(
        ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {
    //I18n
    Locale locale = request.getLocale();
    ResourceBundleManager resourceBundleManager =
            (ResourceBundleManager) servletContext.getAttribute(BaseModule.RESOURCE_BUNDLE_MANAGER);
    ResourceBundle portofinoResourceBundle = resourceBundleManager.getBundle(locale);

    LocalizationContext localizationContext =
            new LocalizationContext(portofinoResourceBundle, locale);
    request.setAttribute(Config.FMT_LOCALIZATION_CONTEXT + ".request", localizationContext);

    //Setup Elements I18n
    ResourceBundle elementsResourceBundle =
            ResourceBundle.getBundle(SimpleTextProvider.DEFAULT_MESSAGE_RESOURCE, locale);

    TextProvider textProvider =
            new MultipleTextProvider(
                    portofinoResourceBundle, elementsResourceBundle);
    ElementsThreadLocals.setTextProvider(textProvider);
    filterChain.doFilter(request, response);
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:25,代码来源:I18nFilter.java

示例5: setTimeZone

import javax.servlet.jsp.jstl.core.Config; //导入依赖的package包/类
private void setTimeZone(Context ctx, User user, HttpServletRequest request) {
    RhnTimeZone tz = null;
    if (user != null) {
        tz = user.getTimeZone();
        LOG.debug("Set timezone from the user.");
    }
    if (tz == null) {
        // Use the Appserver timezone if the User doesn't have one.
        String olsonName = TimeZone.getDefault().getID();
        if (LOG.isDebugEnabled()) {
            LOG.debug("olson name [" + olsonName + "]");
        }
        tz = UserManager.getTimeZone(olsonName);
        // if we're still null set it to a default
        if (tz == null) {
            tz = new RhnTimeZone();
            tz.setOlsonName(olsonName);

            LOG.debug("timezone still null");
        }
    }
    ctx.setTimezone(tz.getTimeZone());
    // Set the timezone on the request so that fmt:formatDate
    // can find it
    Config.set(request, Config.FMT_TIME_ZONE, tz.getTimeZone());
}
 
开发者ID:spacewalkproject,项目名称:spacewalk,代码行数:27,代码来源:LocalizedEnvironmentFilter.java

示例6: setOtherResourceBundles

import javax.servlet.jsp.jstl.core.Config; //导入依赖的package包/类
/**
    * Sets the Stripes error and field resource bundles in the request, if their names have been configured.
    */
@Override
protected void setOtherResourceBundles(HttpServletRequest request)
{
	Locale locale = request.getLocale();

       if (errorBundleName != null)
       {
           ResourceBundle errorBundle = getLocalizationBundleFactory().getErrorMessageBundle(locale);
           Config.set(request, errorBundleName, new LocalizationContext(errorBundle, locale));
           LOGGER.debug("Loaded Stripes error message bundle ", errorBundle, " as ", errorBundleName);
       }

       if (fieldBundleName != null)
       {
           ResourceBundle fieldBundle = getLocalizationBundleFactory().getFormFieldBundle(locale);
           Config.set(request, fieldBundleName, new LocalizationContext(fieldBundle, locale));
           LOGGER.debug("Loaded Stripes field name bundle ", fieldBundle, " as ", fieldBundleName);
       }
}
 
开发者ID:StripesFramework,项目名称:stripes-stuff,代码行数:23,代码来源:JstlBundleInterceptor.java

示例7: findByKey

import javax.servlet.jsp.jstl.core.Config; //导入依赖的package包/类
/**
 * Looks up a configuration variable in the request, session and application scopes. If none is found, return by
 * {@link ServletContext#getInitParameter(String)} method.
 */
private Object findByKey(String key) {
	Object value = Config.get(request, key);
	if (value != null) {
		return value;
	}

	value = Config.get(request.getSession(createNewSession()), key);
	if (value != null) {
		return value;
	}

	value = Config.get(request.getServletContext(), key);
	if (value != null) {
		return value;
	}

	return request.getServletContext().getInitParameter(key);
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:23,代码来源:JstlLocalization.java

示例8: doEndTag

import javax.servlet.jsp.jstl.core.Config; //导入依赖的package包/类
public int doEndTag() throws JspException {
    try {
        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;
}
 
开发者ID:steeleforge,项目名称:ironsites,代码行数:25,代码来源:I18nHelperTag.java

示例9: exposeLocalizationContext

import javax.servlet.jsp.jstl.core.Config; //导入依赖的package包/类
/**
 * Exposes JSTL-specific request attributes specifying locale
 * and resource bundle for JSTL's formatting and message tags,
 * using Spring's locale and MessageSource.
 * @param request the current HTTP request
 * @param messageSource the MessageSource to expose,
 * typically the current ApplicationContext (may be {@code null})
 * @see #exposeLocalizationContext(RequestContext)
 */
public static void exposeLocalizationContext(HttpServletRequest request, MessageSource messageSource) {
	Locale jstlLocale = RequestContextUtils.getLocale(request);
	Config.set(request, Config.FMT_LOCALE, jstlLocale);
	TimeZone timeZone = RequestContextUtils.getTimeZone(request);
	if (timeZone != null) {
		Config.set(request, Config.FMT_TIME_ZONE, timeZone);
	}
	if (messageSource != null) {
		LocalizationContext jstlContext = new SpringLocalizationContext(messageSource, request);
		Config.set(request, Config.FMT_LOCALIZATION_CONTEXT, jstlContext);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:JstlUtils.java

示例10: getResourceBundle

import javax.servlet.jsp.jstl.core.Config; //导入依赖的package包/类
@Override
public ResourceBundle getResourceBundle() {
	HttpSession session = this.request.getSession(false);
	if (session != null) {
		Object lcObject = Config.get(session, Config.FMT_LOCALIZATION_CONTEXT);
		if (lcObject instanceof LocalizationContext) {
			ResourceBundle lcBundle = ((LocalizationContext) lcObject).getResourceBundle();
			return new MessageSourceResourceBundle(this.messageSource, getLocale(), lcBundle);
		}
	}
	return new MessageSourceResourceBundle(this.messageSource, getLocale());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:JstlUtils.java

示例11: getLocale

import javax.servlet.jsp.jstl.core.Config; //导入依赖的package包/类
@Override
public Locale getLocale() {
	HttpSession session = this.request.getSession(false);
	if (session != null) {
		Object localeObject = Config.get(session, Config.FMT_LOCALE);
		if (localeObject instanceof Locale) {
			return (Locale) localeObject;
		}
	}
	return RequestContextUtils.getLocale(this.request);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:12,代码来源:JstlUtils.java

示例12: getJstlLocale

import javax.servlet.jsp.jstl.core.Config; //导入依赖的package包/类
public static Locale getJstlLocale(HttpServletRequest request, ServletContext servletContext) {
	Object localeObject = Config.get(request, Config.FMT_LOCALE);
	if (localeObject == null) {
		HttpSession session = request.getSession(false);
		if (session != null) {
			localeObject = Config.get(session, Config.FMT_LOCALE);
		}
		if (localeObject == null && servletContext != null) {
			localeObject = Config.get(servletContext, Config.FMT_LOCALE);
		}
	}
	return (localeObject instanceof Locale ? (Locale) localeObject : null);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:RequestContext.java

示例13: getJstlTimeZone

import javax.servlet.jsp.jstl.core.Config; //导入依赖的package包/类
public static TimeZone getJstlTimeZone(HttpServletRequest request, ServletContext servletContext) {
	Object timeZoneObject = Config.get(request, Config.FMT_TIME_ZONE);
	if (timeZoneObject == null) {
		HttpSession session = request.getSession(false);
		if (session != null) {
			timeZoneObject = Config.get(session, Config.FMT_TIME_ZONE);
		}
		if (timeZoneObject == null && servletContext != null) {
			timeZoneObject = Config.get(servletContext, Config.FMT_TIME_ZONE);
		}
	}
	return (timeZoneObject instanceof TimeZone ? (TimeZone) timeZoneObject : null);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:RequestContext.java

示例14: testInternalResourceViewResolverWithJstl

import javax.servlet.jsp.jstl.core.Config; //导入依赖的package包/类
@Test
public void testInternalResourceViewResolverWithJstl() throws Exception {
	Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH;

	MockServletContext sc = new MockServletContext();
	StaticWebApplicationContext wac = new StaticWebApplicationContext();
	wac.setServletContext(sc);
	wac.addMessage("code1", locale, "messageX");
	wac.refresh();
	InternalResourceViewResolver vr = new InternalResourceViewResolver();
	vr.setViewClass(JstlView.class);
	vr.setApplicationContext(wac);

	View view = vr.resolveViewName("example1", Locale.getDefault());
	assertEquals("Correct view class", JstlView.class, view.getClass());
	assertEquals("Correct URL", "example1", ((JstlView) view).getUrl());

	view = vr.resolveViewName("example2", Locale.getDefault());
	assertEquals("Correct view class", JstlView.class, view.getClass());
	assertEquals("Correct URL", "example2", ((JstlView) view).getUrl());

	MockHttpServletRequest request = new MockHttpServletRequest(sc);
	HttpServletResponse response = new MockHttpServletResponse();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale));
	Map model = new HashMap();
	TestBean tb = new TestBean();
	model.put("tb", tb);
	view.render(model, request, response);

	assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb")));
	assertTrue("Correct rc attribute", request.getAttribute("rc") == null);

	assertEquals(locale, Config.get(request, Config.FMT_LOCALE));
	LocalizationContext lc = (LocalizationContext) Config.get(request, Config.FMT_LOCALIZATION_CONTEXT);
	assertEquals("messageX", lc.getResourceBundle().getString("code1"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:38,代码来源:ViewResolverTests.java

示例15: testInternalResourceViewResolverWithJstlAndContextParam

import javax.servlet.jsp.jstl.core.Config; //导入依赖的package包/类
@Test
public void testInternalResourceViewResolverWithJstlAndContextParam() throws Exception {
	Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH;

	MockServletContext sc = new MockServletContext();
	sc.addInitParameter(Config.FMT_LOCALIZATION_CONTEXT, "org/springframework/web/context/WEB-INF/context-messages");
	StaticWebApplicationContext wac = new StaticWebApplicationContext();
	wac.setServletContext(sc);
	wac.addMessage("code1", locale, "messageX");
	wac.refresh();
	InternalResourceViewResolver vr = new InternalResourceViewResolver();
	vr.setViewClass(JstlView.class);
	vr.setApplicationContext(wac);

	View view = vr.resolveViewName("example1", Locale.getDefault());
	assertEquals("Correct view class", JstlView.class, view.getClass());
	assertEquals("Correct URL", "example1", ((JstlView) view).getUrl());

	view = vr.resolveViewName("example2", Locale.getDefault());
	assertEquals("Correct view class", JstlView.class, view.getClass());
	assertEquals("Correct URL", "example2", ((JstlView) view).getUrl());

	MockHttpServletRequest request = new MockHttpServletRequest(sc);
	HttpServletResponse response = new MockHttpServletResponse();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale));
	Map model = new HashMap();
	TestBean tb = new TestBean();
	model.put("tb", tb);
	view.render(model, request, response);

	assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb")));
	assertTrue("Correct rc attribute", request.getAttribute("rc") == null);

	assertEquals(locale, Config.get(request, Config.FMT_LOCALE));
	LocalizationContext lc = (LocalizationContext) Config.get(request, Config.FMT_LOCALIZATION_CONTEXT);
	assertEquals("message1", lc.getResourceBundle().getString("code1"));
	assertEquals("message2", lc.getResourceBundle().getString("code2"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:40,代码来源:ViewResolverTests.java


注:本文中的javax.servlet.jsp.jstl.core.Config类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。