Hello,
I'd like to refactor AbstractScriptMacro in order to be able to change
script behavior in the future without fanout violations. Here is the
plan emerged after several discussions with ThomasM:
Introduce a notion of cancelable events. Such events can be canceled by
the receiver (providing an optional reason), the actual canceling is
performed by the sender.
http://dev.xwiki.org/xwiki/bin/view/Design/CancelableEvents
Send a cancelable event ScriptEvaluationStartsEvent in
AbstractScriptMacro just before evaluating the script and a
ScriptEvaluationFinishedEvent right after evaluation has finished (in
finally block).
Add the following 3 listeners to those events (into
rendering.internal.macro.script) and move the corresponding code from
AbstractScriptMacro there:
ScriptClassLoaderHandlerListener
* does class loader manipulations currently performed by
AbstractScriptMacro#getClassLoader& Co
PermissionCheckerListener
* Aborts execution of scripts that need PR if the document is not saved
with PR
* To distinguish velocity and PR scripts, introduce a new interface
PrivilegedScriptMacro extends ScriptMacro and let
AbstractJSR223ScriptMacro implement it
NestedScriptMacroValidatorListener
* Replaces NestedScriptMacroValidator (ScriptMacroValidator component
is removed completely)
The refactoring will remove the following methods (breaks API):
AbstractJSR223ScriptMacro:
* protected boolean canExecuteScript()
* public List execute(JSR223ScriptMacroParameters, String,
MacroTransformationContext)
AbstractScriptMacro:
* protected boolean canHaveJarsParameters()
* protected ClassLoader getClassLoader(String, ClassLoader)
WDYT?