com.oopreserch.web
Interface FormValueEscaper
- All Known Implementing Classes:
- EscapeForHdml, EscapeForHtml, UrlEncodeAscii, EscapeForWml, EscapeForXml
- public interface FormValueEscaper
The interface for getting the escaped String.
On the instance of Form,
you can insert the arbitrary String into the pre-defined
code fragments.
Then, the instance of Form can merge them all
and return the concatenated String.
For example, the String selected from SQL table can be
inserted into the HTML table. In this case, the HTML tags
for the HTML table skeleton will be written as the
pre-defined code fragments.
Please consider what will happen if the String to be
inserted includes the special characters such as
< or >. The concatenated String will
be invalid as the HTML code, which will result in the
corrupted String on the web browser.
To avoid such a problems, the String to be inserted should
be escaped, i.e. all the special characters within
the original String should be replaced with the corresponding
escaped characters. And this is the responsibility
of the implementation of this interface.
The implementation of this interface will be used by the
instance of Form to escape the String
to be inserted.
The list of the available implementations should be
listed in:
- (docBase)/WEB-INF/classes/FormValueEscaperFactory.properties
where the value of each property is the fully qualified
class name of the implementation of this interface.
The key in this property resource file can be specified
as the value of escape.type attribute of
d.value element in the XML.
Then, the corresponding implementation will be used to
escape the String to be inserted.
The implementation of this interface must implement:
The special characters to be escaped differ with the
mark-up-languages. In case of HTML, at least the following
characters should be escaped:
| Original Character |
Escaped Character |
| < |
< |
| > |
> |
| & |
& |
In addition, " and $ should be also
replaced with " and &dol; in HDML.
In XML, the following characters should be escaped:
| Original Character |
Escaped Character |
| < |
< |
| > |
> |
| & |
& |
| " |
" |
| ' |
' |
As for WML, $ should also be replaced
with $$. (See Page 6 of WML Language Reference
which is available at OpenWave's web site.)
Anyway, the 4 implementations are included in this package.
They are:
So, please feel free to use any of them. Or, if you need
additional features, you can define your own implementation
which satisfies your requirement.
In this case, please add the fully qualified class name
of your implementation to:
- (docBase)/WEB-INF/classes/FormValueEscaperFactory.properties
For details about this property resource file, please look
into FormValueEscaperFactory.
Occasionally, you may want to URL-encode the String
to be inserted. To specify the charset by which
the String is URL-encoded, please define your own
implementation of this interface. For example, if you'd
like to URL-encode the String by EUC-JP,
you need to define such an implementation of this
interface. To make your life easier, the class for
ISO-8859-1 is included in this package. It is:
By extending this class, you can easily define
your implementation.
All you have to do is to override the value of:
protected String charset="ISO-8859-1";
within your subclass.
The constructor will be the good place for this task.
For your convenience, the following 2 classes are included
in this package:
All of these are the just the subclass of the above class,
and you can define your own subclasses.
For details, please visit
Introduction of FormGenerator, which shows how to
implement this interface.
- Since:
- 2.0
- Author:
- Jun Inamori
- See Also:
|
Method Summary |
java.lang.String |
getEscaped(java.lang.String str)
This method will be used by Form to escape
the String to be inserted. |
getEscaped
public java.lang.String getEscaped(java.lang.String str)
- This method will be used by
Form to escape
the String to be inserted.
The implementation of this method is responsible for
escaping the special characters in the given String.
Or, it may URL-encode the given String.
This method must be
Thread Safe in all the implementations.
- Parameters:
str - The String to be escaped.- Returns:
- The escaped String
- Since:
- 2.0
ALL CONTENTS COPYRIGHT 2002, Jun Inamori. All rights reserved.
Any questions and comments are welcome to Jun Inamori.