001/* 002 * Copyright 2002-2013 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.servlet.tags; 018 019import org.springframework.context.MessageSource; 020import org.springframework.context.NoSuchMessageException; 021 022/** 023 * Custom tag to look up a theme message in the scope of this page. 024 * Messages are looked up using the ApplicationContext's ThemeSource, 025 * and thus should support internationalization. 026 * 027 * <p>Regards a HTML escaping setting, either on this tag instance, 028 * the page level, or the web.xml level. 029 * 030 * <p>If "code" isn't set or cannot be resolved, "text" will be used 031 * as default message. 032 * 033 * <p>Message arguments can be specified via the {@link #setArguments(Object) arguments} 034 * attribute or by using nested {@code <spring:argument>} tags. 035 * 036 * @author Jean-Pierre Pawlak 037 * @author Juergen Hoeller 038 * @see org.springframework.ui.context.Theme 039 * @see org.springframework.ui.context.ThemeSource 040 * @see #setCode 041 * @see #setText 042 * @see #setHtmlEscape 043 * @see HtmlEscapeTag#setDefaultHtmlEscape 044 * @see org.springframework.web.util.WebUtils#HTML_ESCAPE_CONTEXT_PARAM 045 * @see ArgumentTag 046 */ 047@SuppressWarnings("serial") 048public class ThemeTag extends MessageTag { 049 050 /** 051 * Use the theme MessageSource for theme message resolution. 052 */ 053 @Override 054 protected MessageSource getMessageSource() { 055 return getRequestContext().getTheme().getMessageSource(); 056 } 057 058 /** 059 * Return exception message that indicates the current theme. 060 */ 061 @Override 062 protected String getNoSuchMessageExceptionDescription(NoSuchMessageException ex) { 063 return "Theme '" + getRequestContext().getTheme().getName() + "': " + ex.getMessage(); 064 } 065 066}