org.apache.velocity.app.event.implement
Class EscapeReference

java.lang.Object
  extended by 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 "Perl5" format used by the ORO regular expression library. More info is at http://jakarta.apache.org/oro/api/org/apache/oro/text/perl/package-summary.html.

Since:
1.5
Version:
$Id: EscapeReference.java 685685 2008-08-13 21:43:27Z nbubna $
Author:
Will Glass-Husain

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.velocity.app.event.ReferenceInsertionEventHandler
ReferenceInsertionEventHandler.referenceInsertExecutor
 
Constructor Summary
EscapeReference()
           
 
Method Summary
protected abstract  String escape(Object text)
          Escape the given text.
protected abstract  String getMatchAttribute()
          Specify the configuration attribute that specifies the regular expression.
protected  RuntimeServices getRuntimeServices()
          Retrieve a reference to RuntimeServices.
 Object referenceInsert(String reference, Object value)
          Escape the provided text if it matches the configured regular expression.
 void setRuntimeServices(RuntimeServices rs)
          Called automatically when event cartridge is initialized.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EscapeReference

public EscapeReference()
Method Detail

escape

protected abstract String escape(Object text)
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

protected abstract String getMatchAttribute()
Specify the configuration attribute that specifies the regular expression. Ideally should be in a form
eventhandler.escape.XYZ.match

where XYZ is the type of escaping being done.

Returns:
configuration attribute

referenceInsert

public Object referenceInsert(String reference,
                              Object value)
Escape the provided text if it matches the configured regular expression.

Specified by:
referenceInsert in interface ReferenceInsertionEventHandler
Parameters:
reference -
value -
Returns:
Escaped text.

setRuntimeServices

public void setRuntimeServices(RuntimeServices rs)
Called automatically when event cartridge is initialized.

Specified by:
setRuntimeServices in interface RuntimeServicesAware
Parameters:
rs - instance of RuntimeServices

getRuntimeServices

protected RuntimeServices getRuntimeServices()
Retrieve a reference to RuntimeServices. Use this for checking additional configuration properties.

Returns:
The current runtime services object.


Copyright © 2000-2010 The Apache Software Foundation. All Rights Reserved.