public class Engine
extends java.lang.Object
Settings
object instead of directly using
this class.
fmpp.Engine
vs Settings
:
The design of the Engine
API is driven by the internal
architecture of FMPP. It doesn't consider front-ends, doesn't know
configuration files or similar high-level concepts. Settings
wraps the Engine
object, and implements end-user (front-end) centric
concepts, as the settings and configuration files described in the FMPP
Manual. For a programmer, the API of Engine
is more straightforward
than the API of Settings
object. But Settings
is better
if you want FMPP behave similarly as described in the FMPP Manual from the
viewpoint of end-user, or if you need some of its extra features, like
configuration files.
Engine parameters:
Engine
parameters are very similar to "settings" discussed in the
FMPP Manual. You will usually find trivial one-to-one correspondence between
settings and Engine
parameters, but not always, as Settings
is
a higher level API that adds some new concepts.
The value of Engine
parameters can't be set while a processing session is
executing; attempting that will cause IllegalStateException
.
Thus, for example, you can't change an Engine
parameter from an executing
template. Also, you should not change the objects stored as "data" (i.e. the
variables that are visible for all templates) while the processing session is
executing, even though it's not prevented technically.
Life-cycle: The same Engine
object can be used for multiple
processing sessions. However, the typical usage is that it's used
only for a single processing session. The state of the engine object possibly
changes during sessions because of the engine attributes (see
setAttribute(String, Object)
), and because long-lived objects as local
data builders and progress listeners can maintain state through multiple sessions.
These objects should behave so that the output of a session is not influenced
by earlier sessions.
Modifier and Type | Field and Description |
---|---|
static freemarker.template.Version |
DEFAULT_RECOMMENDED_DEFAULTS
The default value of the
recommendDefaults setting, when null is passed for it to the
Engine constructor. |
static java.lang.String |
PARAMETER_VALUE_HOST
A commonly used reserved parameter value:
"host" . |
static java.lang.String |
PARAMETER_VALUE_OUTPUT
A commonly used reserved parameter value:
"source" . |
static java.lang.String |
PARAMETER_VALUE_SOURCE
A commonly used reserved parameter value:
"source" . |
static int |
PMODE_COPY
Processing mode: Copy the file as-is (binary copy).
|
static int |
PMODE_EXECUTE
Processing mode: Execute the file as template
|
static int |
PMODE_IGNORE
Processing mode: Ignore the file.
|
static int |
PMODE_NONE
Processing mode: N/A
|
static int |
PMODE_RENDER_XML
Processing mode: Render XML with an FTL template.
|
static int |
SKIP_ALL
Used with the "skipUnchanged" engine parameter: skip all unchanged
files
|
static int |
SKIP_NONE
Used with the "skipUnchnaged" engine parameter: never skip files
|
static int |
SKIP_STATIC
Used with the "skipUnchanged" engine parameter: skip unchanged static
files
|
static freemarker.template.Version |
VERSION_0_9_15 |
static freemarker.template.Version |
VERSION_0_9_16 |
static java.lang.String |
XPATH_ENGINE_DEFAULT
Used as the value of the "xmlEngine" engine parameter: Let FreeMarker
choose.
|
static java.lang.String |
XPATH_ENGINE_DONT_SET
Used as the value of the "xmlEngine" engine parameter: keep the current
JVM level setting.
|
static java.lang.String |
XPATH_ENGINE_JAXEN
Used as the value of the "xmlEngine" engine parameter: Force the usage
of Jaxen.
|
static java.lang.String |
XPATH_ENGINE_XALAN
Used as the value of the "xmlEngine" engine parameter: Force the usage
of Xalan.
|
Constructor and Description |
---|
Engine()
Deprecated.
Use
Engine(Version) instead. |
Engine(freemarker.ext.beans.BeansWrapper objectWrapper)
Deprecated.
Use
Engine(Version, Version, BeansWrapper) instead. |
Engine(freemarker.ext.beans.BeansWrapper objectWrapper,
freemarker.template.Version freemarkerIncompatibleImprovements)
Deprecated.
Use
Engine(Version, Version, BeansWrapper) instead. |
Engine(freemarker.template.Version recommendedDefaults)
|
Engine(freemarker.template.Version recommendedDefaults,
freemarker.template.Version freemarkerIncompatibleImprovements,
freemarker.ext.beans.BeansWrapper objectWrapper)
Creates a new FMPP engine instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addData(java.util.Map map)
Adds all entries with
addData(String, Object) . |
void |
addData(java.lang.String name,
boolean value)
Convenience method for adding a
Boolean object. |
void |
addData(java.lang.String name,
byte value)
Convenience method for adding a
Byte object. |
void |
addData(java.lang.String name,
char value)
Convenience method for adding a
Character object. |
void |
addData(java.lang.String name,
double value)
Convenience method for adding a
Double object. |
void |
addData(java.lang.String name,
float value)
Convenience method for adding a
Float object. |
void |
addData(java.lang.String name,
int value)
Convenience method for adding a
Integer object. |
void |
addData(java.lang.String name,
long value)
Convenience method for adding a
Long object. |
void |
addData(java.lang.String name,
java.lang.Object value)
Adds a variable that will be visible for all templates when the
processing session executes.
|
void |
addData(java.lang.String name,
short value)
Convenience method for adding a
Short object. |
void |
addFooterChooser(int layer,
java.lang.String pattern,
java.lang.String footer)
Adds a new entry to the end of path-pattern -> footer mapping list of the
given layer.
|
void |
addFooterChooser(java.lang.String pattern,
java.lang.String footer)
Deprecated.
Use
addFooterChooser(int, String, String) instead. |
void |
addFreemarkerLink(java.lang.String name,
java.io.File fileOrDir)
Adds a FreeMarker link.
|
void |
addHeaderChooser(int layer,
java.lang.String pattern,
java.lang.String footer)
Adds a new entry to the end of path-pattern -> header mapping list of the
given layer.
|
void |
addHeaderChooser(java.lang.String pattern,
java.lang.String header)
Deprecated.
Use
addHeaderChooser(int, String, String) instead. |
void |
addLocalDataBuilder(int layer,
java.lang.String pathPattern,
LocalDataBuilder builder)
Adds a local data builder.
|
void |
addModeChooser(java.lang.String pattern,
int pmode)
Adds a new entry to the end of path-pattern -> processing-mode
mapping list.
|
void |
addOutputFormatChooser(java.lang.String pathPattern,
freemarker.core.OutputFormat outputFormat)
Adds a new entry to the end of path-pattern -> output-format mapping list.
|
void |
addProgressListener(ProgressListener listener)
Adds a progress listener to the list of progress listeners.
|
void |
addRemoveExtension(java.lang.String extension)
Adds an extension to the list of extensions to remove.
|
void |
addRemovePostfix(java.lang.String postfix)
Adds a postfix to the list of file name postfixes to remove.
|
void |
addReplaceExtension(java.lang.String oldExtension,
java.lang.String newExtension)
Adds an old-exension -> new-extension pair to the list of
extension replacements.
|
void |
addTurnChooser(java.lang.String pattern,
int turn)
Adds a new entry to the end of path-pattern -> turn-number mapping list.
|
void |
addXmlRenderingConfiguration(XmlRenderingConfiguration xmlRendering)
Adds as XML rendering configuration.
|
void |
checkXmlSupportAvailability(java.lang.String requiredForThis)
Checks if XML support is available.
|
void |
clearAttribues()
Removes all attributes.
|
void |
clearData()
Removes all data.
|
void |
clearFooterChoosers()
Removes all footer choosers.
|
void |
clearFreemarkerLinks()
Removes all FreeMarker links.
|
void |
clearHeaderChoosers()
Removes all header choosers.
|
void |
clearLocalDataBuilders()
Removes all local data builders.
|
void |
clearModeChoosers()
Removes all processing mode choosers.
|
void |
clearOutputFormatChoosers()
Removes all output format choosers.
|
void |
clearProgressListeners()
Removes all progress listeners from the list of progress listeners that
were added with
addProgressListener(fmpp.ProgressListener) . |
void |
clearRemoveExtensions() |
void |
clearRemovePostfixes() |
void |
clearReplaceExtensions() |
void |
clearSharedVariables()
Deprecated.
Use
clearData() instead. |
void |
clearTurnChoosers()
Removes all turn choosers.
|
void |
clearXmlRenderingConfigurations()
Removes all XML rendering configurations.
|
boolean |
getAlwaysCreateDirectories() |
java.lang.Object |
getAttribute(java.lang.String name)
Reads an engine attribute.
|
static java.lang.String |
getBuildInfo()
Returns FMPP build info.
|
boolean |
getCaseSensitive() |
java.lang.Object |
getData(java.lang.String name)
Gets the value of a variable.
|
java.io.File |
getDataRoot()
Returns the directory used as data root directory.
|
java.lang.String |
getDateFormat() |
java.lang.String |
getDateTimeFormat() |
static freemarker.template.Version |
getDefaultFreemarkerIncompatibleImprovements(freemarker.template.Version fmppRecommendedDefaults)
The default value of the
freemarkerIncompatibleImprovements setting, when null is passed for it
to the Engine constructor. |
boolean |
getDontTraverseDirectories() |
boolean |
getExpertMode() |
freemarker.template.Version |
getFreemarkerIncomplatibleImprovements()
Returns the FreeMarker "incompatible improvements" setting.
|
java.util.List |
getFreemarkerLink(java.lang.String name)
Returns the list of files associated with a FreeMarker link name.
|
static freemarker.template.Version |
getFreeMarkerVersion()
Returns the FreeMarker version used.
|
static java.lang.String |
getFreeMarkerVersionNumber()
Deprecated.
Use
getFreeMarkerVersion() instead. If you have need a String , it has a proper
Version.toString() . |
boolean |
getIgnoreCvsFiles() |
boolean |
getIgnoreSvnFiles() |
boolean |
getIgnoreTemporaryFiles() |
int |
getInterpolationSyntax() |
java.util.Locale |
getLocale()
Returns the actual (non-null) locale in use.
|
boolean |
getMapCommonExtensionsToOutputFormats()
Getter pair of
setMapCommonExtensionsToOutputFormats(boolean) . |
java.lang.String |
getNumberFormat() |
boolean |
getOldTemplateSyntax() |
java.lang.String |
getOutputEncoding()
Retruns the output encoding used; It can be
"source"
(since that can't be resolved to a concrete charset), but never
null or "host" . |
freemarker.core.OutputFormat |
getOutputFormat()
Getter pair of
setOutputFormat(OutputFormat) . |
freemarker.core.OutputFormat |
getOutputFormat(java.lang.String name)
Resolves an FreeMarker "output format" name to an
OutputFormat object. |
java.io.File |
getOutputRoot()
Returns the output root directory.
|
static java.lang.String |
getProgressListenerEventName(int event)
Converts an
ProgressListener.EVENT_... constant to English
text. |
freemarker.template.Version |
getRecommendedDefaults()
See the similarly named constructor parameter of
Engine(Version, Version, BeansWrapper) . |
boolean |
getRemoveFreemarkerExtensions()
Getter pair of
setRemoveFreemarkerExtensions(boolean) . |
int |
getSkipUnchanged() |
java.lang.String |
getSourceEncoding()
Returns the source encoding used for the template files.
|
java.io.File |
getSourceRoot()
Returns the source root directory.
|
boolean |
getStopOnError() |
int |
getTagSyntax() |
TemplateDataModelBuilder |
getTemplateDataModelBuilder() |
TemplateEnvironment |
getTemplateEnvironment()
Returns the
TemplateEnvironment . |
java.lang.String |
getTimeFormat() |
java.util.TimeZone |
getTimeZone() |
java.lang.String |
getUrlEscapingCharset()
Retruns the output encoding used; It can be
"output"
(since that can't be resolved to a concrete charset), but never
null . |
boolean |
getValidateXml() |
static freemarker.template.Version |
getVersion()
Returns the FMPP version number.
|
static java.lang.String |
getVersionNumber()
Deprecated.
Use
getVersion() instead. If you have need a String , it has a proper
Version.toString() . |
java.lang.Object |
getXmlEntiryResolver()
Gets the XML entiry resolver used for reading XML documents.
|
java.lang.String |
getXpathEngine() |
boolean |
isTemplateEnvironmentAvailable()
Tells if
getTemplateEnvironment() will throw exception or not. |
boolean |
isXmlSupportAvailabile()
Quickly tells if XML support is available.
|
void |
process(java.io.File[] sources)
Processes a list of files.
|
void |
process(java.io.File src,
java.io.File out)
Hack to processes a single file.
|
java.lang.Object |
removeAttribute(java.lang.String name)
Removes an attribute.
|
java.lang.Object |
removeData(java.lang.String name)
Removes a variable that would be visible for all templates when the
processing session executes.
|
void |
setAlwaysCreateDirectories(boolean enable)
Sets whether for source directories a corresponding output directory
will be created even if no file output went into it.
|
java.lang.Object |
setAttribute(java.lang.String name,
java.lang.Object value)
Adds/replaces an engine attribute.
|
void |
setBooleanFormat(java.lang.String format)
Sets the boolean format used to convert boolean to strings, as defined
by
Configurable.setBooleanFormat(String) . |
void |
setCaseSensitive(boolean cs)
Sets if the engine differentiates upper- and lower-case letters when it
compares paths or matches path patterns with paths.
|
void |
setDataRoot(java.io.File dataRoot)
Sets the root directory of data files.
|
void |
setDateFormat(java.lang.String format)
Sets the format used to convert date values (year + month + day) to
strings.
|
void |
setDateTimeFormat(java.lang.String format)
Sets the format used to convert date-time values (year + month + day +
hour + minute + second + millisecond) to strings.
|
void |
setDontTraverseDirectories(boolean dontTraverseDirs)
|
void |
setExpertMode(boolean expertMode)
Allows some features that are considered dangerous.
|
void |
setIgnoreCvsFiles(boolean ignoreCvsFiles)
Sets if the CVS files inside the source root directory should be
ignored or not.
|
void |
setIgnoreSvnFiles(boolean ignoreSvnFiles)
Sets if the SVN files inside the source root directory should be
ignored or not.
|
void |
setIgnoreTemporaryFiles(boolean ignoreTemporaryFiles)
Set if well-known temporary files inside the source root directory should
be ignored or not.
|
void |
setInterpolationSyntax(int interpolationSyntax)
Sets the
interpolationSyntax setting of FreeMarker. |
void |
setLocale(java.util.Locale locale)
Sets the locale (country, language).
|
void |
setLocale(java.lang.String locale)
Sets the locale (country, language).
|
void |
setMapCommonExtensionsToOutputFormats(boolean mapCommonExtensionsToOutputFormats)
Sets if some very commonly used file extensions (see below) should be automatically associated with a FreeMarker
OutputFormat , for the purpose of auto-escaping. |
void |
setNumberFormat(java.lang.String format)
Sets the number format used to convert numbers to strings, as defined
by
Configurable.setNumberFormat(String) . |
void |
setOldTemplateSyntax(boolean oldSyntax)
Sets if the
# is required in FTL tags or not. |
void |
setOutputEncoding(java.lang.String outputEncoding)
Sets the encoding used for textural output (template generated files).
|
void |
setOutputFormat(freemarker.core.OutputFormat outputFormat)
Sets the
OutputFormat used in templates when there's no more specific one chosen by path pattern. |
void |
setOutputRoot(java.io.File outputRoot)
Sets the root directory of output files.
|
void |
setRemoveFreemarkerExtensions(boolean removeFreemarkerExtensions)
Sets if the standard FreeMarker file extensions (
ftl , ftlh , ftlx ) should be removed from
the output file name. |
void |
setSkipUnchanged(int skipWhat)
Sets what source file can be skipped if it was not modified after the
last modification time of the output file.
|
void |
setSourceEncoding(java.lang.String encoding)
Sets the encoding (charset) of textual source files.
|
void |
setSourceRoot(java.io.File srcRoot)
Sets the root directory of source files.
|
void |
setSQLDateAndTimeTimeZone(java.lang.String zone)
Same as
setSQLDateAndTimeTimeZone(TimeZone) , but lets FreeMarker parse the value to time zone. |
void |
setSQLDateAndTimeTimeZone(java.util.TimeZone zone)
Sets the time zone used when dealing with
java.sql.Date and
java.sql.Time values. |
void |
setStopOnError(boolean stopOnError) |
void |
setTagSyntax(int tagSyntax)
Sets the
tagSyntax setting of FreeMarker. |
void |
setTemplateDataModelBuilder(java.lang.String className)
Deprecated.
|
void |
setTemplateDataModelBuilder(TemplateDataModelBuilder tdmBuilder)
Deprecated.
|
void |
setTimeFormat(java.lang.String format)
Sets the format used to convert time values (hour + minute + second
+ millisecond) to strings.
|
void |
setTimeZone(java.lang.String zone)
Same as
setTimeZone(TimeZone) , but lets FreeMarker parse the value to time zone. |
void |
setTimeZone(java.util.TimeZone zone)
Sets the time zone used to display date/time/date-time values.
|
void |
setUrlEscapingCharset(java.lang.String urlEscapingCharset)
Sets the charset used for URL escaping.
|
void |
setValidateXml(boolean validateXml)
Sets if XML documents should be validated when they are loaded.
|
void |
setXmlEntityResolver(java.lang.Object xmlEntityResolver)
Sets the XML entiry resolver used for reading XML documents.
|
void |
setXpathEngine(java.lang.String xpathEngine)
Sets if which XPath engine should be used.
|
static void |
validateRecommendedDefaults(freemarker.template.Version recommendedDefaults)
Check if the
recommendedDefaults is in the supported range. |
freemarker.template.TemplateModel |
wrap(java.lang.Object obj)
Wraps any object as
TemplateModel . |
public static final int PMODE_NONE
public static final int PMODE_EXECUTE
public static final int PMODE_COPY
public static final int PMODE_IGNORE
public static final int PMODE_RENDER_XML
public static final int SKIP_NONE
public static final int SKIP_STATIC
public static final int SKIP_ALL
public static final java.lang.String PARAMETER_VALUE_SOURCE
"source"
.public static final java.lang.String PARAMETER_VALUE_OUTPUT
"source"
.public static final java.lang.String PARAMETER_VALUE_HOST
"host"
.public static final java.lang.String XPATH_ENGINE_DONT_SET
public static final java.lang.String XPATH_ENGINE_DEFAULT
public static final java.lang.String XPATH_ENGINE_XALAN
public static final java.lang.String XPATH_ENGINE_JAXEN
public static final freemarker.template.Version VERSION_0_9_15
public static final freemarker.template.Version VERSION_0_9_16
public static final freemarker.template.Version DEFAULT_RECOMMENDED_DEFAULTS
recommendDefaults
setting, when null
is passed for it to the
Engine
constructor. This was exposed as sometimes you need this information earlier than calling the
Engine
constructor.public Engine()
Engine(Version)
instead.Engine((Version) null)
.public Engine(freemarker.template.Version recommendedDefaults)
public Engine(freemarker.ext.beans.BeansWrapper objectWrapper)
Engine(Version, Version, BeansWrapper)
instead.Engine(null, objectWrapper, null)
.public Engine(freemarker.ext.beans.BeansWrapper objectWrapper, freemarker.template.Version freemarkerIncompatibleImprovements)
Engine(Version, Version, BeansWrapper)
instead.public Engine(freemarker.template.Version recommendedDefaults, freemarker.template.Version freemarkerIncompatibleImprovements, freemarker.ext.beans.BeansWrapper objectWrapper)
setProgressListener
) to configure the new
instance.recommendedDefaults
- Instructs the engine to use the setting value defaults recommended as of the specified FMPP version.
When you start a new project, set this to the current FMPP version. In older projects changing this
setting can break things (check what changes below). If null
, then it defaults to the lowest
allowed value, 0.9.15. (That's the lowest allowed because this setting was added in 0.9.16.)
The defaults change as follows:
freemarkerIncompatibleImprovements
to 2.3.28, thus, among many things, templates
with ftlh
and ftlx
file extensions will use HTML
and XML
auto-escaping respectively.mapCommonExtensionsToOutputFormats
to true
, thus, templates with common file extensions like html
,
xml
etc. will have auto-escaping.
removeFreemarkerExtensions
to
true
, thus, the ftl
, ftlh
, and ftlx
file extensions are
automatically removed from the output file name.
objectWrapper
to a DefaultObjectWrapper
, if
freemarkerIncompatibleImprovements
is at least 2.3.21} There are more details,
but see that at the objectWrapper
parameter.
freemarkerIncompatibleImprovements
- Sets the "incompatible improvements" version of FreeMarker. You should set this to the current
FreeMarker version in new projects. See Configuration.Configuration(Version)
for details.
If this is null
and the recommendedDefaults
argument is 0.9.16, then
"incompatible improvements" defaults to 2.3.28. If this is null
and
recommendedDefaults
is 0.9.15 (the lowest possible value) then the default is chosen by
FreeMarker (to 2.3.0 for maximum backward compatibility, at least currently).objectWrapper
- The FreeMarker ObjectWrapper
that this instance will use. Just use null
if you don't
know what's this. When this parameter is null
, FMPP chooses the default, considering
FreeMarker best practices and backward compatibility concerns. So it's somewhat complex, and depends
on both the recommendedDefaults
and the fmIncompImprovements
arguments.
If recommendedDefaults
is at least 0.9.16, and fmIncompImprovements
is either
null
or at least 2.3.22, then FMPP creates a DefaultObjectWrapper
with its
incompatibleImprovements
setting set to FreeMarker incompatibleImprovements
,
its forceLegacyNonListCollections
setting set to false
, its
iterableSupport
setting to true
, and its treatDefaultMethodsAsBeanMembers
setting set to true
.
Otherwise, FMPP creates a BeansWrapper
(not a DefaultObjectWrapper
) with
its simpleMapWrapper
setting set to true
, and also, if the
FreeMarker incompatibleImprovements
will be at least 2.3.21
, it's created using
BeansWrapperBuilder
instead of new BeansWrapper()
, which means that that the resulting
BeansWrapper
will be a shared singleton with read-only settings.public static void validateRecommendedDefaults(freemarker.template.Version recommendedDefaults)
recommendedDefaults
is in the supported range.recommendedDefaults
- The version to validate. If null
, the method returns without doing anything.java.lang.IllegalArgumentException
- If the specified version is out of the valid rangepublic static freemarker.template.Version getDefaultFreemarkerIncompatibleImprovements(freemarker.template.Version fmppRecommendedDefaults)
freemarkerIncompatibleImprovements
setting, when null
is passed for it
to the Engine
constructor. This was exposed as sometimes you need this information earlier than calling
the Engine
constructor.public void process(java.io.File[] sources) throws ProcessingException
The source root and output root directory must be set (non-null) prior to calling this method.
sources
- The list of files to process. All file must be inside
the source root. The files will be processed in the order as they
appear in the list, except that if you use multiple turns, they
are re-sorted based on the associated turns (the original order
of files is kept inside turns).ProcessingException
- if Engine.process
has
thrown any exception. The message of this exception holds nothing
interesting (just a static text). Call its getCause()
method to get the exception that caused the termination. Note that
all (so even non-checked exceptions) thrown be the engine are
catched and wrapped by this exeption.process(File, File)
public void process(java.io.File src, java.io.File out) throws ProcessingException
If the source root and/or output root directory is not set, they will be set for the time of this method call to the parent directories of the source and output files respectively.
src
- the source file (not directory). Can't be null.out
- the output file (not directory). Can't be null.ProcessingException
- if Engine.process
has
thrown any exception. The message of this exception holds nothing
interesting (just a static text). Call its getCause()
method to get the exception that caused the termination. Note that
all (so even non-checked exceptions) thrown be the engine are
catched and wrapped by this exception.process(File[])
public freemarker.template.Version getRecommendedDefaults()
Engine(Version, Version, BeansWrapper)
.public boolean getStopOnError()
public void setStopOnError(boolean stopOnError)
public java.io.File getOutputRoot()
The returned File
is always a canonical
File
.
public void setOutputRoot(java.io.File outputRoot) throws java.io.IOException
java.io.IOException
public java.io.File getSourceRoot()
The returned File
is always a canonical
File
.
public void setSourceRoot(java.io.File srcRoot) throws java.io.IOException
java.io.IOException
public java.io.File getDataRoot()
The returned File
is always a canonical
File
.
public void setDataRoot(java.io.File dataRoot) throws java.io.IOException
"source"
or null
, then the source
directory will be used.java.io.IOException
public void addFreemarkerLink(java.lang.String name, java.io.File fileOrDir) throws java.io.IOException
pp
variables).
A FreeMarker link acts as an alias or hard-link to another file or
directory. This is a hack that allows you to
<#include ...>
or <#import ...>
files
that are outside the source root directory.
The link is visible as a file or directory in the source root
directory with name @
name
. For example, if the link name
is "inc"
, then it can be used as
<#include '/@inc/blah.ftl'>
(assuming the link points
to a directory that contains file blah.ftl
).
In the generic case, a FreeMarker link is associated with a list of
files/directories, not just with a single file/directory. For example,
if inc
is associated with /home/joe/inc1
and
/home/joe/inc2
(in this order), then
<#include '/@inc/blah.ftl'>
will try to read
/home/joe/inc1/blah.ftl
, and if that file is missing,
then /home/joe/inc2/blah.ftl
. You can associate the name with
multiple files/directories by calling this method with the same name for
multiple times. The earlier you have added a file/directory, the higher
its priority is.
name
- the name of fake entry in the source root directory, minus
the @
prefix. To prevent confusion, the name can't start
with @.fileOrDir
- the file or directory the link will point to. It can be
a outside the source root directory.java.io.IOException
public java.util.List getFreemarkerLink(java.lang.String name)
name
- the name of the link (do not use the @
prefix)File
-s associated with this link, or
null
, if no FreeMarker link with the given name exist.public void clearFreemarkerLinks()
addFreemarkerLink(String, File)
public void addProgressListener(ProgressListener listener)
If you want a local data loader or engine attribute to listen engine events, do not add it with this method. It will be automatically notified about events, they need not be added here.
Note that if you try to add the same object for multiple times, the object will added only in the first occasion.
public void clearProgressListeners()
addProgressListener(fmpp.ProgressListener)
. It does not affect
other listening objects, as local data loaders or engine attributes.public void setTemplateDataModelBuilder(TemplateDataModelBuilder tdmBuilder)
addLocalDataBuilder(int, String, LocalDataBuilder)
insteadTemplateDataModelBuilder
public void setTemplateDataModelBuilder(java.lang.String className) throws DataModelBuildingException
addLocalDataBuilder(int, String, LocalDataBuilder)
insteadpublic TemplateDataModelBuilder getTemplateDataModelBuilder()
public void setSourceEncoding(java.lang.String encoding)
<#ftl encoding="...">
.
Initially the encoding is ISO-8859-1.
encoding
- The encoding, or "host"
if the default
encoding (file.encoding
system property) of the host
machine should be used. null
is the same as
"host"
.public java.lang.String getSourceEncoding()
null
or "host"
; this is always
a concrete encoding, such as "UTF-8"
.public void setLocale(java.util.Locale locale)
Initially the locale is en_US
.
locale
- The locale, or null if the default locale of the host
machine should be used.public void setLocale(java.lang.String locale)
Initially the locale is en_US
.
locale
- The locale, or "host" if the default locale of the host
machine should be used. Null is the same as "host".public java.util.Locale getLocale()
public void setOldTemplateSyntax(boolean oldSyntax)
#
is required in FTL tags or not.
In the old template syntax #
was not required.
The default and recommended value for this engine parameter is
false
.public boolean getOldTemplateSyntax()
setOldTemplateSyntax(boolean)
public void setTagSyntax(int tagSyntax)
tagSyntax
setting of FreeMarker.
The recommended value for new projects is
Configuration.AUTO_DETECT_TAG_SYNTAX
, the defalt with
FreeMarker 2.3.x is Configuration.ANGLE_BRACKET_TAG_SYNTAX
.public int getTagSyntax()
setTagSyntax(int)
public void setInterpolationSyntax(int interpolationSyntax)
interpolationSyntax
setting of FreeMarker.
Possible values: Configuration.LEGACY_INTERPOLATION_SYNTAX
(default),
Configuration.DOLLAR_INTERPOLATION_SYNTAX
,
Configuration.SQUARE_BRACKET_INTERPOLATION_SYNTAX
.public int getInterpolationSyntax()
setInterpolationSyntax(int)
public void setOutputEncoding(java.lang.String outputEncoding)
"source"
.outputEncoding
- The name of encoding. If it is
"source"
, then the encoding of the source (template
file) will be used for the output. null
is the same as
"source"
. If it is "host"
then the
default encoding of the host machine will be used.public java.lang.String getOutputEncoding()
"source"
(since that can't be resolved to a concrete charset), but never
null
or "host"
.public void setUrlEscapingCharset(java.lang.String urlEscapingCharset)
"output"
.urlEscapingCharset
- The name of charset (encoding) that is used
for URL escaping. If it is "output"
, then the encoding
of the output will be used. null
is the same as
"output"
. If it is "host"
then the
default encoding of the host machine will be used.public java.lang.String getUrlEscapingCharset()
"output"
(since that can't be resolved to a concrete charset), but never
null
.public void setNumberFormat(java.lang.String format)
Configurable.setNumberFormat(String)
.
At least on FreeMarker 2.3.21, this is a pattern as DecimalFormat
defines it,
or the reserved values "number"
or "currency"
.public void setBooleanFormat(java.lang.String format)
Configurable.setBooleanFormat(String)
. Note that it can't be "true,false"
; for that you have
to print the boolean value with ${foo?c}
.public java.lang.String getNumberFormat()
setNumberFormat(java.lang.String)
public void setDateFormat(java.lang.String format)
Configurable.setDateFormat(String)
in the FreeMarker API
for more information.
The default is the format suggested by the underlying Java platform implementation for the current locale.
public java.lang.String getDateFormat()
setDateFormat(java.lang.String)
public void setTimeFormat(java.lang.String format)
Configurable.setTimeFormat(String)
in the FreeMarker API
for more information.
The default is the format suggested by the underlying Java platform implementation for the current locale.
public java.lang.String getTimeFormat()
setTimeFormat(java.lang.String)
public void setDateTimeFormat(java.lang.String format)
Configurable.setDateTimeFormat(String)
in the FreeMarker API
for more information.
The default is the format suggested by the underlying Java platform implementation for the current locale.
public java.lang.String getDateTimeFormat()
setDateTimeFormat(java.lang.String)
public void setTimeZone(java.util.TimeZone zone)
Configuration.setTimeZone(TimeZone)
for more information.public void setTimeZone(java.lang.String zone)
setTimeZone(TimeZone)
, but lets FreeMarker parse the value to time zone. If the value comes
from a string source anyway, it's recommended to use this instead of the other overload.public void setSQLDateAndTimeTimeZone(java.util.TimeZone zone)
java.sql.Date
and
java.sql.Time
values.
See FreeMarker's Configurable.setSQLDateAndTimeTimeZone(TimeZone)
for more information.public void setSQLDateAndTimeTimeZone(java.lang.String zone)
setSQLDateAndTimeTimeZone(TimeZone)
, but lets FreeMarker parse the value to time zone. If
the value comes from a string source anyway, it's recommended to use this instead of the other overload.public java.util.TimeZone getTimeZone()
setTimeZone(java.util.TimeZone)
public void setMapCommonExtensionsToOutputFormats(boolean mapCommonExtensionsToOutputFormats)
OutputFormat
, for the purpose of auto-escaping. This defaults to true
if
getRecommendedDefaults()
is at least 0.9.16, otherwise it defaults to false
.
The list of common file extensions are (case-insensitive):
html
, htm
xhtml
, xhtm
, xht
xml
, xsd
, xsl
, xslt
, svg
, wsdl
,
dita
, ditamap
rtf
Furthermore, the .ftl
ending (case-insensitive) is ignored when this setting is applied, so
example.rtf.ftl
will be mapped to RTF output format.
public boolean getMapCommonExtensionsToOutputFormats()
setMapCommonExtensionsToOutputFormats(boolean)
.public void setOutputFormat(freemarker.core.OutputFormat outputFormat)
OutputFormat
used in templates when there's no more specific one chosen by path pattern.outputFormat
- Not null
; use UndefinedOutputFormat.INSTANCE
instead.public freemarker.core.OutputFormat getOutputFormat()
setOutputFormat(OutputFormat)
.null
.public void addOutputFormatChooser(java.lang.String pathPattern, freemarker.core.OutputFormat outputFormat)
outputFormatsByPath
setting in the Settings
API.public freemarker.core.OutputFormat getOutputFormat(java.lang.String name) throws freemarker.core.UnregisteredOutputFormatException
OutputFormat
object.freemarker.core.UnregisteredOutputFormatException
Configuration.getOutputFormat(String)
public void addModeChooser(java.lang.String pattern, int pmode)
pattern
- a path pattern as "*.txt" or
"/docs/**/item_??.xml".
You have to use slash (/) or backslash (\) or the platform specific
separator to spearate directories.pmode
- the mode in which you want to process the files. Use the
PMODE_...
constants.public void addHeaderChooser(java.lang.String pattern, java.lang.String header)
addHeaderChooser(int, String, String)
instead.public void addHeaderChooser(int layer, java.lang.String pattern, java.lang.String footer)
public void addFooterChooser(java.lang.String pattern, java.lang.String footer)
addFooterChooser(int, String, String)
instead.public void addFooterChooser(int layer, java.lang.String pattern, java.lang.String footer)
public void addTurnChooser(java.lang.String pattern, int turn)
public void clearOutputFormatChoosers()
outputFormatsByPath
setting in the Settings
API.public void clearModeChoosers()
Engine
(i.e. no processing mode
choosers).public void clearHeaderChoosers()
public void clearFooterChoosers()
public void clearTurnChoosers()
public void setCaseSensitive(boolean cs)
public boolean getCaseSensitive()
setCaseSensitive(boolean)
public void setExpertMode(boolean expertMode)
public boolean getExpertMode()
setExpertMode(boolean)
public void addRemovePostfix(java.lang.String postfix)
postfix
- the postfix to remove. Can't be null or empty
string, and can't contain dot.public void addRemoveExtension(java.lang.String extension)
extension
- the extension to remove without the dot. Can't be
null or empty string, and can't start with dot.public void addReplaceExtension(java.lang.String oldExtension, java.lang.String newExtension)
oldExtension
- the old extension without the preceding dot.newExtension
- the new extension without the preceding dot.public void clearRemovePostfixes()
public void clearRemoveExtensions()
public void clearReplaceExtensions()
public void setRemoveFreemarkerExtensions(boolean removeFreemarkerExtensions)
ftl
, ftlh
, ftlx
) should be removed from
the output file name. Defaults to true
if getRecommendedDefaults()
is at least 0.9.16.public boolean getRemoveFreemarkerExtensions()
setRemoveFreemarkerExtensions(boolean)
.public void setDontTraverseDirectories(boolean dontTraverseDirs)
Engine
should automatically process the files and
directories inside a directory whose processing was asked through the
public Engine
API. Defaults to true
. It is set to
false
by front-ends that explicitly specify the list of
source files and source directories, rather than expecting the
Engine
to discover them.public boolean getDontTraverseDirectories()
public void setSkipUnchanged(int skipWhat)
The initial value of this engine parameter is SKIP_NONE
.
skipWhat
- a SKIP_...
contant.public int getSkipUnchanged()
public void setAlwaysCreateDirectories(boolean enable)
false
.
Notes:
true
, if
a directory contains an ignoredir.fmpp
file, it will not
create output directory.
createdir.fmpp
,
the directory will be created even if this setting is
false
.
public boolean getAlwaysCreateDirectories()
public void setIgnoreCvsFiles(boolean ignoreCvsFiles)
The CVS files are: **
/.cvsignore
,
**
/CVS/**
and **
/.#*
public boolean getIgnoreCvsFiles()
public void setIgnoreSvnFiles(boolean ignoreSvnFiles)
The SVN files are: **
/SVN/**
public boolean getIgnoreSvnFiles()
public void setIgnoreTemporaryFiles(boolean ignoreTemporaryFiles)
public boolean getIgnoreTemporaryFiles()
public void setXpathEngine(java.lang.String xpathEngine)
xpathEngine
- one of the XPATH_ENGINE_...
constants,
or a class name.public java.lang.String getXpathEngine()
public void setXmlEntityResolver(java.lang.Object xmlEntityResolver) throws InstallationException
null
.xmlEntityResolver
- it must implement
org.xml.sax.EntityResolver
(it was declared as
Object
to prevent linkage errors when XML related
features are not used on pre-1.4 Java), or it must be null
.InstallationException
public java.lang.Object getXmlEntiryResolver()
null
of no resolver is used, or an
org.xml.sax.EntityResolver
(it was declared as
Object
to prevent linkage errors when XML related
features are not used on pre-1.4 Java).public void setValidateXml(boolean validateXml)
true
.public boolean getValidateXml()
public void addXmlRenderingConfiguration(XmlRenderingConfiguration xmlRendering)
public void clearXmlRenderingConfigurations()
public void addData(java.lang.String name, java.lang.Object value)
public void addData(java.lang.String name, byte value)
Byte
object.addData(String, Object)
public void addData(java.lang.String name, short value)
Short
object.addData(String, Object)
public void addData(java.lang.String name, int value)
Integer
object.addData(String, Object)
public void addData(java.lang.String name, long value)
Long
object.addData(String, Object)
public void addData(java.lang.String name, float value)
Float
object.addData(String, Object)
public void addData(java.lang.String name, double value)
Double
object.addData(String, Object)
public void addData(java.lang.String name, char value)
Character
object.addData(String, Object)
public void addData(java.lang.String name, boolean value)
Boolean
object.addData(String, Object)
public void addData(java.util.Map map)
addData(String, Object)
.
The name of the variable will be the key of the map entry,
and its value will be the value of the map entry.public void clearData()
addData(String, Object)
public java.lang.Object getData(java.lang.String name)
data
.
Warning! When the processing session is executing, you must not modify the returned object.
null
if no such variable exist.
Values are returned exactly as they were added, that is, without
FreeMarker's wrapping (but note that some variables initially use
FreeMarker TemplateModel
types, such as variables created by
some of the data loaders).addData(String, Object)
public java.lang.Object removeData(java.lang.String name)
null
if there was no value
stored for the given name.addData(String, Object)
public void clearSharedVariables()
clearData()
instead.public void addLocalDataBuilder(int layer, java.lang.String pathPattern, LocalDataBuilder builder)
pathPattern
matches the source file path).layer
- the index of the layer, stating from 0. 0 is the layer with
the highest priority.pathPattern
- the path pattern of source files where this local
data builder will be used.builder
- the local data builder object.public void clearLocalDataBuilders()
public static java.lang.String getProgressListenerEventName(int event)
ProgressListener.EVENT_...
constant to English
text.public freemarker.template.TemplateModel wrap(java.lang.Object obj) throws freemarker.template.TemplateModelException
TemplateModel
.freemarker.template.TemplateModelException
public TemplateEnvironment getTemplateEnvironment()
TemplateEnvironment
.
The template environment is available with this method only when a
template execution is in progress, or when a
TemplateDataModelBuilder
(deprecated) is running.java.lang.IllegalStateException
- if the template environment is not
available.public boolean isTemplateEnvironmentAvailable()
getTemplateEnvironment()
will throw exception or not.public java.lang.Object setAttribute(java.lang.String name, java.lang.Object value)
Engine
object. FMPP reserves all keys starting with
fmpp.
for its own use. Attributes are not understood by the
Engine
, but by data loaders, local data builders, and tools that
create them.
Attributes can be changed (replaced, removed, ...etc.) while the processing session is executing.
name
- the name of the attribute. To prevent name
clashes, it should follow the naming convention of Java classes, e.g.
"com.example.someproject.something"
.value
- the value of the attribute. If it implements
ProgressListener
, then it will receive notifications about
the events of the Engine
. If attribute(s) with that value is
(are) removed, then the value object doesn't receive more
notifications.null
if
there was no attribute with the given name.public java.lang.Object getAttribute(java.lang.String name)
null
if no attribute exists with the given name.setAttribute(String, Object)
public java.lang.Object removeAttribute(java.lang.String name)
null
if there
was no attribute with the given name.setAttribute(String, Object)
public void clearAttribues()
setAttribute(String, Object)
public static java.lang.String getVersionNumber()
getVersion()
instead. If you have need a String
, it has a proper
Version.toString()
.major.minor.sub
or
major.minor.sub.nightly
format, where each part (separated by dots) is an non-negative integer number.public static freemarker.template.Version getVersion()
public static java.lang.String getBuildInfo()
public static java.lang.String getFreeMarkerVersionNumber()
getFreeMarkerVersion()
instead. If you have need a String
, it has a proper
Version.toString()
.public static freemarker.template.Version getFreeMarkerVersion()
public freemarker.template.Version getFreemarkerIncomplatibleImprovements()
public boolean isXmlSupportAvailabile()
public void checkXmlSupportAvailability(java.lang.String requiredForThis) throws InstallationException
MiscUtil.checkXmlSupportAvailability(String)
, so rather use this.requiredForThis
- a short sentence that describes for human reader
if for what do we need the XML support (e.g.
"Usage of xml data loader."
or
"Set XML entity resolver."
). This sentence is used
in error message of the InstallationException
.
Can be null
.InstallationException
- if the XML support is not available.