You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by cm...@apache.org on 2012/06/27 23:48:22 UTC

git commit: WICKET-4617 added javadoc

Updated Branches:
  refs/heads/sandbox/resourcefinder bba8177b4 -> af8492c47


WICKET-4617 added javadoc


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

Branch: refs/heads/sandbox/resourcefinder
Commit: af8492c4716a6949654ea8e40b4227dfb062bf8f
Parents: bba8177
Author: Carl-Eric Menzel <cm...@wicketbuch.de>
Authored: Wed Jun 27 23:47:19 2012 +0200
Committer: Carl-Eric Menzel <cm...@wicketbuch.de>
Committed: Wed Jun 27 23:47:19 2012 +0200

----------------------------------------------------------------------
 .../main/java/org/apache/wicket/Application.java   |    8 ++
 .../wicket/core/util/file/WebApplicationPath.java  |    7 +-
 .../util/resource/ClassPathResourceFinder.java     |   18 +++-
 .../resource/locator/IResourceStreamLocator.java   |    2 +-
 .../resource/locator/ResourceStreamLocator.java    |   88 ++++-----------
 .../wicket/protocol/http/WebApplication.java       |    9 +-
 .../apache/wicket/settings/IResourceSettings.java  |   17 ++-
 .../java/org/apache/wicket/util/file/Path.java     |    7 +-
 8 files changed, 70 insertions(+), 86 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/af8492c4/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 6a5ba84..e50cc0d 100644
--- a/wicket-core/src/main/java/org/apache/wicket/Application.java
+++ b/wicket-core/src/main/java/org/apache/wicket/Application.java
@@ -1704,6 +1704,14 @@ public abstract class Application implements UnboundListener, IEventSink
 		return RuntimeConfigurationType.DEPLOYMENT.equals(getConfigurationType());
 	}
 
