incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r654438 - in /incubator/sling/trunk/sling/servlet-resolver/src: main/java/org/apache/sling/servlet/resolver/ main/java/org/apache/sling/servlet/resolver/helper/ test/java/org/apache/sling/servlet/resolver/helper/
Date Thu, 08 May 2008 07:34:08 GMT
Author: fmeschbe
Date: Thu May  8 00:34:07 2008
New Revision: 654438

URL: http://svn.apache.org/viewvc?rev=654438&view=rev
Log:
SLING-387 Refactor error handler script resolution to also use the new
resolution mechanism, rename some classes to better match their functionality
and cleanup code (remove unused methods and classes).

Added:
    incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/ResourceCollector.java
      - copied, changed from r654076, incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/LocationUtil.java
    incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/ResourceCollectorGet.java
      - copied, changed from r654076, incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/LocationUtilGet.java
    incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/WeightedResource.java
      - copied, changed from r654076, incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/LocationResource.java
    incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/HelperTestBase.java
      - copied, changed from r654076, incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationTestBase.java
    incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/ResourceCollectorGetCalculatePrefixWeightTest.java
      - copied, changed from r654076, incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationUtilCreateLocationResourceTest.java
    incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/ResourceCollectorGetServletsTest.java
      - copied, changed from r654076, incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationUtilGetServletsTest.java
    incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/WeightedResourceTest.java
      - copied, changed from r654076, incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationResourceTest.java
Removed:
    incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/LocationResource.java
    incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/LocationUtil.java
    incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/LocationUtilGet.java
    incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/PathIterator.java
    incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationResourceTest.java
    incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationTestBase.java
    incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationUtilCreateLocationResourceTest.java
    incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationUtilGetServletsTest.java
Modified:
    incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java
    incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/LocationIterator.java
    incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationIteratorTest.java
    incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/ScriptSelectionTest.java

Modified: incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java?rev=654438&r1=654437&r2=654438&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java (original)
+++ incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java Thu May  8 00:34:07 2008
@@ -30,7 +30,6 @@
 import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.Hashtable;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -47,9 +46,9 @@
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.SyntheticResource;
 import org.apache.sling.api.scripting.SlingScript;
 import org.apache.sling.api.scripting.SlingScriptResolver;
-import org.apache.sling.api.servlets.HttpConstants;
 import org.apache.sling.api.servlets.OptingServlet;
 import org.apache.sling.api.servlets.ServletResolver;
 import org.apache.sling.commons.osgi.OsgiUtil;
@@ -57,9 +56,7 @@
 import org.apache.sling.core.servlets.ErrorHandler;
 import org.apache.sling.servlet.resolver.defaults.DefaultErrorHandlerServlet;
 import org.apache.sling.servlet.resolver.defaults.DefaultServlet;
-import org.apache.sling.servlet.resolver.helper.LocationResource;
-import org.apache.sling.servlet.resolver.helper.LocationUtil;
-import org.apache.sling.servlet.resolver.helper.PathIterator;
+import org.apache.sling.servlet.resolver.helper.ResourceCollector;
 import org.apache.sling.servlet.resolver.helper.SlingServletConfig;
 import org.apache.sling.servlet.resolver.resource.ServletResourceProvider;
 import org.osgi.framework.Constants;
@@ -115,8 +112,12 @@
 
     private String servletRoot;
 
-    private Servlet coreDefaultServlet;
+    // the default servlet if no other servlet applies for a request. This
+    // field is set on demand by getDefaultServlet()
+    private Servlet defaultServlet;
 
+    // the default error handler servlet if no other error servlet applies for
+    // a request. This field is set on demand by getDefaultErrorServlet()
     private Servlet defaultErrorServlet;
 
     // ---------- ServletResolver interface -----------------------------------
@@ -127,7 +128,8 @@
 
         // first check whether the type of a resource is the absolute
         // path of a servlet (or script)
-        String type = request.getResource().getResourceType();
+        Resource resource = request.getResource();
+        String type = resource.getResourceType();
         if (type.charAt(0) == '/') {
             Resource res = request.getResourceResolver().getResource(type);
             if (res != null) {
@@ -135,26 +137,15 @@
             }
         }
         
+        // the resource type is not absolute, so lets go for the deep search
         if (servlet == null) {
-            LocationUtil lu = LocationUtil.create(request);
-            Collection<LocationResource> candidates = lu.getScripts(request);
-            Iterator<LocationResource> lri = candidates.iterator();
-            while (lri.hasNext() && servlet == null) {
-                Resource candidateResource = lri.next().getResource();
-                Servlet candidate = candidateResource.adaptTo(Servlet.class);
-                if (candidate != null) {
-                    boolean servletAcceptsRequest = !(candidate instanceof OptingServlet)
-                        || ((OptingServlet) candidate).accepts(request);
-                    if (servletAcceptsRequest) {
-                        servlet = candidate;
-                    }
-                }
-            }
+            ResourceCollector locationUtil = ResourceCollector.create(request);
+            servlet = getServlet(locationUtil, request, resource);
         }
 
         // last resort, use the core bundle default servlet
         if (servlet == null) {
-            servlet = getCoreDefaultServlet();
+            servlet = getDefaultServlet();
         }
 
         if (log.isDebugEnabled()) {
@@ -226,13 +217,14 @@
         }
 
         // find the error handler component
-        ResourceResolver resolver = request.getResourceResolver();
-        String baseName = String.valueOf(status);
+        Resource resource = getErrorResource(request);
+        
+        // find a servlet for the status as the method name
+        ResourceCollector locationUtil = new ResourceCollector(
+            String.valueOf(status), ServletResolverConstants.ERROR_HANDLER_PATH);
+        Servlet servlet = getServlet(locationUtil, request, resource);
 
-        // search the servlet by absolute path
-        PathIterator pathIterator = new PathIterator(
-            ServletResolverConstants.ERROR_HANDLER_PATH, path);
-        Servlet servlet = getServlet(resolver, pathIterator, baseName, request);
+        // fall back to default servlet if none
         if (servlet == null) {
             servlet = getDefaultErrorServlet();
         }
@@ -265,17 +257,15 @@
 
         // find the error handler component
         Servlet servlet = null;
