fmpp
Class TemplateEnvironment

java.lang.Object
  extended by fmpp.TemplateEnvironment

public class TemplateEnvironment
extends java.lang.Object

The runtime FMPP environment of an executing template.


Method Summary
 void beginNestedOutputFile(java.lang.String name)
          It does the same as the begin tag of the corresponding directive of the pp hash.
 void beginNestedOutputFile(java.lang.String name, boolean append)
          It does the same as the begin tag of the corresponding directive of the pp hash.
 void changeOutputFile(java.lang.String name)
          It does the same as the directive in the pp hash.
 void changeOutputFile(java.lang.String name, boolean append)
          It does the same as the directive in the pp hash.
 void dropOutputFile()
          It does the same as the directive in the pp hash.
 void endNestedOutputFile()
          It does the same as the end tag of the corresponding directive of the pp hash.
static TemplateEnvironment getCurrentInstance()
          Returns the TemplateEnvironment object used for the template currently being executed by FMPP in the current thread.
 java.lang.Object getData(java.lang.String name)
          Similar to Engine.getData(java.lang.String), but it also sees file processing specifict variables (local data).
 Engine getEngine()
          Returns the FMPP engine object in use.
 freemarker.core.Environment getFreemarkerEnvironment()
          Returns the FreeMarker environment currently in use.
 java.lang.String getHomePath()
          Returns URL-style path of the output root relative to the current output file.
 java.lang.String getOutputEncoding()
          Returns the output encoding.
 java.io.File getOutputFile()
          Returns the output file.
 java.lang.String getPathTo(java.lang.String dst)
          Calulates the path of another output file relatively to current output file, in UN*X format.
 java.io.File getSourceFile()
          Returns the source file.
 java.lang.String getSourcePathTo(java.lang.String dst)
          Same as getPathTo(java.lang.String) but with the source file and source root directory.
 freemarker.template.Template getTemplate()
          Retuns the FreeMarker Template object for the source file.
 freemarker.template.TemplateNodeModel getWrappedXmlDocument()
          The same as getXmlDocument(), but returns the document as freemarker.ext.dom.NodeModel.
 java.lang.Object getXmlDocument()
          Returns the processed XML document (pp.doc) as org.w3c.dom.Document.
 void renameOutputFile(java.lang.String name)
          It does the same as the directive in the pp hash.
 java.io.File resolveOutputPath(java.lang.String path)
          Resolves a output path to a File object.
 java.io.File resolveSourcePath(java.lang.String path)
          Resolves a source path to a File object.
 void restartOutputFile()
          It does the same as the directive in the pp hash.
 void setOutputEncoding(java.lang.String encoding)
          It does the same as the directive in the pp hash.
 java.lang.String toOutputRelatitvePath(java.lang.String path)
          Same as toSourceRootRelativePath(String) but with the output file and output root directory.
 java.lang.String toOutputRootRelativePath(java.io.File f)
          Convets a file object to an output root relative UN*X style path.
 java.lang.String toSourceRootRelativePath(java.io.File f)
          Convets a file object to a source root relative UN*X style path.
 java.lang.String toSourceRootRelativePath(java.lang.String path)
          Returns the path relative to the source root.
 void warning(java.lang.String message)
          It does the same as the directive in the pp hash.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getCurrentInstance

public static TemplateEnvironment getCurrentInstance()
Returns the TemplateEnvironment object used for the template currently being executed by FMPP in the current thread. The return value of the method is undefined if no such template execution is in progress. In practice it means that it can be safely called from a Java method that is (indirectly) invoked by the executing template. For example, in a TemplateTransformModel that is used in the template with <@...>.


getFreemarkerEnvironment

public freemarker.core.Environment getFreemarkerEnvironment()
Returns the FreeMarker environment currently in use. The FreeMarker environment can be used to set/get variables, among others.

Throws:
java.lang.IllegalStateException - if the FreeMarker environment is not available.

getEngine

public Engine getEngine()
Returns the FMPP engine object in use.


getXmlDocument

public java.lang.Object getXmlDocument()
Returns the processed XML document (pp.doc) as org.w3c.dom.Document. This will return non-null if, and only if the current processing mode is "renderXml".

See Also:
getWrappedXmlDocument()

getWrappedXmlDocument

public freemarker.template.TemplateNodeModel getWrappedXmlDocument()
The same as getXmlDocument(), but returns the document as freemarker.ext.dom.NodeModel.


getData

public java.lang.Object getData(java.lang.String name)
Similar to Engine.getData(java.lang.String), but it also sees file processing specifict variables (local data).

Parameters:
name - the name of the variable.
Returns:
the value of the variable, or null if no variable with the given name exists.

getSourceFile

public java.io.File getSourceFile()
Returns the source file.


getTemplate

public freemarker.template.Template getTemplate()
Retuns the FreeMarker Template object for the source file.


getOutputFile

