Java Doc for Template.java in  » Template-Engine » freemarker-2.3.10 » freemarker » template » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Template Engine » freemarker 2.3.10 » freemarker.template 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   freemarker.core.Configurable
      freemarker.template.Template

Template
public class Template extends Configurable (Code)

A core FreeMarker API that represents a compiled template. Typically, you will use a Configuration object to instantiate a template.

 Configuration cfg = new Configuration();
 ...
 Template myTemplate = cfg.getTemplate("myTemplate.html");
 

However, you can also construct a template directly by passing in to the appropriate constructor a java.io.Reader instance that is set to read the raw template text. The compiled template is stored in an an efficient data structure for later use.

To render the template, i.e. to merge it with a data model, and thus produce "cooked" output, call the process method.

Any error messages from exceptions thrown during compilation will be included in the output stream and thrown back to the calling code. To change this behavior, you can install custom exception handlers using Configurable.setTemplateExceptionHandler(TemplateExceptionHandler) on a Configuration object (for all templates belonging to a configuration) or on a Template object (for a single template).

It's not legal to modify the values of FreeMarker settings: a) while the template is executing; b) if the template object is already accessible from multiple threads.
version:
   $Id: Template.java,v 1.216.2.3 2006/03/10 17:49:02 revusky Exp $


Inner Class :public static class WrongEncodingException extends ParseException

Field Summary
final public static  StringDEFAULT_NAMESPACE_PREFIX
    
final public static  StringNO_NS_PREFIX
    

Constructor Summary
public  Template(String name, Reader reader, Configuration cfg, String encoding)
     Constructs a template from a character stream.
Parameters:
  name - the path of the template file relative to the directory what you use to storethe templates.
public  Template(String name, Reader reader, Configuration cfg)
    
public  Template(String name, Reader reader)
     Constructs a template from a character stream.
 Template(String name, TemplateElement root, Configuration config)
     This constructor is only used internally.

Method Summary
public  voidaddImport(LibraryLoad ll)
    
public  voidaddMacro(Macro macro)
    
public  voidaddPrefixNSMapping(String prefix, String nsURI)
     This is used internally.
public  TreePathcontainingElements(int column, int line)
    
public  EnvironmentcreateProcessingEnvironment(Object rootMap, Writer out, ObjectWrapper wrapper)
     Creates a freemarker.core.Environment Environment object, using this template, the data model provided as the root map object, and the supplied object wrapper to convert map elements to template models. You can then call Environment.process() on the returned environment to set off the actual rendering. Use this method if you want to do some special initialization on the environment before template processing, or if you want to read the environment after template processing.

Example:

This:

 Environment env = myTemplate.createProcessingEnvironment(root, out, null);
 env.process();
 
is equivalent with this:
 myTemplate.process(root, out);
 
But with createProcessingEnvironment, you can manipulate the environment before and after the processing:
 Environment env = myTemplate.createProcessingEnvironment(root, out);
 env.include("include/common.ftl", null, true);  // before processing
 env.process();
 TemplateModel x = env.getVariable("x");  // after processing
 

Parameters:
  rootMap - the root node of the data model.
public  EnvironmentcreateProcessingEnvironment(Object rootMap, Writer out)
     Same as createProcessingEnvironment(rootMap, out, null).
public  voiddump(PrintStream ps)
     Dump the raw template in canonical form.
public  voiddump(Writer out)
     Dump the raw template in canonical form.
public  ConfigurationgetConfiguration()
     Returns the Configuration object associated with this template.
public  StringgetDefaultNS()
    
public  StringgetEncoding()
     Returns the character encoding used for reading included files.
public  ListgetImports()
    
public  MapgetMacros()
    
public  StringgetName()
     The path of the template file relative to the directory what you use to store the templates. For example, if the real path of template is "/www/templates/community/forum.fm", and you use ""/www/templates" as Configuration.setDirectoryForTemplateLoading "directoryForTemplateLoading" , then name should be "community/forum.fm".
