You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by cb...@apache.org on 2018/01/31 13:09:07 UTC

svn commit: r1822795 - in /velocity/tools/trunk: velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ velocity-tools-view/src/main/java/org/apache/velocity/tools/view/

Author: cbrisson
Date: Wed Jan 31 13:09:06 2018
New Revision: 1822795

URL: http://svn.apache.org/viewvc?rev=1822795&view=rev
Log:
[tools] Minor BC fix in APIs of generic tools reading resources; plud on-the-fly and thread-safe init of importSupport

Modified:
    velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ImportTool.java
    velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/JsonTool.java
    velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/XmlTool.java
    velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ImportTool.java
    velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/JsonTool.java
    velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/XmlTool.java

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ImportTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ImportTool.java?rev=1822795&r1=1822794&r2=1822795&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ImportTool.java (original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ImportTool.java Wed Jan 31 13:09:06 2018
@@ -55,10 +55,13 @@ public class ImportTool extends SafeConf
      * Importsupport initialization
      * @param config
      */
-    protected void initializeImportSupport(ValueParser config)
+    protected synchronized void initializeImportSupport(ValueParser config)
     {
-        importSupport = new ImportSupport();
-        importSupport.configure(config);
+        if (importSupport == null)
+        {
+            importSupport = new ImportSupport();
+            importSupport.configure(config);
+        }
     }
 
     /**
@@ -84,6 +87,10 @@ public class ImportTool extends SafeConf
         }
         try
         {
+            if (importSupport == null)
+            {
+                initializeImportSupport(new ValueParser());
+            }
             return importSupport.getResourceString(resource);
         }
         catch (Exception ex)
@@ -107,6 +114,10 @@ public class ImportTool extends SafeConf
         }
         try
         {
+            if (importSupport == null)
+            {
+                initializeImportSupport(new ValueParser());
+            }
             return importSupport.acquireString(url);
         }
         catch (Exception ex)

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/JsonTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/JsonTool.java?rev=1822795&r1=1822794&r2=1822795&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/JsonTool.java (original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/JsonTool.java Wed Jan 31 13:09:06 2018
@@ -88,10 +88,13 @@ public class JsonTool extends ImportSupp
      * ImportSupport initialization
      * @param config
      */
-    protected void initializeImportSupport(ValueParser config)
+    protected synchronized void initializeImportSupport(ValueParser config)
     {
-        importSupport = new ImportSupport();
-        importSupport.configure(config);
+        if (importSupport == null)
+        {
+            importSupport = new ImportSupport();
+            importSupport.configure(config);
+        }
     }
 
     private JsonContent root = null;    
@@ -192,6 +195,10 @@ public class JsonTool extends ImportSupp
             Reader reader = null;
             try
             {
+                if (importSupport == null)
+                {
+                    initializeImportSupport(new ValueParser());
+                }
                 reader = importSupport.getResourceReader(resource);
                 if (reader != null)
                 {
@@ -227,6 +234,10 @@ public class JsonTool extends ImportSupp
             Reader reader = null;
             try
             {
+                if (importSupport == null)
+                {
+                    initializeImportSupport(new ValueParser());
+                }
                 reader = importSupport.acquireReader(url);
                 if (reader != null)
                 {

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/XmlTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/XmlTool.java?rev=1822795&r1=1822794&r2=1822795&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/XmlTool.java (original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/XmlTool.java Wed Jan 31 13:09:06 2018
@@ -97,10 +97,13 @@ public class XmlTool extends SafeConfig
      * ImportSupport initialization
      * @param config
      */
-    protected void initializeImportSupport(ValueParser config)
+    protected synchronized void initializeImportSupport(ValueParser config)
     {
-        importSupport = new ImportSupport();
-        importSupport.configure(config);
+        if (importSupport == null)
+        {
+            importSupport = new ImportSupport();
+            importSupport.configure(config);
+        }
     }
 
     /**
@@ -182,7 +185,7 @@ public class XmlTool extends SafeConfig
      * Parses the given XML string and uses the resulting {@link Document}
      * as the root {@link Node}.
      */
-    public void parse(String xml)
+    public XmlTool parse(String xml)
     {
         try
         {
@@ -195,16 +198,21 @@ public class XmlTool extends SafeConfig
         {
             getLog().error("could not parse given XML string", e);
         }
+        return this;
     }
 
     /**
      * Reads and parses a local resource file
      */
-    public void read(String resource)
+    public XmlTool read(String resource)
     {
         Reader reader = null;
         try
         {
+            if (importSupport == null)
+            {
+                initializeImportSupport(new ValueParser());
+            }
             reader = importSupport.getResourceReader(resource);
             if (reader != null)
             {
@@ -226,16 +234,21 @@ public class XmlTool extends SafeConfig
                 catch (IOException ioe) {}
             }
         }
+        return this;
     }
 
     /**
      * Reads and parses a remote or local URL
      */
-    public void fetch(String url)
+    public XmlTool fetch(String url)
     {
         Reader reader = null;
         try
         {
+            if (importSupport == null)
+            {
+                initializeImportSupport(new ValueParser());
+            }
             reader = importSupport.acquireReader(url);
             if (reader != null)
             {
@@ -257,6 +270,7 @@ public class XmlTool extends SafeConfig
                 catch (IOException ioe) {}
             }
         }
+        return this;
     }
 
     /**

Modified: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ImportTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ImportTool.java?rev=1822795&r1=1822794&r2=1822795&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ImportTool.java (original)
+++ velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ImportTool.java Wed Jan 31 13:09:06 2018
@@ -48,10 +48,13 @@ import org.apache.velocity.tools.generic
 @ValidScope(Scope.REQUEST)
 public class ImportTool extends org.apache.velocity.tools.generic.ImportTool
 {
-    protected void initializeImportSupport(ValueParser config)
+    protected synchronized void initializeImportSupport(ValueParser config)
     {
-        importSupport = new ViewImportSupport();
-        importSupport.configure(config);
+        if (importSupport == null)
+        {
+            importSupport = new ViewImportSupport();
+            importSupport.configure(config);
+        }
     }
 
     protected void configure(ValueParser values)

Modified: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/JsonTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/JsonTool.java?rev=1822795&r1=1822794&r2=1822795&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/JsonTool.java (original)
+++ velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/JsonTool.java Wed Jan 31 13:09:06 2018
@@ -47,10 +47,13 @@ public class JsonTool extends org.apache
      * @param config
      */
     @Override
-    protected void initializeImportSupport(ValueParser config)
+    protected synchronized void initializeImportSupport(ValueParser config)
     {
-        importSupport = new ViewImportSupport();
-        importSupport.configure(config);
+        if (importSupport == null)
+        {
+            importSupport = new ViewImportSupport();
+            importSupport.configure(config);
+        }
     }
 
     /**

Modified: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/XmlTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/XmlTool.java?rev=1822795&r1=1822794&r2=1822795&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/XmlTool.java (original)
+++ velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/XmlTool.java Wed Jan 31 13:09:06 2018
@@ -40,10 +40,13 @@ public class XmlTool extends org.apache.
      * @param config
      */
     @Override
-    protected void initializeImportSupport(ValueParser config)
+    protected synchronized void initializeImportSupport(ValueParser config)
     {
-        importSupport = new ViewImportSupport();
-        importSupport.configure(config);
+        if (importSupport == null)
+        {
+            importSupport = new ViewImportSupport();
+            importSupport.configure(config);
+        }
     }
 
     /**