http://git-wip-us.apache.org/repos/asf/incubator-freemarker-site/blob/a4004324/builds/2.3.26-nightly/pgui_config_errorhandling.html ---------------------------------------------------------------------- diff --git a/builds/2.3.26-nightly/pgui_config_errorhandling.html b/builds/2.3.26-nightly/pgui_config_errorhandling.html deleted file mode 100644 index 1d88582..0000000 --- a/builds/2.3.26-nightly/pgui_config_errorhandling.html +++ /dev/null @@ -1,391 +0,0 @@ -<!doctype html> -<!-- Generated by FreeMarker/Docgen from DocBook --> -<html lang="en" class="page-type-section"> -<head prefix="og: http://ogp.me/ns#"> -<meta charset="utf-8"> -<title>Error handling - Apache FreeMarker Manual</title> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<meta name="viewport" content="width=device-width,initial-scale=1"> -<meta name="format-detection" content="telephone=no"> -<meta property="og:site_name" content="Apache FreeMarker Manual"> -<meta property="og:title" content="Error handling"> -<meta property="og:locale" content="en_US"> -<meta property="og:url" content="http://freemarker.org/docs/pgui_config_errorhandling.html"> -<link rel="canonical" href="http://freemarker.org/docs/pgui_config_errorhandling.html"> -<link rel="icon" href="favicon.png" type="image/png"> -<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Roboto:500,700,400,300|Droid+Sans+Mono"> -<link rel="stylesheet" type="text/css" href="docgen-resources/docgen.min.css?1489402528979"> -<script> -(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ -(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), -m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) -})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); -ga('create', 'UA-55420501-1', 'auto'); -ga('send', 'pageview'); -</script> -</head> -<body itemscope itemtype="https://schema.org/Code"> - <meta itemprop="url" content="http://freemarker.org/docs/"> - <meta itemprop="name" content="Apache FreeMarker Manual"> - - <!--[if lte IE 9]> - <div style="background-color: #C00; color: #fff; padding: 12px 24px;">Please use a modern browser to view this website.</div> - <![endif]--><div class="header-top-bg"><div class="site-width header-top"><a class="logo" href="http://freemarker.org" role="banner"> <img itemprop="image" src="logo.png" alt="FreeMarker"> -</a><ul class="tabs"><li><a href="http://freemarker.org/">Home</a></li><li class="current"><a href="index.html">Manual</a></li><li><a class="external" href="api/index.html">Java API</a></li></ul><ul class="secondary-tabs"><li><a class="tab icon-heart" href="http://freemarker.org/contribute.html" title="Contribute"><span>Contribute</span></a></li><li><a class="tab icon-bug" href="https://issues.apache.org/jira/browse/FREEMARKER/" title="Report a Bug"><span>Report a Bug</span></a></li><li><a class="tab icon-download" href="http://freemarker.org/freemarkerdownload.html" title="Download"><span>Download</span></a></li></ul></div></div><div class="header-bottom-bg"><div class="site-width search-row"><a href="index.html" class="navigation-header">Manual</a><div class="navigation-header"></div><form method="get" class="search-form" action="search-results.html"><fieldset><legend class="sr-only">Search form</legend><label for="search-field" class="sr-only">Search query</label><input id="searc h-field" name="q" type="search" class="search-input" placeholder="Search" spellcheck="false" autocorrect="off" autocomplete="off"><button type="submit" class="search-btn"><span class="sr-only">Search</span></button></fieldset></form></div><div class="site-width breadcrumb-row"><ul class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList"><li class="step-0" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="index.html"><span itemprop="name">Apache FreeMarker Manual</span></a></li><li class="step-1" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="pgui.html"><span itemprop="name">Programmer's Guide</span></a></li><li class="step-2" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="pgui_config.html"><span itemprop="name">The Configuration</span></a></li><li class="step-3" itempr op="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="pgui_config_errorhandling.html"><span itemprop="name">Error handling</span></a></li></ul><div class="bookmarks" title="Bookmarks"><span class="sr-only">Bookmarks:</span><ul class="bookmark-list"><li><a href="alphaidx.html">Alpha. index</a></li><li><a href="gloss.html">Glossary</a></li><li><a href="dgui_template_exp.html#exp_cheatsheet">Expressions</a></li><li><a href="ref_builtins_alphaidx.html">?builtins</a></li><li><a href="ref_directive_alphaidx.html">#directives</a></li><li><a href="ref_specvar.html">.spec_vars</a></li><li><a href="app_faq.html">FAQ</a></li></ul></div></div></div> <div class="main-content site-width"> - <div class="content-wrapper"> - <div id="table-of-contents-wrapper" class="col-left"> - <script>var breadcrumb = ["Apache FreeMarker Manual","Programmer\'s Guide","The Configuration","Error handling"];</script> - <script src="toc.js?1489402528979"></script> - <script src="docgen-resources/main.min.js?1489402528979"></script> - </div> -<div class="col-right"><div class="page-content"><div class="page-title"><div class="pagers top"><a class="paging-arrow previous" href="pgui_config_templateloading.html"><span>Previous</span></a><a class="paging-arrow next" href="pgui_config_templateconfigurations.html"><span>Next</span></a></div><div class="title-wrapper"> -<h1 class="content-header header-section1" id="pgui_config_errorhandling" itemprop="headline">Error handling</h1> -</div></div><div class="page-menu"> -<div class="page-menu-title">Page Contents</div> -<ul><li><a class="page-menu-link" href="#autoid_43" data-menu-target="autoid_43">The possible exceptions</a></li><li><a class="page-menu-link" href="#autoid_44" data-menu-target="autoid_44">Customizing the behavior regarding TemplatException-s</a></li><li><a class="page-menu-link" href="#autoid_45" data-menu-target="autoid_45">TemplateException logging</a></li><li><a class="page-menu-link" href="#autoid_46" data-menu-target="autoid_46">Explicit error handling in templates</a></li></ul> </div> - - - - -<h2 class="content-header header-section2" id="autoid_43">The possible exceptions</h2> - - - <p>The exceptions that can occur regarding FreeMarker could be - classified like this:</p> - - <ul> - <li> - <p>Exceptions occurring when you configure FreeMarker: - Typically you configure FreeMarker only once in your - application, when your application initializes itself. Of - course, during this, exceptions can occur.</p> - </li> - - <li> - <p>Exceptions occurring when loading and parsing templates: - When you call - <code class="inline-code">Configuration.getTemplate(<em class="code-color">...</em>)</code>, - FreeMarker has to load the template into the memory and parse it - (unless the template is already <a href="pgui_config_templateloading.html#pgui_config_templateloading_caching">cached</a> in - that <code class="inline-code">Configuration</code> object). During this, - these kind of exceptions can occur:</p> - - <ul> - <li> - <p><code class="inline-code">TemplateNotFoundException</code> because - the requested template doesn't exist. Note this extends - <code class="inline-code">IOException</code>.</p> - </li> - - <li> - <p><code class="inline-code">freemarker.core.ParseException</code> - because the template is syntactically incorrect according - the rules of the FTL language. Note that this error occurs - when you obtain the <code class="inline-code">Template</code> object - (<code class="inline-code">Configuration.getTemplate(<em class="code-color">...</em>)</code>), - not later when you execute - (<code class="inline-code">Template.process(<em class="code-color">...</em>)</code>) - the template. . Note this extends - <code class="inline-code">IOException</code> (legacy).</p> - </li> - - <li> - <p>Any other kind of <code class="inline-code">IOException</code> - because an error has occurred while reading an existing - template. For example you have no right to read the file, or - the connection through which you read the template is - broken. The emitter of these is the <a href="pgui_config_templateloading.html"><code>TemplateLoader</code> - object</a>, which is plugged into the - <code class="inline-code">Configuration</code> object.</p> - </li> - </ul> - </li> - - <li> - <p>Exceptions occurring when executing (processing) - templates, that is, when you call - <code class="inline-code">Template.process(<em class="code-color">...</em>)</code>. - Two kind of exceptions can occur:</p> - - <ul> - <li> - <p><code class="inline-code">IOException</code> because there was an - error when trying to write into the output writer.</p> - </li> - - <li> - <p><code class="inline-code">freemarker.template.TemplatException</code> - because other problem occurred while executing the template. - For example, a frequent error is referring to a variable - that doesn't exist in the data-model. By default, when a - <code class="inline-code">TemplatException</code> occurs, FreeMarker - prints the FTL error message and the stack trace to the - output writer with plain text format, and then aborts the - template execution by re-throwing the - <code class="inline-code">TemplatException</code>, which then you can - catch as - <code class="inline-code">Template.process(<em class="code-color">...</em>)</code> - throws it. This behavior can be customized, and in fact, it - should be; see the recommended configuration <a href="pgui_quickstart_createconfiguration.html">here</a>. - By default FreeMarker also <a href="pgui_misc_logging.html">logs</a> - <code class="inline-code">TemplatException</code>-s.</p> - </li> - </ul> - </li> - </ul> - - - - - -<h2 class="content-header header-section2" id="autoid_44">Customizing the behavior regarding TemplatException-s</h2> - - - <p><code class="inline-code">TemplateException</code>-s thrown during the - template processing are handled by the - <code class="inline-code">freemarker.template.TemplateExceptionHandler</code> - object, which is plugged into the <code class="inline-code">Configuration</code> - object with its - <code class="inline-code">setTemplateExceptionHandler(<em class="code-color">...</em>)</code> - method. These are the <code class="inline-code">TemplateExceptionHandler</code> - implementations with FreeMarker comes with:</p> - - <ul> - <li> - <p><code class="inline-code">TemplateExceptionHandler.DEBUG_HANDLER</code>: - Prints stack trace (includes FTL error message and FTL stack - trace) and re-throws the exception. This is the default handler, - however, you should be careful not using it in production - environment, as it shows technical information about your - system.</p> - </li> - - <li> - <p><code class="inline-code">TemplateExceptionHandler.HTML_DEBUG_HANDLER</code>: - Same as <code class="inline-code">DEBUG_HANDLER</code>, but it formats the - stack trace so that it will be readable with Web browsers. - Recommended over <code class="inline-code">DEBUG_HANDLER</code> when you - generate HTML pages, but it should only be used for development - as it shows technical information about your system.</p> - </li> - - <li> - <p><code class="inline-code">TemplateExceptionHandler.IGNORE_HANDLER</code>: - Simply suppresses all exceptions (though FreeMarker will still - log them if - <code class="inline-code">Configuration.getLogTemplateExceptions</code> is - <code class="inline-code">true</code>). It does nothing to handle the event. - It does not re-throw the exception.</p> - </li> - - <li> - <p><code class="inline-code">TemplateExceptionHandler.RETHROW_HANDLER</code>: - Simply re-throws all exceptions; it doesn't do anything else. - This should be used in most applications today. It doesn't print - anything to the output about the error, which makes it safe, and - the developers can still get the error details from the logs. - It's not as convenient during template development as - <code class="inline-code">HTML_DEBUG_HANDLER</code> or - <code class="inline-code">DEBUG_HANDLER</code> though. For more information - about handling errors in Web applications <a href="app_faq.html#misc.faq.niceErrorPage">see the FAQ</a>.</p> - </li> - </ul> - - <p>You can also write a custom - <code class="inline-code">TemplateExceptionHandler</code> by implementing that - interface, which contains this method:</p> - - - -<div class="code-wrapper"><pre class="code-block code-unspecified">void handleTemplateException(TemplateException te, Environment env, Writer out) - throws TemplateException;</pre></div> - - <p>Whenever a <code class="inline-code">TemplateException</code> occurs, this - method will be called. The exception to handle is in the - <code class="inline-code">te</code> argument, the runtime environment of the - template processing is in the <code class="inline-code">env</code> argument, and - the handler can print to the output using the <code class="inline-code">out</code> - argument. If this method throws exception (usually it re-throws - <code class="inline-code">te</code>), then the template processing will be - aborted, and - <code class="inline-code">Template.process(<em class="code-color">...</em>)</code> - will throw the same exception. If - <code class="inline-code">handleTemplateException</code> doesn't throw exception, - then template processing continues as if nothing had happen, but the - statement that caused the exception will be skipped (see more - later). Of course, the handler can still print an error indicator to - the output.</p> - - <p>Let's see how FreeMarker skips statements when the error - handler doesn't throw exception, through examples. Assume we are - using this template exception handler:</p> - - - -<div class="code-wrapper"><pre class="code-block code-unspecified">class MyTemplateExceptionHandler implements TemplateExceptionHandler { - public void handleTemplateException(TemplateException te, Environment env, java.io.Writer out) - throws TemplateException { - try { - out.write("[ERROR: " + te.getMessage() + "]"); - } catch (IOException e) { - throw new TemplateException("Failed to print error message. Cause: " + e, env); - } - } -} - -<em>...</em> - -cfg.setTemplateExceptionHandler(new MyTemplateExceptionHandler());</pre></div> - - <p>If an error occurs in an interpolation which is not inside an - FTL tag (that is, not enclosed into - <code class="inline-code"><#<em class="code-color">...</em>></code> or - <code class="inline-code"><@<em class="code-color">...</em>></code>), then - the whole interpolation will be skipped. So this template (assuming - that <code class="inline-code">badVar</code> is missing from the - data-model):</p> - - - -<div class="code-wrapper"><pre class="code-block code-template">a${badVar}b</pre></div> - - <p>will print this if we use the - <code class="inline-code">MyTemplateExceptionHandler</code>:</p> - - - -<div class="code-wrapper"><pre class="code-block code-output">a[ERROR: Expression badVar is undefined on line 1, column 4 in test.ftl.]b</pre></div> - - <p>This template will print the same (except that the column - number will differ...):</p> - - - -<div class="code-wrapper"><pre class="code-block code-template">a${"moo" + badVar}b</pre></div> - - <p>because the whole interpolation is skipped if any error occurs - inside it.</p> - - <p>If an error occurs when evaluating the value of a parameter - for a directive call, or if there are other problems with the - parameter list, or if an error occurs when evaluating - <code class="inline-code"><em class="code-color">exp</em></code> in - <code class="inline-code"><@<em class="code-color">exp</em> - <em class="code-color">...</em>></code>, or if the value of - <code class="inline-code"><em class="code-color">exp</em></code> is not an - user-defined directive, then the whole directive call is skipped. - For example this:</p> - - - -<div class="code-wrapper"><pre class="code-block code-template">a<#if badVar>Foo</#if>b</pre></div> - - <p>will print this:</p> - - - -<div class="code-wrapper"><pre class="code-block code-output">a[ERROR: Expression badVar is undefined on line 1, column 7 in test.ftlh.]b</pre></div> - - <p>Note that the error occurred in the <code class="inline-code">if</code> - start-tag (<code class="inline-code"><#if badVar></code>), but the whole - directive call was skipped. Logically, the nested content - (<code class="inline-code">Foo</code>) was skipped with this, since the nested - content is handled (printed) by the enclosing directive - (<code class="inline-code">if</code>).</p> - - <p>The output will be the same with this (except that the column - number will differ...):</p> - - - -<div class="code-wrapper"><pre class="code-block code-template">a<#if "foo${badVar}" == "foobar">Foo</#if>b</pre></div> - - <p>because whole directive calling will be skipped if any error - occurs during the parameter evaluation.</p> - - <p>The directive call will not be skipped if the error occurs - after the execution of the directive was already started. That is, - if an error occurs in the nested content:</p> - - - -<div class="code-wrapper"><pre class="code-block code-template">a -<#if true> - Foo - ${badVar} - Bar -</#if> -c</pre></div> - - <p>or in the macro definition body:</p> - - - -<div class="code-wrapper"><pre class="code-block code-template">a -<@test /> -b -<#macro test> - Foo - ${badVar} - Bar -</#macro></pre></div> - - <p>the output will be something like:</p> - - - -<div class="code-wrapper"><pre class="code-block code-output">a - Foo - [ERROR: Expression badVar is undefined on line 4, column 5 in test.ftlh.] - Bar -c</pre></div> - - - - - -<h2 class="content-header header-section2" id="autoid_45">TemplateException logging</h2> - - - <p>By default FreeMarker <a href="pgui_misc_logging.html">logs</a> all - <code class="inline-code">TemplateException</code>-s under the - <code class="inline-code">freemarker.runtime</code> log category, even when it - will throw it at you from its public API. As logging has become - common practice in Java applications, this usually leads to double - logging of exceptions now, so it's recommended to disable this - legacy behavior by - <code class="inline-code">cfg.setLogTemplateExceptions(false)</code> (or - <code class="inline-code">log_template_exceptions=false</code>) where you - configure FreeMarker.</p> - - - - - -<h2 class="content-header header-section2" id="autoid_46">Explicit error handling in templates</h2> - - - <p>Although it has nothing to do with the FreeMarker - configuration (the topic of this chapter), for the sake of - completeness it's mentioned here that you can handle errors directly - inside the templates as well:</p> - - <ul> - <li> - <p>Handling missing/null variables: <a href="dgui_template_exp.html#dgui_template_exp_missing">Template Author's Guide/The Template/Expressions/Handling missing values</a></p> - </li> - - <li> - <p>Substituting failing but expendable page sections: <a href="ref_directive_attempt.html">Template Language Reference/Directive Reference/attempt, recover</a></p> - </li> - </ul> - <div class="bottom-pagers-wrapper"><div class="pagers bottom"><a class="paging-arrow previous" href="pgui_config_templateloading.html"><span>Previous</span></a><a class="paging-arrow next" href="pgui_config_templateconfigurations.html"><span>Next</span></a></div></div></div></div> </div> - </div> -<div class="site-footer"><div class="site-width"><div class="footer-top"><div class="col-left sitemap"><div class="column"><h3 class="column-header">Overview</h3><ul><li><a href="http://freemarker.org/">What is FreeMarker?</a></li><li><a href="http://freemarker.org/freemarkerdownload.html">Download</a></li><li><a href="app_versions.html">Version history</a></li><li><a href="http://freemarker.org/history.html">About us</a></li><li><a itemprop="license" href="app_license.html">License</a></li></ul></div><div class="column"><h3 class="column-header">Handy stuff</h3><ul><li><a href="http://freemarker-online.kenshoo.com/">Try template online</a></li><li><a href="dgui_template_exp.html#exp_cheatsheet">Expressions cheatsheet</a></li><li><a href="ref_directive_alphaidx.html">#directives</a></li><li><a href="ref_builtins_alphaidx.html">?built_ins</a></li><li><a href="ref_specvar.html">.special_vars</a></li></ul></div><div class="column"><h3 class="column-header">Community</h3><ul><li><a href ="https://github.com/freemarker/freemarker">FreeMarker on Github</a></li><li><a href="https://twitter.com/freemarker">Follow us on Twitter</a></li><li><a href="https://issues.apache.org/jira/browse/FREEMARKER/">Report a bug</a></li><li><a href="http://stackoverflow.com/questions/ask?tags=freemarker">Ask a question</a></li><li><a href="http://freemarker.org/mailing-lists.html">Mailing lists</a></li></ul></div></div><div class="col-right"><ul class="social-icons"><li><a class="github" href="https://github.com/freemarker/freemarker">Github</a></li><li><a class="twitter" href="https://twitter.com/freemarker">Twitter</a></li><li><a class="stack-overflow" href="http://stackoverflow.com/questions/ask?tags=freemarker">Stack Overflow</a></li></ul><a class="xxe" href="http://www.xmlmind.com/xmleditor/" rel="nofollow" title="Edited with XMLMind XML Editor"><span>Edited with XMLMind XML Editor</span></a></div></div><div class="footer-bottom"> <p class="last-generated"> -Last generated: -<time itemprop="dateModified" datetime="2017-03-13T10:55:28Z" title="Monday, March 13, 2017 10:55:28 AM GMT">2017-03-13 10:55:28 GMT</time>, for Freemarker 2.3.26 </p> -<p class="copyright"> -© <span itemprop="copyrightYear">1999</span>â2017 -<a itemtype="http://schema.org/Organization" itemprop="copyrightHolder" href="http://apache.org/">The Apache Software Foundation</a>. Apache FreeMarker, FreeMarker, Apache Incubator, Apache, the Apache FreeMarker logo are trademarks of The Apache Software Foundation. </p> -</div></div></div></body> -</html>
http://git-wip-us.apache.org/repos/asf/incubator-freemarker-site/blob/a4004324/builds/2.3.26-nightly/pgui_config_incompatible_improvements.html ---------------------------------------------------------------------- diff --git a/builds/2.3.26-nightly/pgui_config_incompatible_improvements.html b/builds/2.3.26-nightly/pgui_config_incompatible_improvements.html deleted file mode 100644 index 01c060d..0000000 --- a/builds/2.3.26-nightly/pgui_config_incompatible_improvements.html +++ /dev/null @@ -1,173 +0,0 @@ -<!doctype html> -<!-- Generated by FreeMarker/Docgen from DocBook --> -<html lang="en" class="page-type-section"> -<head prefix="og: http://ogp.me/ns#"> -<meta charset="utf-8"> -<title>The "incompatible improvements" setting - Apache FreeMarker Manual</title> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<meta name="viewport" content="width=device-width,initial-scale=1"> -<meta name="format-detection" content="telephone=no"> -<meta property="og:site_name" content="Apache FreeMarker Manual"> -<meta property="og:title" content="The "incompatible improvements" setting"> -<meta property="og:locale" content="en_US"> -<meta property="og:url" content="http://freemarker.org/docs/pgui_config_incompatible_improvements.html"> -<link rel="canonical" href="http://freemarker.org/docs/pgui_config_incompatible_improvements.html"> -<link rel="icon" href="favicon.png" type="image/png"> -<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Roboto:500,700,400,300|Droid+Sans+Mono"> -<link rel="stylesheet" type="text/css" href="docgen-resources/docgen.min.css?1489402528979"> -<script> -(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ -(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), -m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) -})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); -ga('create', 'UA-55420501-1', 'auto'); -ga('send', 'pageview'); -</script> -</head> -<body itemscope itemtype="https://schema.org/Code"> - <meta itemprop="url" content="http://freemarker.org/docs/"> - <meta itemprop="name" content="Apache FreeMarker Manual"> - - <!--[if lte IE 9]> - <div style="background-color: #C00; color: #fff; padding: 12px 24px;">Please use a modern browser to view this website.</div> - <![endif]--><div class="header-top-bg"><div class="site-width header-top"><a class="logo" href="http://freemarker.org" role="banner"> <img itemprop="image" src="logo.png" alt="FreeMarker"> -</a><ul class="tabs"><li><a href="http://freemarker.org/">Home</a></li><li class="current"><a href="index.html">Manual</a></li><li><a class="external" href="api/index.html">Java API</a></li></ul><ul class="secondary-tabs"><li><a class="tab icon-heart" href="http://freemarker.org/contribute.html" title="Contribute"><span>Contribute</span></a></li><li><a class="tab icon-bug" href="https://issues.apache.org/jira/browse/FREEMARKER/" title="Report a Bug"><span>Report a Bug</span></a></li><li><a class="tab icon-download" href="http://freemarker.org/freemarkerdownload.html" title="Download"><span>Download</span></a></li></ul></div></div><div class="header-bottom-bg"><div class="site-width search-row"><a href="index.html" class="navigation-header">Manual</a><div class="navigation-header"></div><form method="get" class="search-form" action="search-results.html"><fieldset><legend class="sr-only">Search form</legend><label for="search-field" class="sr-only">Search query</label><input id="searc h-field" name="q" type="search" class="search-input" placeholder="Search" spellcheck="false" autocorrect="off" autocomplete="off"><button type="submit" class="search-btn"><span class="sr-only">Search</span></button></fieldset></form></div><div class="site-width breadcrumb-row"><ul class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList"><li class="step-0" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="index.html"><span itemprop="name">Apache FreeMarker Manual</span></a></li><li class="step-1" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="pgui.html"><span itemprop="name">Programmer's Guide</span></a></li><li class="step-2" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="pgui_config.html"><span itemprop="name">The Configuration</span></a></li><li class="step-3" itempr op="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="pgui_config_incompatible_improvements.html"><span itemprop="name">The "incompatible improvements" setting</span></a></li></ul><div class="bookmarks" title="Bookmarks"><span class="sr-only">Bookmarks:</span><ul class="bookmark-list"><li><a href="alphaidx.html">Alpha. index</a></li><li><a href="gloss.html">Glossary</a></li><li><a href="dgui_template_exp.html#exp_cheatsheet">Expressions</a></li><li><a href="ref_builtins_alphaidx.html">?builtins</a></li><li><a href="ref_directive_alphaidx.html">#directives</a></li><li><a href="ref_specvar.html">.spec_vars</a></li><li><a href="app_faq.html">FAQ</a></li></ul></div></div></div> <div class="main-content site-width"> - <div class="content-wrapper"> - <div id="table-of-contents-wrapper" class="col-left"> - <script>var breadcrumb = ["Apache FreeMarker Manual","Programmer\'s Guide","The Configuration","The \"incompatible improvements\" setting"];</script> - <script src="toc.js?1489402528979"></script> - <script src="docgen-resources/main.min.js?1489402528979"></script> - </div> -<div class="col-right"><div class="page-content"><div class="page-title"><div class="pagers top"><a class="paging-arrow previous" href="pgui_config_custom_formats.html"><span>Previous</span></a><a class="paging-arrow next" href="pgui_misc.html"><span>Next</span></a></div><div class="title-wrapper"> -<h1 class="content-header header-section1" id="pgui_config_incompatible_improvements" itemprop="headline">The "incompatible improvements" setting</h1> -</div></div><div class="page-menu"> -<div class="page-menu-title">Page Contents</div> -<ul><li><a class="page-menu-link" href="#autoid_51" data-menu-target="autoid_51">What does it do</a></li><li><a class="page-menu-link" href="#pgui_config_incompatible_improvements_how_to_set" data-menu-target="pgui_config_incompatible_improvements_how_to_set">How to set it</a></li></ul> </div> - - - - -<h2 class="content-header header-section2" id="autoid_51">What does it do</h2> - - - <p>This setting specifies the FreeMarker version number where the - not 100% backward compatible bug fixes and improvements - <em>that you want to enable</em> were already - implemented. Usually, it's a bad idea to left it on its default, - which is 2.3.0 (maximum backward compatibility).</p> - - <p>In new projects you should set this to the FreeMarker version - that you are actually using. In older projects it's also usually - better to keep this high, however you better check the changes - activated (find them in <a href="http://freemarker.org/docs/api/freemarker/template/Configuration.html#Configuration-freemarker.template.Version-">the - API JavaDoc of the <code>Configuration(Version)</code> - constructor</a>), at least if not only the 3rd version number - (the micro version) of "incompatible improvements" - setting is increased. Generally, as far as you only increase the - last version number of this setting, the changes are low - risk.</p> - - <p>Bug fixes and improvements that are fully backward compatible, - also those that are important security fixes, are enabled regardless - of the "incompatible improvements" setting.</p> - - <p>An important consequence of setting this setting is that now - your application will check if the stated minimum FreeMarker version - requirement is met. Like if you set this setting to 2.3.22, but - accidentally the application is deployed with FreeMarker 2.3.21, - then FreeMarker will fail, telling that a higher version is - required. After all, the fixes/improvements you have requested - aren't available on a lower version.</p> - - - - - -<h2 class="content-header header-section2" id="pgui_config_incompatible_improvements_how_to_set">How to set it</h2> - - - <p>The incompatible improvements setting exists on the - <code class="inline-code">Configuration</code> level. It can be set on multiple - ways:</p> - - <ul> - <li> - <p>Create the - <code class="inline-code">freemarker.template.Configuration</code> object - like:</p> - - - -<div class="code-wrapper"><pre class="code-block code-unspecified">... = new Configuration(Configuration.VERSION_2_3_25)</pre></div> - </li> - - <li> - <p>Or, alter the <code class="inline-code">Configuration</code> singleton - where you initialize its other settings like:</p> - - - -<div class="code-wrapper"><pre class="code-block code-unspecified">cfg.setIncompatibleImprovements(Configuration.VERSION_2_3_25)</pre></div> - </li> - - <li> - <p>Or, if you are configuring FreeMarker with properties - (<code class="inline-code">*.properties</code> file or - <code class="inline-code">java.util.Properties</code> object), add:</p> - - - -<div class="code-wrapper"><pre class="code-block code-unspecified">incompatible_improvements=2.3.25</pre></div> - </li> - - <li> - <p>Or, if you are configuring FreeMarker through - <code class="inline-code">FreemarkerServlet</code>, add this - <code class="inline-code">init-param</code> to it in the - <code class="inline-code">web.xml</code>:</p> - - - -<div class="code-wrapper"><pre class="code-block code-unspecified"><init-param> - <param-name>incompatible_improvements</param-name> - <param-value>2.3.25</param-value> -</init-param></pre></div> - </li> - </ul> - - <p>But, <em>if you set the - <code class="inline-code">object_wrapper</code> setting</em> (same as - <code class="inline-code">Configuration.setObjectWrapper(ObjectWrapper)</code>) of - your configuration, then it's important to know that - <code class="inline-code">BeansWrapper</code> and its subclasses (most - importantly, <code class="inline-code">DefaultObjectWrapper</code>) has its own - independent <code class="inline-code">incompatibleImprovements</code> property, - and some fixes/improvements are activated by that, not by - <code class="inline-code">Configuration</code>'s similar setting. You don't have - to be aware of this complication if you aren't setting the - <code class="inline-code">object_wrapper</code> configuration setting anywhere, - because the default <code class="inline-code">object_wrapper</code> has the same - "incompatible improvements" as of the - <code class="inline-code">Configuration</code>. But if you are setting the - <code class="inline-code">object_wrapper</code>, then you must not forget to set - the <code class="inline-code">incompatibleImprovements</code> property of the - <code class="inline-code">ObjectWrapper</code> itself, in additionally to that of - the <code class="inline-code">Configuration</code>. (Note that it's fine to have - different "incompatible improvements" for the - <code class="inline-code">Configuration</code> and for the - <code class="inline-code">ObjectWrapper</code>, only it should be a conscious - decision.) <a href="pgui_datamodel_objectWrapper.html#topic.setDefaultObjectWrapperIcIIndividually">See here how - to set it</a> in the case of - <code class="inline-code">DefaultObjectWrapper</code> (for - <code class="inline-code">BeansWrapper</code> it's the same, only with different - class name of course).</p> - <div class="bottom-pagers-wrapper"><div class="pagers bottom"><a class="paging-arrow previous" href="pgui_config_custom_formats.html"><span>Previous</span></a><a class="paging-arrow next" href="pgui_misc.html"><span>Next</span></a></div></div></div></div> </div> - </div> -<div class="site-footer"><div class="site-width"><div class="footer-top"><div class="col-left sitemap"><div class="column"><h3 class="column-header">Overview</h3><ul><li><a href="http://freemarker.org/">What is FreeMarker?</a></li><li><a href="http://freemarker.org/freemarkerdownload.html">Download</a></li><li><a href="app_versions.html">Version history</a></li><li><a href="http://freemarker.org/history.html">About us</a></li><li><a itemprop="license" href="app_license.html">License</a></li></ul></div><div class="column"><h3 class="column-header">Handy stuff</h3><ul><li><a href="http://freemarker-online.kenshoo.com/">Try template online</a></li><li><a href="dgui_template_exp.html#exp_cheatsheet">Expressions cheatsheet</a></li><li><a href="ref_directive_alphaidx.html">#directives</a></li><li><a href="ref_builtins_alphaidx.html">?built_ins</a></li><li><a href="ref_specvar.html">.special_vars</a></li></ul></div><div class="column"><h3 class="column-header">Community</h3><ul><li><a href ="https://github.com/freemarker/freemarker">FreeMarker on Github</a></li><li><a href="https://twitter.com/freemarker">Follow us on Twitter</a></li><li><a href="https://issues.apache.org/jira/browse/FREEMARKER/">Report a bug</a></li><li><a href="http://stackoverflow.com/questions/ask?tags=freemarker">Ask a question</a></li><li><a href="http://freemarker.org/mailing-lists.html">Mailing lists</a></li></ul></div></div><div class="col-right"><ul class="social-icons"><li><a class="github" href="https://github.com/freemarker/freemarker">Github</a></li><li><a class="twitter" href="https://twitter.com/freemarker">Twitter</a></li><li><a class="stack-overflow" href="http://stackoverflow.com/questions/ask?tags=freemarker">Stack Overflow</a></li></ul><a class="xxe" href="http://www.xmlmind.com/xmleditor/" rel="nofollow" title="Edited with XMLMind XML Editor"><span>Edited with XMLMind XML Editor</span></a></div></div><div class="footer-bottom"> <p class="last-generated"> -Last generated: -<time itemprop="dateModified" datetime="2017-03-13T10:55:28Z" title="Monday, March 13, 2017 10:55:28 AM GMT">2017-03-13 10:55:28 GMT</time>, for Freemarker 2.3.26 </p> -<p class="copyright"> -© <span itemprop="copyrightYear">1999</span>â2017 -<a itemtype="http://schema.org/Organization" itemprop="copyrightHolder" href="http://apache.org/">The Apache Software Foundation</a>. Apache FreeMarker, FreeMarker, Apache Incubator, Apache, the Apache FreeMarker logo are trademarks of The Apache Software Foundation. </p> -</div></div></div></body> -</html> http://git-wip-us.apache.org/repos/asf/incubator-freemarker-site/blob/a4004324/builds/2.3.26-nightly/pgui_config_outputformatsautoesc.html ---------------------------------------------------------------------- diff --git a/builds/2.3.26-nightly/pgui_config_outputformatsautoesc.html b/builds/2.3.26-nightly/pgui_config_outputformatsautoesc.html deleted file mode 100644 index 2aff9d5..0000000 --- a/builds/2.3.26-nightly/pgui_config_outputformatsautoesc.html +++ /dev/null @@ -1,210 +0,0 @@ -<!doctype html> -<!-- Generated by FreeMarker/Docgen from DocBook --> -<html lang="en" class="page-type-section"> -<head prefix="og: http://ogp.me/ns#"> -<meta charset="utf-8"> -<title>Associating output formats with templates - Apache FreeMarker Manual</title> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<meta name="viewport" content="width=device-width,initial-scale=1"> -<meta name="format-detection" content="telephone=no"> -<meta property="og:site_name" content="Apache FreeMarker Manual"> -<meta property="og:title" content="Associating output formats with templates"> -<meta property="og:locale" content="en_US"> -<meta property="og:url" content="http://freemarker.org/docs/pgui_config_outputformatsautoesc.html"> -<link rel="canonical" href="http://freemarker.org/docs/pgui_config_outputformatsautoesc.html"> -<link rel="icon" href="favicon.png" type="image/png"> -<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Roboto:500,700,400,300|Droid+Sans+Mono"> -<link rel="stylesheet" type="text/css" href="docgen-resources/docgen.min.css?1489402528979"> -<script> -(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ -(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), -m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) -})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); -ga('create', 'UA-55420501-1', 'auto'); -ga('send', 'pageview'); -</script> -</head> -<body itemscope itemtype="https://schema.org/Code"> - <meta itemprop="url" content="http://freemarker.org/docs/"> - <meta itemprop="name" content="Apache FreeMarker Manual"> - - <!--[if lte IE 9]> - <div style="background-color: #C00; color: #fff; padding: 12px 24px;">Please use a modern browser to view this website.</div> - <![endif]--><div class="header-top-bg"><div class="site-width header-top"><a class="logo" href="http://freemarker.org" role="banner"> <img itemprop="image" src="logo.png" alt="FreeMarker"> -</a><ul class="tabs"><li><a href="http://freemarker.org/">Home</a></li><li class="current"><a href="index.html">Manual</a></li><li><a class="external" href="api/index.html">Java API</a></li></ul><ul class="secondary-tabs"><li><a class="tab icon-heart" href="http://freemarker.org/contribute.html" title="Contribute"><span>Contribute</span></a></li><li><a class="tab icon-bug" href="https://issues.apache.org/jira/browse/FREEMARKER/" title="Report a Bug"><span>Report a Bug</span></a></li><li><a class="tab icon-download" href="http://freemarker.org/freemarkerdownload.html" title="Download"><span>Download</span></a></li></ul></div></div><div class="header-bottom-bg"><div class="site-width search-row"><a href="index.html" class="navigation-header">Manual</a><div class="navigation-header"></div><form method="get" class="search-form" action="search-results.html"><fieldset><legend class="sr-only">Search form</legend><label for="search-field" class="sr-only">Search query</label><input id="searc h-field" name="q" type="search" class="search-input" placeholder="Search" spellcheck="false" autocorrect="off" autocomplete="off"><button type="submit" class="search-btn"><span class="sr-only">Search</span></button></fieldset></form></div><div class="site-width breadcrumb-row"><ul class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList"><li class="step-0" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="index.html"><span itemprop="name">Apache FreeMarker Manual</span></a></li><li class="step-1" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="pgui.html"><span itemprop="name">Programmer's Guide</span></a></li><li class="step-2" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="pgui_config.html"><span itemprop="name">The Configuration</span></a></li><li class="step-3" itempr op="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="pgui_config_outputformatsautoesc.html"><span itemprop="name">Associating output formats with templates</span></a></li></ul><div class="bookmarks" title="Bookmarks"><span class="sr-only">Bookmarks:</span><ul class="bookmark-list"><li><a href="alphaidx.html">Alpha. index</a></li><li><a href="gloss.html">Glossary</a></li><li><a href="dgui_template_exp.html#exp_cheatsheet">Expressions</a></li><li><a href="ref_builtins_alphaidx.html">?builtins</a></li><li><a href="ref_directive_alphaidx.html">#directives</a></li><li><a href="ref_specvar.html">.spec_vars</a></li><li><a href="app_faq.html">FAQ</a></li></ul></div></div></div> <div class="main-content site-width"> - <div class="content-wrapper"> - <div id="table-of-contents-wrapper" class="col-left"> - <script>var breadcrumb = ["Apache FreeMarker Manual","Programmer\'s Guide","The Configuration","Associating output formats with templates"];</script> - <script src="toc.js?1489402528979"></script> - <script src="docgen-resources/main.min.js?1489402528979"></script> - </div> -<div class="col-right"><div class="page-content"><div class="page-title"><div class="pagers top"><a class="paging-arrow previous" href="pgui_config_templateconfigurations.html"><span>Previous</span></a><a class="paging-arrow next" href="pgui_config_custom_formats.html"><span>Next</span></a></div><div class="title-wrapper"> -<h1 class="content-header header-section1" id="pgui_config_outputformatsautoesc" itemprop="headline">Associating output formats with templates</h1> -</div></div><p>The output format associated to a template decides if and what - kind of auto-escaping is used in that template (unless the template - <a href="dgui_misc_autoescaping.html#dgui_misc_autoescaping_overrideoformat">overrides that - with directives</a>). By default, templates have - "undefined" output format associated, which does no - escaping, and in general gives the behavior that you would expect from - a template engine that doesn't care about output formats and escaping. - However, if the <code class="inline-code">recognize_standard_file_extensions</code> - <a href="pgui_config_settings.html">setting</a> is - <code class="inline-code">true</code> (which is the default with <a href="pgui_config_incompatible_improvements.html">the - <code>incompatible_improvements</code> setting</a> set to - 2.3.24 or higher), templates whose source name ends with - <code class="inline-code">".ftlh"</code> gets "HTML" output format, and - those with <code class="inline-code">".ftlx"</code> get "XML" output - format. Using the <code class="inline-code">ftlh</code> and <code class="inline-code">ftlx</code> - file extensions is the recommended way of activating HTML and XML - auto-escaping. You can also associate output formats to templates - based on arbitrary name patterns with the <a href="pgui_config_templateconfigurations.html"><code>template_configurations</code> - setting</a>; see some examples of that below.</p><p>There's another a related setting, called - <code class="inline-code">auto_escaping_policy</code>, which can be used to disable - auto-escaping even if the current output format supports it, or enable - auto-escaping even if the format by default doesn't escape (but it - supports it). Using this setting rarely advisable, as it's potentially - confusing for the template authors. (Instead, escaping can be turned - on/off explicitly inside the templates with the - <code class="inline-code">auto_esc</code> parameter of the <a href="ref_directive_ftl.html"><code>ftl</code> directive</a>, - or with the <a href="ref_directive_autoesc.html"><code>noautoesc</code></a> - and <a href="ref_directive_autoesc.html"><code>autoesc</code> - directive</a>s.)</p><p>To check if you have configured FreeMarker properly, you can use - this template:</p> - -<div class="code-wrapper"><pre class="code-block code-template"><p>Output format: ${.output_format} -<p>Auto-escaping: ${.auto_esc?c}</pre></div><p>See the <a href="dgui_misc_autoescaping.html#topic.predefinedOutputFormats">table of - predefined output formats here...</a></p><p>Configuration examples:</p><ul> - <li> - <p>To enable automatic output format associations to - <code class="inline-code">*.ftlh</code> and <code class="inline-code">*.ftlx</code>, - either:</p> - - <ul> - <li> - <p>Use <code class="inline-code">incompatible_improvements</code> 2.3.24 - or higher; see <a href="pgui_config_incompatible_improvements.html#pgui_config_incompatible_improvements_how_to_set">how - to set - <code>incompatible_improvements</code></a></p> - </li> - - <li> - <p>Or, enable standard file extension recognizing - explicitly:</p> - - - -<div class="code-wrapper"><pre class="code-block code-unspecified">// Where you initalize the Configuration singletion, add: -cfg.setRecognizeStandardFileExtensions(true);</pre></div> - - <p>or if you configure FreeMarker with Java - <code class="inline-code">*.properties</code> file:</p> - - - -<div class="code-wrapper"><pre class="code-block code-unspecified">recognizeStandardFileExtensions = true</pre></div> - </li> - </ul> - </li> - - <li> - <p>Let's say that you want to associate all templates in the - <code class="inline-code">mail</code> directory to the HTML output format. You - could achieve that like this (assuming that you are getting the - templates with - <code class="inline-code">cfg.getTemplate(<em class="code-color">...</em>)</code>, - and not instantiating them yourself):</p> - - - -<div class="code-wrapper"><pre class="code-block code-unspecified">// Where you initalize the Configuration singletion, add: - -TemplateConfiguration tcHTML = new TemplateConfiguration(); -tcHTML.setOutputFormat(HTMLOutputFormat.INSTANCE); - -cfg.setTemplateConfigurations( - new ConditionalTemplateConfigurationFactory( - new PathGlobMatcher("mail/**"), - tcHTML));</pre></div> - - <p>or if you are configuring FreeMarker from Java - <code class="inline-code">*.properties</code> file (the <code class="inline-code">\</code>-s - are required for the Java Properties file format only):</p> - - - -<div class="code-wrapper"><pre class="code-block code-unspecified">templateConfigurations = \ - ConditionalTemplateConfigurationFactory( \ - PathGlobMatcher("mail/**"), \ - TemplateConfiguration(outputFormat = HTMLOutputFormat()))</pre></div> - </li> - - <li> - <p>Let's say you want to associate templates with - <code class="inline-code">xml</code> file extension to the XML output format, - templates with <code class="inline-code">html</code> and <code class="inline-code">htm</code> - extension to the HTML output format, and templates with - <code class="inline-code">rtf</code> extension to the <code class="inline-code">RTF</code> - output format. You could achieve that like this (assuming that you - are getting the templates with - <code class="inline-code">cfg.getTemplate(<em class="code-color">...</em>)</code>, - and not instantiating them yourself):</p> - - - -<div class="code-wrapper"><pre class="code-block code-unspecified">TemplateConfiguration tcHTML = new TemplateConfiguration(); -tcHTML.setOutputFormat(HTMLOutputFormat.INSTANCE); - -TemplateConfiguration tcXML = new TemplateConfiguration(); -tcXML.setOutputFormat(XMLOutputFormat.INSTANCE); - -TemplateConfiguration tcRTF = new TemplateConfiguration(); -tcRTF.setOutputFormat(RTFOutputFormat.INSTANCE); - -cfg.setTemplateConfigurations( - new FirstMatchTemplateConfigurationFactory( - new ConditionalTemplateConfigurationFactory( - new FileExtensionMatcher("xml"), - tcXML), - new ConditionalTemplateConfigurationFactory( - new OrMatcher( - new FileExtensionMatcher("html"), - new FileExtensionMatcher("htm")), - tcHTML), - new ConditionalTemplateConfigurationFactory( - new FileExtensionMatcher("rtf"), - tcRTF) - ).allowNoMatch(true) -);</pre></div> - - <p>or if you are configuring FreeMarker from Java - <code class="inline-code">*.properties</code> file (the <code class="inline-code">\</code>-s - are required for the Java Properties file format only):</p> - - - -<div class="code-wrapper"><pre class="code-block code-unspecified">templateConfigurations = \ - FirstMatchTemplateConfigurationFactory( \ - ConditionalTemplateConfigurationFactory( \ - FileExtensionMatcher("xml"), \ - TemplateConfiguration(outputFormat = XMLOutputFormat())), \ - ConditionalTemplateConfigurationFactory( \ - OrMatcher( \ - FileExtensionMatcher("html"), \ - FileExtensionMatcher("htm")), \ - TemplateConfiguration(outputFormat = HTMLOutputFormat())), \ - ConditionalTemplateConfigurationFactory( \ - FileExtensionMatcher("rtf"), \ - TemplateConfiguration(outputFormat = RTFOutputFormat())), \ - allowNoMatch = true)</pre></div> - </li> - </ul><p>(You can find some more complex - <code class="inline-code">template_configurations</code> setups <a href="pgui_config_templateconfigurations.html">here...</a>)</p><div class="bottom-pagers-wrapper"><div class="pagers bottom"><a class="paging-arrow previous" href="pgui_config_templateconfigurations.html"><span>Previous</span></a><a class="paging-arrow next" href="pgui_config_custom_formats.html"><span>Next</span></a></div></div></div></div> </div> - </div> -<div class="site-footer"><div class="site-width"><div class="footer-top"><div class="col-left sitemap"><div class="column"><h3 class="column-header">Overview</h3><ul><li><a href="http://freemarker.org/">What is FreeMarker?</a></li><li><a href="http://freemarker.org/freemarkerdownload.html">Download</a></li><li><a href="app_versions.html">Version history</a></li><li><a href="http://freemarker.org/history.html">About us</a></li><li><a itemprop="license" href="app_license.html">License</a></li></ul></div><div class="column"><h3 class="column-header">Handy stuff</h3><ul><li><a href="http://freemarker-online.kenshoo.com/">Try template online</a></li><li><a href="dgui_template_exp.html#exp_cheatsheet">Expressions cheatsheet</a></li><li><a href="ref_directive_alphaidx.html">#directives</a></li><li><a href="ref_builtins_alphaidx.html">?built_ins</a></li><li><a href="ref_specvar.html">.special_vars</a></li></ul></div><div class="column"><h3 class="column-header">Community</h3><ul><li><a href ="https://github.com/freemarker/freemarker">FreeMarker on Github</a></li><li><a href="https://twitter.com/freemarker">Follow us on Twitter</a></li><li><a href="https://issues.apache.org/jira/browse/FREEMARKER/">Report a bug</a></li><li><a href="http://stackoverflow.com/questions/ask?tags=freemarker">Ask a question</a></li><li><a href="http://freemarker.org/mailing-lists.html">Mailing lists</a></li></ul></div></div><div class="col-right"><ul class="social-icons"><li><a class="github" href="https://github.com/freemarker/freemarker">Github</a></li><li><a class="twitter" href="https://twitter.com/freemarker">Twitter</a></li><li><a class="stack-overflow" href="http://stackoverflow.com/questions/ask?tags=freemarker">Stack Overflow</a></li></ul><a class="xxe" href="http://www.xmlmind.com/xmleditor/" rel="nofollow" title="Edited with XMLMind XML Editor"><span>Edited with XMLMind XML Editor</span></a></div></div><div class="footer-bottom"> <p class="last-generated"> -Last generated: -<time itemprop="dateModified" datetime="2017-03-13T10:55:28Z" title="Monday, March 13, 2017 10:55:28 AM GMT">2017-03-13 10:55:28 GMT</time>, for Freemarker 2.3.26 </p> -<p class="copyright"> -© <span itemprop="copyrightYear">1999</span>â2017 -<a itemtype="http://schema.org/Organization" itemprop="copyrightHolder" href="http://apache.org/">The Apache Software Foundation</a>. Apache FreeMarker, FreeMarker, Apache Incubator, Apache, the Apache FreeMarker logo are trademarks of The Apache Software Foundation. </p> -</div></div></div></body> -</html> http://git-wip-us.apache.org/repos/asf/incubator-freemarker-site/blob/a4004324/builds/2.3.26-nightly/pgui_config_settings.html ---------------------------------------------------------------------- diff --git a/builds/2.3.26-nightly/pgui_config_settings.html b/builds/2.3.26-nightly/pgui_config_settings.html deleted file mode 100644 index 322f062..0000000 --- a/builds/2.3.26-nightly/pgui_config_settings.html +++ /dev/null @@ -1,378 +0,0 @@ -<!doctype html> -<!-- Generated by FreeMarker/Docgen from DocBook --> -<html lang="en" class="page-type-section"> -<head prefix="og: http://ogp.me/ns#"> -<meta charset="utf-8"> -<title>Settings - Apache FreeMarker Manual</title> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<meta name="viewport" content="width=device-width,initial-scale=1"> -<meta name="format-detection" content="telephone=no"> -<meta property="og:site_name" content="Apache FreeMarker Manual"> -<meta property="og:title" content="Settings"> -<meta property="og:locale" content="en_US"> -<meta property="og:url" content="http://freemarker.org/docs/pgui_config_settings.html"> -<link rel="canonical" href="http://freemarker.org/docs/pgui_config_settings.html"> -<link rel="icon" href="favicon.png" type="image/png"> -<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Roboto:500,700,400,300|Droid+Sans+Mono"> -<link rel="stylesheet" type="text/css" href="docgen-resources/docgen.min.css?1489402528979"> -<script> -(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ -(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), -m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) -})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); -ga('create', 'UA-55420501-1', 'auto'); -ga('send', 'pageview'); -</script> -</head> -<body itemscope itemtype="https://schema.org/Code"> - <meta itemprop="url" content="http://freemarker.org/docs/"> - <meta itemprop="name" content="Apache FreeMarker Manual"> - - <!--[if lte IE 9]> - <div style="background-color: #C00; color: #fff; padding: 12px 24px;">Please use a modern browser to view this website.</div> - <![endif]--><div class="header-top-bg"><div class="site-width header-top"><a class="logo" href="http://freemarker.org" role="banner"> <img itemprop="image" src="logo.png" alt="FreeMarker"> -</a><ul class="tabs"><li><a href="http://freemarker.org/">Home</a></li><li class="current"><a href="index.html">Manual</a></li><li><a class="external" href="api/index.html">Java API</a></li></ul><ul class="secondary-tabs"><li><a class="tab icon-heart" href="http://freemarker.org/contribute.html" title="Contribute"><span>Contribute</span></a></li><li><a class="tab icon-bug" href="https://issues.apache.org/jira/browse/FREEMARKER/" title="Report a Bug"><span>Report a Bug</span></a></li><li><a class="tab icon-download" href="http://freemarker.org/freemarkerdownload.html" title="Download"><span>Download</span></a></li></ul></div></div><div class="header-bottom-bg"><div class="site-width search-row"><a href="index.html" class="navigation-header">Manual</a><div class="navigation-header"></div><form method="get" class="search-form" action="search-results.html"><fieldset><legend class="sr-only">Search form</legend><label for="search-field" class="sr-only">Search query</label><input id="searc h-field" name="q" type="search" class="search-input" placeholder="Search" spellcheck="false" autocorrect="off" autocomplete="off"><button type="submit" class="search-btn"><span class="sr-only">Search</span></button></fieldset></form></div><div class="site-width breadcrumb-row"><ul class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList"><li class="step-0" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="index.html"><span itemprop="name">Apache FreeMarker Manual</span></a></li><li class="step-1" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="pgui.html"><span itemprop="name">Programmer's Guide</span></a></li><li class="step-2" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="pgui_config.html"><span itemprop="name">The Configuration</span></a></li><li class="step-3" itempr op="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="pgui_config_settings.html"><span itemprop="name">Settings</span></a></li></ul><div class="bookmarks" title="Bookmarks"><span class="sr-only">Bookmarks:</span><ul class="bookmark-list"><li><a href="alphaidx.html">Alpha. index</a></li><li><a href="gloss.html">Glossary</a></li><li><a href="dgui_template_exp.html#exp_cheatsheet">Expressions</a></li><li><a href="ref_builtins_alphaidx.html">?builtins</a></li><li><a href="ref_directive_alphaidx.html">#directives</a></li><li><a href="ref_specvar.html">.spec_vars</a></li><li><a href="app_faq.html">FAQ</a></li></ul></div></div></div> <div class="main-content site-width"> - <div class="content-wrapper"> - <div id="table-of-contents-wrapper" class="col-left"> - <script>var breadcrumb = ["Apache FreeMarker Manual","Programmer\'s Guide","The Configuration","Settings"];</script> - <script src="toc.js?1489402528979"></script> - <script src="docgen-resources/main.min.js?1489402528979"></script> - </div> -<div class="col-right"><div class="page-content"><div class="page-title"><div class="pagers top"><a class="paging-arrow previous" href="pgui_config_sharedvariables.html"><span>Previous</span></a><a class="paging-arrow next" href="pgui_config_templateloading.html"><span>Next</span></a></div><div class="title-wrapper"> -<h1 class="content-header header-section1" id="pgui_config_settings" itemprop="headline">Settings</h1> -</div></div><p><strong>Settings</strong> are named values that - influence the behavior of FreeMarker. Examples of settings are: - <code class="inline-code">locale</code>, <code class="inline-code">number_format</code>, - <code class="inline-code">default_encoding</code>, - <code class="inline-code">template_exception_handler</code>. The full list of - settings can be found in the <a href="http://freemarker.org/docs/api/freemarker/template/Configuration.html#setSetting-java.lang.String-java.lang.String-">Java - API documentation of - <code>Configuration.setSetting(...)</code></a>.</p><p>The settings coming from the <code class="inline-code">Configuration</code> - can be overridden in a <code class="inline-code">Template</code> instance. For - example, if you set the <code class="inline-code">locale</code> setting to - <code class="inline-code">"en_US"</code> in the configuration, then the - <code class="inline-code">locale</code> in all templates that use this configuration - will be <code class="inline-code">"en_US"</code>, except in templates where the - <code class="inline-code">locale</code> was explicitly specified differently (see - <a href="ref_directive_include.html#ref_directive_include_localized">localization</a>). - Thus, the setting values in the <code class="inline-code">Configuration</code> serve - as defaults that can be overridden in a per template manner. The value - coming from the <code class="inline-code">Configuration</code> instance or - <code class="inline-code">Template</code> instance can be further overridden for a - single <code class="inline-code">Template.process</code> call. For each such call a - <code class="inline-code">freemarker.core.Environment</code> object is created - internally that holds the runtime environment of the template - processing, including the setting values that were overridden on that - level. The values stored there can even be changed during the template - processing, so a template can set settings itself, like switching - <code class="inline-code">locale</code> at the middle of the ongoing - processing.</p><p>This can be imagined as 3 layers - (<code class="inline-code">Configuration</code>, <code class="inline-code">Template</code>, - <code class="inline-code">Environment</code>) of settings, where the topmost layer - that contains the value for a certain setting provides the effective - value of that setting. For example (settings A to F are just imaginary - settings for this example):</p> <div class="table-responsive"> - <table class="table"> - - - - - - <thead> - <tr> - <th align="left"></th> - - - <th align="center">Setting A</th> - - - <th align="center">Setting B</th> - - - <th align="center">Setting C</th> - - - <th align="center">Setting D</th> - - - <th align="center">Setting E</th> - - - <th align="center">Setting F</th> - - </tr> - - </thead> - - - <tbody> - <tr> - <td align="left">Layer 3: <code class="inline-code">Environment</code></td> - - - <td align="center">1</td> - - - <td align="center">-</td> - - - <td align="center">-</td> - - - <td align="center">1</td> - - - <td align="center">-</td> - - - <td align="center">-</td> - - </tr> - - - <tr> - <td align="left">Layer 2: <code class="inline-code">Template</code></td> - - - <td align="center">2</td> - - - <td align="center">2</td> - - - <td align="center">-</td> - - - <td align="center">-</td> - - - <td align="center">2</td> - - - <td align="center">-</td> - - </tr> - - - <tr> - <td align="left">Layer 1: <code class="inline-code">Configuration</code></td> - - - <td align="center">3</td> - - - <td align="center">3</td> - - - <td align="center">3</td> - - - <td align="center">3</td> - - - <td align="center">-</td> - - - <td align="center">-</td> - - </tr> - - </tbody> - - </table> - </div> -<p>The effective value of settings will be: A = 1, B = 2, C = 3, D - = 1, E = 2. The F setting is probably <code class="inline-code">null</code>, or it - throws exception when you try to get it.</p><p>Let's see exactly how to set settings:</p><ul> - <li> - <p><code class="inline-code">Configuration</code> layer: In principle you set - the settings with the setter methods of the - <code class="inline-code">Configuration</code> object, fore example:</p> - - - -<div class="code-wrapper"><pre class="code-block code-unspecified">Configuration myCfg = new Configuration(Configuration.VERSION_2_3_25); -myCfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); -myCfg.setDefaultEncoding("UTF-8"); -DefaultObjectWrapperBuilder owb = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25); -owb.setForceLegacyNonListCollections(false); -owb.setDefaultDateType(TemplateDateModel.DATETIME); -myCfg.setObjectWrapper(owb.build());</pre></div> - - <p>You do this before you start to actually use the - <code class="inline-code">Configuration</code> object (typically, when you - initialize the application); you should treat the object as - read-only after that.</p> - - <p>In practice, in most frameworks you have to specify the - settings in some kind of framework-specific configuration file - that require specifying settings as <code class="inline-code">String</code> - name-value pairs (like in a <code class="inline-code">.properties</code> file). - In that case the authors of the frameworks most probably use the - <code class="inline-code">Confguration.setSetting(String name, String - value)</code> method; see available setting names and the - format of the values in the <a href="http://freemarker.org/docs/api/freemarker/template/Configuration.html#setSetting-java.lang.String-java.lang.String-">API - documentation of <code>setSetting</code></a>. Example for - Spring Framework:</p> - - - -<div class="code-wrapper"><pre class="code-block code-unspecified"><bean id="freemarkerConfig" - class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> - <property name="freemarkerSettings"> - <props> - <prop key="incompatible_improvements">2.3.25</prop> - <prop key="template_exception_handler">rethrow</prop> - <prop key="default_encoding">UTF-8</prop> - <prop key="object_wrapper"> - DefaultObjectWrapper( - 2.3.25, - forceLegacyNonListCollections = false, - defaultDateType = freemarker.template.TemplateDateModel.DATETIME) - </prop> - </props> - </property> -</bean></pre></div> - - <p>Here's the same when configuring FreeMarker for Struts, - which looks for a <code class="inline-code">freemarker.properties</code> in the - classpath:</p> - - - -<div class="code-wrapper"><pre class="code-block code-unspecified">incompatible_improvements=2.3.25 -template_exception_handler=rethrow -default_encoding=UTF-8 -object_wrapper=DefaultObjectWrapper( \ - 2.3.25, \ - forceLegacyNonListCollections = false, \ - defaultDateType = freemarker.template.TemplateDateModel.DATETIME)</pre></div> - - <p>As demonstrated above with - <code class="inline-code">object_wrapper</code>, some settings can accept quite - complex values, which can be used to instantiate objects of - arbitrary classes and set their properties. Still, configuring - with <code class="inline-code">String</code> key-value pairs is limited compared - to directly using the Java API, so in some cases you have to find - a way to do this in Java.</p> - </li> - - <li> - <p><code class="inline-code">Template</code> layer: Settings on individual - templates are normally set by <a href="pgui_config_templateconfigurations.html">template - configurations (see them in their own chapter)</a>, which - basically associate setting assignments to template name (template - path) patterns. There's a deviation from this approach with the - <code class="inline-code">locale</code> setting, because that you can also - specify to <code class="inline-code">Configuration.getTemplate(...)</code> as - parameter, to get the template for the requested locale (so called - localized lookup).</p> - - <div class="callout warning"> - <strong class="callout-label">Warning!</strong> - - <p>You should never set settings directly on the - <code class="inline-code">Template</code> object that you get from - <code class="inline-code">Configuration.getTemplate(...)</code>! Those objects - should be treated as already initialized and read-only.</p> - </div> - - - <p>When a template includes or imports another template, most - of the settings (like <code class="inline-code">locale</code>, - <code class="inline-code">number_format</code>, etc.) will remain those - specified by the top-level template. The exceptions are the - settings that affect the parsing of the template (like - <code class="inline-code">tag_syntax</code>, - <code class="inline-code">whitespace_stripping</code>, etc.), as these are not - inherited from the top-level template, instead each template - always uses its own values, no mater how it was invoked.</p> - - <div class="callout note"> - <strong class="callout-label">Note:</strong> - - <p>If you are going to use template layer settings, you - should set <a href="pgui_config_incompatible_improvements.html">the - <code>incompatible_improvements</code> setting</a> to - 2.3.22 or higher, to avoid some confusing legacy bugs.</p> - </div> - - </li> - - <li> - <p><code class="inline-code">Environment </code>layer: There are two ways of - doing it:</p> - - <ul> - <li> - <p>With Java API: Use the setter methods of the - <code class="inline-code">Environment</code> object. You may run into the - API problem that <code class="inline-code">myTemplate.process(...)</code> - both creates the <code class="inline-code">Environment</code> object - internally and processes the template, so you have no - opportunity to adjust the <code class="inline-code">Environment</code> in - between. The solution is that those two steps can be separated - like this:</p> - - - -<div class="code-wrapper"><pre class="code-block code-unspecified">Environment env = myTemplate.createProcessingEnvironment(root, out); -env.setLocale(java.util.Locale.ITALY); -env.setNumberFormat("0.####"); -env.process(); // process the template</pre></div> - </li> - - <li> - <p>Directly in the Template (considered as bad style, - usually): Use the <a href="ref_directive_setting.html#ref.directive.setting"><code>setting</code> - directive</a>, for example:</p> - - - -<div class="code-wrapper"><pre class="code-block code-template"><#setting locale="it_IT"> -<#setting number_format="0.####"></pre></div> - </li> - </ul> - - <p>There are no restriction regarding when can you change the - settings in this layer.</p> - </li> - </ul><p>To see the list of supported settings and their meaning, please - read the following parts of the FreeMarker Java API - documentation:</p><ul> - <li> - <p>Setter methods of - <code class="inline-code">freemarker.core.Configurable</code> for the settings - that are in all three layers</p> - </li> - - <li> - <p>Setter methods of - <code class="inline-code">freemarker.template.Configuration</code> for the - settings that are available only in the - <code class="inline-code">Configuration</code> layer</p> - </li> - - <li> - <p><code class="inline-code">freemarker.core.Configurable.setSetting(String, - String)</code> for settings that are available in all three - layers and are writable with <code class="inline-code">String</code> key-value - pairs.</p> - </li> - - <li> - <p><code class="inline-code">freemarker.template.Configuration.setSetting(String, - String)</code> for settings that are available only in the - <code class="inline-code">Configuration</code> layer and are writable with - <code class="inline-code">String</code> key-value pairs.</p> - </li> - </ul><div class="bottom-pagers-wrapper"><div class="pagers bottom"><a class="paging-arrow previous" href="pgui_config_sharedvariables.html"><span>Previous</span></a><a class="paging-arrow next" href="pgui_config_templateloading.html"><span>Next</span></a></div></div></div></div> </div> - </div> -<div class="site-footer"><div class="site-width"><div class="footer-top"><div class="col-left sitemap"><div class="column"><h3 class="column-header">Overview</h3><ul><li><a href="http://freemarker.org/">What is FreeMarker?</a></li><li><a href="http://freemarker.org/freemarkerdownload.html">Download</a></li><li><a href="app_versions.html">Version history</a></li><li><a href="http://freemarker.org/history.html">About us</a></li><li><a itemprop="license" href="app_license.html">License</a></li></ul></div><div class="column"><h3 class="column-header">Handy stuff</h3><ul><li><a href="http://freemarker-online.kenshoo.com/">Try template online</a></li><li><a href="dgui_template_exp.html#exp_cheatsheet">Expressions cheatsheet</a></li><li><a href="ref_directive_alphaidx.html">#directives</a></li><li><a href="ref_builtins_alphaidx.html">?built_ins</a></li><li><a href="ref_specvar.html">.special_vars</a></li></ul></div><div class="column"><h3 class="column-header">Community</h3><ul><li><a href ="https://github.com/freemarker/freemarker">FreeMarker on Github</a></li><li><a href="https://twitter.com/freemarker">Follow us on Twitter</a></li><li><a href="https://issues.apache.org/jira/browse/FREEMARKER/">Report a bug</a></li><li><a href="http://stackoverflow.com/questions/ask?tags=freemarker">Ask a question</a></li><li><a href="http://freemarker.org/mailing-lists.html">Mailing lists</a></li></ul></div></div><div class="col-right"><ul class="social-icons"><li><a class="github" href="https://github.com/freemarker/freemarker">Github</a></li><li><a class="twitter" href="https://twitter.com/freemarker">Twitter</a></li><li><a class="stack-overflow" href="http://stackoverflow.com/questions/ask?tags=freemarker">Stack Overflow</a></li></ul><a class="xxe" href="http://www.xmlmind.com/xmleditor/" rel="nofollow" title="Edited with XMLMind XML Editor"><span>Edited with XMLMind XML Editor</span></a></div></div><div class="footer-bottom"> <p class="last-generated"> -Last generated: -<time itemprop="dateModified" datetime="2017-03-13T10:55:28Z" title="Monday, March 13, 2017 10:55:28 AM GMT">2017-03-13 10:55:28 GMT</time>, for Freemarker 2.3.26 </p> -<p class="copyright"> -© <span itemprop="copyrightYear">1999</span>â2017 -<a itemtype="http://schema.org/Organization" itemprop="copyrightHolder" href="http://apache.org/">The Apache Software Foundation</a>. Apache FreeMarker, FreeMarker, Apache Incubator, Apache, the Apache FreeMarker logo are trademarks of The Apache Software Foundation. </p> -</div></div></div></body> -</html>
