// do nothing
}
protected void processImpl( Template pTemplate ) {
Template template = pTemplate;
PropertySet tmps = template.getMergedPropertySet();
boolean successful = false;
PrintStream sysOut = null;
PrintStream sysErr = null;
RecordingUserMessageHandler rumh = new RecordingUserMessageHandler();
Object result = null;
try {
String cwo = makeCodeWriterOptions( tmps, template );
String[] args = ArgUtil.splitQuoted( cwo );
// DO NOT use CommandLineUserMessageHandler here - causes infinite recursion
MessageHandlerOutputStream out = new MessageHandlerOutputStream( UserMessageHandler.INFO, rumh );
MessageHandlerOutputStream err = new MessageHandlerOutputStream( UserMessageHandler.ERROR, rumh );
// space out dots to avoid accidental replace on System DOT out search
sysOut = System . out;
sysErr = System . err;
// set context if not null
Object context = template.getContext();
boolean throwWriterExceptions = tmps.isYes( Property.main_CodeWriter_throwExceptions );
String script = template.getCodeWriterSource();
Context cx = Context.enter();
// DO NOT put System.out in MessageHandler as this will cause infinite loop
System.setOut( new PrintStream( out ) );
System.setErr( new PrintStream( err ) );
Scriptable scope = cx.initStandardObjects();
cx.evaluateString(scope, script, "CodeWriter Line Number: ", 1, null);
Object codewriterObj = scope.get( "codewriter", scope );
if( null == codewriterObj || !(codewriterObj instanceof Scriptable) ) {
throw new RuntimeException( "no codewriter in script" );
}
Scriptable codewriter = (Scriptable) codewriterObj;
Object _setContextObj = codewriter.get( "_setContext", codewriter );
if( null == _setContextObj || !(_setContextObj instanceof Function) ) {
throw new RuntimeException( "no codewriter._setContext in script" );
}
Function _setContext = (Function) _setContextObj;
_setContext.call(cx,scope,codewriter,new Object[]{context});
Object _generateObj = codewriter.get( "_generate", codewriter );
if( null == _generateObj || !(_generateObj instanceof Function) ) {
throw new RuntimeException( "no codewriter._generate in script" );
}
Function _generate = (Function) _generateObj;
result = _generate.call(cx,scope,codewriter,new Object[]{args,new Boolean(throwWriterExceptions)});
template.setResult( result );
}
catch( StandardException se ) {
if( null != sysOut ) {
System.setOut( sysOut );