Removed `Template.createPlainTextTemplate`, as this convenience methods was 
hardly ever used.


Project: http://git-wip-us.apache.org/repos/asf/freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/freemarker/commit/ef409c2b
Tree: http://git-wip-us.apache.org/repos/asf/freemarker/tree/ef409c2b
Diff: http://git-wip-us.apache.org/repos/asf/freemarker/diff/ef409c2b

Branch: refs/heads/3
Commit: ef409c2be180eecbd7a9b747c5935ce9b2cdebb1
Parents: d1a727b
Author: ddekany <ddek...@apache.org>
Authored: Sat Apr 14 16:54:48 2018 +0200
Committer: ddekany <ddek...@apache.org>
Committed: Sat Apr 14 16:55:23 2018 +0200

----------------------------------------------------------------------
 FM3-CHANGE-LOG.txt                              |  1 +
 .../core/OptInTemplateClassResolverTest.java    | 58 ++++++++++----------
 .../freemarker/core/OutputFormatTest.java       | 11 +++-
 .../core/TemplateConstructorsTest.java          |  6 +-
 .../core/TemplateGetEncodingTest.java           |  1 -
 .../org/apache/freemarker/core/Template.java    | 40 --------------
 .../core/UnparsedTemplateLanguage.java          | 12 +++-
 7 files changed, 52 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/freemarker/blob/ef409c2b/FM3-CHANGE-LOG.txt
----------------------------------------------------------------------
diff --git a/FM3-CHANGE-LOG.txt b/FM3-CHANGE-LOG.txt
index c30b690..245be21 100644
--- a/FM3-CHANGE-LOG.txt
+++ b/FM3-CHANGE-LOG.txt
@@ -610,6 +610,7 @@ Core / Miscellaneous
 - Added `org.apache.freemarker.core.util.CallableUtils`, to help in 
implementing (and invoking) `TemplateCallableModel`-s.
 - Renamed `Environment.getDataModel()` to 
`getDataModelWithSharedVariableFallback()`
   Renamed `Environment.getGlobalVariables()` to 
`getGloballyVisibleVariables()()`
+- Removed `Template.createPlainTextTemplate`, as this convenience methods was 
hardly ever used.
 
 Build / development process changes
 -----------------------------------

http://git-wip-us.apache.org/repos/asf/freemarker/blob/ef409c2b/freemarker-core-test/src/test/java/org/apache/freemarker/core/OptInTemplateClassResolverTest.java
----------------------------------------------------------------------
diff --git 
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/OptInTemplateClassResolverTest.java
 
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/OptInTemplateClassResolverTest.java
index ca21391..d68be35 100644
--- 
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/OptInTemplateClassResolverTest.java
+++ 
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/OptInTemplateClassResolverTest.java
@@ -36,13 +36,13 @@ public class OptInTemplateClassResolverTest extends 
TestCase {
         super(name);
     }
     
-    private static final Set ALLOWED_CLASSES = new HashSet();
+    private static final Set<String> ALLOWED_CLASSES = new HashSet<>();
     static {
         ALLOWED_CLASSES.add("java.lang.String");
         ALLOWED_CLASSES.add("java.lang.Integer");
     }
     
-    private static final List TRUSTED_TEMPLATES = new ArrayList();
+    private static final List<String> TRUSTED_TEMPLATES = new ArrayList<>();
     static {
         TRUSTED_TEMPLATES.add("lib/*");
         TRUSTED_TEMPLATES.add("/include/*");
@@ -53,8 +53,8 @@ public class OptInTemplateClassResolverTest extends TestCase {
             ALLOWED_CLASSES, TRUSTED_TEMPLATES);
     
 
-    public void testOptIn() throws TemplateException {
-        Template dummyTemp = Template.createPlainTextTemplate("foo.f3ah", "",
+    public void testOptIn() throws Exception {
+        Template dummyTemp = new Template("foo.f3ah", "",
                 new TestConfigurationBuilder().build());
 
         assertEquals(String.class, resolver.resolve("java.lang.String", null, 
dummyTemp));
@@ -67,24 +67,24 @@ public class OptInTemplateClassResolverTest extends 
TestCase {
         }
     }
 
-    public void testTrusted() throws TemplateException {
+    public void testTrusted() throws Exception {
         Configuration cfg = new TestConfigurationBuilder().build();
 
         assertEquals(Long.class, resolver.resolve("java.lang.Long", null,
-                Template.createPlainTextTemplate("lib/foo.f3ah", "", cfg)));
+                new Template("lib/foo.f3ah", "", cfg)));
         assertEquals(String.class, resolver.resolve("java.lang.String", null,
-                Template.createPlainTextTemplate("lib/foo.f3ah", "", cfg)));
+                new Template("lib/foo.f3ah", "", cfg)));
         assertEquals(Long.class, resolver.resolve("java.lang.Long", null,
-                Template.createPlainTextTemplate("/lib/foo.f3ah", "", cfg)));
+                new Template("/lib/foo.f3ah", "", cfg)));
         assertEquals(Long.class, resolver.resolve("java.lang.Long", null,
-                Template.createPlainTextTemplate("include/foo.f3ah", "", 
cfg)));
+                new Template("include/foo.f3ah", "", cfg)));
         assertEquals(Long.class, resolver.resolve("java.lang.Long", null,
-                Template.createPlainTextTemplate("trusted.f3ah", "", cfg)));
+                new Template("trusted.f3ah", "", cfg)));
         assertEquals(Long.class, resolver.resolve("java.lang.Long", null,
-                Template.createPlainTextTemplate("/trusted.f3ah", "", cfg)));
+                new Template("/trusted.f3ah", "", cfg)));
     }
 
