You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2022/05/08 06:04:36 UTC

svn commit: r1900677 - in /manifoldcf/trunk: build.xml framework/core/src/main/java/org/apache/manifoldcf/core/i18n/MCFVelocityResourceLoader.java framework/core/src/main/java/org/apache/manifoldcf/core/i18n/Messages.java

Author: kwright
Date: Sun May  8 06:04:36 2022
New Revision: 1900677

URL: http://svn.apache.org/viewvc?rev=1900677&view=rev
Log:
CONNECTORS-1712: Rework the way we configure the velocity engine so we can find the templates.  This is a tentative solution that requires vetting.

Modified:
    manifoldcf/trunk/build.xml
    manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/i18n/MCFVelocityResourceLoader.java
    manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/i18n/Messages.java

Modified: manifoldcf/trunk/build.xml
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/build.xml?rev=1900677&r1=1900676&r2=1900677&view=diff
==============================================================================
--- manifoldcf/trunk/build.xml (original)
+++ manifoldcf/trunk/build.xml Sun May  8 06:04:36 2022
@@ -102,7 +102,6 @@
     <property name="servlet-api.version" value="3.1.0"/>
     <property name="stax-api.version" value="1.0.1"/>
     <property name="streambuffer.version" value="1.5.7"/>
-    <property name="velocity.version" value="1.7"/>
     <property name="velocity-engine-core.version" value="2.3"/>
     <property name="wss4j.version" value="1.5.12"/>
     <property name="xmlgraphics-commons.version" value="1.4"/>
@@ -2067,12 +2066,6 @@ Use Apache Forrest version forrest-0.9-d
         <mkdir dir="lib"/>
         <antcall target="download-via-maven"><param name="target" value="lib"/>
             <param name="project-path" value="org/apache/velocity"/>
-            <param name="artifact-version" value="${velocity.version}"/>
-            <param name="artifact-name" value="velocity"/>
-            <param name="artifact-type" value="jar"/>
-        </antcall>
-        <antcall target="download-via-maven"><param name="target" value="lib"/>
-            <param name="project-path" value="org/apache/velocity"/>
             <param name="artifact-version" value="${velocity-engine-core.version}"/>
             <param name="artifact-name" value="velocity-engine-core"/>
             <param name="artifact-type" value="jar"/>

Modified: manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/i18n/MCFVelocityResourceLoader.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/i18n/MCFVelocityResourceLoader.java?rev=1900677&r1=1900676&r2=1900677&view=diff
==============================================================================
--- manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/i18n/MCFVelocityResourceLoader.java (original)
+++ manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/i18n/MCFVelocityResourceLoader.java Sun May  8 06:04:36 2022
@@ -19,25 +19,38 @@
 package org.apache.manifoldcf.core.i18n;
 
 import java.io.*;
+import org.apache.velocity.util.ExtProperties;
 
 /** Our own Velocity resource loader, which uses our class resolution to find Velocity template resources.
 */
 public class MCFVelocityResourceLoader extends org.apache.velocity.runtime.resource.loader.ResourceLoader
 {
+    
   protected Class classInstance;
   
   /** Constructor.
   */
-  public MCFVelocityResourceLoader(Class classInstance)
+  public MCFVelocityResourceLoader()
   {
-    this.classInstance = classInstance;
   }
 
   public long getLastModified(org.apache.velocity.runtime.resource.Resource resource)
   {
     return 0L;
   }
-  
+
+  @Override
+  public Reader getResourceReader(String source, String encoding)
+    throws org.apache.velocity.exception.ResourceNotFoundException
+  {
+    try
+    {
+      return new InputStreamReader(getResourceStream(source), encoding);
+    } catch (UnsupportedEncodingException e) {
+      throw new org.apache.velocity.exception.ResourceNotFoundException("Encoding '"+encoding+"' is illegal");
+    }
+  }
+    
   public InputStream getResourceStream(String source)
     throws org.apache.velocity.exception.ResourceNotFoundException
   {
@@ -47,15 +60,26 @@ public class MCFVelocityResourceLoader e
     return rval;
   }
 
-  public void init(org.apache.commons.collections.ExtendedProperties configuration)
+  @Override
+  public void init(ExtProperties configurations)
   {
-    // Does nothing
+    String className = (String)configurations.getProperty("classinstance");
+    if (className == null) {
+      className = (String)configurations.getProperty("mcf.resource.loader.classinstance");
+    }
+    // We should be able to load it; if not it's a fatal error and we'll fail to find the resource.
+    try {
+      classInstance = Class.forName(className);
+    } catch (Exception e) {
+      classInstance = null;
+    }
   }
 
+  @Override
   public boolean isSourceModified(org.apache.velocity.runtime.resource.Resource resource)
   {
     // This obviously supports caching, which we don't need and may mess us up if the caching is cross-instance
     return true;
   }
 
-}
\ No newline at end of file
+}

Modified: manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/i18n/Messages.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/i18n/Messages.java?rev=1900677&r1=1900676&r2=1900677&view=diff
==============================================================================
--- manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/i18n/Messages.java (original)
+++ manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/i18n/Messages.java Sun May  8 06:04:36 2022
@@ -25,6 +25,7 @@ import java.util.ResourceBundle;
 import java.util.Set;
 import java.util.HashSet;
 import java.util.Vector;
+import java.util.Properties;
 
 import java.io.InputStream;
 
@@ -32,6 +33,7 @@ import org.apache.manifoldcf.core.system
 import org.apache.manifoldcf.core.interfaces.ManifoldCFException;
 import org.apache.velocity.app.VelocityEngine;
 import org.apache.velocity.runtime.RuntimeConstants;
+import org.apache.velocity.util.ExtProperties;
 
 public class Messages
 {
@@ -53,17 +55,19 @@ public class Messages
     throws ManifoldCFException
   {
     VelocityEngine engine = new VelocityEngine();
-    // Now configure it
-    org.apache.commons.collections.ExtendedProperties configuration = new org.apache.commons.collections.ExtendedProperties();
+    Properties configuration = new Properties();
     // This is the property that describes the id's of the resource loaders.
     configuration.setProperty(VelocityEngine.RESOURCE_LOADER,"mcf");
     // This is the property which describes the resource loader itself
-    configuration.setProperty("mcf."+VelocityEngine.RESOURCE_LOADER+".instance",new MCFVelocityResourceLoader(classInstance));
-    engine.setExtendedProperties(configuration);
-    engine.setProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
-      "org.apache.velocity.runtime.log.Log4JLogChute" );
-    engine.setProperty("runtime.log.logsystem.log4j.logger",
-      "velocity");
+    // Used to be ".instance" and accept an instance.  No longer allowed.
+    configuration.setProperty("mcf."+VelocityEngine.RESOURCE_LOADER+".class",MCFVelocityResourceLoader.class.getName() /*new MCFVelocityResourceLoader(classInstance)*/);
+    configuration.setProperty("mcf."+VelocityEngine.RESOURCE_LOADER+".classinstance",classInstance.getName());
+    engine.setProperties(configuration);
+    //engine.setProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
+    //  "org.apache.velocity.runtime.log.Log4JLogChute" );
+    //engine.setProperty("runtime.log.logsystem.log4j.logger",
+    //  "velocity");
+    //"runtime.log.instance"
     return engine;
   }