org.teatrove.tea.engine
Class TemplateSourceImpl

java.lang.Object
  extended by org.teatrove.tea.engine.TemplateSourceImpl
All Implemented Interfaces:
TemplateSource

public class TemplateSourceImpl
extends Object
implements TemplateSource

This class should be created using the TemplateSourceFactory

Author:
Jonathan Colwell

Nested Class Summary
 class TemplateSourceImpl.CompilerStatusLogger
           
protected  class TemplateSourceImpl.ErrorRetriever
           
protected  class TemplateSourceImpl.Results
           
protected  class TemplateSourceImpl.TemplateSourceFileInfo
           
 
Field Summary
protected  File mCompiledDir
           
protected  TemplateSourceConfig mConfig
           
protected  Log mLog
           
protected  boolean mLogCompileStatus
           
protected  PropertyMap mProperties
           
protected  TemplateSourceImpl.Results mResults
           
protected  Map<String,TemplateSourceImpl.TemplateSourceFileInfo> mTemplateSourceFileInfo
           
 
Constructor Summary
TemplateSourceImpl()
           
 
Method Summary
protected  TemplateSourceImpl.Results actuallyCompileTemplates(ClassInjector injector, boolean all)
           
protected  TemplateSourceImpl.Results actuallyCompileTemplates(ClassInjector injector, boolean all, boolean recurse)
           
protected  TemplateSourceImpl.Results actuallyCompileTemplates(ClassInjector injector, boolean all, boolean recurse, StatusListener listener)
           
protected  TemplateSourceImpl.Results actuallyCompileTemplates(ClassInjector injector, boolean all, boolean recurse, TemplateErrorListener errorListener, StatusListener listener)
           
protected  TemplateSourceImpl.Results actuallyCompileTemplates(ClassInjector injector, boolean all, StatusListener listener)
           
protected  TemplateSourceImpl.Results actuallyCompileTemplates(ClassInjector injector, StatusListener listener, String[] selectedTemplates)
           
protected  TemplateSourceImpl.Results actuallyCompileTemplates(ClassInjector injector, String[] selectedTemplates)
           
 TemplateCompilationResults checkTemplates(ClassInjector injector, boolean all, String[] selectedTemplates)
           
static String[] chopString(String target, String delimiters)
           
 TemplateCompilationResults compileTemplates(ClassInjector injector, boolean all)
          Compile templates recursively
 TemplateCompilationResults compileTemplates(ClassInjector injector, boolean all, boolean recurse)
          Compile templates
 TemplateCompilationResults compileTemplates(ClassInjector injector, boolean all, boolean recurse, StatusListener listener)
          Compile templates
 TemplateCompilationResults compileTemplates(ClassInjector injector, boolean all, StatusListener listener)
          Compile templates recursively using the specified status listener.
 TemplateCompilationResults compileTemplates(ClassInjector injector, StatusListener listener, String[] selectedTemplates)
          Compile selected templates
 TemplateCompilationResults compileTemplates(ClassInjector injector, String[] selectedTemplates)
          Compile selected templates
protected  ClassInjector createClassInjector()
          provides a default class injector using the contextType's ClassLoader as a parent.
protected  TemplateErrorListener createErrorListener()
           
static File createTemplateClassesDir(File tmpDir, String dirPath, Log log)
          converts a path to a File for storing compiled template classes.
 ContextSource getContextSource()
           
 String[] getImports()
           
 int getKnownTemplateCount()
          Returns number of all templates that are compiled (failed or succeed)
 String[] getKnownTemplateNames()
          Returns names of all templates that are compiled (failed or succeed)
protected  Set<String> getKnownTemplateNameSet()
          provides subclasses with access to modify the KnownTemplateNames
 Template[] getLoadedTemplates()
          Returns the list of loaded templates
 Template getTemplate(String name)
          Returns the template object of the given template name
 TemplateLoader getTemplateLoader()
           
protected  File[] getTemplateRootDirs()
           
 Date getTimeOfLastReload()
          Returns the time the templates are last reloaded
 void init(TemplateSourceConfig config)
           
 boolean isExceptionGuardianEnabled()
           
 boolean isLogCompileStatus()
           
 Map<String,Boolean> listTouchedTemplates()
          Returns a Map of templates that need reloading - the entry key is the String name of the template - the entry value is a Boolean indicating if the template signature has changed.
protected  void setDestinationDirectory(File compiledDir)
          allows a subclass to set directory to write the compiled templates this directory may be overridden if the ClassInjector passed into the compileTemplates() method points to a different location.
 void setImports(String[] imports)
           
 void setLogCompileStatus(boolean logCompileStatus)
           
protected  void setTemplateResources(String[] resourcePaths)
          allows a subclass to set the resource paths directly rather than using init to parse the config.
