From e8f72ee77726578af79c71fe63bf2cd038d5eeae Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Fri, 20 Jul 2012 06:50:55 +0800 Subject: [PATCH] DEMPIERE-330 Zk Web Client: Failed to register addon component and javascript resources. --- .../OSGI-INF/resourceLocator.xml | 7 --- .../adempiere/webui/session/WebUIServlet.java | 4 ++ .../webui/util/WebUIResourceFinder.java | 3 +- .../webui/util/ZkResourceLocator.java | 44 +++++++------------ org.zkoss.zk.library/.classpath | 2 +- .../OSGI-INF/locatorRegistry.xml | 5 --- .../org/zkoss/util/resource/ClassLocator.java | 15 ++++++- 7 files changed, 36 insertions(+), 44 deletions(-) delete mode 100644 org.adempiere.ui.zk/OSGI-INF/resourceLocator.xml rename org.zkoss.zk.library/src/org/zkoss/util/resource/ResourceLocatorRegistry.java => org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/ZkResourceLocator.java (58%) delete mode 100644 org.zkoss.zk.library/OSGI-INF/locatorRegistry.xml diff --git a/org.adempiere.ui.zk/OSGI-INF/resourceLocator.xml b/org.adempiere.ui.zk/OSGI-INF/resourceLocator.xml deleted file mode 100644 index a96a21340f..0000000000 --- a/org.adempiere.ui.zk/OSGI-INF/resourceLocator.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/session/WebUIServlet.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/session/WebUIServlet.java index 290cb93ed1..d479080ebc 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/session/WebUIServlet.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/session/WebUIServlet.java @@ -32,10 +32,12 @@ import javax.servlet.http.HttpServletResponse; import org.compiere.Adempiere; import org.compiere.util.CLogger; import org.compiere.util.Ini; +import org.zkoss.util.resource.ClassLocator; import org.zkoss.zk.ui.http.DHtmlLayoutServlet; import org.adempiere.util.ServerContext; import org.adempiere.util.ServerContextURLHandler; +import org.adempiere.webui.util.ZkResourceLocator; /** * @@ -52,6 +54,8 @@ public class WebUIServlet extends DHtmlLayoutServlet public void init(ServletConfig servletConfig) throws ServletException { + ClassLocator.addResourceLocator(new ZkResourceLocator()); + super.init(servletConfig); /** Initialise context for the current thread*/ diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/WebUIResourceFinder.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/WebUIResourceFinder.java index 2e64d88562..d14f3c3b8f 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/WebUIResourceFinder.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/WebUIResourceFinder.java @@ -17,14 +17,13 @@ import java.net.URL; import org.adempiere.base.IResourceFinder; import org.adempiere.webui.WebUIActivator; -import org.zkoss.util.resource.IResourceLocator; /** * * @author hengsin * */ -public class WebUIResourceFinder implements IResourceFinder, IResourceLocator { +public class WebUIResourceFinder implements IResourceFinder { @Override public URL getResource(String name) { diff --git a/org.zkoss.zk.library/src/org/zkoss/util/resource/ResourceLocatorRegistry.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/ZkResourceLocator.java similarity index 58% rename from org.zkoss.zk.library/src/org/zkoss/util/resource/ResourceLocatorRegistry.java rename to org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/ZkResourceLocator.java index 5a7cb0a9f9..c95a1e6c66 100644 --- a/org.zkoss.zk.library/src/org/zkoss/util/resource/ResourceLocatorRegistry.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/ZkResourceLocator.java @@ -11,45 +11,35 @@ * with this program; if not, write to the Free Software Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * *****************************************************************************/ -package org.zkoss.util.resource; +package org.adempiere.webui.util; -import java.util.ArrayList; -import java.util.List; +import java.net.URL; + +import org.adempiere.webui.WebUIActivator; +import org.zkoss.util.resource.IResourceLocator; /** * @author hengsin * */ -public class ResourceLocatorRegistry { +public class ZkResourceLocator implements IResourceLocator { - private List locators = new ArrayList(); + private static ZkResourceLocator INSTANCE; - private static ResourceLocatorRegistry INSTANCE = null; - - /** - * - * @param locator - */ - public synchronized void addLocator(IResourceLocator locator) { - System.err.println("addLocator " + locator); - locators.add(locator); - if (INSTANCE == null) { - INSTANCE = this; - } + public ZkResourceLocator() { + INSTANCE = this; } - /** - * - * @param locator + /* (non-Javadoc) + * @see org.zkoss.util.resource.IResourceLocator#getResource(java.lang.String) */ - public synchronized void removeLocator(IResourceLocator locator) { - locators.remove(locator); + @Override + public URL getResource(String name) { + return WebUIActivator.getBundleContext().getBundle().getEntry(name); } - /** - * @return list of resource locator - */ - public synchronized static List getLocators() { - return INSTANCE != null ? INSTANCE.locators : null; + public static boolean isStarted() { + return INSTANCE != null; } + } diff --git a/org.zkoss.zk.library/.classpath b/org.zkoss.zk.library/.classpath index f4f20c766e..7cc726e45d 100644 --- a/org.zkoss.zk.library/.classpath +++ b/org.zkoss.zk.library/.classpath @@ -1,5 +1,6 @@ + @@ -26,7 +27,6 @@ - diff --git a/org.zkoss.zk.library/OSGI-INF/locatorRegistry.xml b/org.zkoss.zk.library/OSGI-INF/locatorRegistry.xml deleted file mode 100644 index d7bef8be43..0000000000 --- a/org.zkoss.zk.library/OSGI-INF/locatorRegistry.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/org.zkoss.zk.library/src/org/zkoss/util/resource/ClassLocator.java b/org.zkoss.zk.library/src/org/zkoss/util/resource/ClassLocator.java index a895044845..e854f75a05 100644 --- a/org.zkoss.zk.library/src/org/zkoss/util/resource/ClassLocator.java +++ b/org.zkoss.zk.library/src/org/zkoss/util/resource/ClassLocator.java @@ -16,6 +16,7 @@ Copyright (C) 2005 Potix Corporation. All Rights Reserved. */ package org.zkoss.util.resource; +import java.util.ArrayList; import java.util.Enumeration; import java.util.LinkedHashMap; import java.util.Map; @@ -51,9 +52,19 @@ import org.zkoss.idom.input.SAXBuilder; */ public class ClassLocator implements XMLResourcesLocator { private static final Log log = Log.lookup(ClassLocator.class); + + private static List resourceLocators = new ArrayList(); public ClassLocator() { } + + public static synchronized void addResourceLocator(IResourceLocator locator) { + resourceLocators.add(locator); + } + + private static synchronized IResourceLocator[] getResourceLocators() { + return resourceLocators.toArray(new IResourceLocator[0]); + } //XMLResourcesLocator// public Enumeration getResources(String name) throws IOException { @@ -84,8 +95,8 @@ public class ClassLocator implements XMLResourcesLocator { final Enumeration en = ClassLoader.getSystemResources(name); list = Collections.list(en); } - List locators = ResourceLocatorRegistry.getLocators(); - if (locators != null) { + IResourceLocator[] locators = ClassLocator.getResourceLocators(); + if (locators != null && locators.length > 0) { for (IResourceLocator locator : locators) { URL url = locator.getResource(name); if (url != null) {