implemented support for "prefix" and "suffix" for macros that
directly write out to response buffer.
This commit is contained in:
parent
00173af1b6
commit
ca2a42e204
2 changed files with 31 additions and 1 deletions
|
@ -143,6 +143,15 @@ public class ResponseTrans implements Externalizable {
|
||||||
return b.toString ();
|
return b.toString ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of characters written to the response buffer so far.
|
||||||
|
*/
|
||||||
|
public int getBufferLength() {
|
||||||
|
if (buffer == null)
|
||||||
|
return 0;
|
||||||
|
return buffer.length ();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append a string to the response unchanged.
|
* Append a string to the response unchanged.
|
||||||
*/
|
*/
|
||||||
|
@ -174,6 +183,16 @@ public class ResponseTrans implements Externalizable {
|
||||||
buffer.append (c, start, length);
|
buffer.append (c, start, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert string somewhere in the response buffer. Caller has to make sure
|
||||||
|
* that buffer exists and its length is larger than offset. str may be null, in which
|
||||||
|
* case nothing happens.
|
||||||
|
*/
|
||||||
|
public void insert (int offset, String str) {
|
||||||
|
if (str != null)
|
||||||
|
buffer.insert (offset, str);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace special characters with entities, including <, > and ", thus allowing
|
* Replace special characters with entities, including <, > and ", thus allowing
|
||||||
* no HTML tags.
|
* no HTML tags.
|
||||||
|
|
|
@ -314,6 +314,8 @@ public class Skin {
|
||||||
// if so, the macro evaluates to the function. Otherwise,
|
// if so, the macro evaluates to the function. Otherwise,
|
||||||
// a property/field with the name is used, if defined.
|
// a property/field with the name is used, if defined.
|
||||||
Object v = null;
|
Object v = null;
|
||||||
|
// remember length of response buffer before calling macro
|
||||||
|
int oldLength = reval.res.getBufferLength ();
|
||||||
if (app.scriptingEngine.hasFunction (handlerObject, name+"_macro", reval)) {
|
if (app.scriptingEngine.hasFunction (handlerObject, name+"_macro", reval)) {
|
||||||
// System.err.println ("Getting macro from function");
|
// System.err.println ("Getting macro from function");
|
||||||
v = app.scriptingEngine.invoke (handlerObject, name+"_macro", arguments, null, reval);
|
v = app.scriptingEngine.invoke (handlerObject, name+"_macro", arguments, null, reval);
|
||||||
|
@ -321,8 +323,17 @@ public class Skin {
|
||||||
// System.err.println ("Getting macro from property");
|
// System.err.println ("Getting macro from property");
|
||||||
v = app.scriptingEngine.get (handlerObject, name, reval);
|
v = app.scriptingEngine.get (handlerObject, name, reval);
|
||||||
}
|
}
|
||||||
if (v != null)
|
// check if macro wrote out to response buffer
|
||||||
|
int newLength = reval.res.getBufferLength ();
|
||||||
|
if (newLength > oldLength) {
|
||||||
|
// insert prefix and append suffix
|
||||||
|
String prefix = (String) parameters.get ("prefix");
|
||||||
|
String suffix = (String) parameters.get ("suffix");
|
||||||
|
reval.res.insert (oldLength, prefix);
|
||||||
|
reval.res.write (suffix);
|
||||||
|
} else if (v != null) {
|
||||||
writeToResponse (v.toString (), reval.res);
|
writeToResponse (v.toString (), reval.res);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
String msg = "[HopMacro unhandled: "+getFullName()+"]";
|
String msg = "[HopMacro unhandled: "+getFullName()+"]";
|
||||||
reval.res.write (" "+msg+" ");
|
reval.res.write (" "+msg+" ");
|
||||||
|
|
Loading…
Add table
Reference in a new issue