freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [1/2] incubator-freemarker git commit: - Configuration.getTemplate has no "encoding" parameter anymore. Similarly #include has no "encoding" parameter either. The charset of templates can be specified via Configuration.defaultEncoding and Configuration.t
Date Mon, 20 Mar 2017 17:32:25 GMT
Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 e365f11bd -> f6a693c57


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f6a693c5/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
new file mode 100644
index 0000000..700e718
--- /dev/null
+++ b/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaltTemplateResolverTest.java
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.freemarker.core;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.util.Locale;
+
+import org.apache.freemarker.core.templateresolver.ConditionalTemplateConfigurationFactory;
+import org.apache.freemarker.core.templateresolver.FileNameGlobMatcher;
+import org.apache.freemarker.core.templateresolver.FirstMatchTemplateConfigurationFactory;
+import org.apache.freemarker.core.templateresolver.MergingTemplateConfigurationFactory;
+import org.apache.freemarker.core.templateresolver.impl.ByteArrayTemplateLoader;
+import org.apache.freemarker.core.templateresolver.impl.StringTemplateLoader;
+import org.junit.Test;
+
+public class TemplateConfigurationWithDefaltTemplateResolverTest {
+
+    private static final String TEXT_WITH_ACCENTS = "pr\u00F3ba";
+
+    private static final CustomAttribute CUST_ATT_1 = new CustomAttribute(CustomAttribute.SCOPE_TEMPLATE);
+    private static final CustomAttribute CUST_ATT_2 = new CustomAttribute(CustomAttribute.SCOPE_TEMPLATE);
+
+    @Test
+    public void testEncoding() throws Exception {
+        Configuration cfg = createCommonEncodingTesterConfig();
+        
+        {
+            Template t = cfg.getTemplate("utf8.ftl");
+            assertEquals("utf-8", t.getEncoding());
+            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
+        }
+        {
+            Template t = cfg.getTemplate("utf16.ftl");
+            assertEquals("utf-16", t.getEncoding());
+            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
+        }
+        {
+            Template t = cfg.getTemplate("default.ftl");
+            assertEquals("iso-8859-1", t.getEncoding());
+            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
+        }
+        {
+            Template t = cfg.getTemplate("utf8-latin2.ftl");
+            assertEquals("iso-8859-2", t.getEncoding());
+            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
+        }
+        {
+            Template t = cfg.getTemplate("default-latin2.ftl");
+            assertEquals("iso-8859-2", t.getEncoding());
+            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
+        }
+    }
+    
+    @Test
+    public void testIncludeAndEncoding() throws Exception {
+        Configuration cfg = createCommonEncodingTesterConfig();
+        ByteArrayTemplateLoader tl = (ByteArrayTemplateLoader) cfg.getTemplateLoader();
+        tl.putTemplate("main.ftl", (
+                        "<#include 'utf8.ftl'>"
+                        + "<#include 'utf16.ftl'>"
+                        + "<#include 'default.ftl'>"
+                        + "<#include 'utf8-latin2.ftl'>"
+                ).getBytes("iso-8859-1"));
+        assertEquals(
+                TEXT_WITH_ACCENTS + TEXT_WITH_ACCENTS + TEXT_WITH_ACCENTS + TEXT_WITH_ACCENTS,
+                getTemplateOutput(cfg.getTemplate("main.ftl")));
+    }
+
+    @Test
+    public void testLocale() throws Exception {
+        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
+        cfg.setLocale(Locale.US);
+        
+        StringTemplateLoader tl = new StringTemplateLoader();
+        tl.putTemplate("(de).ftl", "${.locale}");
+        tl.putTemplate("default.ftl", "${.locale}");
+        tl.putTemplate("(de)-fr.ftl",
+                ("<#ftl locale='fr_FR'>${.locale}"));
+        tl.putTemplate("default-fr.ftl",
+                ("<#ftl locale='fr_FR'>${.locale}"));
+        cfg.setTemplateLoader(tl);
+
+        TemplateConfiguration tcDe = new TemplateConfiguration();
+        tcDe.setLocale(Locale.GERMANY);
+        cfg.setTemplateConfigurations(
+                new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(de)*"), tcDe));
+        
+        {
+            Template t = cfg.getTemplate("(de).ftl");
+            assertEquals(Locale.GERMANY, t.getLocale());
+            assertEquals("de_DE", getTemplateOutput(t));
+        }
+        {
+            Template t = cfg.getTemplate("(de).ftl", Locale.ITALY);
+            assertEquals(Locale.GERMANY, t.getLocale());
+            assertEquals("de_DE", getTemplateOutput(t));
+        }
+        {
+            Template t = cfg.getTemplate("default.ftl");
+            assertEquals(Locale.US, t.getLocale());
+            assertEquals("en_US", getTemplateOutput(t));
+        }
+        {
+            Template t = cfg.getTemplate("default.ftl", Locale.ITALY);
+            assertEquals(Locale.ITALY, t.getLocale());
+            assertEquals("it_IT", getTemplateOutput(t));
+        }
+    }
+
+    @Test
+    public void testConfigurableSettings() throws Exception {
+        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
+        cfg.setLocale(Locale.US);
+        
+        TemplateConfiguration tcFR = new TemplateConfiguration();
+        tcFR.setLocale(Locale.FRANCE);
+        TemplateConfiguration tcYN = new TemplateConfiguration();
+        tcYN.setBooleanFormat("Y,N");
+        TemplateConfiguration tc00 = new TemplateConfiguration();
+        tc00.setNumberFormat("0.00");
+        cfg.setTemplateConfigurations(
+                new MergingTemplateConfigurationFactory(
+                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(fr)*"), tcFR),
+                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(yn)*"), tcYN),
+                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(00)*"), tc00)
+                )
+        );
+        
+        String commonFTL = "${.locale} ${true?string} ${1.2}";
+        StringTemplateLoader tl = new StringTemplateLoader();
+        tl.putTemplate("default", commonFTL);
+        tl.putTemplate("(fr)", commonFTL);
+        tl.putTemplate("(yn)(00)", commonFTL);
+        tl.putTemplate("(00)(fr)", commonFTL);
+        cfg.setTemplateLoader(tl);
+        
+        assertEquals("en_US true 1.2", getTemplateOutput(cfg.getTemplate("default")));
+        assertEquals("fr_FR true 1,2", getTemplateOutput(cfg.getTemplate("(fr)")));
+        assertEquals("en_US Y 1.20", getTemplateOutput(cfg.getTemplate("(yn)(00)")));
+        assertEquals("fr_FR true 1,20", getTemplateOutput(cfg.getTemplate("(00)(fr)")));
+    }
+    
+    @Test
+    public void testCustomAttributes() throws Exception {
+        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
+        
+        TemplateConfiguration tc1 = new TemplateConfiguration();
+        tc1.setCustomAttribute("a1", "a1tc1");
+        tc1.setCustomAttribute("a2", "a2tc1");
+        tc1.setCustomAttribute("a3", "a3tc1");
+        CUST_ATT_1.set("ca1tc1", tc1);
+        CUST_ATT_2.set("ca2tc1", tc1);
+        
+        TemplateConfiguration tc2 = new TemplateConfiguration();
+        tc2.setCustomAttribute("a1", "a1tc2");
+        CUST_ATT_1.set("ca1tc2", tc2);
+        
+        cfg.setTemplateConfigurations(
+                new MergingTemplateConfigurationFactory(
+                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(tc1)*"), tc1),
+                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(tc2)*"), tc2)
+                )
+        );
+        
+        String commonFTL = "<#ftl attributes={ 'a3': 'a3temp' }>";
+        StringTemplateLoader tl = new StringTemplateLoader();
+        tl.putTemplate("(tc1)", commonFTL);
+        tl.putTemplate("(tc1)noHeader", "");
+        tl.putTemplate("(tc2)", commonFTL);
+        tl.putTemplate("(tc1)(tc2)", commonFTL);
+        cfg.setTemplateLoader(tl);
+
+        {
+            Template t = cfg.getTemplate("(tc1)");
+            assertEquals("a1tc1", t.getCustomAttribute("a1"));
+            assertEquals("a2tc1", t.getCustomAttribute("a2"));
+            assertEquals("a3temp", t.getCustomAttribute("a3"));
+            assertEquals("ca1tc1", CUST_ATT_1.get(t));
+            assertEquals("ca2tc1", CUST_ATT_2.get(t));
+        }
+        {
+            Template t = cfg.getTemplate("(tc1)noHeader");
+            assertEquals("a1tc1", t.getCustomAttribute("a1"));
+            assertEquals("a2tc1", t.getCustomAttribute("a2"));
+            assertEquals("a3tc1", t.getCustomAttribute("a3"));
+            assertEquals("ca1tc1", CUST_ATT_1.get(t));
+            assertEquals("ca2tc1", CUST_ATT_2.get(t));
+        }
+        {
+            Template t = cfg.getTemplate("(tc2)");
+            assertEquals("a1tc2", t.getCustomAttribute("a1"));
+            assertNull(t.getCustomAttribute("a2"));
+            assertEquals("a3temp", t.getCustomAttribute("a3"));
+            assertEquals("ca1tc2", CUST_ATT_1.get(t));
+            assertNull(CUST_ATT_2.get(t));
+        }
+        {
+            Template t = cfg.getTemplate("(tc1)(tc2)");
+            assertEquals("a1tc2", t.getCustomAttribute("a1"));
+            assertEquals("a2tc1", t.getCustomAttribute("a2"));
+            assertEquals("a3temp", t.getCustomAttribute("a3"));
+            assertEquals("ca1tc2", CUST_ATT_1.get(t));
+            assertEquals("ca2tc1", CUST_ATT_2.get(t));
+        }
+    }
+    
+    private String getTemplateOutput(Template t) throws TemplateException, IOException {
+        StringWriter sw = new StringWriter();
+        t.process(null, sw);
+        return sw.toString();
+    }
+
+    private Configuration createCommonEncodingTesterConfig() throws UnsupportedEncodingException {
+        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
+        cfg.setDefaultEncoding("iso-8859-1");
+        cfg.setLocale(Locale.US);
+        
+        ByteArrayTemplateLoader tl = new ByteArrayTemplateLoader();
+        tl.putTemplate("utf8.ftl", TEXT_WITH_ACCENTS.getBytes("utf-8"));
+        tl.putTemplate("utf16.ftl", TEXT_WITH_ACCENTS.getBytes("utf-16"));
+        tl.putTemplate("default.ftl", TEXT_WITH_ACCENTS.getBytes("iso-8859-2"));
+        tl.putTemplate("utf8-latin2.ftl",
+                ("<#ftl encoding='iso-8859-2'>" + TEXT_WITH_ACCENTS).getBytes("iso-8859-2"));
+        tl.putTemplate("default-latin2.ftl",
+                ("<#ftl encoding='iso-8859-2'>" + TEXT_WITH_ACCENTS).getBytes("iso-8859-2"));
+        cfg.setTemplateLoader(tl);
+        
+        TemplateConfiguration tcUtf8 = new TemplateConfiguration();
+        tcUtf8.setEncoding("utf-8");
+        TemplateConfiguration tcUtf16 = new TemplateConfiguration();
+        tcUtf16.setEncoding("utf-16");
+        cfg.setTemplateConfigurations(
+                new FirstMatchTemplateConfigurationFactory(
+                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*utf8*"), tcUtf8),
+                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*utf16*"), tcUtf16)
+                ).allowNoMatch(true));
+        return cfg;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f6a693c5/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithTemplateResolverTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithTemplateResolverTest.java b/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithTemplateResolverTest.java
deleted file mode 100644
index ea4ace1..0000000
--- a/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithTemplateResolverTest.java
+++ /dev/null
@@ -1,321 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.freemarker.core;
-
-import static org.junit.Assert.*;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
-import java.util.Locale;
-
-import org.apache.freemarker.core.templateresolver.ConditionalTemplateConfigurationFactory;
-import org.apache.freemarker.core.templateresolver.FileNameGlobMatcher;
-import org.apache.freemarker.core.templateresolver.FirstMatchTemplateConfigurationFactory;
-import org.apache.freemarker.core.templateresolver.MergingTemplateConfigurationFactory;
-import org.apache.freemarker.core.templateresolver.impl.ByteArrayTemplateLoader;
-import org.apache.freemarker.core.templateresolver.impl.StringTemplateLoader;
-import org.junit.Test;
-
-public class TemplateConfigurationWithTemplateResolverTest {
-
-    private static final String TEXT_WITH_ACCENTS = "pr\u00F3ba";
-
-    private static final CustomAttribute CUST_ATT_1 = new CustomAttribute(CustomAttribute.SCOPE_TEMPLATE);
-    private static final CustomAttribute CUST_ATT_2 = new CustomAttribute(CustomAttribute.SCOPE_TEMPLATE);
-
-    @Test
-    public void testEncoding() throws Exception {
-        Configuration cfg = createCommonEncodingTesterConfig();
-        
-        {
-            Template t = cfg.getTemplate("utf8.ftl");
-            assertEquals("utf-8", t.getEncoding());
-            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
-        }
-        {
-            Template t = cfg.getTemplate("utf8.ftl", "iso-8859-1");
-            assertEquals("utf-8", t.getEncoding());
-            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
-        }
-        {
-            Template t = cfg.getTemplate("utf16.ftl");
-            assertEquals("utf-16", t.getEncoding());
-            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
-        }
-        {
-            Template t = cfg.getTemplate("default.ftl");
-            assertEquals("iso-8859-1", t.getEncoding());
-            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
-        }
-        {
-            Template t = cfg.getTemplate("default.ftl", "iso-8859-5");
-            assertEquals("iso-8859-5", t.getEncoding());
-            assertEquals(new String(TEXT_WITH_ACCENTS.getBytes("iso-8859-1"), "iso-8859-5"),
-                    getTemplateOutput(t));
-        }
-        {
-            Template t = cfg.getTemplate("utf8-latin2.ftl");
-            assertEquals("iso-8859-2", t.getEncoding());
-            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
-        }
-        {
-            Template t = cfg.getTemplate("default-latin2.ftl");
-            assertEquals("iso-8859-2", t.getEncoding());
-            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
-        }
-    }
-    
-    @Test
-    public void testIncludeAndEncoding() throws Exception {
-        Configuration cfg = createCommonEncodingTesterConfig();
-        ByteArrayTemplateLoader tl = (ByteArrayTemplateLoader) cfg.getTemplateLoader();
-        tl.putTemplate("main.ftl", (
-                        "<#include 'utf8.ftl'>"
-                        + "<#include 'utf16.ftl'>"
-                        + "<#include 'default.ftl'>"
-                        + "<#include 'utf8-latin2.ftl'>"
-                        // With mostly ignored encoding params:
-                        + "<#include 'utf8.ftl' encoding='utf-16'>"
-                        + "<#include 'utf16.ftl' encoding='iso-8859-5'>"
-                        + "<#include 'default.ftl' encoding='iso-8859-5'>"
-                        + "<#include 'utf8-latin2.ftl' encoding='iso-8859-5'>"
-                ).getBytes("iso-8859-1"));
-        assertEquals(
-                TEXT_WITH_ACCENTS + TEXT_WITH_ACCENTS + TEXT_WITH_ACCENTS + TEXT_WITH_ACCENTS
-                + TEXT_WITH_ACCENTS + TEXT_WITH_ACCENTS
-                + new String(TEXT_WITH_ACCENTS.getBytes("iso-8859-1"), "iso-8859-5")
-                + TEXT_WITH_ACCENTS,
-                getTemplateOutput(cfg.getTemplate("main.ftl")));
-    }
-
-    @Test
-    public void testLocale() throws Exception {
-        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
-        cfg.setLocale(Locale.US);
-        
-        StringTemplateLoader tl = new StringTemplateLoader();
-        tl.putTemplate("(de).ftl", "${.locale}");
-        tl.putTemplate("default.ftl", "${.locale}");
-        tl.putTemplate("(de)-fr.ftl",
-                ("<#ftl locale='fr_FR'>${.locale}"));
-        tl.putTemplate("default-fr.ftl",
-                ("<#ftl locale='fr_FR'>${.locale}"));
-        cfg.setTemplateLoader(tl);
-
-        TemplateConfiguration tcDe = new TemplateConfiguration();
-        tcDe.setLocale(Locale.GERMANY);
-        cfg.setTemplateConfigurations(new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(de)*"), tcDe));
-        
-        {
-            Template t = cfg.getTemplate("(de).ftl");
-            assertEquals(Locale.GERMANY, t.getLocale());
-            assertEquals("de_DE", getTemplateOutput(t));
-        }
-        {
-            Template t = cfg.getTemplate("(de).ftl", Locale.ITALY);
-            assertEquals(Locale.GERMANY, t.getLocale());
-            assertEquals("de_DE", getTemplateOutput(t));
-        }
-        {
-            Template t = cfg.getTemplate("default.ftl");
-            assertEquals(Locale.US, t.getLocale());
-            assertEquals("en_US", getTemplateOutput(t));
-        }
-        {
-            Template t = cfg.getTemplate("default.ftl", Locale.ITALY);
-            assertEquals(Locale.ITALY, t.getLocale());
-            assertEquals("it_IT", getTemplateOutput(t));
-        }
-    }
-
-    @Test
-    public void testPlainText() throws Exception {
-        Configuration cfg = createCommonEncodingTesterConfig();
-        cfg.setIncompatibleImprovements(Configuration.VERSION_3_0_0);
-        
-        TemplateConfiguration tcDE = new TemplateConfiguration();
-        tcDE.setLocale(Locale.GERMANY);
-        TemplateConfiguration tcYN = new TemplateConfiguration();
-        tcYN.setBooleanFormat("Y,N");
-        cfg.setTemplateConfigurations(
-                    new MergingTemplateConfigurationFactory(
-                            cfg.getTemplateConfigurations(),
-                            new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("utf16.ftl"), tcDE),
-                            new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("utf16.ftl"), tcYN)
-                    )
-                );
-        
-        {
-            Template t = cfg.getTemplate("utf8.ftl", null, null, false);
-            assertEquals("utf-8", t.getEncoding());
-            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
-            assertEquals(Locale.US, t.getLocale());
-            assertEquals("true,false", t.getBooleanFormat());
-        }
-        {
-            Template t = cfg.getTemplate("utf8.ftl", null, "iso-8859-1", false);
-            assertEquals("utf-8", t.getEncoding());
-            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
-        }
-        {
-            Template t = cfg.getTemplate("utf16.ftl", null, null, false);
-            assertEquals("utf-16", t.getEncoding());
-            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
-            assertEquals(Locale.GERMANY, t.getLocale());
-            assertEquals("Y,N", t.getBooleanFormat());
-        }
-        {
-            Template t = cfg.getTemplate("default.ftl", null, null, false);
-            assertEquals("iso-8859-1", t.getEncoding());
-            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
-        }
-    }
-
-    @Test
-    public void testConfigurableSettings() throws Exception {
-        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
-        cfg.setLocale(Locale.US);
-        
-        TemplateConfiguration tcFR = new TemplateConfiguration();
-        tcFR.setLocale(Locale.FRANCE);
-        TemplateConfiguration tcYN = new TemplateConfiguration();
-        tcYN.setBooleanFormat("Y,N");
-        TemplateConfiguration tc00 = new TemplateConfiguration();
-        tc00.setNumberFormat("0.00");
-        cfg.setTemplateConfigurations(
-                new MergingTemplateConfigurationFactory(
-                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(fr)*"), tcFR),
-                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(yn)*"), tcYN),
-                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(00)*"), tc00)
-                )
-        );
-        
-        String commonFTL = "${.locale} ${true?string} ${1.2}";
-        StringTemplateLoader tl = new StringTemplateLoader();
-        tl.putTemplate("default", commonFTL);
-        tl.putTemplate("(fr)", commonFTL);
-        tl.putTemplate("(yn)(00)", commonFTL);
-        tl.putTemplate("(00)(fr)", commonFTL);
-        cfg.setTemplateLoader(tl);
-        
-        assertEquals("en_US true 1.2", getTemplateOutput(cfg.getTemplate("default")));
-        assertEquals("fr_FR true 1,2", getTemplateOutput(cfg.getTemplate("(fr)")));
-        assertEquals("en_US Y 1.20", getTemplateOutput(cfg.getTemplate("(yn)(00)")));
-        assertEquals("fr_FR true 1,20", getTemplateOutput(cfg.getTemplate("(00)(fr)")));
-    }
-    
-    @Test
-    public void testCustomAttributes() throws Exception {
-        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
-        
-        TemplateConfiguration tc1 = new TemplateConfiguration();
-        tc1.setCustomAttribute("a1", "a1tc1");
-        tc1.setCustomAttribute("a2", "a2tc1");
-        tc1.setCustomAttribute("a3", "a3tc1");
-        CUST_ATT_1.set("ca1tc1", tc1);
-        CUST_ATT_2.set("ca2tc1", tc1);
-        
-        TemplateConfiguration tc2 = new TemplateConfiguration();
-        tc2.setCustomAttribute("a1", "a1tc2");
-        CUST_ATT_1.set("ca1tc2", tc2);
-        
-        cfg.setTemplateConfigurations(
-                new MergingTemplateConfigurationFactory(
-                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(tc1)*"), tc1),
-                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(tc2)*"), tc2)
-                )
-        );
-        
-        String commonFTL = "<#ftl attributes={ 'a3': 'a3temp' }>";
-        StringTemplateLoader tl = new StringTemplateLoader();
-        tl.putTemplate("(tc1)", commonFTL);
-        tl.putTemplate("(tc1)noHeader", "");
-        tl.putTemplate("(tc2)", commonFTL);
-        tl.putTemplate("(tc1)(tc2)", commonFTL);
-        cfg.setTemplateLoader(tl);
-
-        {
-            Template t = cfg.getTemplate("(tc1)");
-            assertEquals("a1tc1", t.getCustomAttribute("a1"));
-            assertEquals("a2tc1", t.getCustomAttribute("a2"));
-            assertEquals("a3temp", t.getCustomAttribute("a3"));
-            assertEquals("ca1tc1", CUST_ATT_1.get(t));
-            assertEquals("ca2tc1", CUST_ATT_2.get(t));
-        }
-        {
-            Template t = cfg.getTemplate("(tc1)noHeader");
-            assertEquals("a1tc1", t.getCustomAttribute("a1"));
-            assertEquals("a2tc1", t.getCustomAttribute("a2"));
-            assertEquals("a3tc1", t.getCustomAttribute("a3"));
-            assertEquals("ca1tc1", CUST_ATT_1.get(t));
-            assertEquals("ca2tc1", CUST_ATT_2.get(t));
-        }
-        {
-            Template t = cfg.getTemplate("(tc2)");
-            assertEquals("a1tc2", t.getCustomAttribute("a1"));
-            assertNull(t.getCustomAttribute("a2"));
-            assertEquals("a3temp", t.getCustomAttribute("a3"));
-            assertEquals("ca1tc2", CUST_ATT_1.get(t));
-            assertNull(CUST_ATT_2.get(t));
-        }
-        {
-            Template t = cfg.getTemplate("(tc1)(tc2)");
-            assertEquals("a1tc2", t.getCustomAttribute("a1"));
-            assertEquals("a2tc1", t.getCustomAttribute("a2"));
-            assertEquals("a3temp", t.getCustomAttribute("a3"));
-            assertEquals("ca1tc2", CUST_ATT_1.get(t));
-            assertEquals("ca2tc1", CUST_ATT_2.get(t));
-        }
-    }
-    
-    private String getTemplateOutput(Template t) throws TemplateException, IOException {
-        StringWriter sw = new StringWriter();
-        t.process(null, sw);
-        return sw.toString();
-    }
-
-    private Configuration createCommonEncodingTesterConfig() throws UnsupportedEncodingException {
-        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
-        cfg.setDefaultEncoding("iso-8859-1");
-        cfg.setLocale(Locale.US);
-        
-        ByteArrayTemplateLoader tl = new ByteArrayTemplateLoader();
-        tl.putTemplate("utf8.ftl", TEXT_WITH_ACCENTS.getBytes("utf-8"));
-        tl.putTemplate("utf16.ftl", TEXT_WITH_ACCENTS.getBytes("utf-16"));
-        tl.putTemplate("default.ftl", TEXT_WITH_ACCENTS.getBytes("iso-8859-2"));
-        tl.putTemplate("utf8-latin2.ftl",
-                ("<#ftl encoding='iso-8859-2'>" + TEXT_WITH_ACCENTS).getBytes("iso-8859-2"));
-        tl.putTemplate("default-latin2.ftl",
-                ("<#ftl encoding='iso-8859-2'>" + TEXT_WITH_ACCENTS).getBytes("iso-8859-2"));
-        cfg.setTemplateLoader(tl);
-        
-        TemplateConfiguration tcUtf8 = new TemplateConfiguration();
-        tcUtf8.setEncoding("utf-8");
-        TemplateConfiguration tcUtf16 = new TemplateConfiguration();
-        tcUtf16.setEncoding("utf-16");
-        cfg.setTemplateConfigurations(
-                new FirstMatchTemplateConfigurationFactory(
-                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*utf8*"), tcUtf8),
-                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*utf16*"), tcUtf16)
-                ).allowNoMatch(true));
-        return cfg;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f6a693c5/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
new file mode 100644
index 0000000..c387d36
--- /dev/null
+++ b/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.freemarker.core;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+
+import org.apache.freemarker.core.templateresolver.ConditionalTemplateConfigurationFactory;
+import org.apache.freemarker.core.templateresolver.FileNameGlobMatcher;
+import org.apache.freemarker.core.templateresolver.impl.StrongCacheStorage;
+import org.apache.freemarker.test.MonitoredTemplateLoader;
+import org.junit.Test;
+
+public class TemplateGetEncodingTest {
+
+    @Test
+    public void test() throws IOException {
+        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
+        {
+            cfg.setDefaultEncoding("ISO-8859-2");
+            MonitoredTemplateLoader tl = new MonitoredTemplateLoader();
+            tl.putBinaryTemplate("bin", "test");
+            tl.putBinaryTemplate("bin-static", "<#test>");
+            tl.putTextTemplate("text", "test");
+            tl.putTextTemplate("text-static", "<#test>");
+            TemplateConfiguration staticTextTC = new TemplateConfiguration();
+            staticTextTC.setTemplateLanguage(TemplateLanguage.STATIC_TEXT);
+            cfg.setTemplateConfigurations(
+                    new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*-static*"), staticTextTC));
+            cfg.setTemplateLoader(tl);
+            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());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f6a693c5/src/test/java/org/apache/freemarker/core/TemplateLookupStrategyTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/TemplateLookupStrategyTest.java b/src/test/java/org/apache/freemarker/core/TemplateLookupStrategyTest.java
index e991df8..062d8e1 100644
--- a/src/test/java/org/apache/freemarker/core/TemplateLookupStrategyTest.java
+++ b/src/test/java/org/apache/freemarker/core/TemplateLookupStrategyTest.java
@@ -22,6 +22,7 @@ package org.apache.freemarker.core;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
+import java.io.Serializable;
 import java.io.StringWriter;
 import java.util.Locale;
 
@@ -295,7 +296,7 @@ public class TemplateLookupStrategyTest {
             cfg.clearTemplateCache();
         }
     }
-    
+
     @Test
     public void testCustomLookupCondition() throws IOException, TemplateException {
         Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
@@ -331,8 +332,8 @@ public class TemplateLookupStrategyTest {
         
         {
             final Locale locale = new Locale("xx");
-            final String domain = "foo.com";
-            final Template t = cfg.getTemplate("t.ftl", locale, domain, "utf-8", false);
+            final Domain domain = new Domain("foo.com");
+            final Template t = cfg.getTemplate("t.ftl", locale, domain);
             assertEquals("t.ftl", t.getName());
             assertEquals("@foo.com/t.ftl", t.getSourceName());
             assertEquals(locale, t.getLocale());
@@ -354,8 +355,8 @@ public class TemplateLookupStrategyTest {
 
         {
             final Locale locale = new Locale("xx");
-            final String domain = "bar.com";
-            final Template t = cfg.getTemplate("t.ftl", locale, domain, "utf-8", false);
+            final Domain domain = new Domain("bar.com");
+            final Template t = cfg.getTemplate("t.ftl", locale, domain);
             assertEquals("t.ftl", t.getName());
             assertEquals("@bar.com/t.ftl", t.getSourceName());
             assertEquals(locale, t.getLocale());
@@ -379,8 +380,8 @@ public class TemplateLookupStrategyTest {
         
         {
             final Locale locale = new Locale("xx", "YY");
-            final String domain = "baaz.com";
-            final Template t = cfg.getTemplate("t.ftl", locale, domain, "utf-8", false);
+            final Domain domain = new Domain("baaz.com");
+            final Template t = cfg.getTemplate("t.ftl", locale, domain);
             assertEquals("t.ftl", t.getName());
             assertEquals("@default/t.ftl", t.getSourceName());
             assertEquals(locale, t.getLocale());
@@ -404,8 +405,8 @@ public class TemplateLookupStrategyTest {
         
         {
             final Locale locale = new Locale("xx", "YY");
-            final String domain = "nosuch.com";
-            final Template t = cfg.getTemplate("i.ftl", locale, domain, "utf-8", false);
+            final Domain domain = new Domain("nosuch.com");
+            final Template t = cfg.getTemplate("i.ftl", locale, domain);
             assertEquals("i.ftl", t.getName());
             assertEquals("@default/i_xx.ftl", t.getSourceName());
             assertEquals(locale, t.getLocale());
@@ -424,8 +425,8 @@ public class TemplateLookupStrategyTest {
         {
             cfg.setLocalizedLookup(false);
             final Locale locale = new Locale("xx", "YY");
-            final String domain = "nosuch.com";
-            final Template t = cfg.getTemplate("i.ftl", locale, domain, "utf-8", false);
+            final Domain domain = new Domain("nosuch.com");
+            final Template t = cfg.getTemplate("i.ftl", locale, domain);
             assertEquals("i.ftl", t.getName());
             assertEquals("@default/i.ftl", t.getSourceName());
             assertEquals(locale, t.getLocale());
@@ -442,8 +443,8 @@ public class TemplateLookupStrategyTest {
         
         {
             final Locale locale = new Locale("xx");
-            final String domain = "foo.com";
-            final Template t = cfg.getTemplate("t2.ftl", locale, domain, "utf-8", false);
+            final Domain domain = new Domain("foo.com");
+            final Template t = cfg.getTemplate("t2.ftl", locale, domain);
             assertOutputEquals(t2XxLocaleExpectedOutput, t);
             assertEquals(
                     ImmutableList.of(
@@ -458,8 +459,8 @@ public class TemplateLookupStrategyTest {
         
         {
             final Locale locale = new Locale("yy");
-            final String domain = "foo.com";
-            final Template t = cfg.getTemplate("t2.ftl", locale, domain, "utf-8", false);
+            final Domain domain = new Domain("foo.com");
+            final Template t = cfg.getTemplate("t2.ftl", locale, domain);
             assertOutputEquals(t2OtherLocaleExpectedOutput, t);
             assertEquals(
                     ImmutableList.of(
@@ -475,8 +476,8 @@ public class TemplateLookupStrategyTest {
         {
             cfg.setLocalizedLookup(false);
             final Locale locale = new Locale("xx");
-            final String domain = "foo.com";
-            final Template t = cfg.getTemplate("t2.ftl", locale, domain, "utf-8", false);
+            final Domain domain = new Domain("foo.com");
+            final Template t = cfg.getTemplate("t2.ftl", locale, domain);
             assertOutputEquals(t2OtherLocaleExpectedOutput, t);
             assertEquals(
                     ImmutableList.of(
@@ -492,8 +493,8 @@ public class TemplateLookupStrategyTest {
         
         {
             final Locale locale = new Locale("xx");
-            final String domain = "foo.com";
-            cfg.getTemplate("i3.ftl", locale, domain, "utf-8", false);
+            final Domain domain = new Domain("foo.com");
+            cfg.getTemplate("i3.ftl", locale, domain);
             assertEquals(
                     ImmutableList.of("@foo.com/i3_xx.ftl"),
                     tl.getLoadNames());
@@ -504,9 +505,9 @@ public class TemplateLookupStrategyTest {
         
         {
             final Locale locale = new Locale("xx");
-            final String domain = "bar.com";
+            final Domain domain = new Domain("bar.com");
             try {
-                cfg.getTemplate("i3.ftl", locale, domain, "utf-8", false);
+                cfg.getTemplate("i3.ftl", locale, domain);
             } catch (TemplateNotFoundException e) {
                 assertEquals("i3.ftl", e.getTemplateName());
                 assertEquals(domain, e.getCustomLookupCondition());
@@ -522,6 +523,29 @@ public class TemplateLookupStrategyTest {
         }
         
     }
+
+    public static class Domain implements Serializable {
+        private final String name;
+
+        public Domain(String name) {
+            this.name = name;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) return true;
+            if (o == null || getClass() != o.getClass()) return false;
+
+            Domain domain = (Domain) o;
+
+            return name != null ? name.equals(domain.name) : domain.name == null;
+        }
+
+        @Override
+        public int hashCode() {
+            return name != null ? name.hashCode() : 0;
+        }
+    }
     
     @Test
     public void testNonparsed() throws IOException {
@@ -594,9 +618,9 @@ public class TemplateLookupStrategyTest {
         private MyTemplateLookupStrategy() { }
 
         @Override
-        public TemplateLookupResult lookup(TemplateLookupContext ctx) throws IOException {
+        public <R extends TemplateLookupResult> R lookup(TemplateLookupContext<R> ctx) throws IOException {
             String lang = ctx.getTemplateLocale().getLanguage().toLowerCase();
-            TemplateLookupResult lookupResult = ctx.lookupWithAcquisitionStrategy(lang + "/" + ctx.getTemplateName());
+            R lookupResult = ctx.lookupWithAcquisitionStrategy(lang + "/" + ctx.getTemplateName());
             if (lookupResult.isPositive()) {
                 return lookupResult;
             }
@@ -611,8 +635,8 @@ public class TemplateLookupStrategyTest {
         public static final DomainTemplateLookupStrategy INSTANCE = new DomainTemplateLookupStrategy();
 
         @Override
-        public TemplateLookupResult lookup(TemplateLookupContext ctx) throws IOException {
-            String domain = (String) ctx.getCustomLookupCondition();
+        public <R extends TemplateLookupResult> R lookup(TemplateLookupContext<R> ctx) throws IOException {
+            Domain domain = (Domain) ctx.getCustomLookupCondition();
             if (domain == null) {
                 throw new NullPointerException("The domain wasn't specified");
             }
@@ -624,8 +648,8 @@ public class TemplateLookupStrategyTest {
                 return ctx.createNegativeLookupResult();
             }
             
-            TemplateLookupResult lookupResult = ctx.lookupWithLocalizedThenAcquisitionStrategy(
-                    "@" + domain + "/" + templateName,
+            R lookupResult = ctx.lookupWithLocalizedThenAcquisitionStrategy(
+                    "@" + domain.name + "/" + templateName,
                     ctx.getTemplateLocale());
             if (lookupResult.isPositive()) {
                 return lookupResult;

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f6a693c5/src/test/java/org/apache/freemarker/core/TemplateNotFoundMessageTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/TemplateNotFoundMessageTest.java b/src/test/java/org/apache/freemarker/core/TemplateNotFoundMessageTest.java
index 6758771..7348a69 100644
--- a/src/test/java/org/apache/freemarker/core/TemplateNotFoundMessageTest.java
+++ b/src/test/java/org/apache/freemarker/core/TemplateNotFoundMessageTest.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.*;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.Serializable;
 
 import org.apache.freemarker.core.templateresolver.MalformedTemplateNameException;
 import org.apache.freemarker.core.templateresolver.TemplateLoader;
@@ -161,7 +162,12 @@ public class TemplateNotFoundMessageTest {
         }
         
         try {
-            cfg.getTemplate("./missing", null, "example.com", null, false);
+            cfg.getTemplate("./missing", null, new Serializable() {
+                @Override
+                public String toString() {
+                    return "example.com";
+                }
+            });
             fail();
         } catch (TemplateNotFoundException e) {
             showErrorMessage(e.getMessage());

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f6a693c5/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 ab27c2a..996f4fd 100644
--- a/src/test/java/org/apache/freemarker/core/templateresolver/DefaultTemplateResolverTest.java
+++ b/src/test/java/org/apache/freemarker/core/templateresolver/DefaultTemplateResolverTest.java
@@ -23,7 +23,6 @@ import static org.junit.Assert.*;
 
 import java.io.IOException;
 import java.io.Serializable;
-import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.util.Locale;
 
@@ -55,13 +54,13 @@ public class DefaultTemplateResolverTest {
         tr.setTemplateUpdateDelayMilliseconds(1000L);
         loader.setThrowException(true);
         try {
-            tr.getTemplate("t", Locale.getDefault(), null, "").getTemplate();
+            tr.getTemplate("t", Locale.getDefault(), null).getTemplate();
             fail();
         } catch (IOException e) {
             assertEquals("mock IO exception", e.getMessage());
             assertEquals(1, loader.getLoadAttemptCount());
             try {
-                tr.getTemplate("t", Locale.getDefault(), null, "").getTemplate();
+                tr.getTemplate("t", Locale.getDefault(), null).getTemplate();
                 fail();
             } catch (IOException e2) {
                 // Still 1 - returned cached exception
@@ -72,7 +71,7 @@ public class DefaultTemplateResolverTest {
                 assertEquals(1, loader.getLoadAttemptCount());
                 try {
                     Thread.sleep(1100L);
-                    tr.getTemplate("t", Locale.getDefault(), null, "").getTemplate();
+                    tr.getTemplate("t", Locale.getDefault(), null).getTemplate();
                     fail();
                 } catch (IOException e3) {
                     // Cache had to retest
@@ -91,13 +90,13 @@ public class DefaultTemplateResolverTest {
                 DefaultTemplateNameFormat.INSTANCE, new Configuration());
         cache.setTemplateUpdateDelayMilliseconds(1000L);
         cache.setLocalizedLookup(false);
-        assertNull(cache.getTemplate("t", Locale.getDefault(), null, "").getTemplate());
+        assertNull(cache.getTemplate("t", Locale.getDefault(), null).getTemplate());
         assertEquals(1, loader.getLoadAttemptCount());
-        assertNull(cache.getTemplate("t", Locale.getDefault(), null, "").getTemplate());
+        assertNull(cache.getTemplate("t", Locale.getDefault(), null).getTemplate());
         // Still 1 - returned cached exception
         assertEquals(1, loader.getLoadAttemptCount());
         Thread.sleep(1100L);
-        assertNull(cache.getTemplate("t", Locale.getDefault(), null, "").getTemplate());
+        assertNull(cache.getTemplate("t", Locale.getDefault(), null).getTemplate());
         // Cache had to retest
         assertEquals(2, loader.getLoadAttemptCount());
     }
@@ -274,6 +273,7 @@ public class DefaultTemplateResolverTest {
     public void testWrongEncodingReload() throws IOException {
         Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
         cfg.setLocale(Locale.US);
+        cfg.setDefaultEncoding("utf-8");
         
         MonitoredTemplateLoader tl = new MonitoredTemplateLoader();
         tl.putBinaryTemplate("utf-8_en.ftl", "<#ftl encoding='utf-8'>Béka");
@@ -283,25 +283,7 @@ public class DefaultTemplateResolverTest {
         cfg.setTemplateLoader(tl);
         
         {
-            Template t = cfg.getTemplate("utf-8.ftl", "Utf-8");
-            assertEquals("utf-8.ftl", t.getName());
-            assertEquals("utf-8_en.ftl", t.getSourceName());
-            assertEquals("Utf-8", t.getEncoding());
-            assertEquals("Béka", t.toString());
-            
-            assertEquals(
-                    ImmutableList.of(
-                            CreateSessionEvent.INSTANCE,
-                            new LoadEvent("utf-8_en_US.ftl", TemplateLoadingResultStatus.NOT_FOUND),
-                            new LoadEvent("utf-8_en.ftl", TemplateLoadingResultStatus.OPENED),
-                            CloseSessionEvent.INSTANCE),
-                    tl.getEvents());
-        }
-        
-        {
-            tl.clearEvents();
-            
-            Template t = cfg.getTemplate("utf-8.ftl", "ISO-8859-5");
+            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());
@@ -315,11 +297,11 @@ public class DefaultTemplateResolverTest {
                             CloseSessionEvent.INSTANCE),
                     tl.getEvents());
         }
-        
+
         {
             tl.clearEvents();
             
-            Template t = cfg.getTemplate("iso-8859-1.ftl", "utf-8");
+            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());
@@ -338,6 +320,7 @@ public class DefaultTemplateResolverTest {
     public void testNoWrongEncodingForTemplateLoader2WithReader() throws IOException {
         Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
         cfg.setLocale(Locale.US);
+        cfg.setDefaultEncoding("utf-8");
         
         MonitoredTemplateLoader tl = new MonitoredTemplateLoader();
         tl.putTextTemplate("foo_en.ftl", "<#ftl encoding='utf-8'>ő");
@@ -345,25 +328,7 @@ public class DefaultTemplateResolverTest {
         cfg.setTemplateLoader(tl);
         
         {
-            Template t = cfg.getTemplate("foo.ftl", "Utf-8");
-            assertEquals("foo.ftl", t.getName());
-            assertEquals("foo_en.ftl", t.getSourceName());
-            assertNull(t.getEncoding());
-            assertEquals("ő", t.toString());
-            
-            assertEquals(
-                    ImmutableList.of(
-                            CreateSessionEvent.INSTANCE,
-                            new LoadEvent("foo_en_US.ftl", TemplateLoadingResultStatus.NOT_FOUND),
-                            new LoadEvent("foo_en.ftl", TemplateLoadingResultStatus.OPENED),
-                            CloseSessionEvent.INSTANCE),                
-                    tl.getEvents());
-        }
-        
-        {
-            tl.clearEvents();
-            
-            Template t = cfg.getTemplate("foo.ftl", "iso-8859-1");
+            Template t = cfg.getTemplate("foo.ftl");
             assertEquals("foo.ftl", t.getName());
             assertEquals("foo_en.ftl", t.getSourceName());
             assertNull(t.getEncoding());
@@ -378,89 +343,12 @@ public class DefaultTemplateResolverTest {
                     tl.getEvents());
         }
     }
-    
-    @Test
-    public void testEncodingSelection() throws IOException {
-        Locale hungary = new Locale("hu", "HU"); 
-                
-        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
-        cfg.setDefaultEncoding("utf-8");
-        
-        MonitoredTemplateLoader tl = new MonitoredTemplateLoader();
-        tl.putBinaryTemplate("t.ftl", "Foo");
-        tl.putBinaryTemplate("t_de.ftl", "Vuu");
-        tl.putBinaryTemplate("t2.ftl", "<#ftl encoding='ISO-8859-5'>пример", Charset.forName("ISO-8859-5"), "v1");
-        tl.putBinaryTemplate("t2_de.ftl", "<#ftl encoding='ISO-8859-5'>пример", Charset.forName("ISO-8859-5"), "v1");
-        cfg.setTemplateLoader(tl);
 
-        // No locale-to-encoding mapping exists yet:
-        {
-            Template t = cfg.getTemplate("t.ftl", Locale.GERMANY);
-            assertEquals("t.ftl", t.getName());
-            assertEquals("t_de.ftl", t.getSourceName());
-            assertEquals("utf-8", t.getEncoding());
-            assertEquals("Vuu", t.toString());
-        }
-        
-        cfg.setEncoding(Locale.GERMANY, "ISO-8859-1");
-        cfg.setEncoding(hungary, "ISO-8859-2");
-        {
-            Template t = cfg.getTemplate("t.ftl", Locale.CHINESE);
-            assertEquals("t.ftl", t.getName());
-            assertEquals("t.ftl", t.getSourceName());
-            assertEquals("utf-8", t.getEncoding());
-            assertEquals("Foo", t.toString());
-        }
-        {
-            Template t = cfg.getTemplate("t.ftl", Locale.GERMANY);
-            assertEquals("t.ftl", t.getName());
-            assertEquals("t_de.ftl", t.getSourceName());
-            assertEquals("ISO-8859-1", t.getEncoding());
-            assertEquals("Vuu", t.toString());
-        }
-        {
-            Template t = cfg.getTemplate("t.ftl", hungary);
-            assertEquals("t.ftl", t.getName());
-            assertEquals("t.ftl", t.getSourceName());
-            assertEquals("ISO-8859-2", t.getEncoding());
-            assertEquals("Foo", t.toString());
-        }
-        
-        // #ftl header overrides:
-        {
-            Template t = cfg.getTemplate("t2.ftl", Locale.CHINESE);
-            assertEquals("t2.ftl", t.getName());
-            assertEquals("t2.ftl", t.getSourceName());
-            assertEquals("ISO-8859-5", t.getEncoding());
-            assertEquals("пример", t.toString());
-        }
-        {
-            Template t = cfg.getTemplate("t2.ftl", Locale.GERMANY);
-            assertEquals("t2.ftl", t.getName());
-            assertEquals("t2_de.ftl", t.getSourceName());
-            assertEquals("ISO-8859-5", t.getEncoding());
-            assertEquals("пример", t.toString());
-        }
-        {
-            Template t = cfg.getTemplate("t2.ftl", hungary);
-            assertEquals("t2.ftl", t.getName());
-            assertEquals("t2.ftl", t.getSourceName());
-            assertEquals("ISO-8859-5", t.getEncoding());
-            assertEquals("пример", t.toString());
-        }
-    }
-    
     @Test
     public void testTemplateNameFormatException() throws IOException {
         Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
         cfg.setTemplateNameFormat(DefaultTemplateNameFormat.INSTANCE);
         try {
-            cfg.getTemplate("../x", null, null, null, true);
-            fail();
-        } catch (MalformedTemplateNameException e) {
-            // expected
-        }
-        try {
             cfg.getTemplate("../x");
             fail();
         } catch (MalformedTemplateNameException e) {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f6a693c5/src/test/java/org/apache/freemarker/test/templatesuite/TemplateTestCase.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/test/templatesuite/TemplateTestCase.java b/src/test/java/org/apache/freemarker/test/templatesuite/TemplateTestCase.java
index eea08f2..b2f8c26 100644
--- a/src/test/java/org/apache/freemarker/test/templatesuite/TemplateTestCase.java
+++ b/src/test/java/org/apache/freemarker/test/templatesuite/TemplateTestCase.java
@@ -146,10 +146,6 @@ public class TemplateTestCase extends FileTestCase {
             if (!st.hasMoreTokens()) fail("Expecting alias after 'as' in autoimport");
             String alias = st.nextToken();
             conf.addAutoImport(alias, libname);
-        } else if ("clear_encoding_map".equals(param)) {
-            if (_StringUtil.getYesNo(value)) {
-                conf.clearEncodingMap();
-            }
         } else if ("input_encoding".equals(param)) {
             conf.setDefaultEncoding(value);
         // INCOMPATIBLE_IMPROVEMENTS is a list here, and was already set in the constructor.

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f6a693c5/src/test/resources/org/apache/freemarker/test/templatesuite/expected/include2.txt
----------------------------------------------------------------------
diff --git a/src/test/resources/org/apache/freemarker/test/templatesuite/expected/include2.txt b/src/test/resources/org/apache/freemarker/test/templatesuite/expected/include2.txt
index ad47d13..b7c43a9 100644
--- a/src/test/resources/org/apache/freemarker/test/templatesuite/expected/include2.txt
+++ b/src/test/resources/org/apache/freemarker/test/templatesuite/expected/include2.txt
@@ -19,11 +19,6 @@
 A próba
 A próba
 
-A próba
-A próba
-A próba
-A próba
-
 A próba
 A próba
 A próba

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f6a693c5/src/test/resources/org/apache/freemarker/test/templatesuite/templates/charset-in-header_inc2.ftl
----------------------------------------------------------------------
diff --git a/src/test/resources/org/apache/freemarker/test/templatesuite/templates/charset-in-header_inc2.ftl b/src/test/resources/org/apache/freemarker/test/templatesuite/templates/charset-in-header_inc2.ftl
index 0b3427a..66100ec 100644
--- a/src/test/resources/org/apache/freemarker/test/templatesuite/templates/charset-in-header_inc2.ftl
+++ b/src/test/resources/org/apache/freemarker/test/templatesuite/templates/charset-in-header_inc2.ftl
@@ -16,4 +16,4 @@
   specific language governing permissions and limitations
   under the License.
 -->
-����
+őŐűŰ

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f6a693c5/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include2-included-encoding.ftl
----------------------------------------------------------------------
diff --git a/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include2-included-encoding.ftl b/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include2-included-encoding.ftl
deleted file mode 100644
index 8a1a56d..0000000
--- a/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include2-included-encoding.ftl
+++ /dev/null
@@ -1,20 +0,0 @@
-<#ftl encoding='utf-8'>
-<#--
-  Licensed to the Apache Software Foundation (ASF) under one
-  or more contributor license agreements.  See the NOTICE file
-  distributed with this work for additional information
-  regarding copyright ownership.  The ASF licenses this file
-  to you under the Apache License, Version 2.0 (the
-  "License"); you may not use this file except in compliance
-  with the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing,
-  software distributed under the License is distributed on an
-  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-  KIND, either express or implied.  See the License for the
-  specific language governing permissions and limitations
-  under the License.
--->
-${'A'} próba

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f6a693c5/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include2.ftl
----------------------------------------------------------------------
diff --git a/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include2.ftl b/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include2.ftl
index 41b8ed5..5f3ccc3 100644
--- a/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include2.ftl
+++ b/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include2.ftl
@@ -20,12 +20,6 @@
 <#assign s = "de">
 <#include "inclu" + s + "2-included.ftl">
 
-<#assign sEncoding="ISO-8859-1">
-<#include "include2-included.ftl" encoding="ISO-8859-1">
-<#include "include2-included.ftl" encoding=sEncoding>
-<#include "include2-included-encoding.ftl" encoding="ISO-8859-1">
-<#include "include2-included-encoding.ftl" encoding=sEncoding>
-
 <#assign bTrue=true>
 <#assign bFalse=false>
 <#include "include2-included.ftl" ignore_missing=true>

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f6a693c5/src/test/resources/org/apache/freemarker/test/templatesuite/testcases.xml
----------------------------------------------------------------------
diff --git a/src/test/resources/org/apache/freemarker/test/templatesuite/testcases.xml b/src/test/resources/org/apache/freemarker/test/templatesuite/testcases.xml
index fdc65b1..e38110e 100644
--- a/src/test/resources/org/apache/freemarker/test/templatesuite/testcases.xml
+++ b/src/test/resources/org/apache/freemarker/test/templatesuite/testcases.xml
@@ -34,7 +34,6 @@
  <!ELEMENT setting EMPTY>
      <!ATTLIST setting 
             auto_import CDATA #IMPLIED
-            clear_encoding_map (Y|N) #IMPLIED
             input_encoding CDATA #IMPLIED
             locale CDATA #IMPLIED
             object_wrapper CDATA #IMPLIED
@@ -61,9 +60,7 @@ Note that for the incompatible_improvements setting you can specify a list of ve
    <testCase name="arithmetic" />
    <testCase name="assignments" noOutput="true" />
    <testCase name="boolean" />
-   <testCase name="charset-in-header">
-      <setting clear_encoding_map="Y" input_encoding="ISO-8859-5" />
-   </testCase>
+   <testCase name="charset-in-header" />
    <testCase name="comment" />
    <testCase name="comparisons" />
    <testCase name="compress" />


Mime
View raw message