KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.servlet.jsp.JspException JavaDoc;
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 RequestContextAwareTag {
39
40     private Boolean JavaDoc htmlEscape;
41
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 JavaDoc htmlEscape) throws JspException JavaDoc {
49         this.htmlEscape =
50                 new Boolean JavaDoc(ExpressionEvaluationUtils.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         }
61         else {
62             return getRequestContext().isDefaultHtmlEscape();
63         }
64     }
65
66 }
67
Popular Tags