freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [1/6] incubator-freemarker git commit: FREEMARKER-54: Remove ConfigurationFactoryBean#setSettings(...) because ancestor already contains equivalent one. Also, separate spring logger.
Date Mon, 19 Jun 2017 09:29:10 GMT
Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 33320725f -> ed3043856


FREEMARKER-54: Remove ConfigurationFactoryBean#setSettings(...) because ancestor already contains
equivalent one. Also, separate spring logger.


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

Branch: refs/heads/3
Commit: 94828521fc30f0d51c7728d37b537404c8096bfe
Parents: 1988dc0
Author: Woonsan Ko <woonsan@apache.org>
Authored: Sun Jun 18 22:12:03 2017 -0400
Committer: Woonsan Ko <woonsan@apache.org>
Committed: Sun Jun 18 22:12:03 2017 -0400

----------------------------------------------------------------------
 .../spring/ConfigurationFactoryBean.java        | 19 --------
 .../apache/freemarker/spring/_SpringLogs.java   | 35 +++++++++++++++
 .../SpringResourceTemplateLoader.java           |  9 ++--
 .../spring/ConfigurationFactoryBeanTest.java    | 46 ++++++++++++++------
 4 files changed, 71 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/94828521/freemarker-spring/src/main/java/org/apache/freemarker/spring/ConfigurationFactoryBean.java
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/main/java/org/apache/freemarker/spring/ConfigurationFactoryBean.java
b/freemarker-spring/src/main/java/org/apache/freemarker/spring/ConfigurationFactoryBean.java
index da275e7..6f78750 100644
--- a/freemarker-spring/src/main/java/org/apache/freemarker/spring/ConfigurationFactoryBean.java
+++ b/freemarker-spring/src/main/java/org/apache/freemarker/spring/ConfigurationFactoryBean.java
@@ -18,10 +18,6 @@
  */
 package org.apache.freemarker.spring;
 
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
 import org.apache.freemarker.core.Configuration;
 import org.apache.freemarker.core.Configuration.ExtendableBuilder;
 import org.springframework.beans.BeansException;
@@ -41,8 +37,6 @@ public class ConfigurationFactoryBean extends ExtendableBuilder<ConfigurationFac
 
     private AbstractFactoryBean<Configuration> delegate;
 
-    private Map<String, String> settings = new LinkedHashMap<>();
-
     public ConfigurationFactoryBean() {
         // By default, set the default version constant.
         // #setIncompatibleImprovements(Version) can be used to change it.
@@ -57,25 +51,12 @@ public class ConfigurationFactoryBean extends ExtendableBuilder<ConfigurationFac
 
             @Override
             protected Configuration createInstance() throws Exception {
-                for (Map.Entry<String, String> entry : settings.entrySet()) {
-                    setSetting(entry.getKey(), entry.getValue());
-                }
-
                 return build();
             }
 
         };
     }
 