public java.io.File getOutputFile()
                           throws java.io.IOException
Returns the output file. Note that this value can change during the execution of template.

Throws:
java.io.IOException

getHomePath

public java.lang.String getHomePath()
                             throws java.io.IOException
Returns URL-style path of the output root relative to the current output file.

Throws:
java.io.IOException

getOutputEncoding

public java.lang.String getOutputEncoding()
                                   throws java.io.IOException
Returns the output encoding. Note that this value can change during the execution of template.

Throws:
java.io.IOException

changeOutputFile

public void changeOutputFile(java.lang.String name)
                      throws java.io.IOException
It does the same as the directive in the pp hash.

Throws:
java.io.IOException

changeOutputFile

public void changeOutputFile(java.lang.String name,
                             boolean append)
                      throws java.io.IOException
It does the same as the directive in the pp hash.

Throws:
java.io.IOException

renameOutputFile

public void renameOutputFile(java.lang.String name)
                      throws java.io.IOException
It does the same as the directive in the pp hash.

Throws:
java.io.IOException

dropOutputFile

public void dropOutputFile()
                    throws java.io.IOException
It does the same as the directive in the pp hash.

Throws:
java.io.IOException

restartOutputFile

public void restartOutputFile()
                       throws java.io.IOException
It does the same as the directive in the pp hash.

Throws:
java.io.IOException

beginNestedOutputFile

public void beginNestedOutputFile(java.lang.String name)
                           throws java.io.IOException
It does the same as the begin tag of the corresponding directive of the pp hash.

Throws:
java.io.IOException

beginNestedOutputFile

public void beginNestedOutputFile(java.lang.String name,
                                  boolean append)
                           throws java.io.IOException
It does the same as the begin tag of the corresponding directive of the pp hash.

Throws:
java.io.IOException

endNestedOutputFile

public void endNestedOutputFile()
                         throws java.io.IOException
It does the same as the end tag of the corresponding directive of the pp hash.

Throws:
java.io.IOException

setOutputEncoding

public void setOutputEncoding(java.lang.String encoding)
                       throws java.io.IOException
It does the same as the directive in the pp hash.

Throws:
java.io.IOException

warning

public void warning(java.lang.String message)
It does the same as the directive in the pp hash.


resolveSourcePath

public java.io.File resolveSourcePath(java.lang.String path)
                               throws java.io.IOException
Resolves a source path to a File object. Use this for your custom transforms that wants the path of a source file as parameter. When it tries to find the file, paths as foo.jpg will be interpreted relatively to the current source file, while paths like /img/foo.jpg will be interpreted relatively to source root directory.

Note that an IOException will be thrown if the file is outside the source root directory.

Parameters:
path - the path in UN*X or native format.
Returns:
java.io.File object thar points to the file.
Throws:
java.io.IOException

resolveOutputPath

public java.io.File resolveOutputPath(java.lang.String path)
                               throws java.io.IOException
Resolves a output path to a File object. This follows the same logic as resolveSourcePath(java.lang.String), but it uses the output file and the output root directory as appropriate.

Throws:
java.io.IOException

toSourceRootRelativePath

public java.lang.String toSourceRootRelativePath(java.lang.String path)
                                          throws java.io.IOException
Returns the path relative to the source root.

Parameters:
path - the path in UN*X or native format. The virtual root directory will be the source root, not the real root directory of the host system.
Returns:
the source root relative path in UN*X format. It does not start with slash.
Throws:
java.io.IOException

toSourceRootRelativePath

public java.lang.String toSourceRootRelativePath(java.io.File f)
                                          throws java.io.IOException
Convets a file object to a source root relative UN*X style path.

Throws:
java.io.IOException

toOutputRelatitvePath

public java.lang.String toOutputRelatitvePath(java.lang.String path)
                                       throws java.io.IOException
Same as toSourceRootRelativePath(String) but with the output file and output root directory.

Throws:
java.io.IOException

toOutputRootRelativePath

public java.lang.String toOutputRootRelativePath(java.io.File f)
                                          throws java.io.IOException
Convets a file object to an output root relative UN*X style path.

Throws:
java.io.IOException

getPathTo

public java.lang.String getPathTo(java.lang.String dst)
                           throws java.io.IOException
Calulates the path of another output file relatively to current output file, in UN*X format.

Parameters:
dst - the path of the other output file in UN*X or native format. The (virtual) root directory will be the output root directory, not the real root directory of the host system.
Returns:
the path of dst relatively to the current output file, in UN*X format. It never starts with slash. It ends with slash if and only if dst ends with slash, except if the return value would be a signe slash then, in which case the result will be an empty string instead.
Throws:
java.io.IOException

getSourcePathTo

public java.lang.String getSourcePathTo(java.lang.String dst)
                                 throws java.io.IOException
Same as getPathTo(java.lang.String) but with the source file and source root directory.

Throws:
java.io.IOException