Package fmpp
Class TemplateEnvironment
java.lang.Object
fmpp.TemplateEnvironment
The runtime FMPP environment of an executing template.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
beginNestedOutputFile
(String name) It does the same as the begin tag of the corresponding directive of the pp hash.void
beginNestedOutputFile
(String name, boolean append) It does the same as the begin tag of the corresponding directive of the pp hash.void
changeOutputFile
(String name) It does the same as the directive in the pp hash.void
changeOutputFile
(String name, boolean append) It does the same as the directive in the pp hash.void
It does the same as the directive in the pp hash.void
It does the same as the end tag of the corresponding directive of the pp hash.static TemplateEnvironment
Returns theTemplateEnvironment
object used for the template currently being executed by FMPP in the current thread.Similar toEngine.getData(java.lang.String)
, but it also sees file processing specific variables (local data).Returns the FMPP engine object in use.freemarker.core.Environment
Returns the FreeMarker environment currently in use.Returns URL-style path of the output root relative to the current output file.Returns the output encoding.Returns the output file.Calculates the path of another output file relatively to current output file, in UN*X format.Returns the source file.getSourcePathTo
(String dst) Same asgetPathTo(java.lang.String)
but with the source file and source root directory.freemarker.template.Template
Retuns the FreeMarkerTemplate
object for the source file.freemarker.template.TemplateNodeModel
The same asgetXmlDocument()
, but returns the document asNodeModel
.Returns the processed XML document (pp.doc
) asDocument
.void
renameOutputFile
(String name) It does the same as the directive in the pp hash.resolveOutputPath
(String path) Resolves a output path to a File object.resolveSourcePath
(String path) Resolves a source path to a File object.void
It does the same as the directive in the pp hash.void
setOutputEncoding
(String encoding) It does the same as the directive in the pp hash.toOutputRelatitvePath
(String path) Same astoSourceRootRelativePath(String)
but with the output file and output root directory.Convets a file object to an output root relative UN*X style path.Converts a file object to a source root relative UN*X style path.Returns the path relative to the source root.void
It does the same as the directive in the pp hash.
-
Method Details
-
getCurrentInstance
Returns theTemplateEnvironment
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 aTemplateTransformModel
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:
IllegalStateException
- if the FreeMarker environment is not available.
-
getEngine
Returns the FMPP engine object in use. -
getXmlDocument
Returns the processed XML document (pp.doc
) asDocument
. This will return non-null
if, and only if the current processing mode is "renderXml".- See Also:
-
getWrappedXmlDocument
public freemarker.template.TemplateNodeModel getWrappedXmlDocument()The same asgetXmlDocument()
, but returns the document asNodeModel
. -
getData
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
null
if no variable with the given name exists.
-
getSourceFile
Returns the source file. -
getTemplate
public freemarker.template.Template getTemplate()Retuns the FreeMarkerTemplate
object for the source file. -
getOutputFile
Returns the output file. Note that this value can change during the execution of template.- Throws:
IOException
-
getHomePath
Returns URL-style path of the output root relative to the current output file.- Throws:
IOException
-
getOutputEncoding
Returns the output encoding. Note that this value can change during the execution of template.- Throws:
IOException
-
changeOutputFile
It does the same as the directive in the pp hash.- Throws:
IOException
-
changeOutputFile
It does the same as the directive in the pp hash.- Throws:
IOException
-
renameOutputFile
It does the same as the directive in the pp hash.- Throws:
IOException
-
dropOutputFile
It does the same as the directive in the pp hash.- Throws:
IOException
-
restartOutputFile
It does the same as the directive in the pp hash.- Throws:
IOException
-
beginNestedOutputFile
It does the same as the begin tag of the corresponding directive of the pp hash.- Throws:
IOException
-
beginNestedOutputFile
It does the same as the begin tag of the corresponding directive of the pp hash.- Throws:
IOException
-
endNestedOutputFile
It does the same as the end tag of the corresponding directive of the pp hash.- Throws:
IOException
-
setOutputEncoding
It does the same as the directive in the pp hash.- Throws:
IOException
-
warning
It does the same as the directive in the pp hash. -
resolveSourcePath
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 asfoo.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:
File
object that points to the file.- Throws:
IOException
-
resolveOutputPath
Resolves 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:
IOException
-
toSourceRootRelativePath
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:
IOException
-
toSourceRootRelativePath
Converts a file object to a source root relative UN*X style path.- Throws:
IOException
-
toOutputRelatitvePath
Same astoSourceRootRelativePath(String)
but with the output file and output root directory.- Throws:
IOException
-
toOutputRootRelativePath
Convets a file object to an output root relative UN*X style path.- Throws:
IOException
-
getPathTo
Calculates 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 ifdst
ends 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:
IOException
-
getSourcePathTo
Same asgetPathTo(java.lang.String)
but with the source file and source root directory.- Throws:
IOException
-