svn commit: r564914 - in /ofbiz/trunk: ./ framework/base/src/base/org/ofbiz/base/util/template/FreeMarkerWorker.java framework/webapp/config/applicationTransforms.properties framework/webapp/config/frameworkTransforms.properties

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r564914 - in /ofbiz/trunk: ./ framework/base/src/base/org/ofbiz/base/util/template/FreeMarkerWorker.java framework/webapp/config/applicationTransforms.properties framework/webapp/config/frameworkTransforms.properties

jleroux@apache.org
Author: jleroux
Date: Sat Aug 11 05:52:41 2007
New Revision: 564914

URL: http://svn.apache.org/viewvc?view=rev&rev=564914
Log:
A patch from Adrian Crum "FreeMarkerWorker.java flexibility" (https://issues.apache.org/jira/browse/OFBIZ-273)
Uses a sort of dependency injection

Added:
    ofbiz/trunk/framework/webapp/config/applicationTransforms.properties   (with props)
    ofbiz/trunk/framework/webapp/config/frameworkTransforms.properties   (with props)
Modified:
    ofbiz/trunk/   (props changed)
    ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/template/FreeMarkerWorker.java

Propchange: ofbiz/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sat Aug 11 05:52:41 2007
@@ -13,3 +13,4 @@
 *.ipr
 *.iws
 *.time
+startofbizNoLog.bat

Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/template/FreeMarkerWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/template/FreeMarkerWorker.java?view=diff&rev=564914&r1=564913&r2=564914
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/template/FreeMarkerWorker.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/template/FreeMarkerWorker.java Sat Aug 11 05:52:41 2007
@@ -18,7 +18,6 @@
  *******************************************************************************/
 package org.ofbiz.base.util.template;
 
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.Reader;
@@ -33,6 +32,7 @@
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 import java.util.TimeZone;
 
@@ -43,6 +43,7 @@
 
 import org.ofbiz.base.location.FlexibleLocation;
 import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilProperties;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.cache.UtilCache;
 
@@ -75,55 +76,48 @@
 
     public static Map ftlTransforms = new HashMap();
     
-    static {
-        try {
-            ClassLoader loader = Thread.currentThread().getContextClassLoader();
+    public static final String FRAMEWORK_TRANSFORMS = "frameworkTransforms";
+    public static final String APPLICATION_TRANSFORMS = "applicationTransforms";
 
-            // note: loadClass is necessary for these since this class doesn't know anything about them at compile time
-            // double note: may want to make this more dynamic and configurable in the future
-            ftlTransforms.put("ofbizUrl", loader.loadClass("org.ofbiz.webapp.ftl.OfbizUrlTransform").newInstance());
-            ftlTransforms.put("ofbizContentUrl", loader.loadClass("org.ofbiz.webapp.ftl.OfbizContentTransform").newInstance());
-            ftlTransforms.put("ofbizCurrency", loader.loadClass("org.ofbiz.webapp.ftl.OfbizCurrencyTransform").newInstance());
-            ftlTransforms.put("ofbizAmount", loader.loadClass("org.ofbiz.webapp.ftl.OfbizAmountTransform").newInstance());
-            ftlTransforms.put("setRequestAttribute", loader.loadClass("org.ofbiz.webapp.ftl.SetRequestAttributeMethod").newInstance());
-            ftlTransforms.put("renderWrappedText", loader.loadClass("org.ofbiz.webapp.ftl.RenderWrappedTextTransform").newInstance());
-
-            ftlTransforms.put("menuWrap", loader.loadClass("org.ofbiz.widget.menu.MenuWrapTransform").newInstance());
-        } catch (ClassNotFoundException e) {
-            Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module);
-        } catch (IllegalAccessException e) {
-            Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module);
-        } catch (InstantiationException e) {
-            Debug.logError(e, "Could not pre-initialize dynamically loaded class: ", module);
+    static {
+        // Load framework transforms first.
+        // Transforms properties file set up as key=transform name, property=transform class name
+        Properties props = UtilProperties.getProperties(FRAMEWORK_TRANSFORMS);
+        if (props == null || props.isEmpty()) {
+            Debug.logError("Unable to locate properties file " + FRAMEWORK_TRANSFORMS, module);
+        } else {
+            loadTransforms(props);
         }
 
-        // do the applications ones in a separate pass so the framework ones can load even if the applications are not present
-        try {
-            ClassLoader loader = Thread.currentThread().getContextClassLoader();
-
-            ftlTransforms.put("editRenderSubContent", loader.loadClass("org.ofbiz.content.webapp.ftl.EditRenderSubContentTransform").newInstance());
-            ftlTransforms.put("renderSubContent", loader.loadClass("org.ofbiz.content.webapp.ftl.RenderSubContentTransform").newInstance());
-            ftlTransforms.put("loopSubContent", loader.loadClass("org.ofbiz.content.webapp.ftl.LoopSubContentTransform").newInstance());
-            ftlTransforms.put("traverseSubContent", loader.loadClass("org.ofbiz.content.webapp.ftl.TraverseSubContentTransform").newInstance());
-
-            ftlTransforms.put("checkPermission", loader.loadClass("org.ofbiz.content.webapp.ftl.CheckPermissionTransform").newInstance());
-            ftlTransforms.put("injectNodeTrailCsv", loader.loadClass("org.ofbiz.content.webapp.ftl.InjectNodeTrailCsvTransform").newInstance());
-            
-            ftlTransforms.put("editRenderSubContentCache", loader.loadClass("org.ofbiz.content.webapp.ftl.EditRenderSubContentCacheTransform").newInstance());
-            ftlTransforms.put("renderSubContentCache", loader.loadClass("org.ofbiz.content.webapp.ftl.RenderSubContentCacheTransform").newInstance());
-            ftlTransforms.put("loopSubContentCache", loader.loadClass("org.ofbiz.content.webapp.ftl.LoopSubContentCacheTransform").newInstance());
-            ftlTransforms.put("traverseSubContentCache", loader.loadClass("org.ofbiz.content.webapp.ftl.TraverseSubContentCacheTransform").newInstance());
-            ftlTransforms.put("wrapSubContentCache", loader.loadClass("org.ofbiz.content.webapp.ftl.WrapSubContentCacheTransform").newInstance());
-            ftlTransforms.put("limitedSubContent", loader.loadClass("org.ofbiz.content.webapp.ftl.LimitedSubContentCacheTransform").newInstance());
-            ftlTransforms.put("renderSubContentAsText", loader.loadClass("org.ofbiz.content.webapp.ftl.RenderSubContentAsText").newInstance());
-            ftlTransforms.put("renderContentAsText", loader.loadClass("org.ofbiz.content.webapp.ftl.RenderContentAsText").newInstance());
-            ftlTransforms.put("renderContent", loader.loadClass("org.ofbiz.content.webapp.ftl.RenderContentTransform").newInstance());
-        } catch (ClassNotFoundException e) {
-            Debug.logError("Could not pre-initialize dynamically loaded class: " + e.toString(), module);
-        } catch (IllegalAccessException e) {
-            Debug.logError("Could not pre-initialize dynamically loaded class: " + e.toString(), module);
-        } catch (InstantiationException e) {
-            Debug.logError("Could not pre-initialize dynamically loaded class: " + e.toString(), module);
+        // Load application transforms next.
+        props = UtilProperties.getProperties(APPLICATION_TRANSFORMS);
+        if (props == null || props.isEmpty()) {
+            Debug.logError("Unable to locate properties file " + APPLICATION_TRANSFORMS, module);
+        } else {
+            loadTransforms(props);
+        }
+    }
+    
+    /**
+     * Protected helper method.
+     */
+    protected static void loadTransforms(Properties props) {
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+        for (Iterator i = props.keySet().iterator(); i.hasNext();) {
+            String key = (String)i.next();
+            String className = props.getProperty(key);
+            if (Debug.verboseOn()) {
+                Debug.logVerbose("Adding FTL Transform " + key + " with class " + className, module);
+            }
+            try {
+                ftlTransforms.put(key, loader.loadClass(className).newInstance());
+            } catch (ClassNotFoundException e) {
+                Debug.logError(e, "Could not pre-initialize dynamically loaded class: " + className + " ", module);
+            } catch (IllegalAccessException e) {
+                Debug.logError(e, "Could not pre-initialize dynamically loaded class: " + className + " ", module);
+            } catch (InstantiationException e) {
+                Debug.logError(e, "Could not pre-initialize dynamically loaded class: " + className + " ", module);
+            }
         }
     }
 

Added: ofbiz/trunk/framework/webapp/config/applicationTransforms.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/config/applicationTransforms.properties?view=auto&rev=564914
==============================================================================
--- ofbiz/trunk/framework/webapp/config/applicationTransforms.properties (added)
+++ ofbiz/trunk/framework/webapp/config/applicationTransforms.properties Sat Aug 11 05:52:41 2007
@@ -0,0 +1,38 @@
+###############################################################################
+# 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.
+###############################################################################
+### FreeMarker transforms ###
+#############################
+
+# entries are in the form: key=transform name, property=transform class name
+
+editRenderSubContent=org.ofbiz.content.webapp.ftl.EditRenderSubContentTransform
+renderSubContent=org.ofbiz.content.webapp.ftl.RenderSubContentTransform
+loopSubContent=org.ofbiz.content.webapp.ftl.LoopSubContentTransform
+traverseSubContent=org.ofbiz.content.webapp.ftl.TraverseSubContentTransform
+checkPermission=org.ofbiz.content.webapp.ftl.CheckPermissionTransform
+injectNodeTrailCsv=org.ofbiz.content.webapp.ftl.InjectNodeTrailCsvTransform
+editRenderSubContentCache=org.ofbiz.content.webapp.ftl.EditRenderSubContentCacheTransform
+renderSubContentCache=org.ofbiz.content.webapp.ftl.RenderSubContentCacheTransform
+loopSubContentCache=org.ofbiz.content.webapp.ftl.LoopSubContentCacheTransform
+traverseSubContentCache=org.ofbiz.content.webapp.ftl.TraverseSubContentCacheTransform
+wrapSubContentCache=org.ofbiz.content.webapp.ftl.WrapSubContentCacheTransform
+limitedSubContent=org.ofbiz.content.webapp.ftl.LimitedSubContentCacheTransform
+renderSubContentAsText=org.ofbiz.content.webapp.ftl.RenderSubContentAsText
+renderContentAsText=org.ofbiz.content.webapp.ftl.RenderContentAsText
+renderContent=org.ofbiz.content.webapp.ftl.RenderContentTransform

Propchange: ofbiz/trunk/framework/webapp/config/applicationTransforms.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/webapp/config/applicationTransforms.properties
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: ofbiz/trunk/framework/webapp/config/applicationTransforms.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ofbiz/trunk/framework/webapp/config/frameworkTransforms.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/config/frameworkTransforms.properties?view=auto&rev=564914
==============================================================================
--- ofbiz/trunk/framework/webapp/config/frameworkTransforms.properties (added)
+++ ofbiz/trunk/framework/webapp/config/frameworkTransforms.properties Sat Aug 11 05:52:41 2007
@@ -0,0 +1,31 @@
+###############################################################################
+# 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.
+###############################################################################
+### FreeMarker transforms ###
+#############################
+
+# entries are in the form: key=transform name, property=transform class name
+
+ofbizUrl=org.ofbiz.webapp.ftl.OfbizUrlTransform
+ofbizContentUrl=org.ofbiz.webapp.ftl.OfbizContentTransform
+ofbizCurrency=org.ofbiz.webapp.ftl.OfbizCurrencyTransform
+ofbizAmount=org.ofbiz.webapp.ftl.OfbizAmountTransform
+setRequestAttribute=org.ofbiz.webapp.ftl.SetRequestAttributeMethod
+renderWrappedText=org.ofbiz.webapp.ftl.RenderWrappedTextTransform
+barcodeTransform=org.ofbiz.webapp.barcode.BarcodeTransform
+menuWrap=org.ofbiz.widget.menu.MenuWrapTransform

Propchange: ofbiz/trunk/framework/webapp/config/frameworkTransforms.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/webapp/config/frameworkTransforms.properties
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: ofbiz/trunk/framework/webapp/config/frameworkTransforms.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain