Updated Branches:
  refs/heads/sandbox/resourcefinder [created] 55303c08b

WICKET-4617 work in progress - does not compile yet


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/55303c08
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/55303c08
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/55303c08

Branch: refs/heads/sandbox/resourcefinder
Commit: 55303c08bd8e5025030236fd2921a7e826cc75d1
Parents: 54ec772
Author: Carl-Eric Menzel <cmen...@wicketbuch.de>
Authored: Wed Jun 27 01:05:56 2012 +0200
Committer: Carl-Eric Menzel <cmen...@wicketbuch.de>
Committed: Wed Jun 27 01:05:56 2012 +0200

----------------------------------------------------------------------
 .../main/java/org/apache/wicket/Application.java   |   18 +++-
 .../wicket/core/util/file/WebApplicationPath.java  |   94 ++++----------
 .../resource/locator/ResourceStreamLocator.java    |   71 +++++++----
 .../wicket/protocol/http/WebApplication.java       |    8 +-
 .../apache/wicket/settings/IResourceSettings.java  |   29 +++--
 .../wicket/settings/def/ResourceSettings.java      |   41 ++----
 .../org/apache/wicket/jmx/ResourceSettings.java    |    2 +-
 .../wicket/util/file/ClasspathResourceFinder.java  |   89 +++++++++++++
 .../org/apache/wicket/util/file/IResourcePath.java |   31 -----
 .../java/org/apache/wicket/util/file/Path.java     |   99 +++------------
 10 files changed, 227 insertions(+), 255 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/55303c08/wicket-core/src/main/java/org/apache/wicket/Application.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/Application.java 
b/wicket-core/src/main/java/org/apache/wicket/Application.java
index bf16fa9..8164b1a 100644
--- a/wicket-core/src/main/java/org/apache/wicket/Application.java
+++ b/wicket-core/src/main/java/org/apache/wicket/Application.java
@@ -108,6 +108,10 @@ import org.apache.wicket.settings.def.ResourceSettings;
 import org.apache.wicket.settings.def.SecuritySettings;
 import org.apache.wicket.settings.def.StoreSettings;
 import org.apache.wicket.util.IProvider;
+import org.apache.wicket.util.file.ClasspathResourceFinder;
+import org.apache.wicket.util.file.Folder;
+import org.apache.wicket.util.file.IResourceFinder;
+import org.apache.wicket.util.file.Path;
 import org.apache.wicket.util.io.IOUtils;
 import org.apache.wicket.util.io.Streams;
 import org.apache.wicket.util.lang.Args;
@@ -587,7 +591,8 @@ public abstract class Application implements 
UnboundListener, IEventSink
        }
 
        /**
-        * Iterate initializers list, calling their {@link 
IInitializer#destroy(Application) destroy} methods.
+        * Iterate initializers list, calling their {@link 
IInitializer#destroy(Application) destroy}
+        * methods.
         */
        private void destroyInitializers()
        {
@@ -692,6 +697,8 @@ public abstract class Application implements 
UnboundListener, IEventSink
                pageSettings.addComponentResolver(new 
WicketMessageTagHandler());
                pageSettings.addComponentResolver(new 
WicketContainerResolver());
 
+               getResourceSettings().getResourceFinders().add(new 
ClasspathResourceFinder(""));
+
                // Install button image resource factory
                getResourceSettings().addResourceFactory("buttonFactory",
                        new DefaultButtonImageResourceFactory());
@@ -1322,7 +1329,7 @@ public abstract class Application implements 
UnboundListener, IEventSink
        }
 
        /**
-        * 
+        *
         */
        private void checkSettingsAvailable()
        {
@@ -1590,7 +1597,7 @@ public abstract class Application implements 
UnboundListener, IEventSink
        }
 
        /**
-        * 
+        *
         */
        private static class DefaultRequestCycleProvider implements 
