KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > servlet > tags > ThemeTag


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc getNoSuchMessageExceptionDescription(NoSuchMessageException ex) {
58         return "Theme '" + getRequestContext().getTheme().getName() + "': " + ex.getMessage();
59     }
60
61 }
62
Popular Tags