protected  void setTemplateRootDirs(File[] rootDirs)
          allows a subclass to directly specify the directories to be searched for template sources.
protected  void setTemplateStrings(String[] sourceData)
          allows a subclass to set the source strings directly rather than using init to parse the config.
protected  boolean sourceSignatureChanged(String tName, Compiler compiler)
          parses the tea source file and compares the signature to the signature of the current class file in the TemplateRepository
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mConfig

protected TemplateSourceConfig mConfig

mLog

protected Log mLog

mProperties

protected PropertyMap mProperties

mCompiledDir

protected File mCompiledDir

mResults

protected TemplateSourceImpl.Results mResults

mTemplateSourceFileInfo

protected Map<String,TemplateSourceImpl.TemplateSourceFileInfo> mTemplateSourceFileInfo

mLogCompileStatus

protected boolean mLogCompileStatus
Constructor Detail

TemplateSourceImpl

public TemplateSourceImpl()
Method Detail

createTemplateClassesDir

public static File createTemplateClassesDir(File tmpDir,
                                            String dirPath,
                                            Log log)
converts a path to a File for storing compiled template classes.

Returns:
the directory or null if the directory is not there or if it cannot be written to.

chopString

public static String[] chopString(String target,
                                  String delimiters)

init

public void init(TemplateSourceConfig config)
Specified by:
init in interface TemplateSource

getImports

public String[] getImports()

setImports

public void setImports(String[] imports)

compileTemplates

public TemplateCompilationResults compileTemplates(ClassInjector injector,
                                                   boolean all)
                                            throws Exception
Description copied from interface: TemplateSource
Compile templates recursively

Specified by:
compileTemplates in interface TemplateSource
Parameters:
injector - Class injector used for template compilation and template loading
all - When true, compile all source, even if up-to-date
Throws:
Exception

compileTemplates

public TemplateCompilationResults compileTemplates(ClassInjector injector,
                                                   boolean all,
                                                   StatusListener listener)
                                            throws Exception
Description copied from interface: TemplateSource
Compile templates recursively using the specified status listener.

Specified by:
compileTemplates in interface TemplateSource
Parameters:
injector - Class injector used for template compilation and template loading
all - When true, compile all source, even if up-to-date
listener - The status listener to callback
Throws:
Exception

compileTemplates

public TemplateCompilationResults compileTemplates(ClassInjector injector,
                                                   boolean all,
                                                   boolean recurse)
                                            throws Exception
Description copied from interface: TemplateSource
Compile templates

Specified by:
compileTemplates in interface TemplateSource
Parameters:
injector - Class injector used for template compilation and template loading
all - When true, compile all source, even if up-to-date
recurse - When true, recurse and compile through all subdirectories
Throws:
Exception

compileTemplates

public TemplateCompilationResults compileTemplates(ClassInjector injector,
                                                   boolean all,
                                                   boolean recurse,
                                                   StatusListener listener)
                                            throws Exception
Description copied from interface: TemplateSource
Compile templates

Specified by:
compileTemplates in interface TemplateSource
Parameters:
injector - Class injector used for template compilation and template loading
all - When true, compile all source, even if up-to-date
recurse - When true, recurse and compile through all subdirectories
listener - The status listener to callback
Throws:
Exception

compileTemplates

public TemplateCompilationResults compileTemplates(ClassInjector injector,
                                                   String[] selectedTemplates)
                                            throws Exception
Description copied from interface: TemplateSource
Compile selected templates

Specified by:
compileTemplates in interface TemplateSource
Parameters:
injector - Class injector used for template compilation and template loading
selectedTemplates - an array of template names to compile
Throws:
Exception

compileTemplates

public TemplateCompilationResults compileTemplates(ClassInjector injector,
                                                   StatusListener listener,
                                                   String[] selectedTemplates)
                                            throws Exception
Description copied from interface: TemplateSource
Compile selected templates

Specified by:
compileTemplates in interface TemplateSource
Parameters:
injector - Class injector used for template compilation and template loading
listener - The status listener to callback
selectedTemplates - an array of template names to compile
Throws:
Exception

checkTemplates

public TemplateCompilationResults checkTemplates(ClassInjector injector,
                                                 boolean all,
                                                 String[] selectedTemplates)
                                          throws Exception
Throws:
Exception

getContextSource

public ContextSource getContextSource()
Specified by:
getContextSource in interface TemplateSource
Returns:
the context source used internally for template compilation.

getKnownTemplateCount

public int getKnownTemplateCount()
Description copied from interface: TemplateSource
Returns number of all templates that are compiled (failed or succeed)

Specified by:
getKnownTemplateCount in interface TemplateSource

getKnownTemplateNames

public String[] getKnownTemplateNames()
Description copied from interface: TemplateSource
Returns names of all templates that are compiled (failed or succeed)

