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 javax.servlet.jsp.JspException;
20:
21: import org.springframework.web.util.ExpressionEvaluationUtils;
22:
23: /**
24: * Superclass for tags that output content that might get HTML-escaped.
25: *
26: * <p>Provides a "htmlEscape" property for explicitly specifying whether to
27: * apply HTML escaping. If not set, a page-level default (e.g. from the
28: * HtmlEscapeTag) or an application-wide default (the "defaultHtmlEscape"
29: * context-param in web.xml) is used.
30: *
31: * @author Juergen Hoeller
32: * @since 1.1
33: * @see #setHtmlEscape
34: * @see HtmlEscapeTag
35: * @see org.springframework.web.servlet.support.RequestContext#isDefaultHtmlEscape
36: * @see org.springframework.web.util.WebUtils#isDefaultHtmlEscape
37: */
38: public abstract class HtmlEscapingAwareTag extends
39: RequestContextAwareTag {
40:
41: private Boolean htmlEscape;
42:
43: /**
44: * Set HTML escaping for this tag, as boolean value.
45: * Overrides the default HTML escaping setting for the current page.
46: * @see HtmlEscapeTag#setDefaultHtmlEscape
47: */
48: public void setHtmlEscape(String htmlEscape) throws JspException {
49: this .htmlEscape = new Boolean(ExpressionEvaluationUtils
50: .evaluateBoolean("htmlEscape", htmlEscape, pageContext));
51: }
52:
53: /**
54: * Return the HTML escaping setting for this tag,
55: * or the default setting if not overridden.
56: */
57: protected boolean isHtmlEscape() {
58: if (this.htmlEscape != null) {
59: return this.htmlEscape.booleanValue();
60: } else {
61: return getRequestContext().isDefaultHtmlEscape();
62: }
63: }
64:
65: }
|