01: /*
02: * Copyright 2002-2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.web.servlet.tags;
18:
19: import org.springframework.context.MessageSource;
20: import org.springframework.context.NoSuchMessageException;
21: import org.springframework.ui.context.Theme;
22:
23: /**
24: * Custom tag to look up a theme message in the scope of this page.
25: * Messages are looked up using the ApplicationContext's ThemeSource,
26: * and thus should support internationalization.
27: *
28: * <p>Regards a HTML escaping setting, either on this tag instance,
29: * the page level, or the web.xml level.
30: *
31: * <p>If "code" isn't set or cannot be resolved, "text" will be used
32: * as default message.
33: *
34: * @author Jean-Pierre Pawlak
35: * @author Juergen Hoeller
36: * @see org.springframework.ui.context.Theme
37: * @see org.springframework.ui.context.ThemeSource
38: * @see #setCode
39: * @see #setText
40: * @see #setHtmlEscape
41: * @see HtmlEscapeTag#setDefaultHtmlEscape
42: * @see org.springframework.web.util.WebUtils#HTML_ESCAPE_CONTEXT_PARAM
43: */
44: public class ThemeTag extends MessageTag {
45:
46: /**
47: * Use the theme MessageSource for theme message resolution.
48: */
49: protected MessageSource getMessageSource() {
50: Theme theme = getRequestContext().getTheme();
51: return theme.getMessageSource();
52: }
53:
54: /**
55: * Return exception message that indicates the current theme.
56: */
57: protected String getNoSuchMessageExceptionDescription(
58: NoSuchMessageException ex) {
59: return "Theme '" + getRequestContext().getTheme().getName()
60: + "': " + ex.getMessage();
61: }
62:
63: }
|