| 1 | |
package org.webslinger.template.text; |
| 2 | |
|
| 3 | |
import java.io.IOException; |
| 4 | |
import java.io.Writer; |
| 5 | |
import java.util.Arrays; |
| 6 | |
import java.util.Vector; |
| 7 | |
|
| 8 | |
import org.apache.bsf.BSFException; |
| 9 | |
import org.apache.bsf.util.CodeBuffer; |
| 10 | |
|
| 11 | |
import org.webslinger.bsf.LanguageEngineImpl; |
| 12 | |
import org.webslinger.bsf.LanguageEngineInfo; |
| 13 | |
|
| 14 | 0 | public class TextTemplateEngine extends LanguageEngineImpl { |
| 15 | |
public LanguageEngineInfo getLanguageEngineInfo() { |
| 16 | 0 | return TextTemplateInfo.INSTANCE; |
| 17 | |
} |
| 18 | |
|
| 19 | |
public void compileApply(String source, int lineNo, int columnNo, Object body, Vector paramNames, Vector args, CodeBuffer cb) throws BSFException { |
| 20 | 0 | throw new BSFException(BSFException.REASON_UNSUPPORTED_FEATURE, body.toString()); |
| 21 | |
} |
| 22 | |
|
| 23 | |
public void compileExpr(String source, int lineNo, int columnNo, Object expr, CodeBuffer cb) throws BSFException { |
| 24 | 0 | throw new BSFException(BSFException.REASON_UNSUPPORTED_FEATURE, expr.toString()); |
| 25 | |
} |
| 26 | |
|
| 27 | |
public void compileScript(String source, int lineNo, int columnNo, Object script, CodeBuffer cb) throws BSFException { |
| 28 | 0 | throw new BSFException(BSFException.REASON_UNSUPPORTED_FEATURE, script.toString()); |
| 29 | |
} |
| 30 | |
|
| 31 | |
public void iexec(String source, int lineNo, int columnNo, Object script) throws BSFException { |
| 32 | 0 | throw new BSFException(BSFException.REASON_UNSUPPORTED_FEATURE, script.toString()); |
| 33 | |
} |
| 34 | |
|
| 35 | |
public Object apply(String source, int lineNo, int columnNo, Object body, String[] names, Object[] args) throws BSFException { |
| 36 | |
try { |
| 37 | 0 | ((Writer) args[0]).write(getVFSDelegate().getString(body)); |
| 38 | 0 | } catch (IOException e) { |
| 39 | 0 | throw (BSFException) new BSFException(BSFException.REASON_IO_ERROR, e.getMessage()).initCause(e); |
| 40 | 0 | } |
| 41 | 0 | return Boolean.TRUE; |
| 42 | |
} |
| 43 | |
|
| 44 | |
public Object apply(String source, int lineNo, int columnNo, Object body, String[] names, Object[] args, Class[] types) throws BSFException { |
| 45 | |
try { |
| 46 | 0 | ((Writer) args[0]).write(getVFSDelegate().getString(body)); |
| 47 | 0 | } catch (IOException e) { |
| 48 | 0 | throw (BSFException) new BSFException(BSFException.REASON_IO_ERROR, e.getMessage()).initCause(e); |
| 49 | 0 | } |
| 50 | 0 | return Boolean.TRUE; |
| 51 | |
} |
| 52 | |
|
| 53 | |
public Object eval(String source, int lineNo, int columnNo, Object expr) throws BSFException { |
| 54 | 0 | throw new BSFException(BSFException.REASON_UNSUPPORTED_FEATURE, expr.toString()); |
| 55 | |
} |
| 56 | |
|
| 57 | |
public void exec(String source, int lineNo, int columnNo, Object script) throws BSFException { |
| 58 | 0 | throw new BSFException(BSFException.REASON_UNSUPPORTED_FEATURE, script.toString()); |
| 59 | |
} |
| 60 | |
|
| 61 | |
public Object call(Object object, String name, Object[] args) throws BSFException { |
| 62 | 0 | throw new BSFException(BSFException.REASON_UNSUPPORTED_FEATURE, object + "." + name + "(" + Arrays.asList(args) + ")"); |
| 63 | |
} |
| 64 | |
} |