IRequestCycleProvider
        {
@@ -1696,4 +1703,9 @@ public abstract class Application implements 
UnboundListener, IEventSink
        {
                return 
RuntimeConfigurationType.DEPLOYMENT.equals(getConfigurationType());
        }
+
+       public IResourceFinder getResourceFinderForPath(String path)
+       {
+               return new Path(new Folder(path));
+       }
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/55303c08/wicket-core/src/main/java/org/apache/wicket/core/util/file/WebApplicationPath.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/core/util/file/WebApplicationPath.java
 
b/wicket-core/src/main/java/org/apache/wicket/core/util/file/WebApplicationPath.java
index 4394067..78f49fd 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/core/util/file/WebApplicationPath.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/core/util/file/WebApplicationPath.java
@@ -17,16 +17,12 @@
 package org.apache.wicket.core.util.file;
 
 import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
 
 import javax.servlet.ServletContext;
 
-import org.apache.wicket.util.file.Folder;
-import org.apache.wicket.util.file.Path;
-import org.apache.wicket.util.resource.IResourceStream;
 import org.apache.wicket.core.util.resource.UrlResourceStream;
-import org.apache.wicket.util.string.StringList;
+import org.apache.wicket.util.file.IResourceFinder;
+import org.apache.wicket.util.resource.IResourceStream;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -34,111 +30,75 @@ import org.slf4j.LoggerFactory;
 /**
  * Maintain a list of paths which might either be ordinary folders of the 
filesystem or relative
  * paths to the web application's servlet context.
- *
+ * 
  * @author Johan Compagner
  */
-public final class WebApplicationPath extends Path
+public final class WebApplicationPath implements IResourceFinder
 {
        private final static Logger log = 
LoggerFactory.getLogger(WebApplicationPath.class);
 
        private static final String WEB_INF = "WEB-INF/";
 
-       /** The list of urls in the path */
-       private final List<String> webappPaths = new ArrayList<String>();
-
        /** The web apps servlet context */
        private final ServletContext servletContext;
 
+       private String path;
+
        /**
         * Constructor
-        *
+        * 
         * @param servletContext
         *            The webapplication context where the resources must be 
loaded from
         */
-       public WebApplicationPath(final ServletContext servletContext)
+       public WebApplicationPath(final ServletContext servletContext, String 
path)
        {
                this.servletContext = servletContext;
-
-               // adding root so servlet context resources are always checked
-               webappPaths.add("/");
-       }
-
-       /**
-        * @param path
-        *            add a path that is lookup through the servlet context
-        */
-       @Override
-       public void add(String path)
-       {
-               final Folder folder = new Folder(path);
-               if (folder.exists())
+               if (!path.startsWith("/"))
                {
-                       log.debug("Added path '{}' as a folder.", path);
-                       super.add(folder);
+                       path = "/" + path;
                }
-               else
+               if (!path.endsWith("/"))
                {
-                       if (!path.startsWith("/"))
-                       {
-                               path = "/" + path;
-                       }
-                       if (!path.endsWith("/"))
-                       {
-                               path += "/";
-                       }
-                       log.debug("Added path '{}' as a web path.", path);
-                       webappPaths.add(path);
+                       path += "/";
                }
+               this.path = path;
        }
 
+
        /**
-        *
+        * 
         * @see org.apache.wicket.util.file.IResourceFinder#find(Class, String)
         */
        @Override
        public IResourceStream find(final Class<?> clazz, final String pathname)
        {
-               if (pathname == null)
-               {
-                       return null;
-               }
-
-               IResourceStream resourceStream = super.find(clazz, pathname);
-
-               if (resourceStream == null && pathname.startsWith(WEB_INF) == 
false)
+               IResourceStream resourceStream = null;
+               if (pathname.startsWith(WEB_INF) == false)
                {
-                       for (String path : webappPaths)
+                       try
                        {
-                               try
+                               final URL url = servletContext.getResource(path 
+ pathname);
+                               if (url != null)
                                {
-                                       final URL url = 
servletContext.getResource(path + pathname);
-                                       if (url != null)
-                                       {
-                                               resourceStream = new 
UrlResourceStream(url);
-                                               break;
-                                       }
-                               }
-                               catch (Exception ex)
-                               {
-                                       // ignore, file couldn't be found
+                                       resourceStream = new 
UrlResourceStream(url);
                                }
                        }
+                       catch (Exception ex)
+                       {
+                               // ignore, file couldn't be found
+                       }
                }
 
                return resourceStream;
        }
 
-       public List<String> getWebappPaths()
-       {
-               return webappPaths;
-       }
+
        /**
         * @see java.lang.Object#toString()
         */
        @Override
        public String toString()
        {
-               return "[folders = " + StringList.valueOf(getFolders()) + ", 
webapppaths: " +
-                       StringList.valueOf(webappPaths) + "]";
+               return "[webapppath: " + path + "]";
        }
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/55303c08/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/ResourceStreamLocator.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/ResourceStreamLocator.java
 
b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/ResourceStreamLocator.java
index 1fa1f0e..f68b187 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/ResourceStreamLocator.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/ResourceStreamLocator.java
@@ -20,11 +20,15 @@ import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.List;
 import java.util.Locale;
 
 import org.apache.wicket.Application;
+import org.apache.wicket.core.util.file.WebApplicationPath;
 import org.apache.wicket.core.util.resource.UrlResourceStream;
+import org.apache.wicket.settings.IResourceSettings;
 import org.apache.wicket.util.file.IResourceFinder;
+import org.apache.wicket.util.file.Path;
 import org.apache.wicket.util.resource.IResourceStream;
 import org.apache.wicket.util.resource.ResourceUtils;
 import org.apache.wicket.util.resource.ResourceUtils.PathLocale;
@@ -55,6 +59,11 @@ import org.slf4j.LoggerFactory;
  * <li>&lt;language&gt;_&lt;country&gt;</li>
  * <li>&lt;language&gt;</li>
  * </ol>
+ * <p>
+ * Resources will be actually loaded by the {@link IResourceFinder}s defined 
in the resource
+ * settings. By default there are finders that look in the classpath and in 
the classpath in
+ * META-INF/resources. You can add more by adding {@link WebApplicationPath}s 
or {@link Path}s to
+ * {@link IResourceSettings#getResourceFinders()}.
  * 
  * @author Juergen Donnerstag
  * @author Jonathan Locke
@@ -67,24 +76,36 @@ public class ResourceStreamLocator implements 
IResourceStreamLocator
        private static final Iterable<String> NO_EXTENSIONS = new 
ArrayList<String>(0);
 
        /** If null, the application registered finder will be used */
-       private IResourceFinder finder;
+       private List<IResourceFinder> finders;
 
        /**
         * Constructor
         */
        public ResourceStreamLocator()
        {
+               this((List<IResourceFinder>)null);
        }
 
        /**
         * Constructor
         * 
-        * @param finder
-        *            resource finder
+        * @param finders
+        *            resource finders. These will be tried in the given order.
         */
-       public ResourceStreamLocator(final IResourceFinder finder)
+       public ResourceStreamLocator(final IResourceFinder... finders)
        {
-               this.finder = finder;
+               this(Arrays.asList(finders));
+       }
+
+       /**
+        * Constructor
+        * 
+        * @param finders
+        *            resource finders. These will be tried in the given order.
+        */
+       public ResourceStreamLocator(final List<IResourceFinder> finders)
+       {
+               this.finders = finders;
        }
 
        /**
@@ -97,20 +118,7 @@ public class ResourceStreamLocator implements 
IResourceStreamLocator
        {
                // First try with the resource finder registered with the 
application
                // (allows for markup reloading)
-               IResourceStream stream = locateByResourceFinder(clazz, path);
-               if (stream != null)
-               {
-                       return stream;
-               }
-
-               // Then search the resource on the classpath
-               stream = locateByClassLoader(clazz, path);
-               if (stream != null)
-               {
-                       return stream;
-               }
-
-               return null;
+               return locateByResourceFinders(clazz, path);
        }
 
        /**
@@ -230,21 +238,28 @@ public class ResourceStreamLocator implements 
IResourceStreamLocator
         * @param path
         * @return resource stream
         */
-       protected IResourceStream locateByResourceFinder(final Class<?> clazz, 
final String path)
+       protected IResourceStream locateByResourceFinders(final Class<?> clazz, 
final String path)
        {
-               if (finder == null)
+               if (finders == null)
                {
-                       finder = 
Application.get().getResourceSettings().getResourceFinder();
+                       finders = 
Application.get().getResourceSettings().getResourceFinders();
                }
 
-               // Log attempt
-               if (log.isDebugEnabled())
+               IResourceStream result;
+               for (IResourceFinder finder : finders)
                {
-                       log.debug("Attempting to locate resource '" + path + "' 
on path " + finder);
+                       // Log attempt
+                       if (log.isDebugEnabled())
+                       {
+                               log.debug("Attempting to locate resource '" + 
path + "' on path " + finder);
+                       }
+                       result = finder.find(clazz, path);
+                       if (result != null)
+                       {
+                               return result;
+                       }
                }
-
-               // Try to find file resource on the path supplied
-               return finder.find(clazz, path);
+               return null;
        }
 
        /**

http://git-wip-us.apache.org/repos/asf/wicket/blob/55303c08/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
index 9880d5f..f0a8bd2 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
@@ -624,9 +624,6 @@ public abstract class WebApplication extends Application
                getPageSettings().addComponentResolver(new AutoLabelResolver());
                getPageSettings().addComponentResolver(new 
AutoLabelTextResolver());
 
-               // Set resource finder to web app path
-               getResourceSettings().setResourceFinder(getResourceFinder());
-
                getResourceSettings().setFileCleaner(new FileCleaner());
 
                // Add optional sourceFolder for resources.
@@ -786,9 +783,10 @@ public abstract class WebApplication extends Application
         * 
         * @return resource finder
         */
-       protected IResourceFinder getResourceFinder()
+       @Override
+       public IResourceFinder getResourceFinderForPath(String path)
        {
-               return new WebApplicationPath(getServletContext());
+               return new WebApplicationPath(getServletContext(), path);
        }
 
        /**

http://git-wip-us.apache.org/repos/asf/wicket/blob/55303c08/wicket-core/src/main/java/org/apache/wicket/settings/IResourceSettings.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/settings/IResourceSettings.java 
b/wicket-core/src/main/java/org/apache/wicket/settings/IResourceSettings.java
index be9c864..a316616 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/settings/IResourceSettings.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/settings/IResourceSettings.java
@@ -21,6 +21,7 @@ import java.util.List;
 
 import org.apache.wicket.IResourceFactory;
 import org.apache.wicket.Localizer;
+import org.apache.wicket.core.util.resource.locator.IResourceStreamLocator;
 import org.apache.wicket.css.ICssCompressor;
 import org.apache.wicket.javascript.IJavaScriptCompressor;
 import org.apache.wicket.markup.head.PriorityFirstComparator;
@@ -35,7 +36,6 @@ import org.apache.wicket.resource.IPropertiesFactoryContext;
 import org.apache.wicket.resource.loader.IStringResourceLoader;
 import org.apache.wicket.util.file.IFileCleaner;
 import org.apache.wicket.util.file.IResourceFinder;
-import org.apache.wicket.core.util.resource.locator.IResourceStreamLocator;
 import org.apache.wicket.util.time.Duration;
 import org.apache.wicket.util.watch.IModificationWatcher;
 
@@ -138,7 +138,7 @@ public interface IResourceSettings extends 
IPropertiesFactoryContext
         * @return Returns the resourceFinder.
         * @see IResourceSettings#setResourceFinder(IResourceFinder)
         */
-       IResourceFinder getResourceFinder();
+       List<IResourceFinder> getResourceFinders();
 
        /**
         * @return Returns the resourcePollFrequency.
@@ -206,7 +206,7 @@ public interface IResourceSettings extends 
IPropertiesFactoryContext
         * @param resourceFinder
         *            The resourceFinder to set
         */
-       void setResourceFinder(final IResourceFinder resourceFinder);
+       void setResourceFinders(final List<IResourceFinder> resourceFinder);
 
        /**
         * Sets the resource polling frequency. This is the duration of time 
between checks of resource
@@ -385,22 +385,23 @@ public interface IResourceSettings extends 
IPropertiesFactoryContext
        Comparator<? super RecordedHeaderItem> getHeaderItemComparator();
 
        /**
-        * A flag indicating whether static resources should have 
<tt>jsessionid</tt> encoded
-        * in their url.
-        *
-        * @return {@code true} if the jsessionid should be encoded in the url 
for resources implementing
-        * {@link 
org.apache.wicket.request.resource.caching.IStaticCacheableResource} when the 
cookies
-        * are disabled and there is an active http session.
+        * A flag indicating whether static resources should have 
<tt>jsessionid</tt> encoded in their
+        * url.
+        * 
+        * @return {@code true} if the jsessionid should be encoded in the url 
for resources
+        *         implementing
+        *         {@link 
org.apache.wicket.request.resource.caching.IStaticCacheableResource} when the
+        *         cookies are disabled and there is an active http session.
         */
        boolean isEncodeJSessionId();
 
        /**
-        * Sets a flag indicating whether the jsessionid should be encoded in 
the url for resources implementing
-        * {@link 
org.apache.wicket.request.resource.caching.IStaticCacheableResource} when the 
cookies are
-        * disabled and there is an active http session.
-        *
+        * Sets a flag indicating whether the jsessionid should be encoded in 
the url for resources
+        * implementing {@link 
org.apache.wicket.request.resource.caching.IStaticCacheableResource} when
+        * the cookies are disabled and there is an active http session.
+        * 
         * @param encodeJSessionId
-        *      {@code true} when the jsessionid should be encoded, {@code 
false} - otherwise
+        *            {@code true} when the jsessionid should be encoded, 
{@code false} - otherwise
         */
        void setEncodeJSessionId(boolean encodeJSessionId);
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/55303c08/wicket-core/src/main/java/org/apache/wicket/settings/def/ResourceSettings.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/settings/def/ResourceSettings.java
 
b/wicket-core/src/main/java/org/apache/wicket/settings/def/ResourceSettings.java
index e2fbb3e..5c7c472 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/settings/def/ResourceSettings.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/settings/def/ResourceSettings.java
@@ -16,6 +16,7 @@
  */
 package org.apache.wicket.settings.def;
 
+import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
@@ -24,6 +25,9 @@ import org.apache.wicket.Application;
 import org.apache.wicket.Component;
 import org.apache.wicket.IResourceFactory;
 import org.apache.wicket.Localizer;
+import org.apache.wicket.core.util.resource.locator.IResourceStreamLocator;
+import org.apache.wicket.core.util.resource.locator.ResourceStreamLocator;
+import 
org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator;
 import org.apache.wicket.css.ICssCompressor;
 import org.apache.wicket.javascript.IJavaScriptCompressor;
 import org.apache.wicket.markup.head.PriorityFirstComparator;
@@ -49,14 +53,9 @@ import 
org.apache.wicket.resource.loader.ValidatorStringResourceLoader;
 import org.apache.wicket.settings.IResourceSettings;
 import org.apache.wicket.util.file.IFileCleaner;
 import org.apache.wicket.util.file.IResourceFinder;
-import org.apache.wicket.util.file.IResourcePath;
-import org.apache.wicket.util.file.Path;
 import org.apache.wicket.util.lang.Args;
 import org.apache.wicket.util.lang.Generics;
 import org.apache.wicket.util.resource.IResourceStream;
-import org.apache.wicket.core.util.resource.locator.IResourceStreamLocator;
-import org.apache.wicket.core.util.resource.locator.ResourceStreamLocator;
-import 
org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator;
 import org.apache.wicket.util.time.Duration;
 import org.apache.wicket.util.watch.IModificationWatcher;
 import org.apache.wicket.util.watch.ModificationWatcher;
@@ -80,14 +79,14 @@ public class ResourceSettings implements IResourceSettings
        private final Map<String, IResourceFactory> nameToResourceFactory = 
Generics.newHashMap();
 
        /** The package resource guard. */
-       private IPackageResourceGuard packageResourceGuard =
-                       new SecurePackageResourceGuard(new 
SecurePackageResourceGuard.SimpleCache(100));
+       private IPackageResourceGuard packageResourceGuard = new 
SecurePackageResourceGuard(
+               new SecurePackageResourceGuard.SimpleCache(100));
 
        /** The factory to be used for the property files */
        private org.apache.wicket.resource.IPropertiesFactory propertiesFactory;
 
        /** Filesystem Path to search for resources */
-       private IResourceFinder resourceFinder = new Path();
+       private List<IResourceFinder> resourceFinders = new 
ArrayList<IResourceFinder>();
 
        /** Frequency at which files should be polled */
        private Duration resourcePollFrequency = null;
@@ -206,19 +205,7 @@ public class ResourceSettings implements IResourceSettings
        @Override
        public void addResourceFolder(final String resourceFolder)
        {
-               // Get resource finder
-               final IResourceFinder finder = getResourceFinder();
-
-               // Make sure it's a path
-               if (!(finder instanceof IResourcePath))
-               {
-                       throw new IllegalArgumentException(
-                               "To add a resource folder, the application's 
resource finder must be an instance of IResourcePath");
-               }
-
-               // Cast to resource path and add folder
-               final IResourcePath path = (IResourcePath)finder;
-               path.add(resourceFolder);
+               
getResourceFinders().add(Application.get().getResourceFinderForPath(resourceFolder));
        }
 
        /**
@@ -266,12 +253,12 @@ public class ResourceSettings implements IResourceSettings
        }
 
        /**
-        * @see org.apache.wicket.settings.IResourceSettings#getResourceFinder()
+        * @see 
org.apache.wicket.settings.IResourceSettings#getResourceFinders()
         */
        @Override
-       public IResourceFinder getResourceFinder()
+       public List<IResourceFinder> getResourceFinders()
        {
-               return resourceFinder;
+               return resourceFinders;
        }
 
        /**
@@ -293,7 +280,7 @@ public class ResourceSettings implements IResourceSettings
                {
                        // Create compound resource locator using source path 
from
                        // application settings
-                       resourceStreamLocator = new 
ResourceStreamLocator(getResourceFinder());
+                       resourceStreamLocator = new 
ResourceStreamLocator(getResourceFinders());
                        resourceStreamLocator = new 
CachingResourceStreamLocator(resourceStreamLocator);
                }
                return resourceStreamLocator;
@@ -395,9 +382,9 @@ public class ResourceSettings implements IResourceSettings
         * @see 
org.apache.wicket.settings.IResourceSettings#setResourceFinder(org.apache.wicket.util.file.IResourceFinder)
         */
        @Override
-       public void setResourceFinder(final IResourceFinder resourceFinder)
+       public void setResourceFinders(final List<IResourceFinder> 
resourceFinders)
        {
-               this.resourceFinder = resourceFinder;
+               this.resourceFinders = resourceFinders;
 
                // Cause resource locator to get recreated
                resourceStreamLocator = null;

http://git-wip-us.apache.org/repos/asf/wicket/blob/55303c08/wicket-jmx/src/main/java/org/apache/wicket/jmx/ResourceSettings.java
----------------------------------------------------------------------
diff --git 
a/wicket-jmx/src/main/java/org/apache/wicket/jmx/ResourceSettings.java 
b/wicket-jmx/src/main/java/org/apache/wicket/jmx/ResourceSettings.java
index d38e274..2b97815 100644
--- a/wicket-jmx/src/main/java/org/apache/wicket/jmx/ResourceSettings.java
+++ b/wicket-jmx/src/main/java/org/apache/wicket/jmx/ResourceSettings.java
@@ -81,7 +81,7 @@ public class ResourceSettings implements ResourceSettingsMBean
         */
        public String getResourceFinder()
        {
-               return 
Stringz.className(application.getResourceSettings().getResourceFinder());
+               return 
Stringz.className(application.getResourceSettings().getResourceFinders());
        }
 
        /**

http://git-wip-us.apache.org/repos/asf/wicket/blob/55303c08/wicket-util/src/main/java/org/apache/wicket/util/file/ClasspathResourceFinder.java
----------------------------------------------------------------------
diff --git 
a/wicket-util/src/main/java/org/apache/wicket/util/file/ClasspathResourceFinder.java
 
b/wicket-util/src/main/java/org/apache/wicket/util/file/ClasspathResourceFinder.java
new file mode 100644
index 0000000..0fe8e73
--- /dev/null
+++ 
b/wicket-util/src/main/java/org/apache/wicket/util/file/ClasspathResourceFinder.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.util.file;
+
+import java.net.URL;
+
+import org.apache.wicket.util.resource.IResourceStream;
+import org.apache.wicket.util.string.Strings;
+
+public class ClasspathResourceFinder implements IResourceFinder
+{
+
+       private final String prefix;
+
+       public ClasspathResourceFinder(String prefix)
+       {
+               if (Strings.isEmpty(prefix))
+               {
+                       this.prefix = "";
+               }
+               else if (prefix.endsWith("/"))
+               {
+                       this.prefix = prefix;
+               }
+               else
+               {
+                       this.prefix = prefix + "/";
+               }
+       }
+
+       @Override
+       public IResourceStream find(Class<?> clazz, String path)
+       {
+               String fullPath = prefix + path;
+               IResourceStream resourceStream;
+               if (clazz != null)
+               {
+                       resourceStream = 
getResourceStream(clazz.getClassLoader(), fullPath);
+                       if (resourceStream != null)
+                       {
+                               return resourceStream;
+                       }
+               }
+
+               // use context classloader when no specific classloader is set
+               // (package resources for instance)
+               resourceStream = 
getResourceStream(Thread.currentThread().getContextClassLoader(), fullPath);
+               if (resourceStream != null)
+               {
+                       return resourceStream;
+               }
+
+               // use Wicket classloader when no specific classloader is set
+               resourceStream = getResourceStream(getClass().getClassLoader(), 
fullPath);
+               if (resourceStream != null)
+               {
+                       return resourceStream;
+               }
+
+               return null;
+       }
+
+       private IResourceStream getResourceStream(ClassLoader classLoader, 
String path)
+       {
+               URL url = classLoader.getResource(path);
+               if (url != null)
+               {
+                       return new UrlResourceStream(url);
+               }
+               else
+               {
+                       return null;
+               }
+       }
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/55303c08/wicket-util/src/main/java/org/apache/wicket/util/file/IResourcePath.java
----------------------------------------------------------------------
diff --git 
a/wicket-util/src/main/java/org/apache/wicket/util/file/IResourcePath.java 
b/wicket-util/src/main/java/org/apache/wicket/util/file/IResourcePath.java
deleted file mode 100644
index 1ac2fcb..0000000
--- a/wicket-util/src/main/java/org/apache/wicket/util/file/IResourcePath.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.util.file;
-
-/**
- * Knows how to manage paths and folders, and how to find resources in them.
- * 
- * @author jcompagner
- */
-public interface IResourcePath extends IResourceFinder
-{
-       /**
-        * @param folder
-        *            Adds a folder to the path
-        */
-       void add(String folder);
-}

http://git-wip-us.apache.org/repos/asf/wicket/blob/55303c08/wicket-util/src/main/java/org/apache/wicket/util/file/Path.java
----------------------------------------------------------------------
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/file/Path.java 
b/wicket-util/src/main/java/org/apache/wicket/util/file/Path.java
index 107acc6..58cbd5b 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/file/Path.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/file/Path.java
@@ -16,12 +16,10 @@
  */
 package org.apache.wicket.util.file;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.io.IOException;
 
 import org.apache.wicket.util.resource.FileResourceStream;
 import org.apache.wicket.util.resource.IResourceStream;
-import org.apache.wicket.util.string.StringList;
 
 
 /**
@@ -29,17 +27,9 @@ import org.apache.wicket.util.string.StringList;
  * 
  * @author Jonathan Locke
  */
-public class Path implements IResourcePath
+public class Path implements IResourceFinder
 {
-       /** The list of folders in the path */
-       private final List<Folder> folders = new ArrayList<Folder>();
-
-       /**
-        * Constructor
-        */
-       public Path()
-       {
-       }
+       private Folder folder;
 
        /**
         * Constructor
@@ -49,85 +39,29 @@ public class Path implements IResourcePath
         */
        public Path(final Folder folder)
        {
-               add(folder);
-       }
-
-       /**
-        * Constructor
-        * 
-        * @param folders
-        *            An array of folders to add to the path
-        */
-       public Path(final Folder[] folders)
-       {
-               if (folders != null)
-               {
-                       for (Folder folder : folders)
-                       {
-                               add(folder);
-                       }
-               }
-       }
-
-       /**
-        * @param folder
-        *            Folder to add to path
-        */
-       public void add(final Folder folder)
-       {
                if (!folder.exists())
                {
                        throw new IllegalArgumentException("Folder " + folder + 
" does not exist");
                }
-
-               folders.add(folder);
-       }
-
-       /**
-        * @param path
-        *            Folder to add to path
-        * @see org.apache.wicket.util.file.IResourcePath#add(java.lang.String)
-        */
-       @Override
-       public void add(final String path)
-       {
-               add(new Folder(path));
+               this.folder = folder;
        }
 
        /**
-        * 
         * @see org.apache.wicket.util.file.IResourceFinder#find(Class, String)
         */
        @Override
        public IResourceStream find(final Class<?> clazz, final String pathname)
        {
-               for (Folder folder : folders)
-               {
-                       final File file = new File(folder, pathname);
+               final File file = new File(folder, pathname);
 
-                       if (file.exists())
-                       {
-                               return new FileResourceStream(file);
-                       }
+               if (file.exists())
+               {
+                       return new FileResourceStream(file);
+               }
+               else
+               {
+                       return null;
                }
-
-               return null;
-       }
-
-       /**
-        * @return Returns the folders.
-        */
-       public List<Folder> getFolders()
-       {
-               return folders;
-       }
-
-       /**
-        * @return Number of folders on the path.
-        */
-       public int size()
-       {
-               return folders.size();
        }
 
        /**
@@ -136,6 +70,13 @@ public class Path implements IResourcePath
        @Override
        public String toString()
        {
-               return "[folders = " + StringList.valueOf(folders) + "]";
+               try
+               {
+                       return "[folder = " + folder.getCanonicalPath() + "]";
+               }
+               catch (IOException e)
+               {
+                       return "[folder]";
+               }
        }
 }

Reply via email to