public  StringgetNamespaceForPrefix(String prefix)
     the NamespaceUri mapped to this prefix in this template.
public static  TemplategetPlainTextTemplate(String name, String content, Configuration config)
     Returns a trivial template, one that is just a single block of plain text, no dynamic content.
public  StringgetPrefixForNamespace(String nsURI)
     the prefix mapped to this nsURI in this template.
public  StringgetPrefixedName(String localName, String nsURI)
    
public  TemplateElementgetRootTreeNode()
    
public  StringgetSource(int beginColumn, int beginLine, int endColumn, int endLine)
     Returns the template source at the location specified by the coordinates given.
public  voidprocess(Object rootMap, Writer out)
     Processes the template, using data from the map, and outputs the resulting text to the supplied Writer The elements of the map are converted to template models using the default object wrapper returned by the Configuration.getObjectWrapper getObjectWrapper() method of the Configuration.
Parameters:
  rootMap - the root node of the data model.
public  voidprocess(Object rootMap, Writer out, ObjectWrapper wrapper, TemplateNodeModel rootNode)
     Processes the template, using data from the root map object, and outputs the resulting text to the supplied writer, using the supplied object wrapper to convert map elements to template models.
Parameters:
  rootMap - the root node of the data model.
public  voidprocess(Object rootMap, Writer out, ObjectWrapper wrapper)
     Processes the template, using data from the root map object, and outputs the resulting text to the supplied writer, using the supplied object wrapper to convert map elements to template models.
Parameters:
  rootMap - the root node of the data model.
public  voidsetEncoding(String encoding)
     Sets the character encoding to use for included files.
public  StringtoString()
     Returns a string representing the raw template text in canonical form.

Field Detail
DEFAULT_NAMESPACE_PREFIX
final public static String DEFAULT_NAMESPACE_PREFIX(Code)



NO_NS_PREFIX
final public static String NO_NS_PREFIX(Code)




Constructor Detail
Template
public Template(String name, Reader reader, Configuration cfg, String encoding) throws IOException(Code)
Constructs a template from a character stream.
Parameters:
  name - the path of the template file relative to the directory what you use to storethe templates. See Template.getName for more details.
Parameters:
  reader - the character stream to read from. It will always be closed (Reader.close()).
Parameters:
  cfg - the Configuration object that this Template is associated with.If this is null, the "default" Configuration object is used,which is highly discouraged, because it can easily lead toerroneous, unpredictable behaviour.(See more Configuration.getDefaultConfiguration here...)