-    public Map<String, String> getSettings() {
-        return Collections.unmodifiableMap(settings);
-    }
-
-    public void setSettings(Map<String, String> settings) {
-        this.settings.clear();
-        this.settings.putAll(settings);
-    }
-
     @Override
     public Configuration getObject() throws Exception {
         return delegate.getObject();

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/94828521/freemarker-spring/src/main/java/org/apache/freemarker/spring/_SpringLogs.java
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/main/java/org/apache/freemarker/spring/_SpringLogs.java
b/freemarker-spring/src/main/java/org/apache/freemarker/spring/_SpringLogs.java
new file mode 100644
index 0000000..87d0a63
--- /dev/null
+++ b/freemarker-spring/src/main/java/org/apache/freemarker/spring/_SpringLogs.java
@@ -0,0 +1,35 @@
+/*
+ * 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.spring;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * For internal use only; don't depend on this, there's no backward compatibility guarantee
at all!
+ * This class is to work around the lack of module system in Java, i.e., so that other FreeMarker
packages can
+ * access things inside this package that users shouldn't. 
+ */
+public final class _SpringLogs {
+
+    public static final Logger CORE = LoggerFactory.getLogger("org.apache.freemarker.spring");
+
+    public static final Logger TEMPLATE_RESOLVER = LoggerFactory.getLogger("org.apache.freemarker.spring.templateresolver");
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/94828521/freemarker-spring/src/main/java/org/apache/freemarker/spring/templateresolver/SpringResourceTemplateLoader.java
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/main/java/org/apache/freemarker/spring/templateresolver/SpringResourceTemplateLoader.java
b/freemarker-spring/src/main/java/org/apache/freemarker/spring/templateresolver/SpringResourceTemplateLoader.java
index a327bab..3f96228 100644
--- a/freemarker-spring/src/main/java/org/apache/freemarker/spring/templateresolver/SpringResourceTemplateLoader.java
+++ b/freemarker-spring/src/main/java/org/apache/freemarker/spring/templateresolver/SpringResourceTemplateLoader.java
@@ -22,11 +22,11 @@ import java.io.IOException;
 import java.io.Serializable;
 import java.util.Objects;
 
-import org.apache.freemarker.core._CoreLogs;
 import org.apache.freemarker.core.templateresolver.TemplateLoader;
 import org.apache.freemarker.core.templateresolver.TemplateLoaderSession;
 import org.apache.freemarker.core.templateresolver.TemplateLoadingResult;
 import org.apache.freemarker.core.templateresolver.TemplateLoadingSource;
+import org.apache.freemarker.spring._SpringLogs;
 import org.slf4j.Logger;
 import org.springframework.context.ResourceLoaderAware;
 import org.springframework.core.io.Resource;
@@ -37,7 +37,7 @@ import org.springframework.core.io.ResourceLoader;
  */
 public class SpringResourceTemplateLoader implements TemplateLoader, ResourceLoaderAware
{
 
-    private static final Logger LOG = _CoreLogs.TEMPLATE_RESOLVER;
+    private static final Logger LOG = _SpringLogs.TEMPLATE_RESOLVER;
 
     private ResourceLoader resourceLoader;
 
@@ -74,10 +74,7 @@ public class SpringResourceTemplateLoader implements TemplateLoader, ResourceLoa
                 version = lmd;
             }
         } catch (IOException e) {
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("The last modified timestamp of the resource at '{}' may not be
resolved. {}", name,
-                        e.toString());
-            }
+            LOG.debug("The last modified timestamp of the resource at '{}' may not be resolved.",
name, e);
         }
 
         if (ifSourceDiffersFrom != null && ifSourceDiffersFrom.equals(source)

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/94828521/freemarker-spring/src/test/java/org/apache/freemarker/spring/ConfigurationFactoryBeanTest.java
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/test/java/org/apache/freemarker/spring/ConfigurationFactoryBeanTest.java
b/freemarker-spring/src/test/java/org/apache/freemarker/spring/ConfigurationFactoryBeanTest.java
index 0938f5b..ddfd320 100644
--- a/freemarker-spring/src/test/java/org/apache/freemarker/spring/ConfigurationFactoryBeanTest.java
+++ b/freemarker-spring/src/test/java/org/apache/freemarker/spring/ConfigurationFactoryBeanTest.java
@@ -24,8 +24,8 @@ import static org.junit.Assert.assertTrue;
 
 import java.nio.charset.Charset;
 import java.util.HashMap;
-import java.util.LinkedHashMap;
 import java.util.Map;
+import java.util.Properties;
 
 import org.apache.freemarker.core.AutoEscapingPolicy;
 import org.apache.freemarker.core.Configuration;
@@ -65,25 +65,45 @@ public class ConfigurationFactoryBeanTest {
 
     @Test
     public void testConfigurationFactoryBeanSettings() throws Exception {
-        final Map<String, String> settings = new LinkedHashMap<>();
+        final Properties settings = new Properties();
 
-        settings.put(MutableParsingAndProcessingConfiguration.SOURCE_ENCODING_KEY, "UTF-8");
-        settings.put(MutableParsingAndProcessingConfiguration.WHITESPACE_STRIPPING_KEY, "true");
-        settings.put(MutableParsingAndProcessingConfiguration.AUTO_ESCAPING_POLICY_KEY, "enableIfSupported");
-        settings.put(MutableParsingAndProcessingConfiguration.RECOGNIZE_STANDARD_FILE_EXTENSIONS_KEY,
"true");
-        settings.put(MutableParsingAndProcessingConfiguration.TEMPLATE_LANGUAGE_KEY, "FTL");
-        settings.put(MutableParsingAndProcessingConfiguration.TAG_SYNTAX_KEY, "squareBracket");
-        settings.put(MutableParsingAndProcessingConfiguration.NAMING_CONVENTION_KEY, "camelCase");
-        settings.put(MutableParsingAndProcessingConfiguration.TAB_SIZE_KEY, "4");
+        settings.setProperty(MutableParsingAndProcessingConfiguration.SOURCE_ENCODING_KEY,
"UTF-8");
+        settings.setProperty(MutableParsingAndProcessingConfiguration.WHITESPACE_STRIPPING_KEY,
"true");
+        settings.setProperty(MutableParsingAndProcessingConfiguration.AUTO_ESCAPING_POLICY_KEY,
"enableIfSupported");
+        settings.setProperty(MutableParsingAndProcessingConfiguration.RECOGNIZE_STANDARD_FILE_EXTENSIONS_KEY,
"true");
+        settings.setProperty(MutableParsingAndProcessingConfiguration.TEMPLATE_LANGUAGE_KEY,
"FTL");
+        settings.setProperty(MutableParsingAndProcessingConfiguration.TAG_SYNTAX_KEY, "squareBracket");
+        settings.setProperty(MutableParsingAndProcessingConfiguration.NAMING_CONVENTION_KEY,
"camelCase");
+        settings.setProperty(MutableParsingAndProcessingConfiguration.TAB_SIZE_KEY, "4");
 
-        settings.put(ExtendableBuilder.OBJECT_WRAPPER_KEY, "restricted");
-        settings.put(ExtendableBuilder.TEMPLATE_CACHE_STORAGE_KEY, "strong:20, soft:250");
+        settings.setProperty(ExtendableBuilder.OBJECT_WRAPPER_KEY, "restricted");
+        settings.setProperty(ExtendableBuilder.TEMPLATE_CACHE_STORAGE_KEY, "strong:20, soft:250");
 
         final Map<String, Object> sharedVars = new HashMap<>();
         sharedVars.put("sharedVar1", "sharedVal1");
         sharedVars.put("sharedVar2", "sharedVal2");
 
-        // Creating bean definition which is equivalent to <bean/> element in Spring
XML configuration.
+        // Creating bean definition which is equivalent to <bean/> element in Spring
XML configuration like the following:
+        //
+        // <bean class="org.apache.freemarker.spring.ConfigurationFactoryBean">
+        //   <property name="incompatibleImprovements" value="3.0.0" />
+        //   <property name="settings">
+        //     <props>
+        //       <prop key="source_encoding">UTF-8</prop>
+        //       <prop key="whitespace_stripping">true</prop>
+        //       <!-- SNIP -->
+        //       <prop key="template_cache_storage">strong:20, soft:250</prop>
+        //     </props>
+        //   </property>
+        //   <property name="sharedVariables">
+        //     <map>
+        //       <entry key="sharedVar1" value="sharedVal1" />
+        //       <entry key="sharedVar2" value="sharedVal2" />
+        //     </map>
+        //   </property>
+        //   <property name="templateUpdateDelayMilliseconds" value="60000" />
+        //   <property name="localizedTemplateLookup" value="false" />
+        // </bean>
         BeanDefinition beanDef =
                 BeanDefinitionBuilder.genericBeanDefinition(ConfigurationFactoryBean.class.getName())
                 .addPropertyValue("incompatibleImprovements", new Version(3, 0, 0))


Mime
View raw message