Package org.springframework.web.servlet.tags

# Class HtmlEscapingAwareTag

java.lang.Object
jakarta.servlet.jsp.tagext.TagSupport
org.springframework.web.servlet.tags.RequestContextAwareTag
org.springframework.web.servlet.tags.HtmlEscapingAwareTag

All Implemented Interfaces:
  `IterationTag`, `JspTag`, `Tag`, `TryCatchFinally`, `Serializable`

Direct Known Subclasses:
  `AbstractFormTag`, `BindErrorsTag`, `BindTag`, `EscapeBodyTag`, `EvalTag`, `MessageTag`, `TransformTag`, `UrlTag`

public abstract class HtmlEscapingAwareTag extends RequestContextAwareTag
Superclass for tags that output content that might get HTML-escaped.

Provides a "htmlEscape" property for explicitly specifying whether to apply HTML escaping. If not set, a page-level default (for example, from the HtmlEscapeTag) or an application-wide default (the "defaultHtmlEscape" context-param in `web.xml`) is used.

Since:
  1.1
Author:
  Juergen Hoeller, Brian Clozel
See Also:
  - `setHtmlEscape(boolean)`
  - `HtmlEscapeTag`
  - `RequestContext.isDefaultHtmlEscape()`
  - `WebUtils.getDefaultHtmlEscape(jakarta.servlet.ServletContext)`
  - `WebUtils.getResponseEncodedHtmlEscape(jakarta.servlet.ServletContext)`
  - Serialized Form

## Field Summary

### Fields inherited from class org.springframework.web.servlet.tags.RequestContextAwareTag

`logger, REQUEST_CONTEXT_PAGE_ATTRIBUTE`

### Fields inherited from class jakarta.servlet.jsp.tagext.TagSupport

`id, pageContext`

### Fields inherited from interface jakarta.servlet.jsp.tagext.IterationTag

`EVAL_BODY_AGAIN`

### Fields inherited from interface jakarta.servlet.jsp.tagext.Tag

`EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE`

## Constructor Summary

Constructors
Constructor
Description
`HtmlEscapingAwareTag()`

## Method Summary

Modifier and Type
Method
Description
`protected String`
`htmlEscape(String content)`
HTML-encodes the given String, only if the "htmlEscape" setting is enabled.
`protected boolean`
`isDefaultHtmlEscape()`
Return the applicable default HTML escape setting for this tag.
`protected boolean`
`isHtmlEscape()`
Return the HTML escaping setting for this tag, or the default setting if not overridden.
`protected boolean`
`isResponseEncodedHtmlEscape()`
Return the applicable default for the use of response encoding with HTML escaping for this tag.
`void`
`setHtmlEscape(boolean htmlEscape)`
Set HTML escaping for this tag, as boolean value.

### Methods inherited from class org.springframework.web.servlet.tags.RequestContextAwareTag

`doCatch, doFinally, doStartTag, doStartTagInternal, getRequestContext`

### Methods inherited from class jakarta.servlet.jsp.tagext.TagSupport

`doAfterBody, doEndTag, findAncestorWithClass, getId, getParent, getValue, getValues, release, removeValue, setId, setPageContext, setParent, setValue`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### HtmlEscapingAwareTag

public HtmlEscapingAwareTag()

## Method Details

### setHtmlEscape

public void setHtmlEscape(boolean htmlEscape) throws JspException
Set HTML escaping for this tag, as boolean value. Overrides the default HTML escaping setting for the current page.

Throws:
  `JspException`
See Also:
  - `HtmlEscapeTag.setDefaultHtmlEscape(boolean)`

### isHtmlEscape

protected boolean isHtmlEscape()
Return the HTML escaping setting for this tag, or the default setting if not overridden.

See Also:
  - `isDefaultHtmlEscape()`

### isDefaultHtmlEscape

protected boolean isDefaultHtmlEscape()
Return the applicable default HTML escape setting for this tag.

The default implementation checks the RequestContext's setting, falling back to `false` in case of no explicit default given.

See Also:
  - `RequestContextAwareTag.getRequestContext()`

### isResponseEncodedHtmlEscape

protected boolean isResponseEncodedHtmlEscape()
Return the applicable default for the use of response encoding with HTML escaping for this tag.

The default implementation checks the RequestContext's setting, falling back to `false` in case of no explicit default given.

Since:
  4.1.2
See Also:
  - `RequestContextAwareTag.getRequestContext()`

### htmlEscape

protected String htmlEscape(String content)
HTML-encodes the given String, only if the "htmlEscape" setting is enabled.

The response encoding will be taken into account if the "responseEncodedHtmlEscape" setting is enabled as well.

Parameters:
  `content` - the String to escape
Returns:
  the escaped String
Since:
  4.1.2
See Also:
  - `isHtmlEscape()`
  - `isResponseEncodedHtmlEscape()`