Repository: incubator-freemarker Updated Branches: refs/heads/3 053afbf5d -> ad539de9e
Renamed ParserConfiguration.encoding (ParserConfiguration.defaultEncoding in FM2) to sourceEncoding. Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/ad539de9 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/ad539de9 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/ad539de9 Branch: refs/heads/3 Commit: ad539de9e2da9e629165d85ee2d32a9f69f4d068 Parents: 053afbf Author: ddekany <[email protected]> Authored: Mon Mar 27 19:59:00 2017 +0200 Committer: ddekany <[email protected]> Committed: Mon Mar 27 19:59:00 2017 +0200 ---------------------------------------------------------------------- .../apache/freemarker/core/Configuration.java | 32 ++++++------- .../MutableProcessingAndParseConfiguration.java | 21 ++++---- .../freemarker/core/ParserConfiguration.java | 2 +- .../org/apache/freemarker/core/Template.java | 50 +++++++++----------- .../freemarker/core/TemplateConfiguration.java | 33 +++++++------ ..._ParserConfigurationWithInheritedFormat.java | 5 +- .../templateresolver/TemplateLoadingResult.java | 2 +- .../impl/DefaultTemplateResolver.java | 2 +- .../freemarker/servlet/FreemarkerServlet.java | 10 ++-- src/main/javacc/FTL.jj | 10 ++-- src/manual/en_US/FM3-CHANGE-LOG.txt | 5 +- .../freemarker/core/ConfigurationTest.java | 40 ++++++++-------- .../freemarker/core/EncodingOverrideTest.java | 6 +-- .../core/ObjectBuilderSettingsTest.java | 6 +-- .../core/TemplateConfigurationTest.java | 37 ++++++--------- ...igurationWithDefaltTemplateResolverTest.java | 14 +++--- .../core/TemplateConstructorsTest.java | 14 +++--- .../core/TemplateGetEncodingTest.java | 12 ++--- .../DefaultTemplateResolverTest.java | 6 +-- .../TemplateConfigurationExamples.java | 16 +++---- .../servlet/FreemarkerServletTest.java | 4 +- .../TemplateConfigurationExamples1.properties | 2 +- .../TemplateConfigurationExamples3.properties | 2 +- .../servlet/jsp/webapps/basic/WEB-INF/web.xml | 4 +- .../jsp/webapps/multipleLoaders/WEB-INF/web.xml | 2 +- .../jsp/webapps/tldDiscovery/WEB-INF/web.xml | 4 +- .../org/apache/freemarker/test/servlet/web.xml | 2 +- 27 files changed, 164 insertions(+), 179 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/main/java/org/apache/freemarker/core/Configuration.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/Configuration.java b/src/main/java/org/apache/freemarker/core/Configuration.java index 0e76d09..826e2d0 100644 --- a/src/main/java/org/apache/freemarker/core/Configuration.java +++ b/src/main/java/org/apache/freemarker/core/Configuration.java @@ -146,11 +146,11 @@ public final class Configuration extends MutableProcessingConfiguration<Configur private static final String VERSION_PROPERTIES_PATH = "org/apache/freemarker/core/version.properties"; /** Legacy, snake case ({@code like_this}) variation of the setting name. @since 2.3.23 */ - public static final String ENCODING_KEY_SNAKE_CASE = "encoding"; + public static final String SOURCE_ENCODING_KEY_SNAKE_CASE = "source_encoding"; /** Modern, camel case ({@code likeThis}) variation of the setting name. @since 2.3.23 */ - public static final String ENCODING_KEY_CAMEL_CASE = "encoding"; + public static final String SOURCE_ENCODING_KEY_CAMEL_CASE = "sourceEncoding"; /** Alias to the {@code ..._SNAKE_CASE} variation due to backward compatibility constraints. */ - public static final String ENCODING_KEY = ENCODING_KEY_SNAKE_CASE; + public static final String SOURCE_ENCODING_KEY = SOURCE_ENCODING_KEY_SNAKE_CASE; /** Legacy, snake case ({@code like_this}) variation of the setting name. @since 2.3.23 */ public static final String LOCALIZED_LOOKUP_KEY_SNAKE_CASE = "localized_lookup"; @@ -283,13 +283,13 @@ public final class Configuration extends MutableProcessingConfiguration<Configur // Must be sorted alphabetically! AUTO_ESCAPING_POLICY_KEY_SNAKE_CASE, CACHE_STORAGE_KEY_SNAKE_CASE, - ENCODING_KEY_SNAKE_CASE, INCOMPATIBLE_IMPROVEMENTS_KEY_SNAKE_CASE, LOCALIZED_LOOKUP_KEY_SNAKE_CASE, NAMING_CONVENTION_KEY_SNAKE_CASE, OUTPUT_FORMAT_KEY_SNAKE_CASE, RECOGNIZE_STANDARD_FILE_EXTENSIONS_KEY_SNAKE_CASE, REGISTERED_CUSTOM_OUTPUT_FORMATS_KEY_SNAKE_CASE, + SOURCE_ENCODING_KEY_SNAKE_CASE, TAB_SIZE_KEY_SNAKE_CASE, TAG_SYNTAX_KEY_SNAKE_CASE, TEMPLATE_CONFIGURATIONS_KEY_SNAKE_CASE, @@ -305,13 +305,13 @@ public final class Configuration extends MutableProcessingConfiguration<Configur // Must be sorted alphabetically! AUTO_ESCAPING_POLICY_KEY_CAMEL_CASE, CACHE_STORAGE_KEY_CAMEL_CASE, - ENCODING_KEY_CAMEL_CASE, INCOMPATIBLE_IMPROVEMENTS_KEY_CAMEL_CASE, LOCALIZED_LOOKUP_KEY_CAMEL_CASE, NAMING_CONVENTION_KEY_CAMEL_CASE, OUTPUT_FORMAT_KEY_CAMEL_CASE, RECOGNIZE_STANDARD_FILE_EXTENSIONS_KEY_CAMEL_CASE, REGISTERED_CUSTOM_OUTPUT_FORMATS_KEY_CAMEL_CASE, + SOURCE_ENCODING_KEY_CAMEL_CASE, TAB_SIZE_KEY_CAMEL_CASE, TAG_SYNTAX_KEY_CAMEL_CASE, TEMPLATE_CONFIGURATIONS_KEY_CAMEL_CASE, @@ -442,7 +442,7 @@ public final class Configuration extends MutableProcessingConfiguration<Configur */ private HashMap<String, Object> rewrappableSharedVariables = null; - private String encoding = getDefaultEncoding(); + private String encoding = getDefaultSourceEncoding(); /** * @deprecated Use {@link #Configuration(Version)} instead. Note that the version can be still modified later with @@ -2047,8 +2047,7 @@ public final class Configuration extends MutableProcessingConfiguration<Configur defaultEncodingExplicitlySet = true; } - @Override - public String getEncoding() { + public String getSourceEncoding() { return encoding; } @@ -2059,7 +2058,7 @@ public final class Configuration extends MutableProcessingConfiguration<Configur */ public void unsetDefaultEncoding() { if (defaultEncodingExplicitlySet) { - setEncoding(getDefaultEncoding()); + setEncoding(getDefaultSourceEncoding()); defaultEncodingExplicitlySet = false; } } @@ -2074,7 +2073,7 @@ public final class Configuration extends MutableProcessingConfiguration<Configur return defaultEncodingExplicitlySet; } - static private String getDefaultEncoding() { + static private String getDefaultSourceEncoding() { return getJVMDefaultEncoding(); } @@ -2301,10 +2300,10 @@ public final class Configuration extends MutableProcessingConfiguration<Configur if ("TemplateUpdateInterval".equalsIgnoreCase(name)) { name = TEMPLATE_UPDATE_DELAY_KEY; } else if ("DefaultEncoding".equalsIgnoreCase(name)) { - name = ENCODING_KEY; + name = SOURCE_ENCODING_KEY; } - if (ENCODING_KEY_SNAKE_CASE.equals(name) || ENCODING_KEY_CAMEL_CASE.equals(name)) { + if (SOURCE_ENCODING_KEY_SNAKE_CASE.equals(name) || SOURCE_ENCODING_KEY_CAMEL_CASE.equals(name)) { if (JVM_DEFAULT_VALUE.equalsIgnoreCase(value)) { setEncoding(getJVMDefaultEncoding()); } else { @@ -2534,12 +2533,13 @@ public final class Configuration extends MutableProcessingConfiguration<Configur @Override protected String getCorrectedNameForUnknownSetting(String name) { - if ("encoding".equals(name) || "charset".equals(name) || "default_charset".equals(name)) { + if ("encoding".equals(name) || "default_encoding".equals(name) || "charset".equals(name) || "default_charset" + .equals(name)) { // [2.4] Default might changes to camel-case - return ENCODING_KEY; + return SOURCE_ENCODING_KEY; } - if ("defaultCharset".equals(name)) { - return ENCODING_KEY_CAMEL_CASE; + if ("defaultEncoding".equals(name) || "defaultCharset".equals(name)) { + return SOURCE_ENCODING_KEY_CAMEL_CASE; } if (name.equals("incompatible_enhancements")) { return INCOMPATIBLE_IMPROVEMENTS_KEY_SNAKE_CASE; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/main/java/org/apache/freemarker/core/MutableProcessingAndParseConfiguration.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/MutableProcessingAndParseConfiguration.java b/src/main/java/org/apache/freemarker/core/MutableProcessingAndParseConfiguration.java index 2324dce..4d7a1e1 100644 --- a/src/main/java/org/apache/freemarker/core/MutableProcessingAndParseConfiguration.java +++ b/src/main/java/org/apache/freemarker/core/MutableProcessingAndParseConfiguration.java @@ -38,7 +38,7 @@ public abstract class MutableProcessingAndParseConfiguration< private Integer autoEscapingPolicy; private Boolean recognizeStandardFileExtensions; private OutputFormat outputFormat; - private String encoding; + private String sourceEncoding; private Integer tabSize; protected MutableProcessingAndParseConfiguration(Version incompatibleImprovements) { @@ -227,24 +227,23 @@ public abstract class MutableProcessingAndParseConfiguration< return recognizeStandardFileExtensions != null; } - @Override - public String getEncoding() { - return encoding != null ? encoding : getDefaultEncoding(); + public String getSourceEncoding() { + return sourceEncoding != null ? sourceEncoding : getDefaultSourceEncoding(); } - protected abstract String getDefaultEncoding(); + protected abstract String getDefaultSourceEncoding(); /** * The charset to be used when reading the template "file" that the {@link TemplateLoader} returns as binary - * ({@link InputStream}). If the {@code #ftl} header sepcifies an encoding, that will override this. + * ({@link InputStream}). If the {@code #ftl} header specifies an charset, that will override this. */ - public void setEncoding(String encoding) { - _NullArgumentException.check("encoding", encoding); - this.encoding = encoding; + public void setSourceEncoding(String sourceEncoding) { + _NullArgumentException.check("sourceEncoding", sourceEncoding); + this.sourceEncoding = sourceEncoding; } - public boolean isEncodingSet() { - return encoding != null; + public boolean isSourceEncodingSet() { + return sourceEncoding != null; } /** http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/main/java/org/apache/freemarker/core/ParserConfiguration.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ParserConfiguration.java b/src/main/java/org/apache/freemarker/core/ParserConfiguration.java index 7b4b887..a620506 100644 --- a/src/main/java/org/apache/freemarker/core/ParserConfiguration.java +++ b/src/main/java/org/apache/freemarker/core/ParserConfiguration.java @@ -144,6 +144,6 @@ public interface ParserConfiguration { * reading template files in a locale for which no explicit encoding * was specified. Defaults to the default system encoding. */ - String getEncoding(); + String getSourceEncoding(); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/main/java/org/apache/freemarker/core/Template.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/Template.java b/src/main/java/org/apache/freemarker/core/Template.java index 77b5b2d..e4c3669 100644 --- a/src/main/java/org/apache/freemarker/core/Template.java +++ b/src/main/java/org/apache/freemarker/core/Template.java @@ -82,7 +82,7 @@ public class Template extends MutableProcessingConfiguration<Template> implement private Map macros = new HashMap(); private List imports = new Vector(); private ASTElement rootElement; - private String encoding, defaultNS; + private String sourceEncoding, defaultNS; private Serializable customLookupCondition; private int actualTagSyntax; private int actualNamingConvention; @@ -131,7 +131,7 @@ public class Template extends MutableProcessingConfiguration<Template> implement /** * Convenience constructor for {@link #Template(String, String, Reader, Configuration, String) Template(name, null, - * reader, cfg, encoding)}. + * reader, cfg, sourceEncoding)}. */ public Template(String name, Reader reader, Configuration cfg, String encoding) throws IOException { this(name, null, reader, cfg, encoding); @@ -175,24 +175,20 @@ public class Template extends MutableProcessingConfiguration<Template> implement } /** - * Same as {@link #Template(String, String, Reader, Configuration)}, but also specifies the template's encoding (not - * recommended). + * Same as {@link #Template(String, String, Reader, Configuration)}, but also specifies the template's source + * encoding. * - * @param encoding - * This is the encoding that we are supposed to be using. At the first glance it's unnecessary because we - * already have a {@link Reader} (so decoding with the charset has already happened), however, if this is - * non-{@code null} and there's an {@code #ftl} header with {@code encoding} parameter, they must match, - * or else a {@link WrongTemplateCharsetException} is thrown. Thus, it should be set if to decode the template, - * we were using an encoding (a charset), otherwise it should be {@code null}. It's also kept as - * meta-info (returned by {@link #getEncoding()}). It also has an impact when {@code #include}-ing or - * {@code #import}-ing another template from this template, as its default encoding will be this. But - * this behavior of said directives is considered to be harmful, and will be probably phased out. + * @param sourceEncoding + * This is the charset that was used to read the template. This can be {@code null} if the template + * was loaded from a source that returns it already as text. If this is not {@code null} and there's an + * {@code #ftl} header with {@code encoding} parameter, they must match, or else a + * {@link WrongTemplateCharsetException} is thrown. * * @since 2.3.22 */ public Template( - String name, String sourceName, Reader reader, Configuration cfg, String encoding) throws IOException { - this(name, sourceName, reader, cfg, null, encoding); + String name, String sourceName, Reader reader, Configuration cfg, String sourceEncoding) throws IOException { + this(name, sourceName, reader, cfg, null, sourceEncoding); } /** @@ -239,10 +235,10 @@ public class Template extends MutableProcessingConfiguration<Template> implement public Template( String name, String sourceName, Reader reader, Configuration cfg, ParserConfiguration customParserConfiguration, - String encoding, InputStream streamToUnmarkWhenEncEstabd) throws IOException, ParseException { + String sourceEncoding, InputStream streamToUnmarkWhenEncEstabd) throws IOException, ParseException { this(name, sourceName, cfg, customParserConfiguration); - setEncoding(encoding); + setSourceEncoding(sourceEncoding); LineTableBuilder ltbReader; try { ParserConfiguration actualParserConfiguration = getParserConfiguration(); @@ -310,11 +306,11 @@ public class Template extends MutableProcessingConfiguration<Template> implement * @param config * the configuration to which this template belongs * - * @param encoding + * @param sourceEncoding * @since 2.3.22 */ static public Template createPlainTextTemplate(String name, String sourceName, String content, Configuration config, - String encoding) { + String sourceEncoding) { Template template; try { template = new Template(name, sourceName, new StringReader("X"), config); @@ -322,7 +318,7 @@ public class Template extends MutableProcessingConfiguration<Template> implement throw new BugException("Plain text template creation failed", e); } ((ASTStaticText) template.rootElement).replaceText(content); - template.setEncoding(encoding); + template.setSourceEncoding(sourceEncoding); _DebuggerService.registerTemplate(template); @@ -572,20 +568,20 @@ public class Template extends MutableProcessingConfiguration<Template> implement } /** - * @param encoding - * The encoding that was used to read this template, or {@code null} if the source of the template + * @param sourceEncoding + * The sourceEncoding that was used to read this template, or {@code null} if the source of the template * already gives back text (as opposed to binary data), so no decoding with a charset was needed. */ - void setEncoding(String encoding) { - this.encoding = encoding; + void setSourceEncoding(String sourceEncoding) { + this.sourceEncoding = sourceEncoding; } /** - * The encoding that was used to read this template, or {@code null} if the source of the template + * The sourceEncoding that was used to read this template, or {@code null} if the source of the template * already gives back text (as opposed to binary data), so no decoding with a charset was needed. */ - public String getEncoding() { - return encoding; + public String getSourceEncoding() { + return sourceEncoding; } /** http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/main/java/org/apache/freemarker/core/TemplateConfiguration.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/TemplateConfiguration.java b/src/main/java/org/apache/freemarker/core/TemplateConfiguration.java index 3be8b3e..8b4300f 100644 --- a/src/main/java/org/apache/freemarker/core/TemplateConfiguration.java +++ b/src/main/java/org/apache/freemarker/core/TemplateConfiguration.java @@ -47,7 +47,7 @@ import org.apache.freemarker.core.valueformat.TemplateNumberFormatFactory; * already found. * * <p> - * Note on the encoding setting {@code encoding}: See {@link #setEncoding(String)}. + * Note on the sourceEncoding setting {@code sourceEncoding}: See {@link #setSourceEncoding(String)}. * * <p> * Note that the result value of the reader methods (getter and "is" methods) is usually not useful unless the value of @@ -87,7 +87,7 @@ public final class TemplateConfiguration extends MutableProcessingConfiguration< private Integer autoEscapingPolicy; private Boolean recognizeStandardFileExtensions; private OutputFormat outputFormat; - private String encoding; + private String sourceEncoding; private Integer tabSize; /** @@ -187,8 +187,8 @@ public final class TemplateConfiguration extends MutableProcessingConfiguration< if (tc.isDateTimeFormatSet()) { setDateTimeFormat(tc.getDateTimeFormat()); } - if (tc.isEncodingSet()) { - setEncoding(tc.getEncoding()); + if (tc.isSourceEncodingSet()) { + setSourceEncoding(tc.getSourceEncoding()); } if (tc.isLocaleSet()) { setLocale(tc.getLocale()); @@ -284,8 +284,8 @@ public final class TemplateConfiguration extends MutableProcessingConfiguration< * point via the {@link ParserConfiguration}. * * <p> - * Note that the {@code encoding} setting of the {@link Template} counts as unset if it's {@code null}, - * even if {@code null} was set via {@link Template#setEncoding(String)}. + * Note that the {@code sourceEncoding} setting of the {@link Template} counts as unset if it's {@code null}, + * even if {@code null} was set via {@link Template#setSourceEncoding(String)}. * * @throws IllegalStateException * If the parent configuration wasn't yet set. @@ -330,8 +330,8 @@ public final class TemplateConfiguration extends MutableProcessingConfiguration< if (isDateTimeFormatSet() && !template.isDateTimeFormatSet()) { template.setDateTimeFormat(getDateTimeFormat()); } - if (isEncodingSet() && template.getEncoding() == null) { - template.setEncoding(getEncoding()); + if (isSourceEncodingSet() && template.getSourceEncoding() == null) { + template.setSourceEncoding(getSourceEncoding()); } if (isLocaleSet() && !template.isLocaleSet()) { template.setLocale(getLocale()); @@ -558,9 +558,8 @@ public final class TemplateConfiguration extends MutableProcessingConfiguration< return recognizeStandardFileExtensions != null; } - @Override - public String getEncoding() { - return encoding != null ? encoding : getNonNullParentConfiguration().getEncoding(); + public String getSourceEncoding() { + return sourceEncoding != null ? sourceEncoding : getNonNullParentConfiguration().getSourceEncoding(); } /** @@ -570,15 +569,15 @@ public final class TemplateConfiguration extends MutableProcessingConfiguration< * <p> * If you are developing your own template loading/caching mechanism instead of the standard one, note that the * above behavior is not guaranteed by this class alone; you have to ensure it. Also, read the note on - * {@code encoding} in the documentation of {@link #apply(Template)}. + * {@code sourceEncoding} in the documentation of {@link #apply(Template)}. */ - public void setEncoding(String encoding) { - _NullArgumentException.check("encoding", encoding); - this.encoding = encoding; + public void setSourceEncoding(String sourceEncoding) { + _NullArgumentException.check("sourceEncoding", sourceEncoding); + this.sourceEncoding = sourceEncoding; } - public boolean isEncodingSet() { - return encoding != null; + public boolean isSourceEncodingSet() { + return sourceEncoding != null; } /** http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/main/java/org/apache/freemarker/core/_ParserConfigurationWithInheritedFormat.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/_ParserConfigurationWithInheritedFormat.java b/src/main/java/org/apache/freemarker/core/_ParserConfigurationWithInheritedFormat.java index e709862..78acde4 100644 --- a/src/main/java/org/apache/freemarker/core/_ParserConfigurationWithInheritedFormat.java +++ b/src/main/java/org/apache/freemarker/core/_ParserConfigurationWithInheritedFormat.java @@ -127,9 +127,8 @@ public final class _ParserConfigurationWithInheritedFormat implements ParserConf return wrappedPCfg.isTabSizeSet(); } - @Override - public String getEncoding() { - return wrappedPCfg.getEncoding(); + public String getSourceEncoding() { + return wrappedPCfg.getSourceEncoding(); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/main/java/org/apache/freemarker/core/templateresolver/TemplateLoadingResult.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/templateresolver/TemplateLoadingResult.java b/src/main/java/org/apache/freemarker/core/templateresolver/TemplateLoadingResult.java index d937806..6bed700 100644 --- a/src/main/java/org/apache/freemarker/core/templateresolver/TemplateLoadingResult.java +++ b/src/main/java/org/apache/freemarker/core/templateresolver/TemplateLoadingResult.java @@ -94,7 +94,7 @@ public final class TemplateLoadingResult { * @param templateConfiguration * Usually {@code null}, as usually the backing storage mechanism doesn't store such information; see * {@link #getTemplateConfiguration()}. The most probable application is supplying the charset (encoding) - * used by the {@link InputStream} (via {@link TemplateConfiguration#setEncoding(String)}), but only + * used by the {@link InputStream} (via {@link TemplateConfiguration#setSourceEncoding(String)}), but only * do that if the storage mechanism really knows what the charset is. */ public TemplateLoadingResult(TemplateLoadingSource source, Serializable version, InputStream inputStream, http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/main/java/org/apache/freemarker/core/templateresolver/impl/DefaultTemplateResolver.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/templateresolver/impl/DefaultTemplateResolver.java b/src/main/java/org/apache/freemarker/core/templateresolver/impl/DefaultTemplateResolver.java index 4436874..666ef58 100644 --- a/src/main/java/org/apache/freemarker/core/templateresolver/impl/DefaultTemplateResolver.java +++ b/src/main/java/org/apache/freemarker/core/templateresolver/impl/DefaultTemplateResolver.java @@ -551,7 +551,7 @@ public class DefaultTemplateResolver extends TemplateResolver { if (tc != null && tc.isLocaleSet()) { locale = tc.getLocale(); } - String initialEncoding = tc != null ? tc.getEncoding() : config.getEncoding(); + String initialEncoding = tc != null ? tc.getSourceEncoding() : config.getSourceEncoding(); TemplateLanguage templateLanguage = tc != null ? tc.getTemplateLanguage() : config .getTemplateLanguage(); Template template; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/main/java/org/apache/freemarker/servlet/FreemarkerServlet.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/servlet/FreemarkerServlet.java b/src/main/java/org/apache/freemarker/servlet/FreemarkerServlet.java index 48fcde5..5260b86 100644 --- a/src/main/java/org/apache/freemarker/servlet/FreemarkerServlet.java +++ b/src/main/java/org/apache/freemarker/servlet/FreemarkerServlet.java @@ -204,7 +204,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; * response by adding it to the response content type via calling {@link HttpServletResponse#setContentType(String)} (as * that was the only way before Servlet 2.4), not via the more modern * {@link HttpServletResponse#setCharacterEncoding(String)} method. Note that the charset of a template usually comes - * from {@link Configuration#getEncoding()} (i.e., from the {@code encoding} FreeMarker setting), + * from {@link Configuration#getSourceEncoding()} (i.e., from the {@code encoding} FreeMarker setting), * or occasionally from {@link Configuration#getTemplateConfigurations()} (when FreeMarker was * configured to use a specific charset for certain templates). * <li>{@value #INIT_PARAM_VALUE_FROM_TEMPLATE}: This should be used in most applications, but it's not the default for @@ -627,9 +627,9 @@ public class FreemarkerServlet extends HttpServlet { || name.equals(Configuration.INCOMPATIBLE_IMPROVEMENTS_KEY)) { // ignore: we have already processed these } else if (name.equals(DEPR_INITPARAM_ENCODING)) { // BC - if (getInitParameter(Configuration.ENCODING_KEY) != null) { + if (getInitParameter(Configuration.SOURCE_ENCODING_KEY) != null) { throw new ConflictingInitParamsException( - Configuration.ENCODING_KEY, DEPR_INITPARAM_ENCODING); + Configuration.SOURCE_ENCODING_KEY, DEPR_INITPARAM_ENCODING); } config.setEncoding(value); } else if (name.equals(DEPR_INITPARAM_TEMPLATE_DELAY)) { // BC @@ -920,9 +920,9 @@ public class FreemarkerServlet extends HttpServlet { private String getOutputEncodingForTemplate(Template template) { String outputEncoding = responseCharacterEncoding == ResponseCharacterEncoding.LEGACY ? null : template.getOutputEncoding(); - // [FM3] Don't use template.getEncoding() here; it might can't encode the dynamic values inserted. + // [FM3] Don't use template.getSourceEncoding() here; it might can't encode the dynamic values inserted. return outputEncoding != null ? outputEncoding - : template.getEncoding() != null ? template.getEncoding() + : template.getSourceEncoding() != null ? template.getSourceEncoding() : StandardCharsets.UTF_8.name(); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/main/javacc/FTL.jj ---------------------------------------------------------------------- diff --git a/src/main/javacc/FTL.jj b/src/main/javacc/FTL.jj index ac20322..8af611e 100644 --- a/src/main/javacc/FTL.jj +++ b/src/main/javacc/FTL.jj @@ -3887,13 +3887,13 @@ void HeaderElement() : } catch (TemplateModelException tme) {} } if (template != null) { - if (ks.equalsIgnoreCase("encoding")) { + if (ks.equalsIgnoreCase("sourceEncoding")) { if (vs == null) { throw new ParseException("Expected a string constant for \"" + ks + "\".", exp); } - if (template.getEncoding() != null && vs != null - && !template.getEncoding().equalsIgnoreCase(vs)) { - throw new WrongTemplateCharsetException(vs, template.getEncoding()); + if (template.getSourceEncoding() != null && vs != null + && !template.getSourceEncoding().equalsIgnoreCase(vs)) { + throw new WrongTemplateCharsetException(vs, template.getSourceEncoding()); } // There will be no WrongTemplateCharsetException exception, release mark buffer: if (streamToUnmarkWhenEncEstabd != null) { @@ -3965,7 +3965,7 @@ void HeaderElement() : } } else { String correctName; - if (ks.equals("charset")) { + if (ks.equals("charset") || ks.equals("source_encoding") || ks.equals("sourceEncoding")) { correctName = "encoding"; } else if (ks.equals("xmlns")) { // [2.4] If camel case will be the default, update this http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/manual/en_US/FM3-CHANGE-LOG.txt ---------------------------------------------------------------------- diff --git a/src/manual/en_US/FM3-CHANGE-LOG.txt b/src/manual/en_US/FM3-CHANGE-LOG.txt index 9a149b3..bcab8e5 100644 --- a/src/manual/en_US/FM3-CHANGE-LOG.txt +++ b/src/manual/en_US/FM3-CHANGE-LOG.txt @@ -184,5 +184,6 @@ the FreeMarer 3 changelog here: - Added ProcessingConfiguration interface for the read-only access of template processing settings. This is similar to the already existing (in FM2) ParserConfiguration interface. - Renamed Configurable to MutableProcessingAndParserConfiguration. Made it abstract too. - - Renamed Configuration.defaultEncoding to encoding, also added encoding ParserConfiguration. Before this, defaultEncoding was exclusive - to Configuration, but now it's like any other ParserConfiguration setting. \ No newline at end of file + - Renamed Configuration.defaultEncoding to sourceEncoding, also added sourceEncoding to ParserConfiguration, and renamed + TemplateConfiguration.encoding and Template.encoding to sourceEncoding. (Before this, defaultEncoding was exclusive + to Configuration, but now it's like any other ParserConfiguration setting that can be overidden on the 3 levels.) http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/test/java/org/apache/freemarker/core/ConfigurationTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ConfigurationTest.java b/src/test/java/org/apache/freemarker/core/ConfigurationTest.java index c7e3636..c62b078 100644 --- a/src/test/java/org/apache/freemarker/core/ConfigurationTest.java +++ b/src/test/java/org/apache/freemarker/core/ConfigurationTest.java @@ -262,7 +262,7 @@ public class ConfigurationTest extends TestCase { cfg.setEncoding(latin1); TemplateConfiguration huTC = new TemplateConfiguration(); - huTC.setEncoding(latin2); + huTC.setSourceEncoding(latin2); cfg.setTemplateConfigurations( new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*_hu.*"), huTC)); @@ -281,7 +281,7 @@ public class ConfigurationTest extends TestCase { assertEquals(tFtl, t.getSourceName()); assertEquals(Locale.GERMAN, t.getLocale()); assertNull(t.getCustomLookupCondition()); - assertEquals(latin1, t.getEncoding()); + assertEquals(latin1, t.getSourceEncoding()); } { Template t = cfg.getTemplate(tUtf8Ftl); @@ -289,7 +289,7 @@ public class ConfigurationTest extends TestCase { assertEquals(tUtf8Ftl, t.getSourceName()); assertEquals(Locale.GERMAN, t.getLocale()); assertNull(t.getCustomLookupCondition()); - assertEquals(utf8, t.getEncoding()); + assertEquals(utf8, t.getSourceEncoding()); } // 2 args: @@ -299,7 +299,7 @@ public class ConfigurationTest extends TestCase { assertEquals(tFtl, t.getSourceName()); assertEquals(Locale.GERMAN, t.getLocale()); assertNull(t.getCustomLookupCondition()); - assertEquals(latin1, t.getEncoding()); + assertEquals(latin1, t.getSourceEncoding()); } { Template t = cfg.getTemplate(tFtl, (Locale) null); @@ -307,7 +307,7 @@ public class ConfigurationTest extends TestCase { assertEquals(tFtl, t.getSourceName()); assertEquals(Locale.GERMAN, t.getLocale()); assertNull(t.getCustomLookupCondition()); - assertEquals(latin1, t.getEncoding()); + assertEquals(latin1, t.getSourceEncoding()); } { Template t = cfg.getTemplate(tFtl, Locale.US); @@ -315,7 +315,7 @@ public class ConfigurationTest extends TestCase { assertEquals(tEnFtl, t.getSourceName()); assertEquals(Locale.US, t.getLocale()); assertNull(t.getCustomLookupCondition()); - assertEquals(latin1, t.getEncoding()); + assertEquals(latin1, t.getSourceEncoding()); } { Template t = cfg.getTemplate(tUtf8Ftl, Locale.US); @@ -323,7 +323,7 @@ public class ConfigurationTest extends TestCase { assertEquals(tUtf8Ftl, t.getSourceName()); assertEquals(Locale.US, t.getLocale()); assertNull(t.getCustomLookupCondition()); - assertEquals(utf8, t.getEncoding()); + assertEquals(utf8, t.getSourceEncoding()); } { Template t = cfg.getTemplate(tFtl, hu); @@ -331,7 +331,7 @@ public class ConfigurationTest extends TestCase { assertEquals(tHuFtl, t.getSourceName()); assertEquals(hu, t.getLocale()); assertNull(t.getCustomLookupCondition()); - assertEquals(latin2, t.getEncoding()); + assertEquals(latin2, t.getSourceEncoding()); } { Template t = cfg.getTemplate(tUtf8Ftl, hu); @@ -339,7 +339,7 @@ public class ConfigurationTest extends TestCase { assertEquals(tUtf8Ftl, t.getSourceName()); assertEquals(hu, t.getLocale()); assertNull(t.getCustomLookupCondition()); - assertEquals(utf8, t.getEncoding()); + assertEquals(utf8, t.getSourceEncoding()); } // 4 args: @@ -356,7 +356,7 @@ public class ConfigurationTest extends TestCase { assertEquals(tHuFtl, t.getSourceName()); assertEquals(hu, t.getLocale()); assertEquals(custLookupCond, t.getCustomLookupCondition()); - assertEquals(latin2, t.getEncoding()); + assertEquals(latin2, t.getSourceEncoding()); assertOutputEquals("1", t); } { @@ -365,7 +365,7 @@ public class ConfigurationTest extends TestCase { assertEquals(tFtl, t.getSourceName()); assertEquals(Locale.GERMAN, t.getLocale()); assertEquals(custLookupCond, t.getCustomLookupCondition()); - assertEquals(latin1, t.getEncoding()); + assertEquals(latin1, t.getSourceEncoding()); assertOutputEquals("1", t); } } @@ -1339,20 +1339,20 @@ public class ConfigurationTest extends TestCase { String defaultFileEncoding = System.getProperty("file.encoding"); assertNotNull(defaultFileEncoding); - assertEquals(defaultFileEncoding, cfg.getEncoding()); + assertEquals(defaultFileEncoding, cfg.getSourceEncoding()); assertFalse(cfg.isDefaultEncodingExplicitlySet()); String nonDefault = defaultFileEncoding.equalsIgnoreCase("UTF-8") ? "ISO-8859-1" : "UTF-8"; cfg.setEncoding(nonDefault); assertTrue(cfg.isDefaultEncodingExplicitlySet()); - assertEquals(nonDefault, cfg.getEncoding()); + assertEquals(nonDefault, cfg.getSourceEncoding()); cfg.unsetDefaultEncoding(); - assertEquals(defaultFileEncoding, cfg.getEncoding()); + assertEquals(defaultFileEncoding, cfg.getSourceEncoding()); assertFalse(cfg.isDefaultEncodingExplicitlySet()); - cfg.setSetting(Configuration.ENCODING_KEY, "JVM default"); - assertEquals(defaultFileEncoding, cfg.getEncoding()); + cfg.setSetting(Configuration.SOURCE_ENCODING_KEY, "JVM default"); + assertEquals(defaultFileEncoding, cfg.getSourceEncoding()); assertTrue(cfg.isDefaultEncodingExplicitlySet()); } @@ -1453,10 +1453,10 @@ public class ConfigurationTest extends TestCase { public void testSetSettingSupportsBothNamingConventions() throws Exception { Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); - cfg.setSetting(Configuration.ENCODING_KEY_CAMEL_CASE, "UTF-16LE"); - assertEquals("UTF-16LE", cfg.getEncoding()); - cfg.setSetting(Configuration.ENCODING_KEY_SNAKE_CASE, "UTF-8"); - assertEquals("UTF-8", cfg.getEncoding()); + cfg.setSetting(Configuration.SOURCE_ENCODING_KEY_CAMEL_CASE, "UTF-16LE"); + assertEquals("UTF-16LE", cfg.getSourceEncoding()); + cfg.setSetting(Configuration.SOURCE_ENCODING_KEY_SNAKE_CASE, "UTF-8"); + assertEquals("UTF-8", cfg.getSourceEncoding()); for (String nameCC : cfg.getSettingNames(true)) { for (String value : new String[] { "1", "default", "true" }) { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/test/java/org/apache/freemarker/core/EncodingOverrideTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/EncodingOverrideTest.java b/src/test/java/org/apache/freemarker/core/EncodingOverrideTest.java index dd46cf9..d1b70eb 100644 --- a/src/test/java/org/apache/freemarker/core/EncodingOverrideTest.java +++ b/src/test/java/org/apache/freemarker/core/EncodingOverrideTest.java @@ -32,21 +32,21 @@ public class EncodingOverrideTest { @Test public void testExactMarchingCharset() throws Exception { Template t = createConfig("UTF-8").getTemplate("encodingOverride-UTF-8.ftl"); - assertEquals("UTF-8", t.getEncoding()); + assertEquals("UTF-8", t.getSourceEncoding()); checkTempateOutput(t); } @Test public void testCaseDiffCharset() throws Exception { Template t = createConfig("utf-8").getTemplate("encodingOverride-UTF-8.ftl"); - assertEquals("utf-8", t.getEncoding()); + assertEquals("utf-8", t.getSourceEncoding()); checkTempateOutput(t); } @Test public void testReallyDiffCharset() throws Exception { Template t = createConfig("utf-8").getTemplate("encodingOverride-ISO-8859-1.ftl"); - assertEquals("ISO-8859-1", t.getEncoding()); + assertEquals("ISO-8859-1", t.getSourceEncoding()); checkTempateOutput(t); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/test/java/org/apache/freemarker/core/ObjectBuilderSettingsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ObjectBuilderSettingsTest.java b/src/test/java/org/apache/freemarker/core/ObjectBuilderSettingsTest.java index 66bdef6..10e4dfd 100644 --- a/src/test/java/org/apache/freemarker/core/ObjectBuilderSettingsTest.java +++ b/src/test/java/org/apache/freemarker/core/ObjectBuilderSettingsTest.java @@ -367,7 +367,7 @@ public class ObjectBuilderSettingsTest { "org.apache.freemarker.core.ObjectBuilderSettingsTest$DummyCacheStorage()"); props.setProperty(MutableProcessingConfiguration.NEW_BUILTIN_CLASS_RESOLVER_KEY, "org.apache.freemarker.core.ObjectBuilderSettingsTest$DummyNewBuiltinClassResolver()"); - props.setProperty(Configuration.ENCODING_KEY, "utf-8"); + props.setProperty(Configuration.SOURCE_ENCODING_KEY, "utf-8"); props.setProperty(Configuration.TEMPLATE_LOADER_KEY, "org.apache.freemarker.core.ObjectBuilderSettingsTest$DummyTemplateLoader()"); cfg.setSettings(props); @@ -379,7 +379,7 @@ public class ObjectBuilderSettingsTest { assertEquals(DummyCacheStorage.class, cfg.getCacheStorage().getClass()); assertEquals(DummyNewBuiltinClassResolver.class, cfg.getNewBuiltinClassResolver().getClass()); assertEquals(DummyTemplateLoader.class, cfg.getTemplateLoader().getClass()); - assertEquals("utf-8", cfg.getEncoding()); + assertEquals("utf-8", cfg.getSourceEncoding()); } { @@ -401,7 +401,7 @@ public class ObjectBuilderSettingsTest { ((DefaultObjectWrapper) cfg.getObjectWrapper()).getIncompatibleImprovements()); assertEquals(500, ((MruCacheStorage) cfg.getCacheStorage()).getSoftSizeLimit()); assertEquals(TemplateClassResolver.ALLOWS_NOTHING_RESOLVER, cfg.getNewBuiltinClassResolver()); - assertEquals("utf-8", cfg.getEncoding()); + assertEquals("utf-8", cfg.getSourceEncoding()); } { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java b/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java index 07c3a35..3d851cf 100644 --- a/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java +++ b/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java @@ -149,7 +149,7 @@ public class TemplateConfigurationTest { private static final String NON_DEFAULT_ENCODING; static { - String defaultEncoding = DEFAULT_CFG.getEncoding(); + String defaultEncoding = DEFAULT_CFG.getSourceEncoding(); String encoding = "UTF-16"; if (encoding.equals(defaultEncoding)) { encoding = "UTF-8"; @@ -206,7 +206,7 @@ public class TemplateConfigurationTest { SETTING_ASSIGNMENTS.put("autoIncludes", ImmutableList.of("/lib/b.ftl")); // Special settings: - SETTING_ASSIGNMENTS.put("encoding", NON_DEFAULT_ENCODING); + SETTING_ASSIGNMENTS.put("sourceEncoding", NON_DEFAULT_ENCODING); } public static String getIsSetMethodName(String readMethodName) { @@ -215,8 +215,7 @@ public class TemplateConfigurationTest { + "Set"; } - public static List<PropertyDescriptor> getTemplateConfigurationSettingPropDescs( - boolean includeCompilerSettings, boolean includeSpecialSettings) + public static List<PropertyDescriptor> getTemplateConfigurationSettingPropDescs(boolean includeCompilerSettings) throws IntrospectionException { List<PropertyDescriptor> settingPropDescs = new ArrayList<>(); @@ -225,9 +224,7 @@ public class TemplateConfigurationTest { String name = pd.getName(); if (pd.getWriteMethod() != null && !IGNORED_PROP_NAMES.contains(name) && (includeCompilerSettings - || (CONFIGURABLE_PROP_NAMES.contains(name) || !PARSER_PROP_NAMES.contains(name))) - && (includeSpecialSettings - || !SPECIAL_PROP_NAMES.contains(name))) { + || (CONFIGURABLE_PROP_NAMES.contains(name) || !PARSER_PROP_NAMES.contains(name)))) { if (pd.getReadMethod() == null) { throw new AssertionError("Property has no read method: " + pd); } @@ -294,12 +291,6 @@ public class TemplateConfigurationTest { } } - private static final Set<String> SPECIAL_PROP_NAMES; - static { - SPECIAL_PROP_NAMES = new HashSet<>(); - SPECIAL_PROP_NAMES.add("encoding"); - } - private static final Object CA1 = new Object(); private static final Object CA2 = new Object(); private static final Object CA3 = new Object(); @@ -307,8 +298,8 @@ public class TemplateConfigurationTest { @Test public void testMergeBasicFunctionality() throws Exception { - for (PropertyDescriptor propDesc1 : getTemplateConfigurationSettingPropDescs(true, true)) { - for (PropertyDescriptor propDesc2 : getTemplateConfigurationSettingPropDescs(true, true)) { + for (PropertyDescriptor propDesc1 : getTemplateConfigurationSettingPropDescs(true)) { + for (PropertyDescriptor propDesc2 : getTemplateConfigurationSettingPropDescs(true)) { TemplateConfiguration tc1 = new TemplateConfiguration(); TemplateConfiguration tc2 = new TemplateConfiguration(); @@ -541,7 +532,7 @@ public class TemplateConfigurationTest { @Test public void testConfigureNonParserConfig() throws Exception { - for (PropertyDescriptor pd : getTemplateConfigurationSettingPropDescs(false, true)) { + for (PropertyDescriptor pd : getTemplateConfigurationSettingPropDescs(false)) { TemplateConfiguration tc = new TemplateConfiguration(); tc.setParentConfiguration(DEFAULT_CFG); @@ -719,7 +710,7 @@ public class TemplateConfigurationTest { // assertOutput here, as that hard-coded to create an FTL Template. TemplateConfiguration tc = new TemplateConfiguration(); - tc.setEncoding("ISO-8859-1"); + tc.setSourceEncoding("ISO-8859-1"); Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); cfg.setEncoding("utf-8"); @@ -742,7 +733,7 @@ public class TemplateConfigurationTest { assertEquals("próba", out.toString()); } - testedProps.add(Configuration.ENCODING_KEY_CAMEL_CASE); + testedProps.add(Configuration.SOURCE_ENCODING_KEY_CAMEL_CASE); } if (!PARSER_PROP_NAMES.equals(testedProps)) { @@ -936,7 +927,7 @@ public class TemplateConfigurationTest { @Test public void testIsSet() throws Exception { - for (PropertyDescriptor pd : getTemplateConfigurationSettingPropDescs(true, true)) { + for (PropertyDescriptor pd : getTemplateConfigurationSettingPropDescs(true)) { TemplateConfiguration tc = new TemplateConfiguration(); checkAllIsSetFalseExcept(tc, null); pd.getWriteMethod().invoke(tc, SETTING_ASSIGNMENTS.get(pd.getName())); @@ -947,7 +938,7 @@ public class TemplateConfigurationTest { private void checkAllIsSetFalseExcept(TemplateConfiguration tc, String setSetting) throws SecurityException, IntrospectionException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { - for (PropertyDescriptor pd : getTemplateConfigurationSettingPropDescs(true, true)) { + for (PropertyDescriptor pd : getTemplateConfigurationSettingPropDescs(true)) { String isSetMethodName = getIsSetMethodName(pd.getReadMethod().getName()); Method isSetMethod; try { @@ -969,16 +960,16 @@ public class TemplateConfigurationTest { */ @Test public void checkTestAssignments() throws Exception { - for (PropertyDescriptor pd : getTemplateConfigurationSettingPropDescs(true, true)) { + for (PropertyDescriptor pd : getTemplateConfigurationSettingPropDescs(true)) { String propName = pd.getName(); if (!SETTING_ASSIGNMENTS.containsKey(propName)) { fail("Test case doesn't cover all settings in SETTING_ASSIGNMENTS. Missing: " + propName); } Method readMethod = pd.getReadMethod(); String cfgMethodName = readMethod.getName(); - if (cfgMethodName.equals("getEncoding")) { + if (cfgMethodName.equals("getSourceEncoding")) { // Because Configuration has local-to-encoding map too, this has a different name there. - cfgMethodName = "getEncoding"; + cfgMethodName = "getSourceEncoding"; } Method cfgMethod = DEFAULT_CFG.getClass().getMethod(cfgMethodName, readMethod.getParameterTypes()); Object defaultSettingValue = cfgMethod.invoke(DEFAULT_CFG); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaltTemplateResolverTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaltTemplateResolverTest.java b/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaltTemplateResolverTest.java index 34068e5..af3ec9c 100644 --- a/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaltTemplateResolverTest.java +++ b/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaltTemplateResolverTest.java @@ -46,27 +46,27 @@ public class TemplateConfigurationWithDefaltTemplateResolverTest { { Template t = cfg.getTemplate("utf8.ftl"); - assertEquals("utf-8", t.getEncoding()); + assertEquals("utf-8", t.getSourceEncoding()); assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t)); } { Template t = cfg.getTemplate("utf16.ftl"); - assertEquals("utf-16", t.getEncoding()); + assertEquals("utf-16", t.getSourceEncoding()); assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t)); } { Template t = cfg.getTemplate("default.ftl"); - assertEquals("iso-8859-1", t.getEncoding()); + assertEquals("iso-8859-1", t.getSourceEncoding()); assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t)); } { Template t = cfg.getTemplate("utf8-latin2.ftl"); - assertEquals("iso-8859-2", t.getEncoding()); + assertEquals("iso-8859-2", t.getSourceEncoding()); assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t)); } { Template t = cfg.getTemplate("default-latin2.ftl"); - assertEquals("iso-8859-2", t.getEncoding()); + assertEquals("iso-8859-2", t.getSourceEncoding()); assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t)); } } @@ -246,9 +246,9 @@ public class TemplateConfigurationWithDefaltTemplateResolverTest { cfg.setTemplateLoader(tl); TemplateConfiguration tcUtf8 = new TemplateConfiguration(); - tcUtf8.setEncoding("utf-8"); + tcUtf8.setSourceEncoding("utf-8"); TemplateConfiguration tcUtf16 = new TemplateConfiguration(); - tcUtf16.setEncoding("utf-16"); + tcUtf16.setSourceEncoding("utf-16"); cfg.setTemplateConfigurations( new FirstMatchTemplateConfigurationFactory( new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*utf8*"), tcUtf8), http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java b/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java index 3a83bca..aa011a7 100644 --- a/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java +++ b/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java @@ -35,7 +35,7 @@ public class TemplateConstructorsTest { @Test public void test() throws IOException { final Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); - //cfg.setEncoding("ISO-8859-1"); + //cfg.setSourceEncoding("ISO-8859-1"); final String name = "foo/bar.ftl"; final String sourceName = "foo/bar_de.ftl"; @@ -46,42 +46,42 @@ public class TemplateConstructorsTest { assertEquals(name, t.getName()); assertEquals(name, t.getSourceName()); assertEquals(READER_CONTENT, t.toString()); - assertNull(t.getEncoding()); + assertNull(t.getSourceEncoding()); } { Template t = new Template(name, content, cfg); assertEquals(name, t.getName()); assertEquals(name, t.getSourceName()); assertEquals(content, t.toString()); - assertNull(t.getEncoding()); + assertNull(t.getSourceEncoding()); } { Template t = new Template(name, createReader(), cfg, encoding); assertEquals(name, t.getName()); assertEquals(name, t.getSourceName()); assertEquals(READER_CONTENT, t.toString()); - assertEquals("UTF-16LE", t.getEncoding()); + assertEquals("UTF-16LE", t.getSourceEncoding()); } { Template t = new Template(name, sourceName, createReader(), cfg); assertEquals(name, t.getName()); assertEquals(sourceName, t.getSourceName()); assertEquals(READER_CONTENT, t.toString()); - assertNull(t.getEncoding()); + assertNull(t.getSourceEncoding()); } { Template t = new Template(name, sourceName, createReader(), cfg, encoding); assertEquals(name, t.getName()); assertEquals(sourceName, t.getSourceName()); assertEquals(READER_CONTENT, t.toString()); - assertEquals("UTF-16LE", t.getEncoding()); + assertEquals("UTF-16LE", t.getSourceEncoding()); } { Template t = Template.createPlainTextTemplate(name, content, cfg); assertEquals(name, t.getName()); assertEquals(name, t.getSourceName()); assertEquals(content, t.toString()); - assertNull(t.getEncoding()); + assertNull(t.getSourceEncoding()); } { try { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java b/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java index 9669369..685e6ba 100644 --- a/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java +++ b/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java @@ -48,12 +48,12 @@ public class TemplateGetEncodingTest { cfg.setCacheStorage(new StrongCacheStorage()); } - assertEquals("ISO-8859-2", cfg.getTemplate("bin").getEncoding()); - assertEquals("ISO-8859-2", cfg.getTemplate("bin-static").getEncoding()); - assertNull(cfg.getTemplate("text").getEncoding()); - assertNull(cfg.getTemplate("text-static").getEncoding()); - assertNull(new Template(null, "test", cfg).getEncoding()); - assertNull(Template.createPlainTextTemplate(null, "<#test>", cfg).getEncoding()); + assertEquals("ISO-8859-2", cfg.getTemplate("bin").getSourceEncoding()); + assertEquals("ISO-8859-2", cfg.getTemplate("bin-static").getSourceEncoding()); + assertNull(cfg.getTemplate("text").getSourceEncoding()); + assertNull(cfg.getTemplate("text-static").getSourceEncoding()); + assertNull(new Template(null, "test", cfg).getSourceEncoding()); + assertNull(Template.createPlainTextTemplate(null, "<#test>", cfg).getSourceEncoding()); } } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/test/java/org/apache/freemarker/core/templateresolver/DefaultTemplateResolverTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/templateresolver/DefaultTemplateResolverTest.java b/src/test/java/org/apache/freemarker/core/templateresolver/DefaultTemplateResolverTest.java index 598df6b..3605f4b 100644 --- a/src/test/java/org/apache/freemarker/core/templateresolver/DefaultTemplateResolverTest.java +++ b/src/test/java/org/apache/freemarker/core/templateresolver/DefaultTemplateResolverTest.java @@ -286,7 +286,7 @@ public class DefaultTemplateResolverTest { Template t = cfg.getTemplate("utf-8.ftl"); assertEquals("utf-8.ftl", t.getName()); assertEquals("utf-8_en.ftl", t.getSourceName()); - assertEquals("utf-8", t.getEncoding()); + assertEquals("utf-8", t.getSourceEncoding()); assertEquals("Béka", t.toString()); assertEquals( @@ -304,7 +304,7 @@ public class DefaultTemplateResolverTest { Template t = cfg.getTemplate("iso-8859-1.ftl"); assertEquals("iso-8859-1.ftl", t.getName()); assertEquals("iso-8859-1_en_US.ftl", t.getSourceName()); - assertEquals("ISO-8859-1", t.getEncoding()); + assertEquals("ISO-8859-1", t.getSourceEncoding()); assertEquals("Béka", t.toString()); assertEquals( @@ -331,7 +331,7 @@ public class DefaultTemplateResolverTest { Template t = cfg.getTemplate("foo.ftl"); assertEquals("foo.ftl", t.getName()); assertEquals("foo_en.ftl", t.getSourceName()); - assertNull(t.getEncoding()); + assertNull(t.getSourceEncoding()); assertEquals("Å", t.toString()); assertEquals( http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/test/java/org/apache/freemarker/manualtest/TemplateConfigurationExamples.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/manualtest/TemplateConfigurationExamples.java b/src/test/java/org/apache/freemarker/manualtest/TemplateConfigurationExamples.java index bd84755..49efff1 100644 --- a/src/test/java/org/apache/freemarker/manualtest/TemplateConfigurationExamples.java +++ b/src/test/java/org/apache/freemarker/manualtest/TemplateConfigurationExamples.java @@ -48,7 +48,7 @@ public class TemplateConfigurationExamples extends ExamplesTest { addTemplate("t.xml", ""); TemplateConfiguration tcUTF8XML = new TemplateConfiguration(); - tcUTF8XML.setEncoding("utf-8"); + tcUTF8XML.setSourceEncoding("utf-8"); tcUTF8XML.setOutputFormat(XMLOutputFormat.INSTANCE); { @@ -56,7 +56,7 @@ public class TemplateConfigurationExamples extends ExamplesTest { new FileExtensionMatcher("xml"), tcUTF8XML)); Template t = cfg.getTemplate("t.xml"); - assertEquals("utf-8", t.getEncoding()); + assertEquals("utf-8", t.getSourceEncoding()); assertEquals(XMLOutputFormat.INSTANCE, t.getOutputFormat()); } @@ -65,7 +65,7 @@ public class TemplateConfigurationExamples extends ExamplesTest { cfg.setSettings(loadPropertiesFile("TemplateConfigurationExamples1.properties")); Template t = cfg.getTemplate("t.xml"); - assertEquals("utf-8", t.getEncoding()); + assertEquals("utf-8", t.getSourceEncoding()); assertEquals(XMLOutputFormat.INSTANCE, t.getOutputFormat()); } } @@ -131,7 +131,7 @@ public class TemplateConfigurationExamples extends ExamplesTest { tcStats.setTimeZone(_DateUtil.UTC); TemplateConfiguration tcMail = new TemplateConfiguration(); - tcMail.setEncoding("utf-8"); + tcMail.setSourceEncoding("utf-8"); TemplateConfiguration tcHTML = new TemplateConfiguration(); tcHTML.setOutputFormat(HTMLOutputFormat.INSTANCE); @@ -161,12 +161,12 @@ public class TemplateConfigurationExamples extends ExamplesTest { ); assertEquals(HTMLOutputFormat.INSTANCE, cfg.getTemplate("t.html").getOutputFormat()); - assertEquals("ISO-8859-1", cfg.getTemplate("t.html").getEncoding()); + assertEquals("ISO-8859-1", cfg.getTemplate("t.html").getSourceEncoding()); assertEquals(HTMLOutputFormat.INSTANCE, cfg.getTemplate("t.htm").getOutputFormat()); assertEquals(XMLOutputFormat.INSTANCE, cfg.getTemplate("t.xml").getOutputFormat()); assertEquals(HTMLOutputFormat.INSTANCE, cfg.getTemplate("t.stats.html").getOutputFormat()); assertOutputForNamed("t.stats.html", "2015-08-24T15:53:26.011Z 2015-08-24 15:53:26.011Z"); - assertEquals("utf-8", cfg.getTemplate("mail/t.html").getEncoding()); + assertEquals("utf-8", cfg.getTemplate("mail/t.html").getSourceEncoding()); // From properties: @@ -174,12 +174,12 @@ public class TemplateConfigurationExamples extends ExamplesTest { cfg.setSettings(loadPropertiesFile("TemplateConfigurationExamples3.properties")); assertEquals(HTMLOutputFormat.INSTANCE, cfg.getTemplate("t.html").getOutputFormat()); - assertEquals("ISO-8859-1", cfg.getTemplate("t.html").getEncoding()); + assertEquals("ISO-8859-1", cfg.getTemplate("t.html").getSourceEncoding()); assertEquals(HTMLOutputFormat.INSTANCE, cfg.getTemplate("t.htm").getOutputFormat()); assertEquals(XMLOutputFormat.INSTANCE, cfg.getTemplate("t.xml").getOutputFormat()); assertEquals(HTMLOutputFormat.INSTANCE, cfg.getTemplate("t.stats.html").getOutputFormat()); assertOutputForNamed("t.stats.html", "2015-08-24T15:53:26.011Z 2015-08-24 15:53:26.011Z"); - assertEquals("utf-8", cfg.getTemplate("mail/t.html").getEncoding()); + assertEquals("utf-8", cfg.getTemplate("mail/t.html").getSourceEncoding()); } } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/test/java/org/apache/freemarker/servlet/FreemarkerServletTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/servlet/FreemarkerServletTest.java b/src/test/java/org/apache/freemarker/servlet/FreemarkerServletTest.java index 0a3da35..daa44a9 100644 --- a/src/test/java/org/apache/freemarker/servlet/FreemarkerServletTest.java +++ b/src/test/java/org/apache/freemarker/servlet/FreemarkerServletTest.java @@ -412,7 +412,7 @@ public class FreemarkerServletTest { } MockServletConfig servletConfig = new MockServletConfig(servletContext); - servletConfig.addInitParameter(Configuration.ENCODING_KEY, "UTF-8"); + servletConfig.addInitParameter(Configuration.SOURCE_ENCODING_KEY, "UTF-8"); if (ctInitParam != null) { servletConfig.addInitParameter(INIT_PARAM_CONTENT_TYPE, ctInitParam); } @@ -547,7 +547,7 @@ public class FreemarkerServletTest { outUtf8TC.setOutputEncoding("UTF-8"); TemplateConfiguration srcUtf8TC = new TemplateConfiguration(); - srcUtf8TC.setEncoding("UTF-8"); + srcUtf8TC.setSourceEncoding("UTF-8"); cfg.setTemplateConfigurations( new FirstMatchTemplateConfigurationFactory( http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/test/resources/org/apache/freemarker/manualtest/TemplateConfigurationExamples1.properties ---------------------------------------------------------------------- diff --git a/src/test/resources/org/apache/freemarker/manualtest/TemplateConfigurationExamples1.properties b/src/test/resources/org/apache/freemarker/manualtest/TemplateConfigurationExamples1.properties index cffadfb..6c33890 100644 --- a/src/test/resources/org/apache/freemarker/manualtest/TemplateConfigurationExamples1.properties +++ b/src/test/resources/org/apache/freemarker/manualtest/TemplateConfigurationExamples1.properties @@ -19,7 +19,7 @@ templateConfigurations = \ ConditionalTemplateConfigurationFactory( \ FileExtensionMatcher("xml"), \ TemplateConfiguration( \ - encoding = "utf-8", \ + sourceEncoding = "utf-8", \ outputFormat = XMLOutputFormat() \ ) \ ) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/test/resources/org/apache/freemarker/manualtest/TemplateConfigurationExamples3.properties ---------------------------------------------------------------------- diff --git a/src/test/resources/org/apache/freemarker/manualtest/TemplateConfigurationExamples3.properties b/src/test/resources/org/apache/freemarker/manualtest/TemplateConfigurationExamples3.properties index cf4c5a4..27301bf 100644 --- a/src/test/resources/org/apache/freemarker/manualtest/TemplateConfigurationExamples3.properties +++ b/src/test/resources/org/apache/freemarker/manualtest/TemplateConfigurationExamples3.properties @@ -28,7 +28,7 @@ templateConfigurations = \ ), \ ConditionalTemplateConfigurationFactory( \ PathGlobMatcher("mail/**"), \ - TemplateConfiguration(encoding = "utf-8") \ + TemplateConfiguration(sourceEncoding = "utf-8") \ ), \ FirstMatchTemplateConfigurationFactory( \ ConditionalTemplateConfigurationFactory( \ http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/basic/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/basic/WEB-INF/web.xml b/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/basic/WEB-INF/web.xml index e84ca81..d338cbc 100644 --- a/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/basic/WEB-INF/web.xml +++ b/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/basic/WEB-INF/web.xml @@ -71,7 +71,7 @@ <param-value>0</param-value> <!-- 0 is for development only! Use higher value otherwise. --> </init-param> <init-param> - <param-name>encoding</param-name> + <param-name>sourceEncoding</param-name> <param-value>UTF-8</param-value> <!-- The encoding of the template files. --> </init-param> <init-param> @@ -110,7 +110,7 @@ <param-value>en_US</param-value> </init-param> <init-param> - <param-name>encoding</param-name> + <param-name>sourceEncoding</param-name> <param-value>UTF-8</param-value> <!-- The encoding of the template files. --> </init-param> <init-param> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/multipleLoaders/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/multipleLoaders/WEB-INF/web.xml b/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/multipleLoaders/WEB-INF/web.xml index f83c942..eaa6eb9 100644 --- a/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/multipleLoaders/WEB-INF/web.xml +++ b/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/multipleLoaders/WEB-INF/web.xml @@ -51,7 +51,7 @@ <param-value>rethrow</param-value> </init-param> <init-param> - <param-name>encoding</param-name> + <param-name>sourceEncoding</param-name> <param-value>UTF-8</param-value> <!-- The encoding of the template files. --> </init-param> <init-param> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/tldDiscovery/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/tldDiscovery/WEB-INF/web.xml b/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/tldDiscovery/WEB-INF/web.xml index 3508238..bf7a620 100644 --- a/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/tldDiscovery/WEB-INF/web.xml +++ b/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/tldDiscovery/WEB-INF/web.xml @@ -71,7 +71,7 @@ <param-value>0</param-value> <!-- 0 is for development only! Use higher value otherwise. --> </init-param> <init-param> - <param-name>encoding</param-name> + <param-name>sourceEncoding</param-name> <param-value>UTF-8</param-value> <!-- The encoding of the template files. --> </init-param> <init-param> @@ -125,7 +125,7 @@ <param-value>0</param-value> <!-- 0 is for development only! Use higher value otherwise. --> </init-param> <init-param> - <param-name>encoding</param-name> + <param-name>sourceEncoding</param-name> <param-value>UTF-8</param-value> <!-- The encoding of the template files. --> </init-param> <init-param> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ad539de9/src/test/resources/org/apache/freemarker/test/servlet/web.xml ---------------------------------------------------------------------- diff --git a/src/test/resources/org/apache/freemarker/test/servlet/web.xml b/src/test/resources/org/apache/freemarker/test/servlet/web.xml index b54ea92..e406b1a 100644 --- a/src/test/resources/org/apache/freemarker/test/servlet/web.xml +++ b/src/test/resources/org/apache/freemarker/test/servlet/web.xml @@ -69,7 +69,7 @@ <param-value>0</param-value> <!-- 0 is for development only! Use higher value otherwise. --> </init-param> <init-param> - <param-name>encoding</param-name> + <param-name>sourceEncoding</param-name> <param-value>UTF-8</param-value> <!-- The encoding of the template files. --> </init-param> <init-param>
