added encodeForm functions to global object and
response object. This does HTML encoding, but leaves newlines untouched.
This commit is contained in:
parent
5f5d111f95
commit
5eb8e03d77
2 changed files with 24 additions and 0 deletions
|
@ -128,6 +128,18 @@ public class ResponseTrans implements Externalizable {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encode HTML entities, but leave newlines alone. This is for the content of textarea forms.
|
||||
*/
|
||||
public void encodeForm (Object what) {
|
||||
if (what != null) {
|
||||
if (buffer == null)
|
||||
buffer = new StringBuffer (512);
|
||||
HtmlEncoder.encodeAll (what.toString (), buffer, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void append (String what) {
|
||||
if (what != null) {
|
||||
if (buffer == null)
|
||||
|
|
|
@ -98,6 +98,7 @@ public class HopExtension {
|
|||
go.putHiddenProperty("getURL", new GlobalGetURL ("getURL", evaluator, fp));
|
||||
go.putHiddenProperty("encode", new GlobalEncode ("encode", evaluator, fp));
|
||||
go.putHiddenProperty("encodeXml", new GlobalEncodeXml ("encodeXml", evaluator, fp));
|
||||
go.putHiddenProperty("encodeForm", new GlobalEncodeForm ("encodeForm", evaluator, fp));
|
||||
go.putHiddenProperty("format", new GlobalFormat ("format", evaluator, fp));
|
||||
go.putHiddenProperty("stripTags", new GlobalStripTags ("stripTags", evaluator, fp));
|
||||
go.putHiddenProperty("getXmlDocument", new GlobalGetXmlDocument ("getXmlDocument", evaluator, fp));
|
||||
|
@ -836,6 +837,17 @@ public class HopExtension {
|
|||
}
|
||||
}
|
||||
|
||||
class GlobalEncodeForm extends BuiltinFunctionObject {
|
||||
GlobalEncodeForm (String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super (fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
||||
if (arguments.length < 1)
|
||||
return ESNull.theNull;
|
||||
return new ESString (HtmlEncoder.encodeFormValue (arguments[0].toString ()));
|
||||
}
|
||||
}
|
||||
|
||||
// strip tags from XML/HTML text
|
||||
class GlobalStripTags extends BuiltinFunctionObject {
|
||||
GlobalStripTags (String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
|
|
Loading…
Add table
Reference in a new issue