FREEMARKER-55: TaglibFactory must be created only by builder.

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

Branch: refs/heads/3
Commit: 78071707b4ed13e1bcec4dc16fb55ffdf62e12e0
Parents: c0bb490
Author: Woonsan Ko <[email protected]>
Authored: Wed Jul 5 16:45:44 2017 -0400
Committer: Woonsan Ko <[email protected]>
Committed: Wed Jul 5 16:45:44 2017 -0400

----------------------------------------------------------------------
 .../freemarker/servlet/FreemarkerServlet.java   |   4 +-
 .../freemarker/servlet/jsp/TaglibFactory.java   | 118 +++++++++----------
 2 files changed, 61 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/78071707/freemarker-servlet/src/main/java/org/apache/freemarker/servlet/FreemarkerServlet.java
----------------------------------------------------------------------
diff --git 
a/freemarker-servlet/src/main/java/org/apache/freemarker/servlet/FreemarkerServlet.java
 
b/freemarker-servlet/src/main/java/org/apache/freemarker/servlet/FreemarkerServlet.java
index aad3d55..da0435d 100644
--- 
a/freemarker-servlet/src/main/java/org/apache/freemarker/servlet/FreemarkerServlet.java
+++ 
b/freemarker-servlet/src/main/java/org/apache/freemarker/servlet/FreemarkerServlet.java
@@ -636,7 +636,7 @@ public class FreemarkerServlet extends HttpServlet {
                 } else if 