Parameters:
  encoding - This is the encoding that we are supposed to be using. If this isnon-null (It's not actually necessary because we are using a Reader) then it ischecked against the encoding specified in the FTL header -- assuming that is specified,and if they don't match a WrongEncodingException is thrown.



Template
public Template(String name, Reader reader, Configuration cfg) throws IOException(Code)
This is equivalent to Template(name, reader, cfg, null)



Template
public Template(String name, Reader reader) throws IOException(Code)
Constructs a template from a character stream. This is the same as the 3 parameter version when you pass null as the cfg parameter. ConfigurationConfiguration.getDefaultConfiguration here...



Template
Template(String name, TemplateElement root, Configuration config)(Code)
This constructor is only used internally.




Method Detail
addImport
public void addImport(LibraryLoad ll)(Code)
Called by code internally to maintain a list of imports



addMacro
public void addMacro(Macro macro)(Code)
Called by code internally to maintain a table of macros



addPrefixNSMapping
public void addPrefixNSMapping(String prefix, String nsURI)(Code)
This is used internally.



containingElements
public TreePath containingElements(int column, int line)(Code)
an array of the elements containing the given column and line numbers.
Parameters:
  column - the column
Parameters:
  line - the line



createProcessingEnvironment
public Environment createProcessingEnvironment(Object rootMap, Writer out, ObjectWrapper wrapper) throws TemplateException, IOException(Code)
Creates a freemarker.core.Environment Environment object, using this template, the data model provided as the root map object, and the supplied object wrapper to convert map elements to template models. You can then call Environment.process() on the returned environment to set off the actual rendering. Use this method if you want to do some special initialization on the environment before template processing, or if you want to read the environment after template processing.

Example:

This:

 Environment env = myTemplate.createProcessingEnvironment(root, out, null);
 env.process();
 
is equivalent with this:
 myTemplate.process(root, out);
 
But with createProcessingEnvironment, you can manipulate the environment before and after the processing:
 Environment env = myTemplate.createProcessingEnvironment(root, out);
 env.include("include/common.ftl", null, true);  // before processing
 env.process();
 TemplateModel x = env.getVariable("x");  // after processing
 

Parameters:
  rootMap - the root node of the data model. If null, anempty data model is used. Can be any object that the effective objectwrapper can turn into a TemplateHashModel Basically, simple andbeans wrapper can turn java.util.Map objects into hashesand the Jython wrapper can turn both a PyDictionary as well as anyobject that implements __getitem__ into a template hash.Naturally, you can pass any object directly implementingTemplateHashModel as well.
Parameters:
  wrapper - The object wrapper to use to wrap objects intoTemplateModel instances. If null, the default wrapper retrievedby Configurable.getObjectWrapper is used.
Parameters:
  out - the writer to output the text to. the freemarker.core.Environment Environment object created for processing
throws:
  TemplateException - if an exception occurs while setting up the Environment object.
throws:
  IOException - if an exception occurs doing any auto-imports



createProcessingEnvironment
public Environment createProcessingEnvironment(Object rootMap, Writer out) throws TemplateException, IOException(Code)
Same as createProcessingEnvironment(rootMap, out, null).
See Also:   Template.createProcessingEnvironment(Object rootMap,Writer out,ObjectWrapper wrapper)



dump
public void dump(PrintStream ps)(Code)
Dump the raw template in canonical form.



dump
public void dump(Writer out) throws IOException(Code)
Dump the raw template in canonical form.



getConfiguration
public Configuration getConfiguration()(Code)
Returns the Configuration object associated with this template.



getDefaultNS
public String getDefaultNS()(Code)



getEncoding
public String getEncoding()(Code)
Returns the character encoding used for reading included files.



getImports
public List getImports()(Code)



getMacros
public Map getMacros()(Code)



getName
public String getName()(Code)
The path of the template file relative to the directory what you use to store the templates. For example, if the real path of template is "/www/templates/community/forum.fm", and you use ""/www/templates" as Configuration.setDirectoryForTemplateLoading "directoryForTemplateLoading" , then name should be "community/forum.fm". The name is used for example when you use <include ...> and you give a path that is relative to the current template, or in error messages when FreeMarker logs an error while it processes the template.



getNamespaceForPrefix
public String getNamespaceForPrefix(String prefix)(Code)
the NamespaceUri mapped to this prefix in this template. (Or null if there is none.)



getPlainTextTemplate
public static Template getPlainTextTemplate(String name, String content, Configuration config)(Code)
Returns a trivial template, one that is just a single block of plain text, no dynamic content. (Used by the cache module to create unparsed templates.)
Parameters:
  name - the path of the template file relative to the directory what you use to storethe templates. See Template.getName for more details.
Parameters:
  content - the block of text that this template represents
Parameters:
  config - the configuration to which this template belongs



getPrefixForNamespace
public String getPrefixForNamespace(String nsURI)(Code)
the prefix mapped to this nsURI in this template. (Or null if there is none.)



getPrefixedName
public String getPrefixedName(String localName, String nsURI)(Code)
the prefixed name, based on the ns_prefixes definedin this template's header for the local name and node namespacepassed in as parameters.



getRootTreeNode
public TemplateElement getRootTreeNode()(Code)
the root TemplateElement object.



getSource
public String getSource(int beginColumn, int beginLine, int endColumn, int endLine)(Code)
Returns the template source at the location specified by the coordinates given.
Parameters:
  beginColumn - the first column of the requested source, 1-based
Parameters:
  beginLine - the first line of the requested source, 1-based
Parameters:
  endColumn - the last column of the requested source, 1-based
Parameters:
  endLine - the last line of the requested source, 1-based
See Also:   freemarker.core.TemplateObject.getSource



process
public void process(Object rootMap, Writer out) throws TemplateException, IOException(Code)
Processes the template, using data from the map, and outputs the resulting text to the supplied Writer The elements of the map are converted to template models using the default object wrapper returned by the Configuration.getObjectWrapper getObjectWrapper() method of the Configuration.
Parameters:
  rootMap - the root node of the data model. If null, anempty data model is used. Can be any object that the effective objectwrapper can turn into a TemplateHashModel. Basically, simple andbeans wrapper can turn java.util.Map objects into hashesand the Jython wrapper can turn both a PyDictionary as well asany object that implements __getitem__ into a template hash.Naturally, you can pass any object directly implementingTemplateHashModel as well.
Parameters:
  out - a Writer to output the text to.
throws:
  TemplateException - if an exception occurs during template processing
throws:
  IOException - if an I/O exception occurs during writing to the writer.



process
public void process(Object rootMap, Writer out, ObjectWrapper wrapper, TemplateNodeModel rootNode) throws TemplateException, IOException(Code)
Processes the template, using data from the root map object, and outputs the resulting text to the supplied writer, using the supplied object wrapper to convert map elements to template models.
Parameters:
  rootMap - the root node of the data model. If null, anempty data model is used. Can be any object that the effective objectwrapper can turn into a TemplateHashModel Basically, simple andbeans wrapper can turn java.util.Map objects into hashesand the Jython wrapper can turn both a PyDictionary as well as anyobject that implements __getitem__ into a template hash.Naturally, you can pass any object directly implementingTemplateHashModel as well.
Parameters:
  wrapper - The object wrapper to use to wrap objects intoTemplateModel instances. If null, the default wrapper retrievedby Configurable.getObjectWrapper is used.
Parameters:
  out - the writer to output the text to.
Parameters:
  rootNode - The root node for recursive processing, this may be null.
throws:
  TemplateException - if an exception occurs during template processing
throws:
  IOException - if an I/O exception occurs during writing to the writer.



process
public void process(Object rootMap, Writer out, ObjectWrapper wrapper) throws TemplateException, IOException(Code)
Processes the template, using data from the root map object, and outputs the resulting text to the supplied writer, using the supplied object wrapper to convert map elements to template models.
Parameters:
  rootMap - the root node of the data model. If null, anempty data model is used. Can be any object that the effective objectwrapper can turn into a TemplateHashModel Basically, simple andbeans wrapper can turn java.util.Map objects into hashesand the Jython wrapper can turn both a PyDictionary as well as anyobject that implements __getitem__ into a template hash.Naturally, you can pass any object directly implementingTemplateHashModel as well.
Parameters:
  wrapper - The object wrapper to use to wrap objects intoTemplateModel instances. If null, the default wrapper retrievedby Configurable.getObjectWrapper is used.
Parameters:
  out - the writer to output the text to.
throws:
  TemplateException - if an exception occurs during template processing
throws:
  IOException - if an I/O exception occurs during writing to the writer.



setEncoding
public void setEncoding(String encoding)(Code)
Sets the character encoding to use for included files. Usually you don't set this value manually, instead it is assigned to the template upon loading.



toString
public String toString()(Code)
Returns a string representing the raw template text in canonical form.



Fields inherited from freemarker.core.Configurable
final public static String ARITHMETIC_ENGINE_KEY(Code)(Java Doc)
final public static String BOOLEAN_FORMAT_KEY(Code)(Java Doc)
final public static String CLASSIC_COMPATIBLE_KEY(Code)(Java Doc)
final public static String DATETIME_FORMAT_KEY(Code)(Java Doc)
final public static String DATE_FORMAT_KEY(Code)(Java Doc)
final public static String LOCALE_KEY(Code)(Java Doc)
final public static String NUMBER_FORMAT_KEY(Code)(Java Doc)
final public static String OBJECT_WRAPPER_KEY(Code)(Java Doc)
final public static String OUTPUT_ENCODING_KEY(Code)(Java Doc)
final public static String STRICT_BEAN_MODELS(Code)(Java Doc)
final public static String TEMPLATE_EXCEPTION_HANDLER_KEY(Code)(Java Doc)
final public static String TIME_FORMAT_KEY(Code)(Java Doc)
final public static String TIME_ZONE_KEY(Code)(Java Doc)
final public static String URL_ESCAPING_CHARSET_KEY(Code)(Java Doc)

Methods inherited from freemarker.core.Configurable
protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public ArithmeticEngine getArithmeticEngine()(Code)(Java Doc)
public String getBooleanFormat()(Code)(Java Doc)
public Object getCustomAttribute(String name)(Code)(Java Doc)
public String[] getCustomAttributeNames()(Code)(Java Doc)
public String getDateFormat()(Code)(Java Doc)
public String getDateTimeFormat()(Code)(Java Doc)
protected Environment getEnvironment()(Code)(Java Doc)
public Locale getLocale()(Code)(Java Doc)
public String getNumberFormat()(Code)(Java Doc)
public ObjectWrapper getObjectWrapper()(Code)(Java Doc)
public String getOutputEncoding()(Code)(Java Doc)
final public Configurable getParent()(Code)(Java Doc)
public String getSetting(String key)(Code)(Java Doc)
public Map getSettings()(Code)(Java Doc)
public TemplateExceptionHandler getTemplateExceptionHandler()(Code)(Java Doc)
public String getTimeFormat()(Code)(Java Doc)
public TimeZone getTimeZone()(Code)(Java Doc)
public String getURLEscapingCharset()(Code)(Java Doc)
protected TemplateException invalidSettingValueException(String name, String value)(Code)(Java Doc)
public boolean isClassicCompatible()(Code)(Java Doc)
public void removeCustomAttribute(String name)(Code)(Java Doc)
public void setArithmeticEngine(ArithmeticEngine arithmeticEngine)(Code)(Java Doc)
public void setBooleanFormat(String booleanFormat)(Code)(Java Doc)
public void setClassicCompatible(boolean classicCompatibility)(Code)(Java Doc)
public void setCustomAttribute(String name, Object value)(Code)(Java Doc)
public void setDateFormat(String dateFormat)(Code)(Java Doc)
public void setDateTimeFormat(String dateTimeFormat)(Code)(Java Doc)
public void setLocale(Locale locale)(Code)(Java Doc)
public void setNumberFormat(String numberFormat)(Code)(Java Doc)
public void setObjectWrapper(ObjectWrapper objectWrapper)(Code)(Java Doc)
public void setOutputEncoding(String outputEncoding)(Code)(Java Doc)
public void setSetting(String key, String value) throws TemplateException(Code)(Java Doc)
public void setSettings(Properties props) throws TemplateException(Code)(Java Doc)
public void setSettings(InputStream propsIn) throws TemplateException, IOException(Code)(Java Doc)
public void setStrictBeanModels(boolean strict)(Code)(Java Doc)
public void setTemplateExceptionHandler(TemplateExceptionHandler templateExceptionHandler)(Code)(Java Doc)
public void setTimeFormat(String timeFormat)(Code)(Java Doc)
public void setTimeZone(TimeZone timeZone)(Code)(Java Doc)
public void setURLEscapingCharset(String urlEscapingCharset)(Code)(Java Doc)
protected TemplateException unknownSettingException(String name)(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.