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

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


The following commit(s) were added to refs/heads/release24.09 by this push:
     new e01a5448f5 Improved: Resolve component: locations with 
ComponentLocationResolver in CommonEvents.openSourceFile and make 
ComponentConfig.getComponentConfig(String) lookup-only (OFBIZ-13629)
e01a5448f5 is described below

commit e01a5448f5b470ed78e8b10a35e107852a6573e0
Author: Mridul Pathak <[email protected]>
AuthorDate: Wed Sep 30 16:25:17 2026 +0530

    Improved: Resolve component: locations with ComponentLocationResolver in 
CommonEvents.openSourceFile and make ComponentConfig.getComponentConfig(String) 
lookup-only (OFBIZ-13629)
    
    CommonEvents.openSourceFile() only accepts locations starting with 
"component:" but resolved them through FlexibleLocation, which accepts every 
location type. It now uses ComponentLocationResolver directly.
    
    ComponentConfig.getComponentConfig(String) delegated to the two-argument 
overload with a null root location, which can only return a cached 
configuration or throw. It is now an explicit lookup that never loads a 
component, and getFullLocation() uses it. The TODO asking for lazy loading of 
components by name is removed, since all components are loaded at startup. The 
behavior of both methods is unchanged.
---
 .../apache/ofbiz/base/component/ComponentConfig.java  | 19 ++++++++++++++++---
 .../java/org/apache/ofbiz/common/CommonEvents.java    |  8 +++++---
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git 
a/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
 
b/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
index 3dcb13bdbd..6adb3b7d5f 100644
--- 
a/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
+++ 
b/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
@@ -176,9 +176,22 @@ public final class ComponentConfig {
                 .collect(Collectors.toList());
     }
 
+    /**
+     * Provides the already loaded configuration of a component. This is a 
pure lookup: it never
+     * loads a component, so a name that is not cached is an error.
+     * @param globalName  the global name of the component
+     * @return the cached component configuration
+     * @throws ComponentException when no component with that name has been 
loaded
+     */
     public static ComponentConfig getComponentConfig(String globalName) throws 
ComponentException {
-        // TODO: we need to look up the rootLocation from the container 
config, or this will blow up
-        return getComponentConfig(globalName, null);
+        ComponentConfig componentConfig = null;
+        if (globalName != null && !globalName.isEmpty()) {
+            componentConfig = 
COMPONENT_CONFIG_CACHE.fromGlobalName(globalName);
+        }
+        if (componentConfig == null) {
+            throw new ComponentException("No component found named : " + 
globalName);
+        }
+        return componentConfig;
     }
 
     public static ComponentConfig getComponentConfig(String globalName, String 
rootLocation) throws ComponentException {
@@ -207,7 +220,7 @@ public final class ComponentConfig {
     }
 
     static String getFullLocation(String componentName, String 
resourceLoaderName, String location) throws ComponentException {
-        ComponentConfig cc = getComponentConfig(componentName, null);
+        ComponentConfig cc = getComponentConfig(componentName);
         return cc.getFullLocation(resourceLoaderName, location);
     }
 
diff --git 
a/framework/common/src/main/java/org/apache/ofbiz/common/CommonEvents.java 
b/framework/common/src/main/java/org/apache/ofbiz/common/CommonEvents.java
index 66af92d7cf..855378c9c2 100644
--- a/framework/common/src/main/java/org/apache/ofbiz/common/CommonEvents.java
+++ b/framework/common/src/main/java/org/apache/ofbiz/common/CommonEvents.java
@@ -45,7 +45,7 @@ import javax.servlet.http.HttpSession;
 import org.apache.commons.lang.RandomStringUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.ofbiz.base.lang.JSON;
-import org.apache.ofbiz.base.location.FlexibleLocation;
+import org.apache.ofbiz.base.location.ComponentLocationResolver;
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.GeneralException;
 import org.apache.ofbiz.base.util.UtilGenerics;
@@ -402,15 +402,17 @@ public class CommonEvents {
             String sourceLocation = request.getParameter("sourceLocation");
             if (UtilValidate.isNotEmpty(sourceLocation) && 
sourceLocation.startsWith("component:")) {
                 try {
+                    // only component: locations are accepted, so resolve them 
with the component resolver directly
+                    ComponentLocationResolver componentLocationResolver = new 
ComponentLocationResolver();
                     // find absolute path of file
                     URL sourceFileUrl = null;
                     String fragment = "";
                     if (sourceLocation.contains("#")) {
                         int indexOfHash = sourceLocation.indexOf("#");
-                        sourceFileUrl = 
FlexibleLocation.resolveLocation(sourceLocation.substring(0, indexOfHash));
+                        sourceFileUrl = 
componentLocationResolver.resolveLocation(sourceLocation.substring(0, 
indexOfHash));
                         fragment = sourceLocation.substring(indexOfHash + 1);
                     } else {
-                        sourceFileUrl = 
FlexibleLocation.resolveLocation(sourceLocation);
+                        sourceFileUrl = 
componentLocationResolver.resolveLocation(sourceLocation);
                     }
                     String platformSpecificPath = sourceFileUrl.getFile();
                     // ensure file separator in location is correct

Reply via email to