Package fmpp
Class TemplateEnvironment
- java.lang.Object
-
- fmpp.TemplateEnvironment
-
public class TemplateEnvironment extends java.lang.ObjectThe runtime FMPP environment of an executing template.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeginNestedOutputFile(java.lang.String name)It does the same as the begin tag of the corresponding directive of the pp hash.voidbeginNestedOutputFile(java.lang.String name, boolean append)It does the same as the begin tag of the corresponding directive of the pp hash.voidchangeOutputFile(java.lang.String name)It does the same as the directive in the pp hash.voidchangeOutputFile(java.lang.String name, boolean append)It does the same as the directive in the pp hash.voiddropOutputFile()It does the same as the directive in the pp hash.voidendNestedOutputFile()It does the same as the end tag of the corresponding directive of the pp hash.static TemplateEnvironmentgetCurrentInstance()Returns theTemplateEnvironmentobject used for the template currently being executed by FMPP in the current thread.java.lang.ObjectgetData(java.lang.String name)Similar toEngine.getData(java.lang.String), but it also sees file processing specific variables (local data).EnginegetEngine()Returns the FMPP engine object in use.freemarker.core.EnvironmentgetFreemarkerEnvironment()Returns the FreeMarker environment currently in use.java.lang.StringgetHomePath()Returns URL-style path of the output root relative to the current output file.java.lang.StringgetOutputEncoding()Returns the output encoding.java.io.FilegetOutputFile()Returns the output file.java.lang.StringgetPathTo(java.lang.String dst)Calculates the path of another output file relatively to current output file, in UN*X format.java.io.FilegetSourceFile()Returns the source file.java.lang.StringgetSourcePathTo(java.lang.String dst)Same asgetPathTo(java.lang.String)but with the source file and source root directory.freemarker.template.TemplategetTemplate()Retuns the FreeMarkerTemplateobject for the source file.freemarker.template.TemplateNodeModelgetWrappedXmlDocument()The same asgetXmlDocument(), but returns the document asNodeModel.java.lang.ObjectgetXmlDocument()Returns the processed XML document (pp.doc) asDocument.voidrenameOutputFile(java.lang.String name)It does the same as the directive in the pp hash.java.io.FileresolveOutputPath(java.lang.String path)Resolves a output path to a File object.java.io.FileresolveSourcePath(java.lang.String path)Resolves a source path to a File object.voidrestartOutputFile()It does the same as the directive in the pp hash.voidsetOutputEncoding(java.lang.String encoding)It does the same as the directive in the pp hash.java.lang.StringtoOutputRelatitvePath(java.lang.String path)Same astoSourceRootRelativePath(String)but with the output file and output root directory.java.lang.StringtoOutputRootRelativePath(java.io.File f)Convets a file object to an output root relative UN*X style path.java.lang.StringtoSourceRootRelativePath(java.io.File f)Converts a file object to a source root relative UN*X style path.java.lang.StringtoSourceRootRelativePath(java.lang.String path)Returns the path relative to the source root.voidwarning(java.lang.String message)It does the same as the directive in the pp hash.
-
-
-
Method Detail
-
getCurrentInstance
public static TemplateEnvironment getCurrentInstance()
Returns theTemplateEnvironmentobject 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 aTemplateTransformModelthat 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) asDocument. This will return non-nullif, and only if the current processing mode is "renderXml".- See Also:
getWrappedXmlDocument()
-
getWrappedXmlDocument
public freemarker.template.TemplateNodeModel getWrappedXmlDocument()
The same asgetXmlDocument(), but returns the document asNodeModel.
-
getData
public java.lang.Object getData(java.lang.String name)
Similar toEngine.getData(java.lang.String), but it also sees file processing specific variables (local data).- Parameters:
name- the name of the variable.- Returns:
- the value of the variable, or
nullif 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 FreeMarkerTemplateobject for the source file.
-
getOutputFile
public java.io.File getOutputFile() throws java.io.IOExceptionReturns 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.IOExceptionReturns 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.IOExceptionReturns 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.IOExceptionIt 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.IOExceptionIt 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.IOExceptionIt does the same as the directive in the pp hash.- Throws:
java.io.IOException
-
dropOutputFile
public void dropOutputFile() throws java.io.IOExceptionIt does the same as the directive in the pp hash.- Throws:
java.io.IOException
-
restartOutputFile
public void restartOutputFile() throws java.io.IOExceptionIt 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.IOExceptionIt 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.IOExceptionIt 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.IOExceptionIt 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.IOExceptionIt 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.IOExceptionResolves 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 asfoo.jpgwill be interpreted relatively to the current source file, while paths like/img/foo.jpgwill 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:
Fileobject that points to the file.- Throws:
java.io.IOException
-
resolveOutputPath
public java.io.File resolveOutputPath(java.lang.String path) throws java.io.IOExceptionResolves a output path to a File object. This follows the same logic asresolveSourcePath(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.IOExceptionReturns 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.IOExceptionConverts 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.IOExceptionSame astoSourceRootRelativePath(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.IOExceptionConvets 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.IOExceptionCalculates 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
dstrelatively to the current output file, in UN*X format. It never starts with slash. It ends with slash if and only ifdstends with slash, except if the return value would be a single 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.IOExceptionSame asgetPathTo(java.lang.String)but with the source file and source root directory.- Throws:
java.io.IOException
-
-