Class EscapeReference
java.lang.Object
org.apache.velocity.app.event.implement.EscapeReference
- All Implemented Interfaces:
EventHandler,ReferenceInsertionEventHandler,RuntimeServicesAware
- Direct Known Subclasses:
EscapeHtmlReference,EscapeJavaScriptReference,EscapeSqlReference,EscapeXmlReference
public abstract class EscapeReference
extends Object
implements ReferenceInsertionEventHandler, RuntimeServicesAware
Base class for escaping references. To use it, override the following methods:
String escape(String text)- escape the provided text
String getMatchAttribute()- retrieve the configuration attribute used to match references (see below)
By default, all references are escaped. However, by setting the match attribute
in the configuration file to a regular expression, users can specify which references
to escape. For example the following configuration property tells the EscapeSqlReference
event handler to only escape references that start with "sql".
(e.g. $sql, $sql.toString(),, etc).
eventhandler.escape.sql.match = sql.*
Regular expressions should follow the format used by the Java language. More info in the
Pattern class documentation.- Since:
- 1.5
- Version:
- $Id$
- Author:
- Will Glass-Husain
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract StringEscape the given text.protected abstract StringSpecify the configuration attribute that specifies the regular expression.protected RuntimeServicesRetrieve a reference to RuntimeServices.referenceInsert(Context context, String reference, Object value) Escape the provided text if it matches the configured regular expression.voidCalled automatically when event cartridge is initialized.
-
Field Details
-
log
protected org.slf4j.Logger log
-
-
Constructor Details
-
EscapeReference
public EscapeReference()
-
-
Method Details
-
escape
Escape the given text. Override this in a subclass to do the actual escaping.- Parameters:
text- the text to escape- Returns:
- the escaped text
-
getMatchAttribute
Specify the configuration attribute that specifies the regular expression. Ideally should be in a formeventhandler.escape.XYZ.matchwhere
XYZis the type of escaping being done.- Returns:
- configuration attribute
-
referenceInsert
Escape the provided text if it matches the configured regular expression.- Specified by:
referenceInsertin interfaceReferenceInsertionEventHandler- Parameters:
context- current contextreference-value-- Returns:
- Escaped text.
-
setRuntimeServices
Called automatically when event cartridge is initialized.- Specified by:
setRuntimeServicesin interfaceRuntimeServicesAware- Parameters:
rs- instance of RuntimeServices
-
getRuntimeServices
Retrieve a reference to RuntimeServices. Use this for checking additional configuration properties.- Returns:
- The current runtime services object.
-