-    public void testCraftedTrusted() throws TemplateException {
+    public void testCraftedTrusted() throws Exception {
         testTrusted_checkFails("lib/../foo.f3ah");
         testTrusted_checkFails("lib\\..\\foo.f3ah");
         testTrusted_checkFails("lib\\../foo.f3ah");
@@ -113,10 +113,10 @@ public class OptInTemplateClassResolverTest extends 
TestCase {
         }
     }
     
-    public void testTrusted_checkFails(String templateName) {
+    public void testTrusted_checkFails(String templateName) throws Exception {
         try {
             resolver.resolve("java.lang.Long", null,
-                    Template.createPlainTextTemplate(templateName, "",
+                    new Template(templateName, "",
                             new TestConfigurationBuilder().build()));
             fail();
         } catch (TemplateException e) {
@@ -134,12 +134,12 @@ public class OptInTemplateClassResolverTest extends 
TestCase {
 
             TemplateClassResolver res = cfg.getNewBuiltinClassResolver();
             assertEquals(String.class, res.resolve("java.lang.String", null,
-                    Template.createPlainTextTemplate("foo.f3ah", "", cfg)));
+                    new Template("foo.f3ah", "", cfg)));
             assertEquals(String.class, res.resolve("java.lang.String", null,
-                    Template.createPlainTextTemplate("lib/bar.f3ah", "", 
cfg)));
+                    new Template("lib/bar.f3ah", "", cfg)));
             try {
                 res.resolve("java.lang.String", null,
-                        Template.createPlainTextTemplate("bar.f3ah", "", cfg));
+                        new Template("bar.f3ah", "", cfg));
                 fail();
             } catch (TemplateException e) {
                 // Expected
@@ -155,12 +155,12 @@ public class OptInTemplateClassResolverTest extends 
TestCase {
 
             TemplateClassResolver res = cfg.getNewBuiltinClassResolver();
             assertEquals(String.class, res.resolve("java.lang.String", null,
-                    Template.createPlainTextTemplate("foo.f3ah", "", cfg)));
+                    new Template("foo.f3ah", "", cfg)));
             assertEquals(Integer.class, res.resolve("java.lang.Integer", null,
-                    Template.createPlainTextTemplate("foo.f3ah", "", cfg)));
+                    new Template("foo.f3ah", "", cfg)));
             try {
                 res.resolve("java.lang.Long", null,
-                        Template.createPlainTextTemplate("foo.f3ah", "", cfg));
+                        new Template("foo.f3ah", "", cfg));
                 fail();
             } catch (TemplateException e) {
                 // good
@@ -176,23 +176,23 @@ public class OptInTemplateClassResolverTest extends 
TestCase {
                     .build();
             TemplateClassResolver res = cfg.getNewBuiltinClassResolver();
             assertEquals(String.class, res.resolve("java.lang.String", null,
-                    Template.createPlainTextTemplate("x.f3ah", "", cfg)));
+                    new Template("x.f3ah", "", cfg)));
             assertEquals(Integer.class, res.resolve("java.lang.Integer", null,
-                    Template.createPlainTextTemplate("x.f3ah", "", cfg)));
+                    new Template("x.f3ah", "", cfg)));
             try {
                 res.resolve("java.lang.Long", null,
-                        Template.createPlainTextTemplate("x.f3ah", "", cfg));
+                        new Template("x.f3ah", "", cfg));
                 fail();
             } catch (TemplateException e) {
                 // Expected
             }
             assertEquals(Long.class, res.resolve("java.lang.Long", null,
-                    Template.createPlainTextTemplate("foo.f3ah", "", cfg)));
+                    new Template("foo.f3ah", "", cfg)));
             assertEquals(Long.class, res.resolve("java.lang.Long", null,
-                    Template.createPlainTextTemplate("lib/bar.f3ah", "", 
cfg)));
+                    new Template("lib/bar.f3ah", "", cfg)));
             try {
                 res.resolve("java.lang.Long", null,
-                        Template.createPlainTextTemplate("x.f3ah", "", cfg));
+                        new Template("x.f3ah", "", cfg));
                 fail();
             } catch (TemplateException e) {
                 // Expected
@@ -214,16 +214,16 @@ public class OptInTemplateClassResolverTest extends 
TestCase {
                     .build();
             TemplateClassResolver res = cfg.getNewBuiltinClassResolver();
             assertEquals(String.class, res.resolve("java.lang.String", null,
-                    Template.createPlainTextTemplate("x.f3ah", "", cfg)));
+                    new Template("x.f3ah", "", cfg)));
             try {
                 res.resolve("java.lang.Long", null,
-                        Template.createPlainTextTemplate("x.f3ah", "", cfg));
+                        new Template("x.f3ah", "", cfg));
                 fail();
             } catch (TemplateException e) {
                 // Expected
             }
             assertEquals(Long.class, res.resolve("java.lang.Long", null,
-                    Template.createPlainTextTemplate("lib:bar.f3ah", "", 
cfg)));
+                    new Template("lib:bar.f3ah", "", cfg)));
         }
     }
     