(name.equals(INIT_PARAM_EXCEPTION_ON_MISSING_TEMPLATE)) {
                     exceptionOnMissingTemplate = _StringUtil.getYesNo(value);
                 } else if (name.equals(INIT_PARAM_META_INF_TLD_LOCATIONS)) {
-                    metaInfTldSources = 
TaglibFactory.Builder.parseMetaInfTldLocations(InitParamParser.parseCommaSeparatedList(value));
+                    metaInfTldSources = 
TaglibFactory.parseMetaInfTldLocations(InitParamParser.parseCommaSeparatedList(value));
                 } else if (name.equals(INIT_PARAM_CLASSPATH_TLDS)) {
                     List newClasspathTlds = new ArrayList();
                     if (classpathTlds != null) {
@@ -1000,7 +1000,7 @@ public class FreemarkerServlet extends HttpServlet {
         try {
             final String prop = 
_SecurityUtil.getSystemProperty(SYSTEM_PROPERTY_META_INF_TLD_SOURCES, null);
             metaInfTldSourcesFromSysProp = (List<MetaInfTldSource>) ((prop != 
null)
-                    ? 
TaglibFactory.Builder.parseMetaInfTldLocations(InitParamParser.parseCommaSeparatedList(prop))
+                    ? 
TaglibFactory.parseMetaInfTldLocations(InitParamParser.parseCommaSeparatedList(prop))
                     : Collections.emptyList());
         } catch (ParseException e) {
             throw new TemplateModelException(

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/78071707/freemarker-servlet/src/main/java/org/apache/freemarker/servlet/jsp/TaglibFactory.java
----------------------------------------------------------------------
diff --git 
a/freemarker-servlet/src/main/java/org/apache/freemarker/servlet/jsp/TaglibFactory.java
 
b/freemarker-servlet/src/main/java/org/apache/freemarker/servlet/jsp/TaglibFactory.java
index 4679e27..2026f8b 100644
--- 
a/freemarker-servlet/src/main/java/org/apache/freemarker/servlet/jsp/TaglibFactory.java
+++ 
b/freemarker-servlet/src/main/java/org/apache/freemarker/servlet/jsp/TaglibFactory.java
@@ -137,6 +137,59 @@ public class TaglibFactory implements TemplateHashModel {
     private List/*<String>*/ failedTldLocations = new ArrayList();
     private int nextTldLocationLookupPhase = 0;
 
+    public static MetaInfTldSource parseMetaInfTldLocation(String value) 
throws ParseException {
+        MetaInfTldSource metaInfTldSource;
+
+        if 
(value.equals(FreemarkerServlet.META_INF_TLD_LOCATION_WEB_INF_PER_LIB_JARS)) {
+            metaInfTldSource = WebInfPerLibJarMetaInfTldSource.INSTANCE;
+        } else if 
(value.startsWith(FreemarkerServlet.META_INF_TLD_LOCATION_CLASSPATH)) {
+            String itemRightSide = 
value.substring(FreemarkerServlet.META_INF_TLD_LOCATION_CLASSPATH.length())
+                    .trim();
+
+            if (itemRightSide.length() == 0) {
+                metaInfTldSource = new 
ClasspathMetaInfTldSource(Pattern.compile(".*", Pattern.DOTALL));
+            } else if (itemRightSide.startsWith(":")) {
+                final String regexpStr = itemRightSide.substring(1).trim();
+                if (regexpStr.length() == 0) {
+                    throw new ParseException("Empty regular expression after 
\""
+                            + 
FreemarkerServlet.META_INF_TLD_LOCATION_CLASSPATH + ":\"", -1);
+                }
+                metaInfTldSource = new 
ClasspathMetaInfTldSource(Pattern.compile(regexpStr));
+            } else {
+                throw new ParseException("Invalid \"" + 
FreemarkerServlet.META_INF_TLD_LOCATION_CLASSPATH
+                        + "\" value syntax: " + value, -1);
+            }
+        } else if 
(value.startsWith(FreemarkerServlet.META_INF_TLD_LOCATION_CLEAR)) {
+            metaInfTldSource = ClearMetaInfTldSource.INSTANCE;
+        } else {
+            throw new ParseException("Item has no recognized source type 
prefix: " + value, -1);
+        }
+
+        return metaInfTldSource;
+    }
+
+    public static List<MetaInfTldSource> parseMetaInfTldLocations(List<String> 
values) throws ParseException {
+        List<MetaInfTldSource> metaInfTldSources = null;
+
+        if (values != null) {
+            for (String value : values) {
+                final MetaInfTldSource metaInfTldSource = 
parseMetaInfTldLocation(value);
+
+                if (metaInfTldSources == null) {
+                    metaInfTldSources = new ArrayList();
+                }
+
+                metaInfTldSources.add(metaInfTldSource);
+            }
+        }
+
+        if (metaInfTldSources == null) {
+            metaInfTldSources = Collections.emptyList();
+        }
+
+        return metaInfTldSources;
+    }
+
     /**
     /**
      * Creates a new JSP taglib factory that will be used to load JSP tag 
libraries and functions for the web
@@ -149,8 +202,11 @@ public class TaglibFactory implements TemplateHashModel {
      * @param servletContext
      *            The servlet context whose JSP tag libraries this factory 
will load.
      */
-    public TaglibFactory(ServletContext servletContext) {
-        this.servletContext = servletContext;
+    private TaglibFactory(Builder builder) {
+        servletContext = builder.getServletContext();
+        objectWrapper = builder.getObjectWrapper();
+        metaInfTldSources = builder.getMetaInfTldSources();
+        classpathTlds = builder.getClassPathTlds();
     }
 
     /**
@@ -2101,65 +2157,9 @@ public class TaglibFactory implements TemplateHashModel {
         }
 
         public TaglibFactory build() throws ConfigurationException {
-            TaglibFactory taglibFactory = new TaglibFactory(servletContext);
-            taglibFactory.setObjectWrapper(objectWrapper);
-            taglibFactory.setMetaInfTldSources(metaInfTldSources);
-            taglibFactory.setClasspathTlds(classPathTlds);
+            TaglibFactory taglibFactory = new TaglibFactory(this);
             return taglibFactory;
         }
-
-        public static MetaInfTldSource parseMetaInfTldLocation(String value) 
throws ParseException {
-            MetaInfTldSource metaInfTldSource;
-
-            if 
(value.equals(FreemarkerServlet.META_INF_TLD_LOCATION_WEB_INF_PER_LIB_JARS)) {
-                metaInfTldSource = WebInfPerLibJarMetaInfTldSource.INSTANCE;
-            } else if 
(value.startsWith(FreemarkerServlet.META_INF_TLD_LOCATION_CLASSPATH)) {
-                String itemRightSide = 
value.substring(FreemarkerServlet.META_INF_TLD_LOCATION_CLASSPATH.length())
-                        .trim();
-
-                if (itemRightSide.length() == 0) {
-                    metaInfTldSource = new 
ClasspathMetaInfTldSource(Pattern.compile(".*", Pattern.DOTALL));
-                } else if (itemRightSide.startsWith(":")) {
-                    final String regexpStr = itemRightSide.substring(1).trim();
-                    if (regexpStr.length() == 0) {
-                        throw new ParseException("Empty regular expression 
after \""
-                                + 
FreemarkerServlet.META_INF_TLD_LOCATION_CLASSPATH + ":\"", -1);
-                    }
-                    metaInfTldSource = new 
ClasspathMetaInfTldSource(Pattern.compile(regexpStr));
-                } else {
-                    throw new ParseException("Invalid \"" + 
FreemarkerServlet.META_INF_TLD_LOCATION_CLASSPATH
-                            + "\" value syntax: " + value, -1);
-                }
-            } else if 
(value.startsWith(FreemarkerServlet.META_INF_TLD_LOCATION_CLEAR)) {
-                metaInfTldSource = ClearMetaInfTldSource.INSTANCE;
-            } else {
-                throw new ParseException("Item has no recognized source type 
prefix: " + value, -1);
-            }
-
-            return metaInfTldSource;
-        }
-
-        public static List<MetaInfTldSource> 
parseMetaInfTldLocations(List<String> values) throws ParseException {
-            List<MetaInfTldSource> metaInfTldSources = null;
-
-            if (values != null) {
-                for (String value : values) {
-                    final MetaInfTldSource metaInfTldSource = 
parseMetaInfTldLocation(value);
-
-                    if (metaInfTldSources == null) {
-                        metaInfTldSources = new ArrayList();
-                    }
-
-                    metaInfTldSources.add(metaInfTldSource);
-                }
-            }
-
-            if (metaInfTldSources == null) {
-                metaInfTldSources = Collections.emptyList();
-            }
-
-            return metaInfTldSources;
-        }
     }
 
 }

Reply via email to