001/* 002 * Copyright 2002-2018 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 javax.servlet.jsp.JspException; 020 021/** 022 * The {@code <htmlEscape>} tag sets default HTML escape value for the current 023 * page. The actual value can be overridden by escaping-aware tags. 024 * The default is "false". 025 * 026 * <p>Note: You can also set a "defaultHtmlEscape" web.xml context-param. 027 * A page-level setting overrides a context-param. 028 * 029 * <table> 030 * <caption>Attribute Summary</caption> 031 * <thead> 032 * <tr> 033 * <th>Attribute</th> 034 * <th>Required?</th> 035 * <th>Runtime Expression?</th> 036 * <th>Description</th> 037 * </tr> 038 * </thead> 039 * <tbody> 040 * <tr> 041 * <td>defaultHtmlEscape</td> 042 * <td>true</td> 043 * <td>true</td> 044 * <td>Set the default value for HTML escaping, to be put into the current 045 * PageContext.</td> 046 * </tr> 047 * </tbody> 048 * </table> 049 * 050 * @author Juergen Hoeller 051 * @since 04.03.2003 052 * @see HtmlEscapingAwareTag#setHtmlEscape 053 */ 054@SuppressWarnings("serial") 055public class HtmlEscapeTag extends RequestContextAwareTag { 056 057 private boolean defaultHtmlEscape; 058 059 060 /** 061 * Set the default value for HTML escaping, 062 * to be put into the current PageContext. 063 */ 064 public void setDefaultHtmlEscape(boolean defaultHtmlEscape) { 065 this.defaultHtmlEscape = defaultHtmlEscape; 066 } 067 068 069 @Override 070 protected int doStartTagInternal() throws JspException { 071 getRequestContext().setDefaultHtmlEscape(this.defaultHtmlEscape); 072 return EVAL_BODY_INCLUDE; 073 } 074 075}