本文整理汇总了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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
}
示例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());
}
示例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);
}
示例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);
}
示例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);
}
示例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"));
}
示例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"));
}