diff --git a/source/java/org/alfresco/filesys/alfresco/DesktopAction.java b/source/java/org/alfresco/filesys/alfresco/DesktopAction.java index 2a6754e041..906d8065bd 100644 --- a/source/java/org/alfresco/filesys/alfresco/DesktopAction.java +++ b/source/java/org/alfresco/filesys/alfresco/DesktopAction.java @@ -25,18 +25,18 @@ package org.alfresco.filesys.alfresco; import java.io.File; -import java.io.UnsupportedEncodingException; +import java.io.IOException; import java.net.InetAddress; -import java.net.URL; -import java.net.URLDecoder; import org.alfresco.config.ConfigElement; import org.alfresco.jlan.server.filesys.DiskSharedDevice; import org.alfresco.jlan.server.filesys.pseudo.LocalPseudoFile; import org.alfresco.jlan.server.filesys.pseudo.PseudoFile; import org.alfresco.service.ServiceRegistry; +import org.alfresco.util.ResourceFinder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.core.io.Resource; /** * Desktop Action Class @@ -409,28 +409,31 @@ public abstract class DesktopAction { throw new DesktopActionException("Desktop action executable path not specified"); // Check that the application exists on the local filesystem - - URL appURL = this.getClass().getClassLoader().getResource(m_path); - if ( appURL == null) + Resource resource = new ResourceFinder().getResource(m_path); + if (!resource.exists()) + { throw new DesktopActionException("Failed to find drag and drop application, " + m_path); + } // Decode the URL path, it might contain escaped characters - String appURLPath = null; - try - { - appURLPath = URLDecoder.decode( appURL.getFile(), "UTF-8"); - } - catch ( UnsupportedEncodingException ex) - { - throw new DesktopActionException("Failed to decode drag/drop path, " + ex.getMessage()); - } // Check that the drag/drop file exists - - File appFile = new File(appURLPath); - if ( appFile.exists() == false) - throw new DesktopActionException("Drag and drop application not found, " + appFile); + File appFile; + try + { + appFile = resource.getFile(); + + if (!appFile.exists()) + { + throw new DesktopActionException("Drag and drop application not found, " + appFile); + } + } + catch (IOException e) + { + throw new DesktopActionException("Unable to resolve drag and drop application as a file, " + + resource.getDescription()); + } // Create the pseudo file for the action diff --git a/source/java/org/alfresco/filesys/repo/desk/JavaScriptDesktopAction.java b/source/java/org/alfresco/filesys/repo/desk/JavaScriptDesktopAction.java index 1abaa90439..eb7bc02f75 100644 --- a/source/java/org/alfresco/filesys/repo/desk/JavaScriptDesktopAction.java +++ b/source/java/org/alfresco/filesys/repo/desk/JavaScriptDesktopAction.java @@ -27,9 +27,6 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URL; -import java.net.URLDecoder; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; @@ -44,6 +41,8 @@ import org.alfresco.filesys.alfresco.DesktopResponse; import org.alfresco.jlan.server.filesys.DiskSharedDevice; import org.alfresco.scripts.ScriptException; import org.alfresco.service.cmr.repository.ScriptService; +import org.alfresco.util.ResourceFinder; +import org.springframework.core.io.Resource; /** * Javascript Desktop Action Class @@ -155,28 +154,25 @@ public class JavaScriptDesktopAction extends DesktopAction { } // Check if the script exists on the classpath - - URL scriptURL = this.getClass().getClassLoader().getResource(m_scriptName); - if ( scriptURL == null) + Resource resource = new ResourceFinder().getResource(m_scriptName); + if (!resource.exists()) + { throw new DesktopActionException("Failed to find script on classpath, " + getScriptName()); + } - // Decode the URL path, it might contain escaped characters - - String scriptURLPath = null; - try - { - scriptURLPath = URLDecoder.decode( scriptURL.getFile(), "UTF-8"); - } - catch ( UnsupportedEncodingException ex) - { - throw new DesktopActionException("Failed to decode script path, " + ex.getMessage()); - } // Check that the script file exists - - File scriptFile = new File(scriptURLPath); - if ( scriptFile.exists() == false) - throw new DesktopActionException("Script file not found, " + m_scriptName); + File scriptFile; + try + { + scriptFile = resource.getFile(); + if (scriptFile.exists() == false) + throw new DesktopActionException("Script file not found, " + m_scriptName); + } + catch (IOException e) + { + throw new DesktopActionException("Unable to resolve script as a file, " + resource.getDescription()); + } m_scriptPath = scriptFile.getAbsolutePath(); m_lastModified =scriptFile.lastModified(); diff --git a/source/java/org/alfresco/repo/admin/Log4JHierarchyInit.java b/source/java/org/alfresco/repo/admin/Log4JHierarchyInit.java index 302998a02b..d2542f251e 100644 --- a/source/java/org/alfresco/repo/admin/Log4JHierarchyInit.java +++ b/source/java/org/alfresco/repo/admin/Log4JHierarchyInit.java @@ -31,8 +31,12 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.core.io.support.ResourcePatternResolver; /** * Initialises Log4j's HierarchyDynamicMBean (refer to core-services-context.xml) and any overriding log4.properties files. @@ -62,10 +66,11 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver; * WEB - INF / classes / alfresco / module / org.alfresco.module.avmCompare / log4j.properties * */ -public class Log4JHierarchyInit +public class Log4JHierarchyInit implements ApplicationContextAware { private static Log logger = LogFactory.getLog(Log4JHierarchyInit.class); private List extraLog4jUrls; + private ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); public Log4JHierarchyInit() { @@ -85,6 +90,16 @@ public class Log4JHierarchyInit extraLog4jUrls.add(url); } } + + + + /* (non-Javadoc) + * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext) + */ + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException + { + this.resolver = applicationContext; + } @SuppressWarnings("unchecked") public void init() @@ -120,7 +135,6 @@ public class Log4JHierarchyInit private void importLogSettings(Method method, String springUrl) { - PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Resource[] resources = null; try diff --git a/source/java/org/alfresco/repo/domain/schema/SchemaBootstrap.java b/source/java/org/alfresco/repo/domain/schema/SchemaBootstrap.java index 74d90968c1..3c53bcd2f0 100644 --- a/source/java/org/alfresco/repo/domain/schema/SchemaBootstrap.java +++ b/source/java/org/alfresco/repo/domain/schema/SchemaBootstrap.java @@ -132,10 +132,9 @@ public class SchemaBootstrap extends AbstractLifecycleBean public static final int DEFAULT_MAX_STRING_LENGTH = 1024; private static volatile int maxStringLength = DEFAULT_MAX_STRING_LENGTH; - - - - + + private ResourcePatternResolver rpr = new PathMatchingResourcePatternResolver(this.getClass().getClassLoader()); + /** * @see PropertyValue#DEFAULT_MAX_STRING_LENGTH @@ -838,7 +837,6 @@ public class SchemaBootstrap extends AbstractLifecycleBean // replace the dialect placeholder String dialectScriptUrl = scriptUrl.replaceAll(PLACEHOLDER_SCRIPT_DIALECT, dialectClazz.getName()); // get a handle on the resource - ResourcePatternResolver rpr = new PathMatchingResourcePatternResolver(this.getClass().getClassLoader()); Resource resource = rpr.getResource(dialectScriptUrl); if (!resource.exists()) { @@ -1147,6 +1145,9 @@ public class SchemaBootstrap extends AbstractLifecycleBean @Override protected synchronized void onBootstrap(ApplicationEvent event) { + // Use the application context to load resources + rpr = (ApplicationContext)event.getSource(); + // do everything in a transaction Session session = getSessionFactory().openSession(); Connection connection = null; diff --git a/source/java/org/alfresco/repo/management/subsystems/ChildApplicationContextFactory.java b/source/java/org/alfresco/repo/management/subsystems/ChildApplicationContextFactory.java index 902aee8a2e..8e6adec635 100644 --- a/source/java/org/alfresco/repo/management/subsystems/ChildApplicationContextFactory.java +++ b/source/java/org/alfresco/repo/management/subsystems/ChildApplicationContextFactory.java @@ -30,6 +30,7 @@ import java.util.Properties; import java.util.Set; import java.util.TreeSet; +import org.alfresco.config.JBossEnabledResourcePatternResolver; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeansException; @@ -43,6 +44,7 @@ import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.io.Resource; +import org.springframework.core.io.support.ResourcePatternResolver; /** * A factory allowing initialization of an entire 'subsystem' in a child application context. As with other @@ -309,7 +311,20 @@ public class ChildApplicationContextFactory extends AbstractPropertyBackedBean i + ChildApplicationContextFactory.CONTEXT_SUFFIX, ChildApplicationContextFactory.EXTENSION_CLASSPATH_PREFIX + getCategory() + '/' + getTypeName() + '/' + getId() + '/' + ChildApplicationContextFactory.CONTEXT_SUFFIX - }, false, this.parent); + }, false, this.parent) + { + + /* + * (non-Javadoc) + * @see org.springframework.context.support.AbstractApplicationContext#getResourcePatternResolver() + */ + @Override + protected ResourcePatternResolver getResourcePatternResolver() + { + return new JBossEnabledResourcePatternResolver(this); + } + + }; // Add a property placeholder configurer, with the subsystem-scoped default properties PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); diff --git a/source/java/org/alfresco/repo/module/ModuleServiceImpl.java b/source/java/org/alfresco/repo/module/ModuleServiceImpl.java index 86bf7e3916..a156443fc3 100644 --- a/source/java/org/alfresco/repo/module/ModuleServiceImpl.java +++ b/source/java/org/alfresco/repo/module/ModuleServiceImpl.java @@ -43,8 +43,12 @@ import org.alfresco.service.cmr.module.ModuleService; import org.alfresco.service.descriptor.DescriptorService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.core.io.support.ResourcePatternResolver; /** * This component controls the execution of @@ -63,7 +67,7 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver; * @author Derek Hulley * @since 2.0 */ -public class ModuleServiceImpl implements ModuleService +public class ModuleServiceImpl implements ApplicationContextAware, ModuleService { /** Error messages **/ private static final String ERR_UNABLE_TO_OPEN_MODULE_PROPETIES = "module.err.unable_to_open_module_properties"; @@ -78,6 +82,8 @@ public class ModuleServiceImpl implements ModuleService /** A cache of module details by module ID */ private Map moduleDetailsById; + ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); + /** Default constructor */ public ModuleServiceImpl() { @@ -109,6 +115,16 @@ public class ModuleServiceImpl implements ModuleService this.moduleComponentHelper.setTenantAdminService(tenantAdminService); } + + + /* (non-Javadoc) + * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext) + */ + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException + { + this.resolver = applicationContext; + } + /** * @see ModuleComponentHelper#registerComponent(ModuleComponent) */ @@ -169,7 +185,6 @@ public class ModuleServiceImpl implements ModuleService { moduleDetailsById = new HashMap(13); - PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Resource[] resources = resolver.getResources(MODULE_CONFIG_SEARCH_ALL); // Read each resource diff --git a/source/java/org/alfresco/util/ResourceFinder.java b/source/java/org/alfresco/util/ResourceFinder.java index 44ef681d6b..33a111ebda 100644 --- a/source/java/org/alfresco/util/ResourceFinder.java +++ b/source/java/org/alfresco/util/ResourceFinder.java @@ -29,33 +29,21 @@ import java.util.Arrays; import java.util.LinkedList; import java.util.List; +import org.alfresco.config.JBossEnabledResourcePatternResolver; +import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; /** * Can be used in Spring configuration to search for all resources matching an array of patterns. * * @author dward */ -public class ResourceFinder extends PathMatchingResourcePatternResolver +public class ResourceFinder extends JBossEnabledResourcePatternResolver { - /** - * Instantiates a new resource finder. - */ public ResourceFinder() { - } - - /** - * The Constructor. - * - * @param classLoader - * the class loader - */ - public ResourceFinder(ClassLoader classLoader) - { - super(classLoader); + super(new DefaultResourceLoader()); } /**