Specified by:
getKnownTemplateNames in interface TemplateSource

getTimeOfLastReload

public Date getTimeOfLastReload()
Description copied from interface: TemplateSource
Returns the time the templates are last reloaded

Specified by:
getTimeOfLastReload in interface TemplateSource

isExceptionGuardianEnabled

public boolean isExceptionGuardianEnabled()
Specified by:
isExceptionGuardianEnabled in interface TemplateSource

getTemplateLoader

public TemplateLoader getTemplateLoader()
Specified by:
getTemplateLoader in interface TemplateSource

getLoadedTemplates

public Template[] getLoadedTemplates()
Description copied from interface: TemplateSource
Returns the list of loaded templates

Specified by:
getLoadedTemplates in interface TemplateSource

getTemplate

public Template getTemplate(String name)
                     throws ClassNotFoundException,
                            NoSuchMethodException
Description copied from interface: TemplateSource
Returns the template object of the given template name

Specified by:
getTemplate in interface TemplateSource
Throws:
ClassNotFoundException
NoSuchMethodException

actuallyCompileTemplates

protected TemplateSourceImpl.Results actuallyCompileTemplates(ClassInjector injector,
                                                              boolean all)
                                                       throws Exception
Throws:
Exception

actuallyCompileTemplates

protected TemplateSourceImpl.Results actuallyCompileTemplates(ClassInjector injector,
                                                              boolean all,
                                                              StatusListener listener)
                                                       throws Exception
Throws:
Exception

actuallyCompileTemplates

protected TemplateSourceImpl.Results actuallyCompileTemplates(ClassInjector injector,
                                                              boolean all,
                                                              boolean recurse)
                                                       throws Exception
Throws:
Exception

actuallyCompileTemplates

protected TemplateSourceImpl.Results actuallyCompileTemplates(ClassInjector injector,
                                                              boolean all,
                                                              boolean recurse,
                                                              StatusListener listener)
                                                       throws Exception
Throws:
Exception

actuallyCompileTemplates

protected TemplateSourceImpl.Results actuallyCompileTemplates(ClassInjector injector,
                                                              boolean all,
                                                              boolean recurse,
                                                              TemplateErrorListener errorListener,
                                                              StatusListener listener)
                                                       throws Exception
Throws:
Exception

actuallyCompileTemplates

protected TemplateSourceImpl.Results actuallyCompileTemplates(ClassInjector injector,
                                                              String[] selectedTemplates)
                                                       throws Exception
Throws:
Exception

actuallyCompileTemplates

protected TemplateSourceImpl.Results actuallyCompileTemplates(ClassInjector injector,
                                                              StatusListener listener,
                                                              String[] selectedTemplates)
                                                       throws Exception
Throws:
Exception

getKnownTemplateNameSet

protected Set<String> getKnownTemplateNameSet()
provides subclasses with access to modify the KnownTemplateNames


setTemplateStrings

protected void setTemplateStrings(String[] sourceData)
allows a subclass to set the source strings directly rather than using init to parse the config.


setTemplateResources

protected void setTemplateResources(String[] resourcePaths)
allows a subclass to set the resource paths directly rather than using init to parse the config.


setTemplateRootDirs

protected void setTemplateRootDirs(File[] rootDirs)
allows a subclass to directly specify the directories to be searched for template sources.


getTemplateRootDirs

protected File[] getTemplateRootDirs()

setDestinationDirectory

protected void setDestinationDirectory(File compiledDir)
allows a subclass to set directory to write the compiled templates this directory may be overridden if the ClassInjector passed into the compileTemplates() method points to a different location.


createClassInjector

protected ClassInjector createClassInjector()
                                     throws Exception
provides a default class injector using the contextType's ClassLoader as a parent.

Throws:
Exception

createErrorListener

protected TemplateErrorListener createErrorListener()

listTouchedTemplates

public Map<String,Boolean> listTouchedTemplates()
                                         throws Exception
Description copied from interface: TemplateSource
Returns a Map of templates that need reloading - the entry key is the String name of the template - the entry value is a Boolean indicating if the template signature has changed. TRUE indicates the signature has changed. FALSE indicates the signature has not changed.

Specified by:
listTouchedTemplates in interface TemplateSource
Throws:
Exception

sourceSignatureChanged

protected boolean sourceSignatureChanged(String tName,
                                         Compiler compiler)
                                  throws IOException
parses the tea source file and compares the signature to the signature of the current class file in the TemplateRepository

Returns:
true if tea source signature is different than the class file signature or class file does not exist
Throws:
IOException

isLogCompileStatus

public boolean isLogCompileStatus()

setLogCompileStatus

public void setLogCompileStatus(boolean logCompileStatus)


Copyright © 1997-2012 TeaTrove.org. All Rights Reserved.