kawigi.template
Class Template

java.lang.Object
  |
  +--kawigi.template.Template
All Implemented Interfaces:
java.io.Serializable

public class Template
extends java.lang.Object
implements java.io.Serializable

Represents the template of a class that can be extended by a template. It's probably best to think of this as a template template. Even though it doesn't literally define a template for a template, it's the template for how a template is interpreted (in fact, it interprets the real templates). This class is JavaBean compliant, so that it can be serialized by java's XMLEncoder (and deserialized by java's XMLDecoder). Of course, the XMLEncoder has some serious issues with the complicated system of classloaders involved TopCoder plugins, so I don't actually use it.

See Also:
Serialized Form

Field Summary
protected  java.lang.String methodName
          Represents the method that should be overridden by this template.
protected  java.lang.String[] parameters
          A list of parameters to the method that is overridden by the template.
protected  java.lang.String templateName
          The name of the template, which should be the name of the class extended by this template.
 
Constructor Summary
Template()
          Constructs a new Template object with initially null properties.
Template(java.lang.String templateName, java.lang.String methodName, java.lang.String[] parameters)
          Constructs a new Template object with the given values.
 
Method Summary
protected  java.lang.String encode(java.lang.String startString)
          Encodes a string to escape new lines, tabs, carriage returns, single and double quotes, and forward slashes.
 java.lang.String getMethodName()
          Accessor for methodName.
 java.lang.String[] getMethodParameters()
          Accessor for parameters
 java.lang.String getName()
          Accessor for templateName.
 void insert(java.io.File directory, java.util.List lines, java.util.Set methodsUsed, java.util.List tagLibs, java.lang.String templateCode)
          Does the main actual translation of template code into java code.
protected  kawigi.template.MethodInfo locateMethod(java.util.List tagLibs, java.lang.String tagName)
          Resolves the name of the tag in the list of tag libraries.
static kawigi.template.Template readKTT(java.io.File folder, java.lang.String filename)
          Reads a .ktt file from disk, deserializing it from XML.
 void setMethodName(java.lang.String name)
          Mutator for methodName.
 void setMethodParameters(java.lang.String[] parameters)
          Mutator for parameters.
 void setName(java.lang.String name)
          Mutator for templatename.
 java.lang.String[] translateCode(java.io.File directory, java.lang.String templateCode, java.lang.String className)
          Translates the KawigiEdit Template (KET) code into java code implementing the template.
 void translateFile(java.io.File folder, java.lang.String templateClass)
          Opens /.ket and parses it into /.java.
 void write(java.io.File folder)
          Writes the given template to disk at /.ktt.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

templateName

protected java.lang.String templateName
The name of the template, which should be the name of the class extended by this template.


methodName

protected java.lang.String methodName
Represents the method that should be overridden by this template.


parameters

protected java.lang.String[] parameters
A list of parameters to the method that is overridden by the template. Each element should already be of the format . The type and name should also be documented somewhere, as they may be used by template writers. Please do not name any of your parameters "code", as the template translation declares and uses "code" as the name of the return variable, and this will cause the output code to not compile.

Constructor Detail

Template

public Template(java.lang.String templateName,
                java.lang.String methodName,
                java.lang.String[] parameters)
Constructs a new Template object with the given values.


Template

public Template()
Constructs a new Template object with initially null properties.

Method Detail

getName

public java.lang.String getName()
Accessor for templateName.


setName

public void setName(java.lang.String name)
Mutator for templatename. name should be the name of the class extended by this template.


getMethodName

public java.lang.String getMethodName()
Accessor for methodName.


setMethodName

public void setMethodName(java.lang.String name)
Mutator for methodName.


getMethodParameters

public java.lang.String[] getMethodParameters()
Accessor for parameters


setMethodParameters

public void setMethodParameters(java.lang.String[] parameters)
Mutator for parameters.


write

public void write(java.io.File folder)
Writes the given template to disk at /.ktt. The ktt extension is for "Kawigiedit Template Template".


translateCode

public java.lang.String[] translateCode(java.io.File directory,
                                        java.lang.String templateCode,
                                        java.lang.String className)
                                 throws TemplateSyntaxException
Translates the KawigiEdit Template (KET) code into java code implementing the template. The new class has the name given in className and searches for tag libraries in directory.

TemplateSyntaxException

insert

public void insert(java.io.File directory,
                   java.util.List lines,
                   java.util.Set methodsUsed,
                   java.util.List tagLibs,
                   java.lang.String templateCode)
            throws TemplateSyntaxException
Does the main actual translation of template code into java code. This code used to be in the translateCode method, but it was seperated from it to better afford nested templates.

TemplateSyntaxException

locateMethod

protected kawigi.template.MethodInfo locateMethod(java.util.List tagLibs,
                                                  java.lang.String tagName)
Resolves the name of the tag in the list of tag libraries. Returns null if the method was not found.


translateFile

public void translateFile(java.io.File folder,
                          java.lang.String templateClass)
                   throws java.io.IOException,
                          TemplateSyntaxException
Opens /.ket and parses it into /.java.

java.io.IOException
TemplateSyntaxException

encode

protected java.lang.String encode(java.lang.String startString)
Encodes a string to escape new lines, tabs, carriage returns, single and double quotes, and forward slashes.


readKTT

public static kawigi.template.Template readKTT(java.io.File folder,
                                               java.lang.String filename)
                                        throws java.io.IOException,
                                               TemplateSyntaxException
Reads a .ktt file from disk, deserializing it from XML. Returns null if the file is not found or cannot be read.

java.io.IOException
TemplateSyntaxException