DEMPIERE-330 Zk Web Client: Failed to register addon component and javascript resources.

This commit is contained in:
Heng Sin Low 2012-07-20 06:50:55 +08:00
parent 57c669ce71
commit e8f72ee777
7 changed files with 36 additions and 44 deletions

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="org.adempiere.ui.zk.ResourceLocator">
<implementation class="org.adempiere.webui.util.WebUIResourceFinder"/>
<service>
<provide interface="org.zkoss.util.resource.IResourceLocator"/>
</service>
</scr:component>

View File

@ -32,10 +32,12 @@ import javax.servlet.http.HttpServletResponse;
import org.compiere.Adempiere; import org.compiere.Adempiere;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.Ini; import org.compiere.util.Ini;
import org.zkoss.util.resource.ClassLocator;
import org.zkoss.zk.ui.http.DHtmlLayoutServlet; import org.zkoss.zk.ui.http.DHtmlLayoutServlet;
import org.adempiere.util.ServerContext; import org.adempiere.util.ServerContext;
import org.adempiere.util.ServerContextURLHandler; 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 public void init(ServletConfig servletConfig) throws ServletException
{ {
ClassLocator.addResourceLocator(new ZkResourceLocator());
super.init(servletConfig); super.init(servletConfig);
/** Initialise context for the current thread*/ /** Initialise context for the current thread*/

View File

@ -17,14 +17,13 @@ import java.net.URL;
import org.adempiere.base.IResourceFinder; import org.adempiere.base.IResourceFinder;
import org.adempiere.webui.WebUIActivator; import org.adempiere.webui.WebUIActivator;
import org.zkoss.util.resource.IResourceLocator;
/** /**
* *
* @author hengsin * @author hengsin
* *
*/ */
public class WebUIResourceFinder implements IResourceFinder, IResourceLocator { public class WebUIResourceFinder implements IResourceFinder {
@Override @Override
public URL getResource(String name) { public URL getResource(String name) {

View File

@ -11,45 +11,35 @@
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 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.net.URL;
import java.util.List;
import org.adempiere.webui.WebUIActivator;
import org.zkoss.util.resource.IResourceLocator;
/** /**
* @author hengsin * @author hengsin
* *
*/ */
public class ResourceLocatorRegistry { public class ZkResourceLocator implements IResourceLocator {
private List<IResourceLocator> locators = new ArrayList<IResourceLocator>(); private static ZkResourceLocator INSTANCE;
private static ResourceLocatorRegistry INSTANCE = null; public ZkResourceLocator() {
INSTANCE = this;
/**
*
* @param locator
*/
public synchronized void addLocator(IResourceLocator locator) {
System.err.println("addLocator " + locator);
locators.add(locator);
if (INSTANCE == null) {
INSTANCE = this;
}
} }
/** /* (non-Javadoc)
* * @see org.zkoss.util.resource.IResourceLocator#getResource(java.lang.String)
* @param locator
*/ */
public synchronized void removeLocator(IResourceLocator locator) { @Override
locators.remove(locator); public URL getResource(String name) {
return WebUIActivator.getBundleContext().getBundle().getEntry(name);
} }
/** public static boolean isStarted() {
* @return list of resource locator return INSTANCE != null;
*/
public synchronized static List<IResourceLocator> getLocators() {
return INSTANCE != null ? INSTANCE.locators : null;
} }
} }

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="lib" path="lib/asm.jar"/> <classpathentry exported="true" kind="lib" path="lib/asm.jar"/>
<classpathentry exported="true" kind="lib" path="lib/cglib.jar"/> <classpathentry exported="true" kind="lib" path="lib/cglib.jar"/>
<classpathentry exported="true" kind="lib" path="lib/commons-el.jar"/> <classpathentry exported="true" kind="lib" path="lib/commons-el.jar"/>
@ -26,7 +27,6 @@
<classpathentry exported="true" kind="lib" path="lib/zweb.jar" sourcepath="lib/zweb-sources.jar"/> <classpathentry exported="true" kind="lib" path="lib/zweb.jar" sourcepath="lib/zweb-sources.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="lib" path="lib/ckez.jar"/> <classpathentry exported="true" kind="lib" path="lib/ckez.jar"/>
<classpathentry exported="true" kind="lib" path="lib/zel.jar"/> <classpathentry exported="true" kind="lib" path="lib/zel.jar"/>
<classpathentry exported="true" kind="lib" path="lib/zkbind.jar"/> <classpathentry exported="true" kind="lib" path="lib/zkbind.jar"/>

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.zkoss.zk.library.ResourceLocatorRegistry">
<implementation class="org.zkoss.util.resource.ResourceLocatorRegistry"/>
<reference bind="addLocator" cardinality="0..n" interface="org.zkoss.util.resource.IResourceLocator" name="IResourceLocator" policy="dynamic" unbind="removeLocator"/>
</scr:component>

View File

@ -16,6 +16,7 @@ Copyright (C) 2005 Potix Corporation. All Rights Reserved.
*/ */
package org.zkoss.util.resource; package org.zkoss.util.resource;
import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
@ -51,9 +52,19 @@ import org.zkoss.idom.input.SAXBuilder;
*/ */
public class ClassLocator implements XMLResourcesLocator { public class ClassLocator implements XMLResourcesLocator {
private static final Log log = Log.lookup(ClassLocator.class); private static final Log log = Log.lookup(ClassLocator.class);
private static List<IResourceLocator> resourceLocators = new ArrayList<IResourceLocator>();
public ClassLocator() { public ClassLocator() {
} }
public static synchronized void addResourceLocator(IResourceLocator locator) {
resourceLocators.add(locator);
}
private static synchronized IResourceLocator[] getResourceLocators() {
return resourceLocators.toArray(new IResourceLocator[0]);
}
//XMLResourcesLocator// //XMLResourcesLocator//
public Enumeration<URL> getResources(String name) throws IOException { public Enumeration<URL> getResources(String name) throws IOException {
@ -84,8 +95,8 @@ public class ClassLocator implements XMLResourcesLocator {
final Enumeration<URL> en = ClassLoader.getSystemResources(name); final Enumeration<URL> en = ClassLoader.getSystemResources(name);
list = Collections.list(en); list = Collections.list(en);
} }
List<IResourceLocator> locators = ResourceLocatorRegistry.getLocators(); IResourceLocator[] locators = ClassLocator.getResourceLocators();
if (locators != null) { if (locators != null && locators.length > 0) {
for (IResourceLocator locator : locators) { for (IResourceLocator locator : locators) {
URL url = locator.getResource(name); URL url = locator.getResource(name);
if (url != null) { if (url != null) {