+	/**
+	 * Create a resource finder to look in the given path. The default implementation returns a
+	 * {@link Path} which will look in the filesystem.
+	 * 
+	 * @param path
+	 *            path
+	 * @return a {@link Path}
+	 */
 	public IResourceFinder getResourceFinderForPath(String path)
 	{
 		return new Path(new Folder(path));

http://git-wip-us.apache.org/repos/asf/wicket/blob/af8492c4/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 78f49fd..7bdd94d 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
@@ -28,10 +28,11 @@ 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.
+ * An {@link IResourceFinder} that looks in a folder in the webapp context path. It will
+ * <em>not</em> load files inside WEB-INF.
  * 
  * @author Johan Compagner
+ * @author Carl-Eric Menzel
  */
 public final class WebApplicationPath implements IResourceFinder
 {
@@ -49,6 +50,8 @@ public final class WebApplicationPath implements IResourceFinder
 	 * 
 	 * @param servletContext
 	 *            The webapplication context where the resources must be loaded from
+	 * @param path
+	 *            The path inside the app context where to look.
 	 */
 	public WebApplicationPath(final ServletContext servletContext, String path)
 	{

http://git-wip-us.apache.org/repos/asf/wicket/blob/af8492c4/wicket-core/src/main/java/org/apache/wicket/core/util/resource/ClassPathResourceFinder.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/ClassPathResourceFinder.java b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/ClassPathResourceFinder.java
index 5a71c2b..bc304cf 100644
--- a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/ClassPathResourceFinder.java
+++ b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/ClassPathResourceFinder.java
@@ -22,10 +22,19 @@ import org.apache.wicket.util.file.IResourceFinder;
 import org.apache.wicket.util.resource.IResourceStream;
 import org.apache.wicket.util.string.Strings;
 
+/**
+ * An {@link IResourceFinder} that looks in a folder in the classpath.
+ * 
+ * @author Carl-Eric Menzel
+ */
 public class ClassPathResourceFinder implements IResourceFinder
 {
 	private final String prefix;
 
+	/**
+	 * @param prefix
+	 *            The path prefix. May be null or empty to look in the classpath root.
+	 */
 	public ClassPathResourceFinder(String prefix)
 	{
 		if (Strings.isEmpty(prefix))
@@ -45,7 +54,7 @@ public class ClassPathResourceFinder implements IResourceFinder
 		IResourceStream resourceStream;
 		if (clazz != null)
 		{
-			resourceStream = getResourceStream(clazz.getClassLoader(), fullPath);
+			resourceStream = getResourceStreamWithClassLoader(clazz.getClassLoader(), fullPath);
 			if (resourceStream != null)
 			{
 				return resourceStream;
@@ -54,14 +63,15 @@ public class ClassPathResourceFinder implements IResourceFinder
 
 		// use context classloader when no specific classloader is set
 		// (package resources for instance)
-		resourceStream = getResourceStream(Thread.currentThread().getContextClassLoader(), fullPath);
+		resourceStream = getResourceStreamWithClassLoader(Thread.currentThread()
+			.getContextClassLoader(), fullPath);
 		if (resourceStream != null)
 		{
 			return resourceStream;
 		}
 
 		// use Wicket classloader when no specific classloader is set
-		resourceStream = getResourceStream(getClass().getClassLoader(), fullPath);
+		resourceStream = getResourceStreamWithClassLoader(getClass().getClassLoader(), fullPath);
 		if (resourceStream != null)
 		{
 			return resourceStream;
@@ -70,7 +80,7 @@ public class ClassPathResourceFinder implements IResourceFinder
 		return null;
 	}
 
-	private IResourceStream getResourceStream(ClassLoader classLoader, String path)
+	private IResourceStream getResourceStreamWithClassLoader(ClassLoader classLoader, String path)
 	{
 		if (classLoader != null)
 		{

http://git-wip-us.apache.org/repos/asf/wicket/blob/af8492c4/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/IResourceStreamLocator.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/IResourceStreamLocator.java b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/IResourceStreamLocator.java
index 86fa41a..c0a34e3 100644
--- a/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/IResourceStreamLocator.java
+++ b/wicket-core/src/main/java/org/apache/wicket/core/util/resource/locator/IResourceStreamLocator.java
@@ -22,7 +22,7 @@ import org.apache.wicket.util.resource.IResourceStream;
 
 
 /**
- * Interface for code that locates resources.
+ * Interface for code that locates resources, taking into account variations for locale and style.
  * 
  * @author Jonathan Locke
  */

http://git-wip-us.apache.org/repos/asf/wicket/blob/af8492c4/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 3bb279e..d18910d 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
@@ -118,7 +118,26 @@ public class ResourceStreamLocator implements IResourceStreamLocator
 	{
 		// First try with the resource finder registered with the application
 		// (allows for markup reloading)
-		return locateByResourceFinders(clazz, path);
+		if (finders == null)
+		{
+			finders = Application.get().getResourceSettings().getResourceFinders();
+		}
+
+		IResourceStream result;
+		for (IResourceFinder finder : finders)
+		{
+			// 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;
+			}
+		}
+		return null;
 	}
 
 	/**
@@ -159,42 +178,6 @@ public class ResourceStreamLocator implements IResourceStreamLocator
 		return null;
 	}
 
-	/**
-	 * Search the the resource my means of the various classloaders available
-	 * 
-	 * @param clazz
-	 * @param path
-	 * @return resource stream
-	 */
-	protected IResourceStream locateByClassLoader(final Class<?> clazz, final String path)
-	{
-		IResourceStream resourceStream = null;
-
-		if (clazz != null)
-		{
-			resourceStream = getResourceStream(clazz.getClassLoader(), path);
-			if (resourceStream != null)
-			{
-				return resourceStream;
-			}
-		}
-
-		// use context classloader when no specific classloader is set
-		// (package resources for instance)
-		resourceStream = getResourceStream(Thread.currentThread().getContextClassLoader(), path);
-		if (resourceStream != null)
-		{
-			return resourceStream;
-		}
-
-		// use Wicket classloader when no specific classloader is set
-		resourceStream = getResourceStream(getClass().getClassLoader(), path);
-		if (resourceStream != null)
-		{
-			return resourceStream;
-		}
-		return null;
-	}
 
 	/**
 	 * Get the resource
@@ -233,37 +216,6 @@ public class ResourceStreamLocator implements IResourceStreamLocator
 	}
 
 	/**
-	 * Search the resource by means of the application registered resource finder
-	 * 
-	 * @param clazz
-	 * @param path
-	 * @return resource stream
-	 */
-	protected IResourceStream locateByResourceFinders(final Class<?> clazz, final String path)
-	{
-		if (finders == null)
-		{
-			finders = Application.get().getResourceSettings().getResourceFinders();
-		}
-
-		IResourceStream result;
-		for (IResourceFinder finder : finders)
-		{
-			// 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;
-			}
-		}
-		return null;
-	}
-
-	/**
 	 * 
 	 * @see org.apache.wicket.core.util.resource.locator.IResourceStreamLocator#newResourceNameIterator(java.lang.String,
 	 *      java.util.Locale, java.lang.String, java.lang.String, java.lang.String, boolean)

http://git-wip-us.apache.org/repos/asf/wicket/blob/af8492c4/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 fcb145e..f2775b5 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
@@ -76,6 +76,7 @@ import org.apache.wicket.util.crypt.CharEncoding;
 import org.apache.wicket.util.file.FileCleaner;
 import org.apache.wicket.util.file.IFileCleaner;
 import org.apache.wicket.util.file.IResourceFinder;
+import org.apache.wicket.util.file.Path;
 import org.apache.wicket.util.lang.Args;
 import org.apache.wicket.util.lang.PackageName;
 import org.apache.wicket.util.string.Strings;
@@ -787,9 +788,13 @@ public abstract class WebApplication extends Application
 	}
 
 	/**
-	 * By default it return a WebApplicationPath
+	 * Create a resource finder to look in the given path. The implementation in
+	 * {@link WebApplication} returns a {@link WebApplicationPath} which will look in the webapp
+	 * context.
 	 * 
-	 * @return resource finder
+	 * @param path
+	 *            path
+	 * @return a {@link Path}
 	 */
 	@Override
 	public IResourceFinder getResourceFinderForPath(String path)

http://git-wip-us.apache.org/repos/asf/wicket/blob/af8492c4/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 a316616..8e89ed9 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
@@ -30,6 +30,7 @@ import org.apache.wicket.markup.head.ResourceAggregator.RecordedHeaderItem;
 import org.apache.wicket.markup.html.IPackageResourceGuard;
 import org.apache.wicket.markup.html.PackageResourceGuard;
 import org.apache.wicket.model.IModel;
+import org.apache.wicket.protocol.http.WebApplication;
 import org.apache.wicket.request.resource.caching.IResourceCachingStrategy;
 import org.apache.wicket.resource.IPropertiesFactory;
 import org.apache.wicket.resource.IPropertiesFactoryContext;
@@ -46,7 +47,7 @@ import org.apache.wicket.util.watch.IModificationWatcher;
  * <i>resourcePollFrequency </i> (defaults to no polling frequency) - Frequency at which resources
  * should be polled for changes.
  * <p>
- * <i>resourceFinder </i> (classpath) - Set this to alter the search path for resources.
+ * <i>resourceFinders</i> - Add/modify this to alter the search path for resources.
  * <p>
  * <i>useDefaultOnMissingResource </i> (defaults to true) - Set to true to return a default value if
  * available when a required string resource is not found. If set to false then the
@@ -133,9 +134,12 @@ public interface IResourceSettings extends IPropertiesFactoryContext
 	IResourceFactory getResourceFactory(final String name);
 
 	/**
-	 * Gets the resource finder to use when searching for resources.
+	 * Gets the resource finders to use when searching for resources. By default, a finder that
+	 * looks in the classpath root is configured. {@link WebApplication} adds the classpath
+	 * directory META-INF/resources. To configure additional search paths or filesystem paths, add
+	 * to this list.
 	 * 
-	 * @return Returns the resourceFinder.
+	 * @return Returns the resourceFinders.
 	 * @see IResourceSettings#setResourceFinder(IResourceFinder)
 	 */
 	List<IResourceFinder> getResourceFinders();
@@ -199,9 +203,10 @@ public interface IResourceSettings extends IPropertiesFactoryContext
 	void setPropertiesFactory(IPropertiesFactory factory);
 
 	/**
-	 * Sets the finder to use when searching for resources. By default, the resources are located on
-	 * the classpath. If you want to configure other, additional, search paths, you can use this
-	 * method.
+	 * Sets the finders to use when searching for resources. By default, the resources are located
+	 * on the classpath. To add additional search paths, add to the list given by
+	 * {@link #getResourceFinders()}. Use this method if you want to completely exchange the list of
+	 * resource finders.
 	 * 
 	 * @param resourceFinder
 	 *            The resourceFinder to set

http://git-wip-us.apache.org/repos/asf/wicket/blob/af8492c4/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 cd62c98..efa1924 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
@@ -23,9 +23,10 @@ import org.apache.wicket.util.resource.IResourceStream;
 
 
 /**
- * Maintains a list of folders as a path.
+ * An {@link IResourceFinder} that looks for its resources in a filesystem path.
  * 
  * @author Jonathan Locke
+ * @author Carl-Eric Menzel
  */
 public class Path implements IResourceFinder
 {
@@ -83,11 +84,11 @@ public class Path implements IResourceFinder
 	{
 		try
 		{
-			return "[folder = " + folder.getCanonicalPath() + "]";
+			return "[Path: folder = " + folder.getCanonicalPath() + "]";
 		}
 		catch (IOException e)
 		{
-			return "[folder]";
+			return "[Path: exception while inspecting folder]";
 		}
 	}
 }