to.etc.template
Class JSTemplateCompiler

java.lang.Object
  extended by to.etc.template.JSTemplateCompiler

public class JSTemplateCompiler
extends java.lang.Object

This singleton creates a compiled template for a JSP like template. The language is Javascript, using JDK 6 scripting engine. The template's data is copied verbatim to output until a <% or <%= is found; from there it assumes the code is Javascript. The engine first creates a Javascript program from the code entered, then it compiles it into the JSTemplate.

Author:
Frits Jalvingh Created on Nov 26, 2010

Constructor Summary
JSTemplateCompiler()
           
 
Method Summary
 JSTemplate compile(java.lang.Class<?> clz, java.lang.String resource, java.lang.String encoding)
          Get a class resource as a template and compile it.
 JSTemplate compile(java.io.Reader input, java.lang.String sourceName)
          Create a template from input.
protected  void error(java.lang.String string)
           
 java.lang.Object execute(java.lang.Appendable res, java.lang.Class<?> clz, java.lang.String resource, java.lang.Object... assignments)
           
 void execute(java.lang.Appendable res, java.io.Reader input, java.lang.String sourceName, java.lang.Object... assignments)
          Compile, then execute the specified template once.
 void execute(IJSTemplateContext tc, java.io.Reader input, java.lang.String sourceName, java.util.Map<java.lang.String,java.lang.Object> assignments)
           
 void execute(IJSTemplateContext tc, java.io.Reader input, java.lang.String sourceName, java.lang.Object... assignments)
          Compile, then execute the specified template once.
 java.lang.Object executeMap(java.lang.Appendable res, java.lang.Class<?> clz, java.lang.String resource, java.util.Map<java.lang.String,java.lang.Object> assignments)
           
 void executeMap(java.lang.Appendable tc, java.io.Reader input, java.lang.String sourceName, java.util.Map<java.lang.String,java.lang.Object> assignments)
           
 java.lang.String getTranslation()
           
static int[] remapLocation(java.util.List<JSLocationMapping> mapList, int lineNumber, int columnNumber)
          Walk the remap list, and try to calculate a source location for a given output location.
static void strToJavascriptString(java.lang.StringBuilder w, java.lang.CharSequence cs, boolean dblquote)
           
protected  void translate(java.io.Reader input)
          Translate input to a Javascript program.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSTemplateCompiler

public JSTemplateCompiler()
Method Detail

compile

@Nonnull
public JSTemplate compile(java.io.Reader input,
                                  java.lang.String sourceName)
                   throws java.lang.Exception
Create a template from input.

Parameters:
input -
Returns:
Throws:
java.lang.Exception

getTranslation

public java.lang.String getTranslation()

compile

public JSTemplate compile(@Nonnull
                          java.lang.Class<?> clz,
                          @Nonnull
                          java.lang.String resource,
                          @Nullable
                          java.lang.String encoding)
                   throws java.lang.Exception
Get a class resource as a template and compile it.

Parameters:
clz -
resource -
encoding -
Returns:
Throws:
java.lang.Exception

execute

public void execute(java.lang.Appendable res,
                    java.io.Reader input,
                    java.lang.String sourceName,
                    java.lang.Object... assignments)
             throws java.lang.Exception
Compile, then execute the specified template once.

Parameters:
res -
input -
sourceName -
Throws:
java.lang.Exception

execute

public void execute(IJSTemplateContext tc,
                    java.io.Reader input,
                    java.lang.String sourceName,
                    java.lang.Object... assignments)
             throws java.lang.Exception
Compile, then execute the specified template once.

Parameters:
tc -
input -
sourceName -
assignments -
Throws:
java.lang.Exception

execute

public java.lang.Object execute(java.lang.Appendable res,
                                java.lang.Class<?> clz,
                                java.lang.String resource,
                                java.lang.Object... assignments)
                         throws java.lang.Exception
Throws:
java.lang.Exception

execute

public void execute(IJSTemplateContext tc,
                    java.io.Reader input,
                    java.lang.String sourceName,
                    java.util.Map<java.lang.String,java.lang.Object> assignments)
             throws java.lang.Exception
Throws:
java.lang.Exception

executeMap

public void executeMap(java.lang.Appendable tc,
                       java.io.Reader input,
                       java.lang.String sourceName,
                       java.util.Map<java.lang.String,java.lang.Object> assignments)
                throws java.lang.Exception
Throws:
java.lang.Exception

executeMap

public java.lang.Object executeMap(java.lang.Appendable res,
                                   java.lang.Class<?> clz,
                                   java.lang.String resource,
                                   java.util.Map<java.lang.String,java.lang.Object> assignments)
                            throws java.lang.Exception
Throws:
java.lang.Exception

remapLocation

public static int[] remapLocation(java.util.List<JSLocationMapping> mapList,
                                  int lineNumber,
                                  int columnNumber)
Walk the remap list, and try to calculate a source location for a given output location.

Parameters:
mapList -
lineNumber -
columnNumber -
Returns:

translate

protected void translate(java.io.Reader input)
                  throws java.lang.Exception
Translate input to a Javascript program.

Parameters:
input -
Throws:
java.lang.Exception

strToJavascriptString

public static void strToJavascriptString(java.lang.StringBuilder w,
                                         java.lang.CharSequence cs,
                                         boolean dblquote)

error

protected void error(java.lang.String string)