-        ResourceResolver resolver = request.getResourceResolver();
-
-        PathIterator pathIterator = new PathIterator(
-            ServletResolverConstants.ERROR_HANDLER_PATH, path);
+        Resource resource = getErrorResource(request);
 
         Class<?> tClass = throwable.getClass();
         while (servlet == null && tClass != Object.class) {
-            String baseName = tClass.getSimpleName();
-
-            pathIterator.reset();
-            servlet = getServlet(resolver, pathIterator, baseName, request);
+            // find a servlet for the simple class name as the method name
+            ResourceCollector locationUtil = new ResourceCollector(
+                tClass.getSimpleName(),
+                ServletResolverConstants.ERROR_HANDLER_PATH);
+            servlet = getServlet(locationUtil, request, resource);
 
             // go to the base class
             tClass = tClass.getSuperclass();
@@ -297,90 +287,92 @@
 
     // ---------- internal helper ---------------------------------------------
 
-    private Servlet getServlet(ResourceResolver resolver,
-            Iterator<String> paths, String baseName,
-            SlingHttpServletRequest request) {
-
-        while (paths.hasNext()) {
-            String location = paths.next();
-            try {
-                Servlet result = getServletAt(resolver, location, baseName);
-                if (result != null) {
-                    boolean servletAcceptsRequest = !(result instanceof OptingServlet)
-                        || ((OptingServlet) result).accepts(request);
-                    if (servletAcceptsRequest) {
-                        return result;
-                    }
-                }
-            } catch (SlingException se) {
-                log.warn("getServlet: Problem resolving servlet at " + location
-                    + "/" + baseName, se);
-            }
+    /**
+     * Returns the resource of the given request to be used as the basis for
+     * error handling. If the resource has not yet been set in the request
+     * because the error occurred before the resource could be set (e.g. during
+     * resource resolution) a synthetic resource is returned whose type is
+     * {@link ServletResolverConstants#ERROR_HANDLER_PATH}.
+     * 
+     * @param request The request whose resource is to be returned.
+     */
+    private Resource getErrorResource(SlingHttpServletRequest request) {
+        Resource res = request.getResource();
+        if (res == null) {
+            res = new SyntheticResource(request.getResourceResolver(),
+                request.getPathInfo(),
+                ServletResolverConstants.ERROR_HANDLER_PATH);
         }
-
-        // exhausted all
-        return null;
+        return res;
     }
-
-    private Servlet getServletAt(ResourceResolver resolver, String location,
-            String baseName) throws SlingException {
-        Servlet result = null;
-
-        Resource scriptRoot = resolver.getResource(location);
-        if (scriptRoot != null) {
-
-            log.debug("Looking for servlet with filename={} under {}",
-                baseName, scriptRoot.getPath());
-
-            // get the item and ensure it is a node
-            Iterator<Resource> children = resolver.listChildren(scriptRoot);
-            while (result == null && children.hasNext()) {
-                Resource resource = children.next();
-
-                // extract the name of the resource
-                int lastSlash = resource.getPath().lastIndexOf('/');
-                String name = resource.getPath().substring(lastSlash + 1);
-
-                // only accept it if it is equal to the base name or
-                // if there is just a single extension after the base name
-                if (name.startsWith(baseName)
-                    && (name.length() == baseName.length() || name.lastIndexOf('.') == baseName.length())) {
-                    result = resource.adaptTo(Servlet.class);
+    
+    /**
+     * Returns a servlet suitable for handling a request. The
+     * <code>locationUtil</code> is used find any servlets or scripts usable
+     * for the request. Each servlet returned is in turn asked whether it is
+     * actually willing to handle the request in case the servlet is an
+     * <code>OptingServlet</code>. The first servlet willing to handle the
+     * request is used.
+     * 
+     * @param locationUtil The helper used to find appropriate servlets ordered
+     *            by matching priority.
+     * @param request The request used to give to any <code>OptingServlet</code>
+     *            for them to decide on whether they are willing to handle the
+     *            request
+     * @param resource The <code>Resource</code> for which to find a script.
+     *            This need not be the same as
+     *            <code>request.getResource()</code> in case of error handling
+     *            where the resource may not have been assigned to the request
+     *            yet.
+     * @return a servlet for handling the request or <code>null</code> if no
+     *         such servlet willing to handle the request could be found.
+     */
+    private Servlet getServlet(ResourceCollector locationUtil,
+            SlingHttpServletRequest request, Resource resource) {
+        Collection<Resource> candidates = locationUtil.getServlets(resource);
+        for (Resource candidateResource : candidates) {
+            Servlet candidate = candidateResource.adaptTo(Servlet.class);
+            if (candidate != null) {
+                boolean servletAcceptsRequest = !(candidate instanceof OptingServlet)
+                    || ((OptingServlet) candidate).accepts(request);
+                if (servletAcceptsRequest) {
+                    return candidate;
                 }
             }
-
-            // there is no child node with the basename, try without
-            if (result == null) {
-                result = scriptRoot.adaptTo(Servlet.class);
-            }
-
-        } else {
-            // check alternative variant using location/basename directly
-            Resource scriptResource = resolver.getResource(location + "/"
-                + baseName);
-            if (scriptResource != null) {
-                result = scriptResource.adaptTo(Servlet.class);
-            }
         }
-
-        return result;
+        
+        // exhausted all candidates, we don't have a servlet
+        return null;
     }
-
-    private Servlet getCoreDefaultServlet() {
-        if (coreDefaultServlet == null) {
+    
+    /**
+     * Returns the internal default servlet which is called in case no other
+     * servlet applies for handling a request. This servlet should really only
+     * be used if the default servlets have not been registered (yet).
+     */
+    private Servlet getDefaultServlet() {
+        if (defaultServlet == null) {
             try {
                 Servlet servlet = new DefaultServlet();
                 servlet.init(new SlingServletConfig(servletContext, null,
                     "Sling Core Default Servlet"));
-                coreDefaultServlet = servlet;
+                defaultServlet = servlet;
             } catch (ServletException se) {
                 log.error("Failed to initiliaze Servlet", se);
             }
         }
 
-        return coreDefaultServlet;
+        return defaultServlet;
     }
 
+
+    /**
+     * Returns the default error handler servlet, which is called in case there
+     * is no other - better matching - servlet registered to handle an error or
+     * exception. As it is expected, that most of the time, there will be no
+     * such more specific servlet, the default error handler servlet is quite
+     * complete.
+     */
     private Servlet getDefaultErrorServlet() {
         if (defaultErrorServlet == null) {
             try {
@@ -601,26 +593,4 @@
             }
         }
     }
-
-    private static String getScriptBaseName(SlingHttpServletRequest request) {
-        String methodName = request.getMethod();
-        String extension = request.getRequestPathInfo().getExtension();
-
-        if (methodName == null || methodName.length() == 0) {
-
-            throw new IllegalArgumentException(
-                "HTTP Method name must not be empty");
-
-        } else if ((HttpConstants.METHOD_GET.equalsIgnoreCase(methodName) || HttpConstants.METHOD_HEAD.equalsIgnoreCase(methodName))
-            && extension != null && extension.length() > 0) {
-
-            // for GET, we use the request extension
-            return extension;
-
-        } else {
-
-            // for other methods use the method name
-            return methodName;
-        }
-    }
 }

Modified: incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/LocationIterator.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/LocationIterator.java?rev=654438&r1=654437&r2=654438&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/LocationIterator.java (original)
+++ incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/LocationIterator.java Thu May  8 00:34:07 2008
@@ -21,41 +21,82 @@
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 
-import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.jcr.resource.JcrResourceUtil;
 import org.apache.sling.servlet.resolver.ServletResolverConstants;
 
+/**
+ * The <code>LocationIterator</code> provides access to an ordered collection
+ * of absolute paths containing potential request handling. The primary order of
+ * the collection is the resource type hierarchy with the base resource type at
+ * the top. The secondary order is the search path retrieved from the resource
+ * resolver.
+ * <p>
+ * Example: For a node type hierarchy "sample" > "super" > "default" and a
+ * search path of [ "/apps", "/libs" ], the iterator would provide access to the
+ * following list of paths:
+ * <ol>
+ * <li><code>/apps/sample</code></li>
+ * <li><code>/libs/sample</code></li>
+ * <li><code>/apps/super</code></li>
+ * <li><code>/libs/super</code></li>
+ * <li><code>/apps/default</code></li>
+ * <li><code>/libs/default</code></li>
+ * </ol>
+ */
 public class LocationIterator implements Iterator<String> {
 
+    // The resource for which this iterator is created. This resource
+    // gives the initial resource type and the first resource super type
     private final Resource resource;
 
+    // The resource resolver used to find resource super types of
+    // resource types
     private final ResourceResolver resolver;
 
+    // The base resource type to be used as a final entry if there is
+    // no more resource super type. This is kind of the java.lang.Object
+    // the resource type hierarchy.
+    private final String baseResourceType;
+
+    // The search path of the resource resolver
     private final String[] searchPath;
 
+    // counter into the search path array
+    private int pathCounter;
+
+    // The resource type to use for the next iteration loop
     private String resourceType;
 
+    // The current relative path generated from the resource type
     private String relPath;
 
-    private int pathCounter;
-
+    // the next absolute path to return from next(). This is null
+    // if there is no more location to return
     private String nextLocation;
 
-    public LocationIterator(SlingHttpServletRequest request) {
-        resource = request.getResource();
-        resolver = request.getResourceResolver();
+    /**
+     * Creates an instance of this iterator starting with a location built from
+     * the resource type of the <code>resource</code> and ending with the
+     * given <code>baseResourceType</code>.
+     * 
+     * @param resource The <code>Resource</code> used to define the initial
+     *            resource type and resource super type.
+     * @param baseResourceType The base resource type. If this is
+     *            <code>null</code> the
+     *            {@link ServletResolverConstants#DEFAULT_SERVLET_NAME} is used.
+     */
+    public LocationIterator(Resource resource, String baseResourceType) {
+        this.resource = resource;
+        this.resolver = resource.getResourceResolver();
+        this.baseResourceType = (baseResourceType != null)
+                ? baseResourceType
+                : ServletResolverConstants.DEFAULT_SERVLET_NAME;
 
         String[] tmpPath = resolver.getSearchPath();
         if (tmpPath == null || tmpPath.length == 0) {
             tmpPath = new String[] { "/" };
-        } else {
-            for (int i=0; i< tmpPath.length; i++) {
-                if (!tmpPath[i].endsWith("/")) {
-                    tmpPath[i] = tmpPath[i].concat("/");
-                }
-            }
         }
         searchPath = tmpPath;
 
@@ -64,10 +105,19 @@
         nextLocation = seek();
     }
 
+    /**
+     * Returns <code>true</code> if there is another entry
+     */
     public boolean hasNext() {
         return nextLocation != null;
     }
 
+    /**
+     * Returns the next entry of this iterator.
+     * 
+     * @throws NoSuchElementException if {@link #hasNext()} returns
+     *             <code>false</code>.
+     */
     public String next() {
         if (!hasNext()) {
             throw new NoSuchElementException();
@@ -78,6 +128,9 @@
         return result;
     }
 
+    /**
+     * @throws UnsupportedOperationException
+     */
     public void remove() {
         throw new UnsupportedOperationException();
     }
@@ -89,10 +142,10 @@
             if (resourceType == null) {
                 return null;
             }
-            
+
             String typePath = JcrResourceUtil.resourceTypeToPath(resourceType);
             if (typePath.startsWith("/")) {
-                resourceType = getResourceSuperType();
+                resourceType = getResourceSuperType(resourceType);
                 return typePath;
             }
 
@@ -104,23 +157,35 @@
         pathCounter++;
         if (pathCounter >= searchPath.length) {
             relPath = null;
-            resourceType = getResourceSuperType();
+            resourceType = getResourceSuperType(resourceType);
             pathCounter = 0;
         }
 
         return result;
     }
 
-    private String getResourceSuperType() {
+    /**
+     * Returns the resource super type of the given resource type:
+     * <ol>
+     * <li>If the resource type is the base resource type <code>null</code>
+     * is returned.</li>
+     * <li>If the resource type is the resource type of the resource the
+     * resource super type from the resource is returned.</li>
+     * <li>Otherwise the resource super type is tried to be found in the
+     * resource tree. If one is found, it is returned.</li>
+     * <li>Otherwise the base resource type is returned.</li>
+     * </ol>
+     */
+    private String getResourceSuperType(String resourceType) {
 
         // if the current resource type is the default value, there are no more
-        if (resourceType == ServletResolverConstants.DEFAULT_SERVLET_NAME) {
+        if (resourceType.equals(baseResourceType)) {
             return null;
         }
 
         // get the super type of the current resource type
         String superType;
-        if (resourceType == resource.getResourceType()) {
+        if (resourceType.equals(resource.getResourceType())) {
             superType = resource.getResourceSuperType();
         } else {
             superType = JcrResourceUtil.getResourceSuperType(resolver,
@@ -129,7 +194,7 @@
 
         // use default resource type if there is no super type any more
         if (superType == null) {
-            superType = ServletResolverConstants.DEFAULT_SERVLET_NAME;
+            superType = baseResourceType;
         }
 
         return superType;

Copied: incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/ResourceCollector.java (from r654076, incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/LocationUtil.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/ResourceCollector.java?p2=incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/ResourceCollector.java&p1=incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/LocationUtil.java&r1=654076&r2=654438&rev=654438&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/LocationUtil.java (original)
+++ incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/ResourceCollector.java Thu May  8 00:34:07 2008
@@ -32,52 +32,97 @@
 import org.apache.sling.api.servlets.HttpConstants;
 import org.apache.sling.servlet.resolver.resource.ServletResourceProvider;
 
-public class LocationUtil {
-
-    private final ResourceResolver resolver;
+/**
+ * The <code>ResourceCollector</code> class provides a single public method -
+ * {@link #getServlets(Resource)} - which is used to find an ordered collection
+ * of <code>Resource</code> instances which may be used to find a servlet or
+ * script to handle a request to the given resource.
+ */
+public class ResourceCollector {
 
+    // the request method name used to indicate the script name
     private final String methodName;
 
-    public static LocationUtil create(SlingHttpServletRequest request) {
+    // the most generic resource type to use. This may be null in which
+    // case the default servlet name will be used as the base name
+    private final String baseResourceType;
+
+    /**
+     * Creates a <code>ResourceCollector</code> for the given
+     * <code>request</code>. If the request is a GET or HEAD request, a
+     * specialized instance is returned which also takes the request selectors
+     * and request extension into account for finding servlet resources.
+     * Otherwise an instance of this class itself is returned which just takes
+     * the resource type and request method name into account.
+     * 
+     * @param request The <code>SlingHttpServletRequest</code> for which to
+     *            return a <code>ResourceCollector</code>.
+     * @return The <code>ResourceCollector</code> to find servlets and scripts
+     *         suitable for handling the <code>request</code>.
+     */
+    public static ResourceCollector create(SlingHttpServletRequest request) {
         if (HttpConstants.METHOD_GET.equals(request.getMethod())
             || HttpConstants.METHOD_HEAD.equals(request.getMethod())) {
-            return new LocationUtilGet(request);
+            return new ResourceCollectorGet(request);
         }
 
-        return new LocationUtil(request);
+        return new ResourceCollector(request.getMethod(), null);
     }
 
-    protected LocationUtil(SlingHttpServletRequest request) {
-        resolver = request.getResourceResolver();
-        methodName = request.getMethod();
+    /**
+     * Creates a <code>ResourceCollector</code> finding servlets and scripts
+     * for the given <code>methodName</code>.
+     * 
+     * @param methodName The <code>methodName</code> used to find scripts for.
+     *            This must not be <code>null</code>.
+     * @param baseResourceType The basic resource type to use as a final
+     *            resource super type. If this is <code>null</code> the
+     *            default value
+     *            {@link org.apache.sling.servlet.resolver.ServletResolverConstants#DEFAULT_SERVLET_NAME}
+     *            is assumed.
+     */
+    public ResourceCollector(String methodName, String baseResourceType) {
+        this.methodName = methodName;
+        this.baseResourceType = baseResourceType;
     }
 
-    public Collection<LocationResource> getScripts(
-            SlingHttpServletRequest request) {
-
-        SortedSet<LocationResource> resources = new TreeSet<LocationResource>();
+    public final Collection<Resource> getServlets(Resource resource) {
 
-        int ordinal = 0;
+        SortedSet<Resource> resources = new TreeSet<Resource>();
 
-        Iterator<String> locations = new LocationIterator(request);
+        ResourceResolver resolver = resource.getResourceResolver();
+        Iterator<String> locations = new LocationIterator(resource,
+            getBaseResourceType());
         while (locations.hasNext()) {
             String location = locations.next();
 
             // get the location resource, use a synthetic resource if there
             // is no real location. There may still be children at this
             // location
-            Resource locationRes = getResource(null, location);
-            ordinal = getLocationResources(ordinal, locationRes, resources);
+            Resource locationRes = getResource(resolver, null, location);
+            getWeightedResources(resources, locationRes);
         }
 
         return resources;
     }
 
-    protected int getLocationResources(int ordinal, Resource location,
-            Set<LocationResource> resources) {
+    /**
+     * Returns all resources inside the <code>location</code> whose base name
+     * equals the {@link #getMethodName()} and which just have a single
+     * extension after the base name. In addition, the special resource at
+     * <code>location.getPath + ".servlet"</code> is checked to find servlets
+     * which are registered with no specific method name.
+     * 
+     * @param resources The collection into which any resources found are added.
+     * @param location The location in the resource tree where the servlets and
+     *            scripts are to be found.
+     */
+    protected void getWeightedResources(Set<Resource> resources,
+            Resource location) {
 
         // now list the children and check them
-        Iterator<Resource> children = getResolver().listChildren(location);
+        Iterator<Resource> children = location.getResourceResolver().listChildren(
+            location);
         while (children.hasNext()) {
             Resource child = children.next();
 
@@ -86,10 +131,8 @@
 
             // require method name plus script extension
             if (parts.length == 2 && getMethodName().equals(parts[0])) {
-                LocationResource lr = new LocationResource(ordinal, child, 0,
-                    LocationResource.WEIGHT_NONE);
-                resources.add(lr);
-                ordinal++;
+                addWeightedResource(resources, child, 0,
+                    WeightedResource.WEIGHT_NONE);
             }
         }
 
@@ -97,31 +140,71 @@
         // name nor extensions and selectors
         String path = location.getPath()
             + ServletResourceProvider.SERVLET_PATH_EXTENSION;
-        location = getResolver().getResource(path);
+        location = location.getResourceResolver().getResource(path);
         if (location != null) {
-            LocationResource lr = new LocationResource(ordinal, location, 0,
-                LocationResource.WEIGHT_LAST_RESSORT);
-            resources.add(lr);
-            ordinal++;
+            addWeightedResource(resources, location, 0,
+                WeightedResource.WEIGHT_LAST_RESSORT);
         }
-
-        return ordinal;
     }
 
-    public String getMethodName() {
-        return methodName;
+    /**
+     * Returns the basic resource type assigned to this instance
+     */
+    public final String getBaseResourceType() {
+        return baseResourceType;
     }
 
-    public ResourceResolver getResolver() {
-        return resolver;
+    /**
+     * Returns the method name assigned to this instance
+     */
+    public final String getMethodName() {
+        return methodName;
     }
 
-    protected Resource getResource(Resource base, String path) {
+    /**
+     * Creates a {@link WeightedResource} and adds it to the set of resources.
+     * The number of resources already present in the set is used as the ordinal
+     * number for the newly created resource.
+     * 
+     * @param resources The set of resource to which the
+     *            {@link WeightedResource} is added.
+     * @param resource The <code>Resource</code> on which the
+     *            {@link WeightedResource} is based.
+     * @param numSelectors The number of request selectors which are matched by
+     *            the name of the resource.
+     * @param methodPrefixWeight The method/prefix weight assigned to the
+     *            resource according to the resource name.
+     */
+    protected final void addWeightedResource(Set<Resource> resources,
+            Resource resource, int numSelectors, int methodPrefixWeight) {
+        WeightedResource lr = new WeightedResource(resources.size(), resource,
+            numSelectors, methodPrefixWeight);
+        resources.add(lr);
+    }
+
+    /**
+     * Returns a resource for the given <code>path</code>. If the
+     * <code>path</code> is relative, the resource is accessed relative to the
+     * <code>base</code> resource. If no resource exists at the given path -
+     * absolute or relative to the base resource - a
+     * <code>SyntheticResource</code> is returned.
+     * 
+     * @param resolver The <code>ResourceResolver</code> used to access the
+     *            resource.
+     * @param base The (optional) base resource. This may be <code>null</code>
+     *            if the <code>path</code> is absolute.
+     * @param path The absolute or relative (to the base resource) path of the
+     *            resource to return.
+     * @return The actual resource at the given <code>path</code> or a
+     *         synthetic resource representing the path location.
+     */
+    protected final Resource getResource(ResourceResolver resolver,
+            Resource base, String path) {
         Resource res;
         if (base == null) {
-            res = getResolver().getResource(path);
+            res = resolver.getResource(path);
         } else {
-            res = getResolver().getResource(base, path);
+            res = resolver.getResource(base, path);
         }
 
         if (res == null) {

Copied: incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/ResourceCollectorGet.java (from r654076, incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/LocationUtilGet.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/ResourceCollectorGet.java?p2=incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/ResourceCollectorGet.java&p1=incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/LocationUtilGet.java&r1=654076&r2=654438&rev=654438&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/LocationUtilGet.java (original)
+++ incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/ResourceCollectorGet.java Thu May  8 00:34:07 2008
@@ -22,62 +22,98 @@
 import java.util.Set;
 
 import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.request.RequestPathInfo;
 import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class LocationUtilGet extends LocationUtil {
+/**
+ * The <code>ResourceCollectorGet</code> is a special
+ * {@link ResourceCollector} which takes into account the request selectors and
+ * request extension to find servlets and scripts. This class is instantiated by
+ * the {@link ResourceCollector#create(SlingHttpServletRequest)} method on
+ * behalf of GET and HEAD requests.
+ */
+class ResourceCollectorGet extends ResourceCollector {
+
+    /**
+     * The special value returned by
+     * {@link #calculatePrefixMethodWeight(Resource, String, boolean)} if the
+     * resource is not suitable to handle the request according to the location
+     * prefix, request selectors and request extension (value is
+     * <code>Integer.MIN_VALUE</code>).
+     */
+    protected static final int WEIGHT_NO_MATCH = Integer.MIN_VALUE;
 
     /** default log */
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-    private final String selectors;
+    // the request selectors as a string converted to a realtive path or
+    // null if the request has no selectors
+    private final String requestSelectors;
 
-    private final int numSelectors;
+    // the number of request selectors of the request or 0 if none
+    private final int numRequestSelectors;
 
+    // the request extension or null if the request has no extension
     private final String extension;
 
-    private final boolean isGetHtmlRequest;
+    // whether the request extension is "html"
+    private final boolean isHtmlRequest;
 
-    protected LocationUtilGet(SlingHttpServletRequest request) {
-        super(request);
+    ResourceCollectorGet(SlingHttpServletRequest request) {
+        super(request.getMethod(), null);
 
-        selectors = request.getRequestPathInfo().getSelectorString();
-        numSelectors = request.getRequestPathInfo().getSelectors().length;
-        extension = request.getRequestPathInfo().getExtension();
-        isGetHtmlRequest = "html".equals(request.getRequestPathInfo().getExtension());
+        RequestPathInfo requestpaInfo = request.getRequestPathInfo();
+        String rs = requestpaInfo.getSelectorString();
+        if (rs == null || rs.length() == 0) {
+            requestSelectors = null;
+            numRequestSelectors = 0;
+        } else {
+            requestSelectors = rs.replace('.', '/');
+            numRequestSelectors = requestpaInfo.getSelectors().length;
+        }
+
+        extension = requestpaInfo.getExtension();
+        isHtmlRequest = "html".equals(extension);
     }
 
+    /**
+     * In addition to the base class implementation this method also considers
+     * resources for the request selectors, request extension and location name.
+     */
     @Override
-    protected int getLocationResources(int ordinal, Resource location,
-            Set<LocationResource> resources) {
+    protected void getWeightedResources(Set<Resource> resources,
+            Resource location) {
+
+        ResourceResolver resolver = location.getResourceResolver();
 
         // print/a4.html.esp
         // print.html.esp
-        if (selectors != null && selectors.length() > 0) {
-            String relString = selectors.replace('.', '/');
-            int numSelectors = this.numSelectors;
-            while (relString.length() > 0) {
+        if (requestSelectors != null) {
+            String relativePath = requestSelectors;
+            int numSelectors = numRequestSelectors;
+            while (relativePath.length() > 0) {
 
                 String parent;
                 String name;
                 Resource loc;
 
-                int slash = relString.lastIndexOf('/');
+                int slash = relativePath.lastIndexOf('/');
                 if (slash > 0) {
-                    parent = relString.substring(0, slash);
-                    name = relString.substring(slash + 1);
-                    loc = getResource(location, parent);
+                    parent = relativePath.substring(0, slash);
+                    name = relativePath.substring(slash + 1);
+                    loc = getResource(resolver, location, parent);
                 } else {
                     parent = "";
-                    name = relString;
+                    name = relativePath;
                     loc = location;
                 }
 
-                ordinal = getLocationResources(ordinal, loc, name, false,
-                    numSelectors, resources);
-                relString = parent;
+                getWeightedResources(resources, loc, name, false, numSelectors);
+                relativePath = parent;
 
                 numSelectors--;
             }
@@ -86,35 +122,82 @@
         // sample.html.esp
         // sample.esp
         // html.esp
-        ordinal = getLocationResources(ordinal, location,
-            ResourceUtil.getName(location.getPath()), true, 0, resources);
+        getWeightedResources(resources, location,
+            ResourceUtil.getName(location.getPath()), true, 0);
 
         // base class implementation supporting the method name
-        return super.getLocationResources(ordinal, location, resources);
+        super.getWeightedResources(resources, location);
     }
 
-    protected int getLocationResources(int ordinal, Resource location,
-            String locationPrefix, boolean optionalLocationPrefix,
-            int numSelectors, Set<LocationResource> resources) {
+    /**
+     * Scan the given <code>location</code> for any resources whose name
+     * starts with the <code>locationPrefix</code> (optionally if
+     * <code>optionalLocationPrefix</code> is <code>true</code>) and
+     * contains the request method and/or request extension.
+     * 
+     * @param location The location in which to find resources.
+     * @param locationPrefix The prefix to be matched by resources.
+     * @param optionalLocationPrefix Whether the resources must start with the
+     *            <code>locationPrefix</code> or not. If this is
+     *            <code>true</code>, the resources name need not start with
+     *            the prefix.
+     * @param numSelectors The number of selectors matched by the resources in
+     *            this location. This value is only used to created
+     *            {@link WeightedResource} instances to be added to the resource
+     *            set.
+     * @param resources The set of resources to which any more
+     *            <code>WeightedResource</code> instances are added.
+     */
+    protected void getWeightedResources(Set<Resource> resources,
+            Resource location, String locationPrefix,
+            boolean optionalLocationPrefix, int numSelectors) {
 
         // now list the children and check them
-        Iterator<Resource> children = getResolver().listChildren(location);
+        Iterator<Resource> children = location.getResourceResolver().listChildren(
+            location);
         while (children.hasNext()) {
             Resource child = children.next();
-            LocationResource lr = createLocationResource(ordinal,
-                locationPrefix, optionalLocationPrefix, child, numSelectors);
-            if (lr != null) {
-                resources.add(lr);
-                ordinal++;
+            int methodPrefixWeight = calculatePrefixMethodWeight(child,
+                locationPrefix, optionalLocationPrefix);
+            if (methodPrefixWeight != WEIGHT_NO_MATCH) {
+                addWeightedResource(resources, child, numSelectors,
+                    methodPrefixWeight);
             }
         }
-
-        return ordinal;
     }
 
-    protected LocationResource createLocationResource(int ordinal,
-            String locationPrefix, boolean optionalLocationPrefix,
-            Resource resource, int numSelectors) {
+    /**
+     * Calculates the method/prefix weight to be assigned to a
+     * {@link WeightedResource} created for the given <code>resource</code>.
+     * If the name of the resource does not meet the requirements for matching
+     * resources the special value {@link #WEIGHT_NO_MATCH} is returned.
+     * Otherwise the actual method/prefix weight to use is returned.
+     * <p>
+     * The requirements for resource names to be accepted are:
+     * <ul>
+     * <li>If <code>optionalLocationPrefix</code> is <code>false</code>,
+     * the resource name must be prefixed with the <code>locationPrefix</code>.</li>
+     * <li>If the request has an extension the resource name must contain this
+     * request extension unless the resource name is prefixed with the
+     * <code>locationPrefix</code> and the request extension is
+     * <code>html</code>.</li>
+     * <li>Besides the location prefix and method name, just a single extension
+     * is allowed.</li>
+     * </ul>
+     * 
+     * @param resource The <code>resource</code> whose name is to be checked
+     * @param locationPrefix The prefix to be matched by resources.
+     * @param optionalLocationPrefix Whether the resources must start with the
+     *            <code>locationPrefix</code> or not. If this is
+     *            <code>true</code>, the resources name need not start with
+     *            the prefix.
+     * @return The method/prefix weight to assign a {@link WeightedResource}
+     *         based on the given <code>resource</code> or
+     *         {@link #WEIGHT_NO_MATCH} if the resource name does not meet above
+     *         listed requirements.
+     */
+    protected int calculatePrefixMethodWeight(final Resource resource,
+            final String locationPrefix, final boolean optionalLocationPrefix) {
 
         // split the remaing name to ease further checks
         String resPath = resource.getPath();
@@ -124,17 +207,17 @@
 
         // flag whether we require the request extension in the script name
         // to begin with, this is only required for non-html requests
-        boolean requireExtension = !isGetHtmlRequest;
+        boolean requireExtension = !isHtmlRequest;
+
+        int methodExtensionWeight = WeightedResource.WEIGHT_NONE;
 
-        int methodExtensionWeight = LocationResource.WEIGHT_NONE;
-        
         // expect locationPrefix being the last part of the selector
         if (i >= parts.length || !locationPrefix.equals(parts[i])) {
             if (!optionalLocationPrefix) {
                 log.debug(
                     "createLocationResource: Ignoring Resource {}: Name does not start with {}",
                     resource, locationPrefix);
-                return null;
+                return WEIGHT_NO_MATCH;
             }
 
             log.debug(
@@ -146,31 +229,29 @@
         } else {
             // increment counter, we have the locationPrefix
             i++;
-            methodExtensionWeight += LocationResource.WEIGHT_PREFIX;
+            methodExtensionWeight += WeightedResource.WEIGHT_PREFIX;
         }
 
         // next may be extension name
-        boolean hasExtension = false;
         if (extension != null) {
             if (i < parts.length && extension.equals(parts[i])) {
                 i++;
-                methodExtensionWeight += LocationResource.WEIGHT_EXTENSION;
+                methodExtensionWeight += WeightedResource.WEIGHT_EXTENSION;
             } else if (requireExtension) {
                 log.debug(
                     "createLocationResource: Ignoring Resource {} because request extension {} is missing in the name",
                     resource, extension);
-                return null;
+                return WEIGHT_NO_MATCH;
             }
         }
 
         // next would be script extension
         if ((i + 1) != parts.length) {
             // more than one more part, we expect just a single one or none
-            return null;
+            return WEIGHT_NO_MATCH;
         }
 
-        return new LocationResource(ordinal, resource, numSelectors,
-            methodExtensionWeight);
+        return methodExtensionWeight;
     }
 
 }

Copied: incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/WeightedResource.java (from r654076, incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/LocationResource.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/WeightedResource.java?p2=incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/WeightedResource.java&p1=incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/LocationResource.java&r1=654076&r2=654438&rev=654438&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/LocationResource.java (original)
+++ incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/helper/WeightedResource.java Thu May  8 00:34:07 2008
@@ -21,61 +21,97 @@
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceWrapper;
 
-public class LocationResource extends ResourceWrapper implements Comparable<LocationResource> {
-
+/**
+ * The <code>WeightedResource</code> is a <code>Resource</code> which is
+ * attributed with weight values to make it a <code>Comparable</code> to be
+ * used to build the result collection returned by
+ * {@link ResourceCollector#getServlets(Resource)}.
+ * <p>
+ * The order amongst <code>WeightedResource</code> instances is defined as
+ * follows and implemented in the {@link #compareTo(WeightedResource)} method:
+ * <ol>
+ * <li>The instance with more matching selectors ({@link #getNumSelectors()})
+ * is ordered before the instance with less matching selectors.</li>
+ * <li>If the matching selectors are equal, the instance with the higher
+ * method/prefix weight ({@link #getMethodPrefixWeight()}) is order before the
+ * instance with a lower method/prefix weight.</li>
+ * <li>Finally, if also the method/prefix weights are equal, the instance with
+ * the lower ordinal number ({@link #getOrdinal()} is ordered before the
+ * instance with the higher ordinal number.</li>
+ * </ol>
+ */
+final class WeightedResource extends ResourceWrapper implements
+        Comparable<WeightedResource> {
+
+    /**
+     * Weight value assigned to an instance just bearing request method name.
+     */
     static final int WEIGHT_NONE = 0;
 
+    /**
+     * Weight value assigned to an instance if the the resource name neither
+     * contains the parent resource name as a prefix, nor the request method
+     * name nor the request extension.
+     */
     static final int WEIGHT_LAST_RESSORT = -1;
 
+    /**
+     * Weight value added to method/prefix weight if the resource name contains
+     * the the name of the parent resource as its prefix.
+     */
     static final int WEIGHT_PREFIX = 1;
 
+    /**
+     * Weight value added to method/prefix weight if the resource name contains
+     * the request extension.
+     */
     static final int WEIGHT_EXTENSION = 2;
 
     private final int ordinal;
 
     private final int numSelectors;
 
-    private int methodPrefixWeight;
+    private final int methodPrefixWeight;
 
-    public LocationResource(int ordinal, Resource resource, int numSelectors,
+    WeightedResource(int ordinal, Resource resource, int numSelectors,
             int methodPrefixWeight) {
         super(resource);
-        
+
         this.ordinal = ordinal;
         this.numSelectors = numSelectors;
         this.methodPrefixWeight = methodPrefixWeight;
     }
 
-    public int getOrdinal() {
+    final public int getOrdinal() {
         return ordinal;
     }
 
-    public int getNumSelectors() {
+    final public int getNumSelectors() {
         return numSelectors;
     }
 
-    public int getMethodPrefixWeight() {
+    final public int getMethodPrefixWeight() {
         return methodPrefixWeight;
     }
 
     @Override
-    public int hashCode() {
+    final public int hashCode() {
         return ordinal;
     }
 
     @Override
-    public boolean equals(Object obj) {
+    final public boolean equals(Object obj) {
         return obj == this;
     }
 
     @Override
-    public String toString() {
+    final public String toString() {
         return getClass().getSimpleName() + "[" + getOrdinal() + "]: "
             + getResource() + ", #selectors=" + getNumSelectors()
             + ", methodPrefixWeight=" + getMethodPrefixWeight();
     }
 
-    public int compareTo(LocationResource o) {
+    final public int compareTo(WeightedResource o) {
         if (equals(o)) {
             return 0;
         }

Copied: incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/HelperTestBase.java (from r654076, incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationTestBase.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/HelperTestBase.java?p2=incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/HelperTestBase.java&p1=incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationTestBase.java&r1=654076&r2=654438&rev=654438&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationTestBase.java (original)
+++ incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/HelperTestBase.java Thu May  8 00:34:07 2008
@@ -25,7 +25,7 @@
 import org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest;
 import org.apache.sling.jcr.resource.JcrResourceUtil;
 
-public abstract class LocationTestBase extends TestCase {
+public abstract class HelperTestBase extends TestCase {
 
     protected MockResourceResolver resourceResolver;
 

Modified: incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationIteratorTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationIteratorTest.java?rev=654438&r1=654437&r2=654438&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationIteratorTest.java (original)
+++ incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationIteratorTest.java Thu May  8 00:34:07 2008
@@ -22,141 +22,147 @@
 
 import org.apache.sling.jcr.resource.JcrResourceUtil;
 
-public class LocationIteratorTest extends LocationTestBase {
+public class LocationIteratorTest extends HelperTestBase {
 
     public void testSearchPathEmpty() {
         // expect path gets { "/" }
         resourceResolver.setSearchPath((String[]) null);
-        
-        LocationIterator li = new LocationIterator(request);
-        
+
+        LocationIterator li = new LocationIterator(request.getResource(),
+            DEFAULT_SERVLET_NAME);
+
         // 1. /foo/bar
         assertTrue(li.hasNext());
         assertEquals("/" + resourceTypePath, li.next());
-        
+
         // 2. /sling/servlet/default
         assertTrue(li.hasNext());
         assertEquals("/" + DEFAULT_SERVLET_NAME, li.next());
-        
+
         // 3. finished
         assertFalse(li.hasNext());
     }
-    
+
     public void testSearchPath1Element() {
         String root0 = "/apps";
         resourceResolver.setSearchPath(root0);
-        
-        LocationIterator li = new LocationIterator(request);
-        
+
+        LocationIterator li = new LocationIterator(request.getResource(),
+            DEFAULT_SERVLET_NAME);
+
         // 1. /apps/foo/bar
         assertTrue(li.hasNext());
         assertEquals(root0 + "/" + resourceTypePath, li.next());
-        
+
         // 2. /apps/sling/servlet/default
         assertTrue(li.hasNext());
         assertEquals(root0 + "/" + DEFAULT_SERVLET_NAME, li.next());
-        
+
         // 3. finished
         assertFalse(li.hasNext());
     }
-    
+
     public void testSearchPath2Elements() {
         String root0 = "/apps";
         String root1 = "/libs";
         resourceResolver.setSearchPath(root0, root1);
-        
-        LocationIterator li = new LocationIterator(request);
-        
+
+        LocationIterator li = new LocationIterator(request.getResource(),
+            DEFAULT_SERVLET_NAME);
+
         // 1. /apps/foo/bar
         assertTrue(li.hasNext());
         assertEquals(root0 + "/" + resourceTypePath, li.next());
-        
+
         // 2. /libs/foo/bar
         assertTrue(li.hasNext());
         assertEquals(root1 + "/" + resourceTypePath, li.next());
-        
+
         // 3. /apps/sling/servlet/default
         assertTrue(li.hasNext());
         assertEquals(root0 + "/" + DEFAULT_SERVLET_NAME, li.next());
-        
+
         // 4. /libs/sling/servlet/default
         assertTrue(li.hasNext());
         assertEquals(root1 + "/" + DEFAULT_SERVLET_NAME, li.next());
-        
+
         // 5. finished
         assertFalse(li.hasNext());
     }
-    
+
     public void testSearchPathEmptyAbsoluteType() {
         // expect path gets { "/" }
         resourceResolver.setSearchPath((String[]) null);
-        
+
         // absolute resource type
         resourceType = "/foo/bar";
         resourceTypePath = JcrResourceUtil.resourceTypeToPath(resourceType);
         resource.setResourceType(resourceType);
-        
-        LocationIterator li = new LocationIterator(request);
-        
+
+        LocationIterator li = new LocationIterator(request.getResource(),
+            DEFAULT_SERVLET_NAME);
+
         // 1. /foo/bar
         assertTrue(li.hasNext());
         assertEquals(resourceTypePath, li.next());
-        
+
         // 2. /sling/servlet/default
         assertTrue(li.hasNext());
         assertEquals("/" + DEFAULT_SERVLET_NAME, li.next());
-        
+
         // 3. finished
         assertFalse(li.hasNext());
     }
-    
+
     public void testSearchPath1ElementAbsoluteType() {
         String root0 = "/apps";
         resourceResolver.setSearchPath(root0);
-        
+
         // absolute resource type
         resourceType = "/foo/bar";
         resourceTypePath = JcrResourceUtil.resourceTypeToPath(resourceType);
         resource.setResourceType(resourceType);
-        
-        LocationIterator li = new LocationIterator(request);
-        
+
+        LocationIterator li = new LocationIterator(request.getResource(),
+            DEFAULT_SERVLET_NAME);
+
         // 1. /foo/bar
         assertTrue(li.hasNext());
         assertEquals(resourceTypePath, li.next());
-        
+
         // 2. /apps/sling/servlet/default
         assertTrue(li.hasNext());
         assertEquals(root0 + "/" + DEFAULT_SERVLET_NAME, li.next());
-        
+
         // 3. finished
         assertFalse(li.hasNext());
     }
-    
+
     public void testSearchPath2ElementsAbsoluteType() {
         String root0 = "/apps";
         String root1 = "/libs";
         resourceResolver.setSearchPath(root0, root1);
-        
+
         // absolute resource type
         resourceType = "/foo/bar";
         resourceTypePath = JcrResourceUtil.resourceTypeToPath(resourceType);
         resource.setResourceType(resourceType);
-        
-        LocationIterator li = new LocationIterator(request);
-        
+
+        LocationIterator li = new LocationIterator(request.getResource(),
+            DEFAULT_SERVLET_NAME);
+
         // 1. /foo/bar
         assertTrue(li.hasNext());
         assertEquals(resourceTypePath, li.next());
-        
+
         // 2. /apps/sling/servlet/default
         assertTrue(li.hasNext());
         assertEquals(root0 + "/" + DEFAULT_SERVLET_NAME, li.next());
-        
+
         // 3. /libs/sling/servlet/default
         assertTrue(li.hasNext());
         assertEquals(root1 + "/" + DEFAULT_SERVLET_NAME, li.next());
-        
+
         // 4. finished
         assertFalse(li.hasNext());
     }
@@ -169,13 +175,14 @@
         resourceSuperType = "foo:superBar";
         resourceSuperTypePath = JcrResourceUtil.resourceTypeToPath(resourceSuperType);
         resource.setResourceSuperType(resourceSuperType);
-        
-        LocationIterator li = new LocationIterator(request);
+
+        LocationIterator li = new LocationIterator(request.getResource(),
+            DEFAULT_SERVLET_NAME);
 
         // 1. /foo/bar
         assertTrue(li.hasNext());
         assertEquals("/" + resourceTypePath, li.next());
-        
+
         // 2. /foo/superBar
         assertTrue(li.hasNext());
         assertEquals("/" + resourceSuperTypePath, li.next());
@@ -196,8 +203,9 @@
         resourceSuperType = "foo:superBar";
         resourceSuperTypePath = JcrResourceUtil.resourceTypeToPath(resourceSuperType);
         resource.setResourceSuperType(resourceSuperType);
-        
-        LocationIterator li = new LocationIterator(request);
+
+        LocationIterator li = new LocationIterator(request.getResource(),
+            DEFAULT_SERVLET_NAME);
 
         // 1. /apps/foo/bar
         assertTrue(li.hasNext());
@@ -224,8 +232,9 @@
         resourceSuperType = "foo:superBar";
         resourceSuperTypePath = JcrResourceUtil.resourceTypeToPath(resourceSuperType);
         resource.setResourceSuperType(resourceSuperType);
-        
-        LocationIterator li = new LocationIterator(request);
+
+        LocationIterator li = new LocationIterator(request.getResource(),
+            DEFAULT_SERVLET_NAME);
 
         // 1. /apps/foo/bar
         assertTrue(li.hasNext());
@@ -268,8 +277,9 @@
         resourceSuperType = "foo:superBar";
         resourceSuperTypePath = JcrResourceUtil.resourceTypeToPath(resourceSuperType);
         resource.setResourceSuperType(resourceSuperType);
-        
-        LocationIterator li = new LocationIterator(request);
+
+        LocationIterator li = new LocationIterator(request.getResource(),
+            DEFAULT_SERVLET_NAME);
 
         // 1. /foo/bar
         assertTrue(li.hasNext());
@@ -300,8 +310,9 @@
         resourceSuperType = "foo:superBar";
         resourceSuperTypePath = JcrResourceUtil.resourceTypeToPath(resourceSuperType);
         resource.setResourceSuperType(resourceSuperType);
-        
-        LocationIterator li = new LocationIterator(request);
+
+        LocationIterator li = new LocationIterator(request.getResource(),
+            DEFAULT_SERVLET_NAME);
 
         // 1. /foo/bar
         assertTrue(li.hasNext());
@@ -333,8 +344,9 @@
         resourceSuperType = "foo:superBar";
         resourceSuperTypePath = JcrResourceUtil.resourceTypeToPath(resourceSuperType);
         resource.setResourceSuperType(resourceSuperType);
-        
-        LocationIterator li = new LocationIterator(request);
+
+        LocationIterator li = new LocationIterator(request.getResource(),
+            DEFAULT_SERVLET_NAME);
 
         // 1. /foo/bar
         assertTrue(li.hasNext());

Copied: incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/ResourceCollectorGetCalculatePrefixWeightTest.java (from r654076, incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationUtilCreateLocationResourceTest.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/ResourceCollectorGetCalculatePrefixWeightTest.java?p2=incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/ResourceCollectorGetCalculatePrefixWeightTest.java&p1=incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationUtilCreateLocationResourceTest.java&r1=654076&r2=654438&rev=654438&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationUtilCreateLocationResourceTest.java (original)
+++ incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/ResourceCollectorGetCalculatePrefixWeightTest.java Thu May  8 00:34:07 2008
@@ -25,7 +25,7 @@
 import org.apache.sling.commons.testing.sling.MockResource;
 import org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest;
 
-public class LocationUtilCreateLocationResourceTest extends TestCase {
+public class ResourceCollectorGetCalculatePrefixWeightTest extends TestCase {
 
     private static final String LOCATION_NAME = "sample";
 
@@ -40,12 +40,12 @@
         final MockResource res0 = new MockResource(null, SCRIPT_BASE, "foo:bar");
 
         // this resource has no extension, we require one
-        final LocationResource lr0 = createLocationResource(res0, "GET", null,
+        final WeightedResource lr0 = createLocationResource(res0, "GET", null,
             "html");
         assertNull(lr0);
 
         // this resource has no extension, we require one
-        final LocationResource lr1 = createLocationResource(res0, "GET", null,
+        final WeightedResource lr1 = createLocationResource(res0, "GET", null,
             "foo");
         assertNull(lr1);
     }
@@ -56,14 +56,14 @@
             "foo:bar");
 
         // allow simple name for GET and html
-        final LocationResource lr10 = createLocationResource(res1, "GET", null,
+        final WeightedResource lr10 = createLocationResource(res1, "GET", null,
             "html");
         assertNotNull(lr10);
         assertEquals(0, lr10.getNumSelectors());
-        assertEquals(LocationResource.WEIGHT_PREFIX, lr10.getMethodPrefixWeight());
+        assertEquals(WeightedResource.WEIGHT_PREFIX, lr10.getMethodPrefixWeight());
 
         // this resource has no extension, we require one
-        final LocationResource lr11 = createLocationResource(res1, "GET", null,
+        final WeightedResource lr11 = createLocationResource(res1, "GET", null,
             "foo");
         assertNull(lr11);
     }
@@ -73,14 +73,14 @@
             + ".html.esp", "foo:bar");
 
         // allow simple name for GET and html
-        final LocationResource lr20 = createLocationResource(res2, "GET", null,
+        final WeightedResource lr20 = createLocationResource(res2, "GET", null,
             "html");
         assertNotNull(lr20);
         assertEquals(0, lr20.getNumSelectors());
-        assertEquals(LocationResource.WEIGHT_PREFIX+LocationResource.WEIGHT_EXTENSION, lr20.getMethodPrefixWeight());
+        assertEquals(WeightedResource.WEIGHT_PREFIX+WeightedResource.WEIGHT_EXTENSION, lr20.getMethodPrefixWeight());
 
         // script does not match for .foo request
-        final LocationResource lr21 = createLocationResource(res2, "GET", null,
+        final WeightedResource lr21 = createLocationResource(res2, "GET", null,
             "foo");
         assertNull(lr21);
     }
@@ -90,16 +90,16 @@
             + ".foo.esp", "foo:bar");
 
         // script does not match for .html request
-        final LocationResource lr30 = createLocationResource(res3, "GET", null,
+        final WeightedResource lr30 = createLocationResource(res3, "GET", null,
             "html");
         assertNull(lr30);
 
         // allow simple name for GET and foo
-        final LocationResource lr31 = createLocationResource(res3, "GET", null,
+        final WeightedResource lr31 = createLocationResource(res3, "GET", null,
             "foo");
         assertNotNull(lr31);
         assertEquals(0, lr31.getNumSelectors());
-        assertEquals(LocationResource.WEIGHT_PREFIX+LocationResource.WEIGHT_EXTENSION, lr31.getMethodPrefixWeight());
+        assertEquals(WeightedResource.WEIGHT_PREFIX+WeightedResource.WEIGHT_EXTENSION, lr31.getMethodPrefixWeight());
     }
 
     public void testCreateLocationResourceGETGET() {
@@ -108,13 +108,13 @@
             "foo:bar");
 
         // side-effect: .GET is assumed to be the script extension
-        final LocationResource lr0 = createLocationResource(res0, "GET", null,
+        final WeightedResource lr0 = createLocationResource(res0, "GET", null,
             "html");
         assertNotNull(lr0);
-        assertEquals(LocationResource.WEIGHT_PREFIX, lr0.getMethodPrefixWeight());
+        assertEquals(WeightedResource.WEIGHT_PREFIX, lr0.getMethodPrefixWeight());
 
         // this resource has no extension, we require one
-        final LocationResource lr1 = createLocationResource(res0, "GET", null,
+        final WeightedResource lr1 = createLocationResource(res0, "GET", null,
             "foo");
         assertNull(lr1);
     }
@@ -124,17 +124,17 @@
             + ".GET.esp", "foo:bar");
 
         // GET would be the extension and is not allowed like this
-        final LocationResource lr10 = createLocationResource(res1, "GET", null,
+        final WeightedResource lr10 = createLocationResource(res1, "GET", null,
             "html");
         assertNull(lr10);
 
         // GET would be the extension and is not allowed like this
-        final LocationResource lr11 = createLocationResource(res1, "GET", null,
+        final WeightedResource lr11 = createLocationResource(res1, "GET", null,
             "foo");
         assertNull(lr11);
     }
 
-    private LocationResource createLocationResource(
+    private WeightedResource createLocationResource(
             final Resource scriptResource, final String method,
             final String selectorString, final String extension) {
 
@@ -145,9 +145,12 @@
                 return method;
             }
         };
-        final LocationUtilGet locationUtil = new LocationUtilGet(request);
-        return locationUtil.createLocationResource(0, LOCATION_PREFIX, true,
-            scriptResource, 0);
-
+        final ResourceCollectorGet locationUtil = new ResourceCollectorGet(request);
+        final int methodPrefixWeight = locationUtil.calculatePrefixMethodWeight(scriptResource, LOCATION_PREFIX, true);
+        if (methodPrefixWeight != ResourceCollectorGet.WEIGHT_NO_MATCH) {
+            return new WeightedResource(0, scriptResource, 0, methodPrefixWeight);
+        }
+        
+        return null;
     }
 }

Copied: incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/ResourceCollectorGetServletsTest.java (from r654076, incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationUtilGetServletsTest.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/ResourceCollectorGetServletsTest.java?p2=incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/ResourceCollectorGetServletsTest.java&p1=incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationUtilGetServletsTest.java&r1=654076&r2=654438&rev=654438&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationUtilGetServletsTest.java (original)
+++ incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/ResourceCollectorGetServletsTest.java Thu May  8 00:34:07 2008
@@ -23,10 +23,11 @@
 import java.util.Iterator;
 import java.util.Map;
 
+import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.commons.testing.sling.MockResource;
 
-public class LocationUtilGetServletsTest extends LocationTestBase {
+public class ResourceCollectorGetServletsTest extends HelperTestBase {
 
     private String label;
     
@@ -144,19 +145,19 @@
             pathMap.put(name, path);
         }
         
-        LocationUtil lu = LocationUtil.create(request);
-        Collection<LocationResource> res = lu.getScripts(request);
-        Iterator<LocationResource> rIter = res.iterator();
+        ResourceCollector lu = ResourceCollector.create(request);
+        Collection<Resource> res = lu.getServlets(request.getResource());
+        Iterator<Resource> rIter = res.iterator();
 
         for (int index : indices) {
             assertTrue(rIter.hasNext());
 
-            LocationResource lr = rIter.next();
+            Resource lr = rIter.next();
 
             String name = names[index];
             String path = pathMap.get(name);
 
-            assertEquals(path, lr.getResource().getPath());
+            assertEquals(path, lr.getPath());
         }
 
         assertFalse(rIter.hasNext());

Modified: incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/ScriptSelectionTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/ScriptSelectionTest.java?rev=654438&r1=654437&r2=654438&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/ScriptSelectionTest.java (original)
+++ incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/ScriptSelectionTest.java Thu May  8 00:34:07 2008
@@ -20,13 +20,14 @@
 
 import java.util.Collection;
 
+import org.apache.sling.api.resource.Resource;
 import org.apache.sling.commons.testing.sling.MockResource;
 import org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest;
 
 /** Various tests that explain and demonstrate how scripts are 
  *  selected
  */
-public class ScriptSelectionTest extends LocationTestBase {
+public class ScriptSelectionTest extends HelperTestBase {
     
     /** Test set of available scripts */
     protected final String [] SET_A = {
@@ -40,7 +41,7 @@
     
     /** Given a list of available scripts and the request method, selectors 
      *  and extension, check that the expected script is selected.
-     *  The resource type is foo:bar, set by LocationTestBase
+     *  The resource type is foo:bar, set by HelperTestBase
      */ 
     protected void assertScript(String method, String selectors, String extension,
             String [] scripts, String expectedScript) 
@@ -51,17 +52,17 @@
             resourceResolver.addResource(r);            
         }
         
-        // Create mock request and get scripts from LocationUtil
+        // Create mock request and get scripts from ResourceCollector
         final MockSlingHttpServletRequest req = makeRequest(method, selectors, extension);
-        final LocationUtil u = LocationUtil.create(req);
-        final Collection<LocationResource> s = u.getScripts(req);
+        final ResourceCollector u = ResourceCollector.create(req);
+        final Collection<Resource> s = u.getServlets(req.getResource());
         
         if(expectedScript == null) {
             assertFalse("No script must be found", s.iterator().hasNext());
         } else {
             // Verify that the expected script is the first in the list of candidates
             assertTrue("A script must be found", s.iterator().hasNext());
-            final String scriptPath = s.iterator().next().getResource().getPath();
+            final String scriptPath = s.iterator().next().getPath();
             assertEquals("First script is the expected one", expectedScript, scriptPath);
         }
     }

Copied: incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/WeightedResourceTest.java (from r654076, incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationResourceTest.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/WeightedResourceTest.java?p2=incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/WeightedResourceTest.java&p1=incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationResourceTest.java&r1=654076&r2=654438&rev=654438&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/LocationResourceTest.java (original)
+++ incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/helper/WeightedResourceTest.java Thu May  8 00:34:07 2008
@@ -20,11 +20,11 @@
 
 import junit.framework.TestCase;
 
-public class LocationResourceTest extends TestCase {
+public class WeightedResourceTest extends TestCase {
 
     public void testEquality() {
-        LocationResource lr1 = new LocationResource(0, null, 0, LocationResource.WEIGHT_NONE);
-        LocationResource lr2 = new LocationResource(0, null, 0, LocationResource.WEIGHT_NONE);
+        WeightedResource lr1 = new WeightedResource(0, null, 0, WeightedResource.WEIGHT_NONE);
+        WeightedResource lr2 = new WeightedResource(0, null, 0, WeightedResource.WEIGHT_NONE);
         
         // expect same objects to be equal
         assertTrue(lr1.equals(lr1));
@@ -37,8 +37,8 @@
     }
     
     public void testCompareToSelectors() {
-        LocationResource lr1 = new LocationResource(0, null, 1, LocationResource.WEIGHT_NONE);
-        LocationResource lr2 = new LocationResource(1, null, 0, LocationResource.WEIGHT_NONE);
+        WeightedResource lr1 = new WeightedResource(0, null, 1, WeightedResource.WEIGHT_NONE);
+        WeightedResource lr2 = new WeightedResource(1, null, 0, WeightedResource.WEIGHT_NONE);
         
         // expect the same objects to compare equal
         assertEquals(0, lr1.compareTo(lr1));
@@ -49,8 +49,8 @@
     }
     
     public void testCompareToPrefix() {
-        LocationResource lr1 = new LocationResource(0, null, 2, LocationResource.WEIGHT_PREFIX);
-        LocationResource lr2 = new LocationResource(1, null, 2, LocationResource.WEIGHT_NONE);
+        WeightedResource lr1 = new WeightedResource(0, null, 2, WeightedResource.WEIGHT_PREFIX);
+        WeightedResource lr2 = new WeightedResource(1, null, 2, WeightedResource.WEIGHT_NONE);
         
         // expect the same objects to compare equal
         assertEquals(0, lr1.compareTo(lr1));
@@ -61,8 +61,8 @@
     }
     
     public void testCompareToExtension() {
-        LocationResource lr1 = new LocationResource(0, null, 2, LocationResource.WEIGHT_EXTENSION);
-        LocationResource lr2 = new LocationResource(1, null, 2, LocationResource.WEIGHT_NONE);
+        WeightedResource lr1 = new WeightedResource(0, null, 2, WeightedResource.WEIGHT_EXTENSION);
+        WeightedResource lr2 = new WeightedResource(1, null, 2, WeightedResource.WEIGHT_NONE);
         
         // expect the same objects to compare equal
         assertEquals(0, lr1.compareTo(lr1));
@@ -73,8 +73,8 @@
     }
  
     public void testCompareToOrdinal() {
-        LocationResource lr1 = new LocationResource(0, null, 0, LocationResource.WEIGHT_NONE);
-        LocationResource lr2 = new LocationResource(1, null, 0, LocationResource.WEIGHT_NONE);
+        WeightedResource lr1 = new WeightedResource(0, null, 0, WeightedResource.WEIGHT_NONE);
+        WeightedResource lr2 = new WeightedResource(1, null, 0, WeightedResource.WEIGHT_NONE);
         
         // expect the same objects to compare equal
         assertEquals(0, lr1.compareTo(lr1));



Mime
View raw message