This is an automated email from the ASF dual-hosted git repository.

jamesyong pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 8c4a191  Refactor ThemeFactory.java
8c4a191 is described below

commit 8c4a19118d59ed0cd2e567997568f656aa7f4f41
Author: James Yong <jamesy...@apache.org>
AuthorDate: Fri Sep 11 20:14:58 2020 +0800

    Refactor ThemeFactory.java
---
 .../apache/ofbiz/widget/model/ThemeFactory.java    | 31 +++++++++++++++-------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git 
a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ThemeFactory.java
 
b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ThemeFactory.java
index 20720b7..62d23d6 100644
--- 
a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ThemeFactory.java
+++ 
b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ThemeFactory.java
@@ -52,7 +52,7 @@ import org.xml.sax.SAXException;
 /**
  * Widget Theme Library - Theme factory class
  */
-public class ThemeFactory {
+public final class ThemeFactory {
 
     private static final String MODULE = ThemeFactory.class.getName();
 
@@ -61,6 +61,7 @@ public class ThemeFactory {
     private static final UtilCache<String, VisualTheme> 
THEME_VISUAL_THEME_ID_CACHE =
             UtilCache.createUtilCache("widget.theme.idAndVisualTheme", 0, 0, 
false);
 
+    private ThemeFactory() { }
     /**
      * From a w3c Document return the modelTheme instantiated
      * @param themeFileDoc
@@ -76,18 +77,11 @@ public class ThemeFactory {
     }
 
     /**
-     * Scann all Theme.xml definition to reload all VisualTheme oin cache
+     * Reload all VisualTheme in cache
      */
     private static void pullModelThemesFromXmlToCache() {
-        String ofbizHome = System.getProperty("ofbiz.home");
-        String themeFolderPath = ofbizHome + "/themes";
-        String pluginsFolderPath = ofbizHome + "/plugins";
         try {
-            List<File> xmlThemes = FileUtil.findXmlFiles(themeFolderPath, 
null, "theme", "widget-theme.xsd");
-            List<File> xmlPluginThemes = 
FileUtil.findXmlFiles(pluginsFolderPath, null, "theme", "widget-theme.xsd");
-            if (UtilValidate.isNotEmpty(xmlPluginThemes)) {
-                xmlThemes.addAll(xmlPluginThemes);
-            }
+            List<File> xmlThemes = getThemeXmlFiles();
             for (File xmlTheme : xmlThemes) {
                 ModelTheme modelTheme = 
getModelThemeFromLocation(xmlTheme.toURI().toURL().toString());
                 if (modelTheme != null) {
@@ -102,6 +96,23 @@ public class ThemeFactory {
     }
 
     /**
+     * Scan all Theme.xml definition
+     * @return
+     * @throws IOException
+     */
+    public static List<File> getThemeXmlFiles() throws IOException {
+        String ofbizHome = System.getProperty("ofbiz.home");
+        String themeFolderPath = ofbizHome + "/themes";
+        String pluginsFolderPath = ofbizHome + "/plugins";
+        List<File> xmlThemes = FileUtil.findXmlFiles(themeFolderPath, null, 
"theme", "widget-theme.xsd");
+        List<File> xmlPluginThemes = FileUtil.findXmlFiles(pluginsFolderPath, 
null, "theme", "widget-theme.xsd");
+        if (UtilValidate.isNotEmpty(xmlPluginThemes)) {
+            xmlThemes.addAll(xmlPluginThemes);
+        }
+        return xmlThemes;
+    }
+
+    /**
      * From a visualThemeId return the VisualTheme object corresponding in 
cache
      * If it's empty, reload the cache from all Theme definition
      * @param visualThemeId

Reply via email to