http://git-wip-us.apache.org/repos/asf/freemarker/blob/ef409c2b/freemarker-core-test/src/test/java/org/apache/freemarker/core/OutputFormatTest.java
----------------------------------------------------------------------
diff --git 
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/OutputFormatTest.java
 
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/OutputFormatTest.java
index 8ce2396..1a3e65c 100644
--- 
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/OutputFormatTest.java
+++ 
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/OutputFormatTest.java
@@ -399,18 +399,23 @@ public class OutputFormatTest extends TemplateTest {
     
     @Test
     public void testUnparsedTemplate() throws IOException, TemplateException {
+        TemplateConfiguration tc = new TemplateConfiguration.Builder()
+                .templateLanguage(new UnparsedTemplateLanguage("x", null))
+                .recognizeStandardFileExtensions(false)
+                .build(); 
+        
         String content = "<#ftl>a<#foo>b${x}";
+        
         {
-            Template t = Template.createPlainTextTemplate("x", content, 
getConfiguration());
+            Template t = new Template("x", content, getConfiguration(), tc);
             Writer sw = new StringWriter();
             t.process(null, sw);
             assertEquals(content, sw.toString());
             assertEquals(UndefinedOutputFormat.INSTANCE, t.getOutputFormat());
         }
-        
         {
             setConfiguration(new 
TestConfigurationBuilder().outputFormat(HTMLOutputFormat.INSTANCE).build());
-            Template t = Template.createPlainTextTemplate("x", content, 
getConfiguration());
+            Template t = new Template("x", content, getConfiguration(), tc);
             Writer sw = new StringWriter();
             t.process(null, sw);
             assertEquals(content, sw.toString());

http://git-wip-us.apache.org/repos/asf/freemarker/blob/ef409c2b/freemarker-core-test/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java
----------------------------------------------------------------------
diff --git 
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java
 
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java
index ab51cd6..635c452 100644
--- 
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java
+++ 
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java
@@ -85,7 +85,11 @@ public class TemplateConstructorsTest {
             assertEquals(StandardCharsets.UTF_16LE, 
t.getActualSourceEncoding());
         }
         {
-            Template t = Template.createPlainTextTemplate(name, CONTENT, cfg);
+            Template t = new Template(name, CONTENT, cfg,
+                    new TemplateConfiguration.Builder()
+                    .templateLanguage(UnparsedTemplateLanguage.F3UU)
+                    .recognizeStandardFileExtensions(false)
+                    .build());
             assertEquals(name, t.getLookupName());
             assertNull(t.getSourceName());
             assertEquals(CONTENT, t.toString());

http://git-wip-us.apache.org/repos/asf/freemarker/blob/ef409c2b/freemarker-core-test/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java
----------------------------------------------------------------------
diff --git 
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java
 
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java
index c9263bc..e1ce734 100644
--- 
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java
+++ 
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java
@@ -58,7 +58,6 @@ public class TemplateGetEncodingTest {
         assertNull(cfg.getTemplate("text").getActualSourceEncoding());
         assertNull(cfg.getTemplate("text-unparsed").getActualSourceEncoding());
         assertNull(new Template(null, "test", cfg).getActualSourceEncoding());
-        assertNull(Template.createPlainTextTemplate(null, "<#test>", 
cfg).getActualSourceEncoding());
     }
 
 }

http://git-wip-us.apache.org/repos/asf/freemarker/blob/ef409c2b/freemarker-core/src/main/java/org/apache/freemarker/core/Template.java
----------------------------------------------------------------------
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/Template.java 
b/freemarker-core/src/main/java/org/apache/freemarker/core/Template.java
index c3df6c1..42e2686 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/Template.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/Template.java
@@ -56,7 +56,6 @@ import 
org.apache.freemarker.core.templateresolver.TemplateLoader;
 import org.apache.freemarker.core.templateresolver.TemplateLookupStrategy;
 import 
org.apache.freemarker.core.templateresolver.impl.DefaultTemplateResolver;
 import org.apache.freemarker.core.templateresolver.impl.FileTemplateLoader;
-import org.apache.freemarker.core.util.BugException;
 import org.apache.freemarker.core.util._CollectionUtils;
 import org.apache.freemarker.core.util._NullArgumentException;
 import org.apache.freemarker.core.valueformat.TemplateDateFormatFactory;
@@ -458,45 +457,6 @@ public class Template implements ProcessingConfiguration, 
CustomStateScope {
     }
 
     /**
-     * Same as {@link #createPlainTextTemplate(String, String, String, 
Configuration, Charset)} with {@code null}
-     * {@code sourceName} argument.
-     */
-    static public Template createPlainTextTemplate(String lookupName, String 
content, Configuration config) {
-        return createPlainTextTemplate(lookupName, null, content, config, 
null);
-    }
-
-    /**
-     * Creates a {@link Template} that only contains a single block of static 
text, no dynamic content.
-     * 
-     * @param lookupName
-     *            See {@link #getLookupName} for more details.
-     * @param sourceName
-     *            See {@link #getSourceName} for more details. If {@code 
null}, it will be the same as the {@code name}.
-     * @param content
-     *            the block of text that this template represents
-     * @param config
-     *            the configuration to which this template belongs
-     *
-     * @param sourceEncoding The charset used to decode the template content 
to the {@link String} passed in with the
-     *            {@code content} parameter. If that information is not known 
or irrelevant, this should be
-     *            {@code null}.
-     */
-    static public Template createPlainTextTemplate(String lookupName, String 
sourceName, String content, Configuration config,
-               Charset sourceEncoding) {
-        Template template;
-        try {
-            template = new Template(lookupName, sourceName, new 
StringReader(""), config, sourceEncoding);
-        } catch (IOException e) {
-            throw new BugException("Plain text template creation failed", e);
-        }
-        ((ASTStaticText) template.rootElement).replaceText(content);
-
-        _DebuggerService.registerTemplate(template);
-
-        return template;
-    }
-
-    /**
      * Executes template, using the data-model provided, writing the generated 
output to the supplied {@link Writer}.
      * 
      * <p>

http://git-wip-us.apache.org/repos/asf/freemarker/blob/ef409c2b/freemarker-core/src/main/java/org/apache/freemarker/core/UnparsedTemplateLanguage.java
----------------------------------------------------------------------
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/UnparsedTemplateLanguage.java
 
b/freemarker-core/src/main/java/org/apache/freemarker/core/UnparsedTemplateLanguage.java
index 336dfd3..2119ee3 100644
--- 
a/freemarker-core/src/main/java/org/apache/freemarker/core/UnparsedTemplateLanguage.java
+++ 
b/freemarker-core/src/main/java/org/apache/freemarker/core/UnparsedTemplateLanguage.java
@@ -36,10 +36,16 @@ public final class UnparsedTemplateLanguage extends 
TemplateLanguage {
     /**
      * Instance with {@link UndefinedOutputFormat} output format. 
      */
-    public static final UnparsedTemplateLanguage F3UU = new 
UnparsedTemplateLanguage(UndefinedOutputFormat.INSTANCE);
+    public static final UnparsedTemplateLanguage F3UU = new 
UnparsedTemplateLanguage(
+            "f3uu", true, UndefinedOutputFormat.INSTANCE);
 
-    private UnparsedTemplateLanguage(OutputFormat outputFormat) {
-        super("f3uu", true, outputFormat, 
AutoEscapingPolicy.ENABLE_IF_DEFAULT);
+    public UnparsedTemplateLanguage(String fileExtension, OutputFormat 
outputFormat) {
+        this(fileExtension, false, outputFormat);
+    }
+    
+    private UnparsedTemplateLanguage(String fileExtension, boolean 
allowExtensionStartingWithF,
+            OutputFormat outputFormat) {
+        super(fileExtension, allowExtensionStartingWithF, outputFormat, 
AutoEscapingPolicy.ENABLE_IF_DEFAULT);
     }
 
     /**

Reply via email to