incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1479945 - in /sling/trunk/bundles/scripting/jsp-taglib/src: main/java/org/apache/sling/scripting/jsp/taglib/ main/resources/META-INF/ test/java/org/apache/sling/scripting/jsp/taglib/
Date Tue, 07 May 2013 15:33:36 GMT
Author: dklco
Date: Tue May  7 15:33:36 2013
New Revision: 1479945

URL: http://svn.apache.org/r1479945
Log:
Updated to add the new tag and functions for finding resources, adding the ability to set a base resource in get resource adding some additional functions and adding further tests

Added:
    sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/FindResourcesTag.java
    sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestFindResourceTag.java
Modified:
    sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/GetResourceTag.java
    sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/SlingFunctions.java
    sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/taglib13.tld
    sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestGetResourceTag.java
    sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestSlingFunctions.java

Added: sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/FindResourcesTag.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/FindResourcesTag.java?rev=1479945&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/FindResourcesTag.java (added)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/FindResourcesTag.java Tue May  7 15:33:36 2013
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.scripting.jsp.taglib;
+
+import java.util.Iterator;
+
+import javax.servlet.jsp.tagext.TagSupport;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.scripting.SlingBindings;
+import org.apache.sling.api.scripting.SlingScriptHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tag for searching for resources using the given query formulated in the given
+ * language.
+ */
+public class FindResourcesTag extends TagSupport {
+
+	/** The Constant log. */
+	private static final Logger log = LoggerFactory
+			.getLogger(FindResourcesTag.class);
+	
+	/** The Constant serialVersionUID. */
+	private static final long serialVersionUID = 8717969268407440925L;
+	
+	/** The query. */
+	private String query;
+	
+	/** The language. */
+	private String language;
+	
+	/** The var. */
+	private String var;
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
+	 */
+	@Override
+	public int doEndTag() {
+		log.trace("doEndTag");
+
+		log.debug("Finding resources using query: {} of language {}", query,
+				language);
+
+		ResourceResolver resolver = getResourceResolver();
+		final Iterator<Resource> resources = resolver.findResources(query,
+				language);
+		
+		log.debug("Saving resources to variable {}", var);
+		pageContext.setAttribute(var, resources);
+
+		return EVAL_PAGE;
+	}
+
+	/**
+	 * Gets the language.
+	 *
+	 * @return the language
+	 */
+	public String getLanguage() {
+		return language;
+	}
+
+	/**
+	 * Gets the query.
+	 *
+	 * @return the query
+	 */
+	public String getQuery() {
+		return query;
+	}
+
+	/**
+	 * Method for retrieving the ResourceResolver from the page context.
+	 * 
+	 * @return the resource resolver
+	 */
+	protected ResourceResolver getResourceResolver() {
+		final SlingBindings bindings = (SlingBindings) pageContext.getRequest()
+				.getAttribute(SlingBindings.class.getName());
+		final SlingScriptHelper scriptHelper = bindings.getSling();
+		final ResourceResolver resolver = scriptHelper.getRequest()
+				.getResourceResolver();
+		return resolver;
+	}
+
+	/**
+	 * Gets the variable name to which to save the list of children.
+	 * 
+	 * @return the variable name
+	 */
+	public String getVar() {
+		return var;
+	}
+
+	/**
+	 * Sets the language.
+	 *
+	 * @param language the new language
+	 */
+	public void setLanguage(String language) {
+		this.language = language;
+	}
+
+	/**
+	 * Sets the query.
+	 *
+	 * @param query the new query
+	 */
+	public void setQuery(String query) {
+		this.query = query;
+	}
+
+	/**
+	 * Sets the variable name to which to save the list of children.
+	 * 
+	 * @param var
+	 *            the variable name
+	 */
+	public void setVar(String var) {
+		this.var = var;
+	}
+}

Modified: sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/GetResourceTag.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/GetResourceTag.java?rev=1479945&r1=1479944&r2=1479945&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/GetResourceTag.java (original)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/GetResourceTag.java Tue May  7 15:33:36 2013
@@ -26,37 +26,79 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Tag for retrieving a resource based a path.
+ * Tag for retrieving resources based on either an absolute path or a relative
+ * path and a base resource.
  */
 public class GetResourceTag extends TagSupport {
 
+	/** The Constant log. */
 	private static final Logger log = LoggerFactory
 			.getLogger(GetResourceTag.class);
+
+	/** The Constant serialVersionUID. */
 	private static final long serialVersionUID = -1945089681840552408L;
+
+	/** The base. */
+	private Resource base;
+
+	/** The path. */
 	private String path;
+
+	/** The var. */
 	private String var;
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
-	 */
 	@Override
 	public int doEndTag() {
 		log.trace("doEndTag");
 
-		log.debug("Retrieving resource at path: " + path);
-
 		ResourceResolver resolver = getResourceResolver();
-		final Resource resource = resolver.getResource(path);
+		Resource resource = null;
+		if (path.startsWith("/")) {
+			log.debug("Retrieving resource at absolute path: {}", path);
+			resource = resolver.getResource(path);
+		} else {
+			if (base != null) {
+				log.debug(
+						"Retrieving resource at relative path: {} to resource {}",
+						path, base.getPath());
+				resource = resolver.getResource(base, path);
+			} else {
+				log.warn(
+						"Unable to retrieve resource at relative path {}, no base resource specified",
+						path);
+			}
+		}
 
-		log.debug("Saving " + resource + " to variable " + var);
+		log.debug("Saving {} to variable {}", resource, var);
 		pageContext.setAttribute(var, resource);
 
 		return EVAL_PAGE;
 	}
 
 	/**
+	 * Gets the base resource.
+	 * 
+	 * @return the base resource
+	 */
+	public Resource getBase() {
+		return base;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
+	 */
+	/**
+	 * Get the path of the resource to retrieve.
+	 * 
+	 * @return the path
+	 */
+	public String getPath() {
+		return path;
+	}
+
+	/**
 	 * Method for retrieving the ResourceResolver from the page context.
 	 * 
 	 * @return the resource resolver
@@ -71,21 +113,22 @@ public class GetResourceTag extends TagS
 	}
 
 	/**
-	 * Get the path of the resource to retrieve.
+	 * Gets the variable name to which to save the list of children.
 	 * 
-	 * @return the path
+	 * @return the variable name
 	 */
-	public String getPath() {
-		return path;
+	public String getVar() {
+		return var;
 	}
 
 	/**
-	 * Gets the variable name to which to save the list of children.
+	 * Sets the base resource.
 	 * 
-	 * @return the variable name
+	 * @param base
+	 *            the new base resource
 	 */
-	public String getVar() {
-		return var;
+	public void setBase(Resource base) {
+		this.base = base;
 	}
 
 	/**

Modified: sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/SlingFunctions.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/SlingFunctions.java?rev=1479945&r1=1479944&r2=1479945&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/SlingFunctions.java (original)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/SlingFunctions.java Tue May  7 15:33:36 2013
@@ -18,6 +18,7 @@ package org.apache.sling.scripting.jsp.t
 
 import java.util.Iterator;
 
+import org.apache.sling.api.adapter.Adaptable;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.slf4j.Logger;
@@ -35,15 +36,112 @@ public class SlingFunctions {
 			.getLogger(SlingFunctions.class);
 
 	/**
+	 * Adapt the adaptable to the adapter class.
+	 * 
+	 * @param adaptable
+	 *            the adaptable instance
+	 * @param adapter
+	 *            the class to which to adapt the adaptable
+	 * @return the adapted class instance
+	 */
+	public static Object adaptTo(Adaptable adaptable, String adapter)
+			throws ClassNotFoundException {
+		log.trace("adaptTo");
+		Object adapted = null;
+
+		if (adaptable != null) {
+			log.debug("Adapting {} to class {}", adaptable, adapter);
+			try {
+				Class<?> adapterClass = loadClass(adapter);
+				adapted = adaptable.adaptTo(adapterClass);
+			} catch (ClassNotFoundException e) {
+				log.error("Could not load class " + adapter, e);
+			}
+		} else {
+			log.warn("Null adaptable specified");
+		}
+		return adapted;
+	}
+
+	/**
+	 * Searches for resources using the given query formulated in the given
+	 * language.
+	 * 
+	 * @param resourceResolver
+	 * @param query
+	 *            The query string to use to find the resources.
+	 * @param language
+	 *            The language in which the query is formulated.
+	 * @return An Iterator of Resource objects matching the query.
+	 */
+	public static Iterator<Resource> findResources(
+			ResourceResolver resourceResolver, String query, String language) {
+		log.trace("findResources");
+
+		Iterator<Resource> resources = null;
+		if (resourceResolver != null) {
+			log.debug("Finding resources with query {} of type {}", query,
+					language);
+			resources = resourceResolver.findResources(query, language);
+		} else {
+			log.warn("Null resolver specified");
+		}
+		return resources;
+	}
+
+	/**
+	 * Loads the Class for the name from the current thread's classload.
+	 * 
+	 * @param className
+	 *            The name of the class to load
+	 * @return the class
+	 * @throws ClassNotFoundException
+	 *             a class with the specified name could not be found
+	 */
+	private static Class<?> loadClass(String className)
+			throws ClassNotFoundException {
+		return Thread.currentThread().getContextClassLoader()
+				.loadClass(className);
+	}
+
+	/**
+	 * Gets the resource at the relative path to the provided resource.
+	 * 
+	 * @param base
+	 *            the resource relative to which to find the path
+	 * @param path
+	 *            the relative path at which to find the resource
+	 * @return the resource
+	 */
+	public static Resource getRelativeResource(Resource base, String path) {
+		log.trace("getRelativeResource");
+
+		Resource relative = null;
+		if (base != null) {
+			log.debug("Getting relative resource of {} at path {}",
+					base.getPath(), path);
+			relative = base.getResourceResolver().getResource(base, path);
+		} else {
+			log.warn("Null base resource specified");
+		}
+
+		return relative;
+	}
+
+	/**
 	 * Method allow for the retrieval of resources.
 	 * 
 	 * @param resolver
 	 *            the current resource resolver
 	 * @param path
 	 *            the path of the resource to retrieve
-	 * @return
+	 * @return the resource at the path or null
 	 */
-	public static final Resource getResource(ResourceResolver resolver, String path) {
+	public static final Resource getResource(ResourceResolver resolver,
+			String path) {
+		log.trace("getResource");
+
+		log.debug("Getting resource at path {}", path);
 		return resolver.getResource(path);
 	}
 
@@ -58,10 +156,14 @@ public class SlingFunctions {
 	 */
 	public static final Iterator<Resource> listChildResources(Resource resource) {
 		log.trace("listChildren");
+		
+		Iterator<Resource> children = null;
 		if (resource != null) {
-			return resource.listChildren();
+			log.debug("Listing children at path {}", resource.getPath());
+			children = resource.listChildren();
 		} else {
-			return null;
+			log.warn("Null resource specified");
 		}
+		return children;
 	}
 }

Modified: sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/taglib13.tld
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/taglib13.tld?rev=1479945&r1=1479944&r2=1479945&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/taglib13.tld (original)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/taglib13.tld Tue May  7 15:33:36 2013
@@ -1,492 +1,611 @@
 <?xml version="1.0" encoding="ISO-8859-1" ?>
-<!--
-    Licensed to the Apache Software Foundation (ASF) under one
-    or more contributor license agreements.  See the NOTICE file
-    distributed with this work for additional information
-    regarding copyright ownership.  The ASF licenses this file
-    to you under the Apache License, Version 2.0 (the
-    "License"); you may not use this file except in compliance
-    with the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing,
-    software distributed under the License is distributed on an
-    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-    KIND, either express or implied.  See the License for the
-    specific language governing permissions and limitations
-    under the License.
--->
-<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
-    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
-    version="2.0">
-
-    <description>A supporting tab library for Apache Sling</description>
-    <tlib-version>1.3</tlib-version>
-    <short-name>sling</short-name>
-    <uri>http://sling.apache.org/taglibs/sling/1.3</uri>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor 
+	license agreements. See the NOTICE file distributed with this work for additional 
+	information regarding copyright ownership. The ASF licenses this file to 
+	you under the Apache License, Version 2.0 (the "License"); you may not use 
+	this file except in compliance with the License. You may obtain a copy of 
+	the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required 
+	by applicable law or agreed to in writing, software distributed under the 
+	License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 
+	OF ANY KIND, either express or implied. See the License for the specific 
+	language governing permissions and limitations under the License. -->
+<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
+	version="2.0">
+
+	<description>A supporting tab library for Apache Sling</description>
+	<tlib-version>1.3</tlib-version>
+	<short-name>sling</short-name>
+	<uri>http://sling.apache.org/taglibs/sling/1.3</uri>
+
+	<function>
+		<name>adaptTo</name>
+		<function-class>org.apache.sling.scripting.jsp.taglib.SlingFunctions
+		</function-class>
+		<function-signature>java.lang.Object
+			adaptTo(org.apache.sling.api.adapter.Adaptable, java.lang.String)
+		</function-signature>
+	</function>
+
+	<function>
+		<name>findResources</name>
+		<function-class>org.apache.sling.scripting.jsp.taglib.SlingFunctions
+		</function-class>
+		<function-signature>java.util.Iterator
+			findResources(org.apache.sling.api.resource.ResourceResolver,
+			java.lang.String, java.lang.String)
+		</function-signature>
+	</function>
+
+	<function>
+		<name>getRelativeResource</name>
+		<function-class>org.apache.sling.scripting.jsp.taglib.SlingFunctions
+		</function-class>
+		<function-signature>org.apache.sling.api.resource.Resource
+			getRelativeResource(org.apache.sling.api.resource.Resource,
+			java.lang.String)
+		</function-signature>
+	</function>
 
 	<function>
 		<name>getResource</name>
-		<function-class>org.apache.sling.scripting.jsp.taglib.SlingFunctions</function-class>
-		<function-signature>org.apache.sling.api.resource.Resource getResource(org.apache.sling.api.resource.ResourceResolver, java.lang.String)</function-signature>
+		<function-class>org.apache.sling.scripting.jsp.taglib.SlingFunctions
+		</function-class>
+		<function-signature>org.apache.sling.api.resource.Resource
+			getResource(org.apache.sling.api.resource.ResourceResolver,
+			java.lang.String)
+		</function-signature>
 	</function>
 
 	<function>
 		<name>listChildResources</name>
-		<function-class>org.apache.sling.scripting.jsp.taglib.SlingFunctions</function-class>
-		<function-signature>java.util.Iterator listChildResources(org.apache.sling.api.resource.Resource)</function-signature>
+		<function-class>org.apache.sling.scripting.jsp.taglib.SlingFunctions
+		</function-class>
+		<function-signature>java.util.Iterator
+			listChildResources(org.apache.sling.api.resource.Resource)
+		</function-signature>
 	</function>
 
-    <tag>
-        <description>
-            Execute a script.
-        </description>
-        <name>call</name>
-        <tag-class>
-            org.apache.sling.scripting.jsp.taglib.CallTag
-        </tag-class>
-        <body-content>empty</body-content>
-        <attribute>
-            <description>
-                Whether to flush the output before including the target
-            </description>
-            <name>flush</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-            <type>boolean</type>
-        </attribute>
-        <attribute>
-            <description>
-                The script to include.
-            </description>
-            <name>script</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-        <attribute>
-            <description>
-                Controls if the component hierarchy should be ignored for script
-                resolution. If true, only the search paths are respected.
-            </description>
-            <name>ignoreComponentHierarchy</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-    </tag>
-
-    <tag>
-        <description>
-            Includes a resource rendering into the current page
-        </description>
-        <name>include</name>
-        <tag-class>
-            org.apache.sling.scripting.jsp.taglib.IncludeTagHandler
-        </tag-class>
-        <body-content>empty</body-content>
-        <attribute>
-            <description>
-                Whether to flush the output before including the target
-            </description>
-            <name>flush</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-            <type>boolean</type>
-        </attribute>
-        <attribute>
-            <description>
-                The resource object to include in the current request
-                processing. Either resource or path must be specified. If
-                both are specified, the resource takes precedences.
-            </description>
-            <name>resource</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-            <type>org.apache.sling.api.resource.Resource</type>
-        </attribute>
-        <attribute>
-            <description>
-                The path to the resource object to include in the current
-                request processing. If this path is relative it is
-                appended to the path of the current resource whose
-                script is including the given resource. Either resource
-                or path must be specified. If both are specified, the
-                resource takes precedences.
-            </description>
-            <name>path</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-        <attribute>
-            <description>
-                The resource type of a resource to include. If the resource
-                to be included is specified with the path attribute,
-                which cannot be resolved to a resource, the tag may
-                create a synthetic resource object out of the path and
-                this resource type. If the resource type is set the path
-                must be the exact path to a resource object. That is,
-                adding parameters, selectors and extensions to the path
-                is not supported if the resource type is set.
-            </description>
-            <name>resourceType</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-        <attribute>
-            <description>
-                When dispatching, replace selectors by the value
-                provided by this option.
-            </description>
-            <name>replaceSelectors</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-        <attribute>
-            <description>
-                When dispatching, add the value provided by this option to the selectors.
-            </description>
-            <name>addSelectors</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-        <attribute>
-            <description>
-                When dispatching, replace the suffix by the value
-                provided by this option.
-            </description>
-            <name>replaceSuffix</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-    </tag>
-
-    <tag>
-        <description>
-            Forwards a request to a resource rendering the current page
-        </description>
-        <name>forward</name>
-        <tag-class>
-            org.apache.sling.scripting.jsp.taglib.ForwardTagHandler
-        </tag-class>
-        <body-content>empty</body-content>
-        <attribute>
-            <description>
-                The resource object to forward the request to. Either
-                resource or path must be specified. If both are
-                specified, the resource takes precedences.
-            </description>
-            <name>resource</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-            <type>org.apache.sling.api.resource.Resource</type>
-        </attribute>
-        <attribute>
-            <description>
-                The path to the resource object to forward the request
-                to. If this path is relative it is appended to the path
-                of the current resource whose script is forwarding the
-                given resource. Either resource or path must be specified.
-                If both are specified, the resource takes precedences.
-            </description>
-            <name>path</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-        <attribute>
-            <description>
-                The resource type of a resource to forward. If the resource
-                to be forwarded is specified with the path attribute,
-                which cannot be resolved to a resource, the tag may
-                create a synthetic resource object out of the path and
-                this resource type. If the resource type is set the path
-                must be the exact path to a resource object. That is,
-                adding parameters, selectors and extensions to the path
-                is not supported if the resource type is set.
-            </description>
-            <name>resourceType</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-        <attribute>
-            <description>
-                When dispatching, replace selectors by the value
-                provided by this option.
-            </description>
-            <name>replaceSelectors</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-        <attribute>
-            <description>
-                When dispatching, add the value provided by this option to the selectors.
-            </description>
-            <name>addSelectors</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-        <attribute>
-            <description>
-                When dispatching, replace the suffix by the value
-                provided by this option.
-            </description>
-            <name>replaceSuffix</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-    </tag>
-
-    <tag>
-        <description>
-            Defines regularly used scripting variables
-        </description>
-        <name>defineObjects</name>
-        <tag-class>
-            org.apache.sling.scripting.jsp.taglib.DefineObjectsTag
-        </tag-class>
-        <tei-class>
-            org.apache.sling.scripting.jsp.taglib.DefineObjectsTEI
-        </tei-class>
-        <body-content>empty</body-content>
-        <attribute>
-            <name>requestName</name>
-            <required>false</required>
-            <rtexprvalue>false</rtexprvalue>
-        </attribute>
-        <attribute>
-            <name>responseName</name>
-            <required>false</required>
-            <rtexprvalue>false</rtexprvalue>
-        </attribute>
-        <attribute>
-            <name>resourceName</name>
-            <required>false</required>
-            <rtexprvalue>false</rtexprvalue>
-        </attribute>
-        <attribute>
-            <name>nodeName</name>
-            <required>false</required>
-            <rtexprvalue>false</rtexprvalue>
-        </attribute>
-        <attribute>
-            <name>logName</name>
-            <required>false</required>
-            <rtexprvalue>false</rtexprvalue>
-        </attribute>
-        <attribute>
-            <name>resourceResolverName</name>
-            <required>false</required>
-            <rtexprvalue>false</rtexprvalue>
-        </attribute>
-        <attribute>
-            <name>slingName</name>
-            <required>false</required>
-            <rtexprvalue>false</rtexprvalue>
-        </attribute>
-    </tag>
-
-    <tag>
-        <description>
-            Evaluates a script invocation and includes the result
-            in the current page.
-        </description>
-        <name>eval</name>
-        <tag-class>
-            org.apache.sling.scripting.jsp.taglib.EvalTagHandler
-        </tag-class>
-        <body-content>empty</body-content>
-        <attribute>
-            <description>
-                Whether to flush the output before including the target
-            </description>
-            <name>flush</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-            <type>boolean</type>
-        </attribute>
-        <attribute>
-            <description>
-                The path to the script object to include in the current
-                request processing. By default, the current resource
-                is used for script resolving. This behaviour can 
-                be changed by specifying either resource, resourceType
-                or ignoreResourceTypeHierarchy.
-            </description>
-            <name>script</name>
-            <required>true</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-        <attribute>
-            <description>
-                The resource object to include in the current request
-                processing. This attribute is optional. If it is
-                specified, resourceType should not be used. If both
-                are used, resource takes precedence.
-            </description>
-            <name>resource</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-            <type>org.apache.sling.api.resource.Resource</type>
-        </attribute>
-        <attribute>
-            <description>
-                The resource type of a resource to include. This
-                attribute is optional. If it is specified, resource
-                should not be used. If bot are used, resource
-                takes precedence.
-            </description>
-            <name>resourceType</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-        <attribute>
-            <description>
-                Prevents using the resource type hierarchy for searching
-                a script.
-            </description>
-            <name>ignoreResourceTypeHierarchy</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-            <type>boolean</type>
-        </attribute>
-    </tag>
-    <tag>
-        <description>
-            Adapts adaptables to objects of other types.
-        </description>
-        <name>adapt</name>
-        <tag-class>
-            org.apache.sling.scripting.jsp.taglib.AdaptObjectTag
-        </tag-class>
-        <body-content>empty</body-content>
-        <attribute>
-            <description>
-                The adaptable object to adapt.
-            </description>
-            <name>adaptable</name>
-            <required>true</required>
-            <rtexprvalue>true</rtexprvalue>
-            <type>org.apache.sling.api.adapter.Adaptable</type>
-        </attribute>
-        <attribute>
-            <description>
-                The class name to which to adapt the adaptable.
-            </description>
-            <name>adaptTo</name>
-            <required>true</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-        <attribute>
-            <description>
-                The name of the variable to which to save the adapted object.
-            </description>
-            <name>var</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-    </tag>
-    <tag>
-        <description>
-            Lists the children of a Sling Resource.
-        </description>
-        <name>listChildren</name>
-        <tag-class>
-            org.apache.sling.scripting.jsp.taglib.ListChildrenTag
-        </tag-class>
-        <body-content>empty</body-content>
-        <attribute>
-            <description>
-                The resource for which to retrieve the children.
-            </description>
-            <name>resource</name>
-            <required>true</required>
-            <rtexprvalue>true</rtexprvalue>
-            <type>org.apache.sling.api.resource.Resource</type>
-        </attribute>
-        <attribute>
-            <description>
-                The name of the variable to which to save the child resources.
-            </description>
-            <name>var</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-    </tag>
-    <tag>
-        <description>
-            Retrieves the resource at the specified path.
-        </description>
-        <name>getResource</name>
-        <tag-class>
-            org.apache.sling.scripting.jsp.taglib.GetResourceTag
-        </tag-class>
-        <body-content>empty</body-content>
-        <attribute>
-            <description>
-                The path of the resource to retrieve.
-            </description>
-            <name>path</name>
-            <required>true</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-        <attribute>
-            <description>
-                The name of the variable to which to save the resource.
-            </description>
-            <name>var</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-    </tag>
-    <tag>
-        <description>
-            Retrieves the value from the ValueMap, allowing for a default value or coercing the return value. 
-        </description>
-        <name>getProperty</name>
-        <tag-class>
-            org.apache.sling.scripting.jsp.taglib.GetPropertyTag
-        </tag-class>
-        <body-content>empty</body-content>
-        <attribute>
-            <description>
-                The name of the variable to which to save the resource.
-            </description>
-            <name>var</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-        <attribute>
-            <description>
-                The ValueMap from which to retrieve the value.
-            </description>
-            <name>properties</name>
-            <required>true</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-        <attribute>
-            <description>
-                The key to retrieve the value from from the ValueMap.
-            </description>
-            <name>key</name>
-            <required>true</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-        <attribute>
-            <description>
-                The default value to return if no value exists for the key.  
-                If specified, this takes precedence over returnClass.
-            </description>
-            <name>defaultValue</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-        <attribute>
-            <description>
-                The class into which to coerce the returned value.
-            </description>
-            <name>returnClass</name>
-            <required>false</required>
-            <rtexprvalue>true</rtexprvalue>
-        </attribute>
-    </tag>
+	<tag>
+		<description>
+			Execute a script.
+		</description>
+		<name>call</name>
+		<tag-class>
+			org.apache.sling.scripting.jsp.taglib.CallTag
+		</tag-class>
+		<body-content>empty</body-content>
+		<attribute>
+			<description>
+				Whether to flush the output before including the target
+			</description>
+			<name>flush</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+			<type>boolean</type>
+		</attribute>
+		<attribute>
+			<description>
+				The script to include.
+			</description>
+			<name>script</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+		<attribute>
+			<description>
+				Controls if the component hierarchy should be ignored
+				for script
+				resolution. If true, only the search paths are respected.
+			</description>
+			<name>ignoreComponentHierarchy</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+	</tag>
+
+	<tag>
+		<description>
+			Includes a resource rendering into the current page
+		</description>
+		<name>include</name>
+		<tag-class>
+			org.apache.sling.scripting.jsp.taglib.IncludeTagHandler
+		</tag-class>
+		<body-content>empty</body-content>
+		<attribute>
+			<description>
+				Whether to flush the output before including the target
+			</description>
+			<name>flush</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+			<type>boolean</type>
+		</attribute>
+		<attribute>
+			<description>
+				The resource object to include in the current request
+				processing. Either resource or path must be specified. If
+				both are
+				specified, the resource takes precedences.
+			</description>
+			<name>resource</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+			<type>org.apache.sling.api.resource.Resource</type>
+		</attribute>
+		<attribute>
+			<description>
+				The path to the resource object to include in the
+				current
+				request processing. If this path is relative it is
+				appended to
+				the path of the current resource whose
+				script is including the given
+				resource. Either resource
+				or path must be specified. If both are
+				specified, the
+				resource takes precedences.
+			</description>
+			<name>path</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+		<attribute>
+			<description>
+				The resource type of a resource to include. If the
+				resource
+				to be included is specified with the path attribute,
+				which
+				cannot be resolved to a resource, the tag may
+				create a synthetic
+				resource object out of the path and
+				this resource type. If the
+				resource type is set the path
+				must be the exact path to a resource
+				object. That is,
+				adding parameters, selectors and extensions to the
+				path
+				is not supported if the resource type is set.
+			</description>
+			<name>resourceType</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+		<attribute>
+			<description>
+				When dispatching, replace selectors by the value
+				provided by this option.
+			</description>
+			<name>replaceSelectors</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+		<attribute>
+			<description>
+				When dispatching, add the value provided by this option
+				to the
+				selectors.
+			</description>
+			<name>addSelectors</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+		<attribute>
+			<description>
+				When dispatching, replace the suffix by the value
+				provided by this option.
+			</description>
+			<name>replaceSuffix</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+	</tag>
+
+	<tag>
+		<description>
+			Forwards a request to a resource rendering the current
+			page
+		</description>
+		<name>forward</name>
+		<tag-class>
+			org.apache.sling.scripting.jsp.taglib.ForwardTagHandler
+		</tag-class>
+		<body-content>empty</body-content>
+		<attribute>
+			<description>
+				The resource object to forward the request to. Either
+				resource or path must be specified. If both are
+				specified, the
+				resource takes precedences.
+			</description>
+			<name>resource</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+			<type>org.apache.sling.api.resource.Resource</type>
+		</attribute>
+		<attribute>
+			<description>
+				The path to the resource object to forward the request
+				to. If this path is relative it is appended to the path
+				of the
+				current resource whose script is forwarding the
+				given resource.
+				Either resource or path must be specified.
+				If both are specified, the
+				resource takes precedences.
+			</description>
+			<name>path</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+		<attribute>
+			<description>
+				The resource type of a resource to forward. If the
+				resource
+				to be forwarded is specified with the path attribute,
+				which
+				cannot be resolved to a resource, the tag may
+				create a synthetic
+				resource object out of the path and
+				this resource type. If the
+				resource type is set the path
+				must be the exact path to a resource
+				object. That is,
+				adding parameters, selectors and extensions to the
+				path
+				is not supported if the resource type is set.
+			</description>
+			<name>resourceType</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+		<attribute>
+			<description>
+				When dispatching, replace selectors by the value
+				provided by this option.
+			</description>
+			<name>replaceSelectors</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+		<attribute>
+			<description>
+				When dispatching, add the value provided by this option
+				to the
+				selectors.
+			</description>
+			<name>addSelectors</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+		<attribute>
+			<description>
+				When dispatching, replace the suffix by the value
+				provided by this option.
+			</description>
+			<name>replaceSuffix</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+	</tag>
+
+	<tag>
+		<description>
+			Defines regularly used scripting variables
+		</description>
+		<name>defineObjects</name>
+		<tag-class>
+			org.apache.sling.scripting.jsp.taglib.DefineObjectsTag
+		</tag-class>
+		<tei-class>
+			org.apache.sling.scripting.jsp.taglib.DefineObjectsTEI
+		</tei-class>
+		<body-content>empty</body-content>
+		<attribute>
+			<name>requestName</name>
+			<required>false</required>
+			<rtexprvalue>false</rtexprvalue>
+		</attribute>
+		<attribute>
+			<name>responseName</name>
+			<required>false</required>
+			<rtexprvalue>false</rtexprvalue>
+		</attribute>
+		<attribute>
+			<name>resourceName</name>
+			<required>false</required>
+			<rtexprvalue>false</rtexprvalue>
+		</attribute>
+		<attribute>
+			<name>nodeName</name>
+			<required>false</required>
+			<rtexprvalue>false</rtexprvalue>
+		</attribute>
+		<attribute>
+			<name>logName</name>
+			<required>false</required>
+			<rtexprvalue>false</rtexprvalue>
+		</attribute>
+		<attribute>
+			<name>resourceResolverName</name>
+			<required>false</required>
+			<rtexprvalue>false</rtexprvalue>
+		</attribute>
+		<attribute>
+			<name>slingName</name>
+			<required>false</required>
+			<rtexprvalue>false</rtexprvalue>
+		</attribute>
+	</tag>
+
+	<tag>
+		<description>
+			Evaluates a script invocation and includes the result
+			in
+			the current page.
+		</description>
+		<name>eval</name>
+		<tag-class>
+			org.apache.sling.scripting.jsp.taglib.EvalTagHandler
+		</tag-class>
+		<body-content>empty</body-content>
+		<attribute>
+			<description>
+				Whether to flush the output before including the target
+			</description>
+			<name>flush</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+			<type>boolean</type>
+		</attribute>
+		<attribute>
+			<description>
+				The path to the script object to include in the current
+				request processing. By default, the current resource
+				is used for
+				script resolving. This behaviour can
+				be changed by specifying either
+				resource, resourceType
+				or ignoreResourceTypeHierarchy.
+			</description>
+			<name>script</name>
+			<required>true</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+		<attribute>
+			<description>
+				The resource object to include in the current request
+				processing. This attribute is optional. If it is
+				specified,
+				resourceType should not be used. If both
+				are used, resource takes
+				precedence.
+			</description>
+			<name>resource</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+			<type>org.apache.sling.api.resource.Resource</type>
+		</attribute>
+		<attribute>
+			<description>
+				The resource type of a resource to include. This
+				attribute is optional. If it is specified, resource
+				should not be
+				used. If bot are used, resource
+				takes precedence.
+			</description>
+			<name>resourceType</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+		<attribute>
+			<description>
+				Prevents using the resource type hierarchy for searching
+				a script.
+			</description>
+			<name>ignoreResourceTypeHierarchy</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+			<type>boolean</type>
+		</attribute>
+	</tag>
+
+	<tag>
+		<description>
+			Adapts adaptables to objects of other types.
+		</description>
+		<name>adapt</name>
+		<tag-class>
+			org.apache.sling.scripting.jsp.taglib.AdaptObjectTag
+		</tag-class>
+		<body-content>empty</body-content>
+		<attribute>
+			<description>
+				The adaptable object to adapt.
+			</description>
+			<name>adaptable</name>
+			<required>true</required>
+			<rtexprvalue>true</rtexprvalue>
+			<type>org.apache.sling.api.adapter.Adaptable</type>
+		</attribute>
+		<attribute>
+			<description>
+				The class name to which to adapt the adaptable.
+			</description>
+			<name>adaptTo</name>
+			<required>true</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+		<attribute>
+			<description>
+				The name of the variable to which to save the adapted
+				object.
+			</description>
+			<name>var</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+	</tag>
+
+	<tag>
+		<description>
+			Lists the children of a Sling Resource.
+		</description>
+		<name>listChildren</name>
+		<tag-class>
+			org.apache.sling.scripting.jsp.taglib.ListChildrenTag
+		</tag-class>
+		<body-content>empty</body-content>
+		<attribute>
+			<description>
+				The resource for which to retrieve the children.
+			</description>
+			<name>resource</name>
+			<required>true</required>
+			<rtexprvalue>true</rtexprvalue>
+			<type>org.apache.sling.api.resource.Resource</type>
+		</attribute>
+		<attribute>
+			<description>
+				The name of the variable to which to save the child
+				resources.
+			</description>
+			<name>var</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+	</tag>
+
+	<tag>
+		<description>
+			Tag for searching for resources using the given query
+			formulated in the
+			given language.
+		</description>
+		<name>findResources</name>
+		<tag-class>
+			org.apache.sling.scripting.jsp.taglib.FindResourcesTag
+		</tag-class>
+		<body-content>empty</body-content>
+		<attribute>
+			<description>
+				The query string to find the resources.
+			</description>
+			<name>query</name>
+			<required>true</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+		<attribute>
+			<description>
+				The query language to use.
+			</description>
+			<name>language</name>
+			<required>true</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+		<attribute>
+			<description>
+				The name of the variable to which to save the resources.
+			</description>
+			<name>var</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+	</tag>
+
+	<tag>
+		<description>
+			Retrieves resources based on either an absolute path or a
+			relative path and a
+			base resource.
+		</description>
+		<name>getResource</name>
+		<tag-class>
+			org.apache.sling.scripting.jsp.taglib.GetResourceTag
+		</tag-class>
+		<body-content>empty</body-content>
+		<attribute>
+			<description>
+				The base resource under which to retrieve the child
+				resource, will only
+				be considered if a relative path is specified.
+			</description>
+			<name>base</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+		<attribute>
+			<description>
+				The path of the resource to retrieve, if relative, the
+				base resource must be specified.
+			</description>
+			<name>path</name>
+			<required>true</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+		<attribute>
+			<description>
+				The name of the variable to which to save the resource.
+			</description>
+			<name>var</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+	</tag>
+
+	<tag>
+		<description>
+			Retrieves the value from the ValueMap, allowing for a
+			default value or
+			coercing the return value.
+		</description>
+		<name>getProperty</name>
+		<tag-class>
+			org.apache.sling.scripting.jsp.taglib.GetPropertyTag
+		</tag-class>
+		<body-content>empty</body-content>
+		<attribute>
+			<description>
+				The name of the variable to which to save the resource.
+			</description>
+			<name>var</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+		<attribute>
+			<description>
+				The ValueMap from which to retrieve the value.
+			</description>
+			<name>properties</name>
+			<required>true</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+		<attribute>
+			<description>
+				The key to retrieve the value from from the ValueMap.
+			</description>
+			<name>key</name>
+			<required>true</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+		<attribute>
+			<description>
+				The default value to return if no value exists for the
+				key.
+				If specified, this takes precedence over returnClass.
+			</description>
+			<name>defaultValue</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+		<attribute>
+			<description>
+				The class into which to coerce the returned value.
+			</description>
+			<name>returnClass</name>
+			<required>false</required>
+			<rtexprvalue>true</rtexprvalue>
+		</attribute>
+	</tag>
 </taglib>

Added: sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestFindResourceTag.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestFindResourceTag.java?rev=1479945&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestFindResourceTag.java (added)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestFindResourceTag.java Tue May  7 15:33:36 2013
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.scripting.jsp.taglib;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.commons.testing.sling.MockResource;
+import org.apache.sling.commons.testing.sling.MockResourceResolver;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Unit Tests for the Class FindResourceTag.
+ * 
+ * @see org.apache.sling.scripting.jsp.taglib.FindResourceTag
+ */
+public class TestFindResourceTag {
+
+	private static final Logger log = LoggerFactory
+			.getLogger(TestFindResourceTag.class);
+	private FindResourcesTag getResourceTag;
+	private MockResource resource;
+	private MockPageContext pageContext;
+	private static final String VAR_KEY = "resource";
+	private static final String TEST_PATH = "/content";
+
+	/**
+	 * Initializes the fields for this test.
+	 */
+	@SuppressWarnings("serial")
+	@Before
+	public void init() {
+		log.info("init");
+
+		final MockResourceResolver resolver = new MockResourceResolver() {
+			@Override
+			public Iterator<Resource> findResources(String query,
+					String language) {
+				if (query.equals("query") && language.equals("language")) {
+					List<Resource> resources = new ArrayList<Resource>();
+					resources.add(resource);
+					return resources.iterator();
+				} else {
+					return null;
+				}
+			}
+		};
+		resource = new MockResource(resolver, TEST_PATH, "test");
+		resolver.addResource(resource);
+
+		getResourceTag = new FindResourcesTag() {
+			protected ResourceResolver getResourceResolver() {
+				return resolver;
+			}
+		};
+
+		pageContext = new MockPageContext();
+		getResourceTag.setPageContext(pageContext);
+
+		log.info("init Complete");
+	}
+
+	/**
+	 * Tests the find resources functionalty.
+	 */
+	@Test
+	public void testFindResources() {
+		log.info("testGoodPath");
+
+		getResourceTag.setVar(VAR_KEY);
+		getResourceTag.setQuery("query");
+		getResourceTag.setLanguage("language");
+		getResourceTag.doEndTag();
+		Object result = pageContext.getAttribute(VAR_KEY);
+		assertNotNull(result);
+		assertTrue(result instanceof Iterator);
+		@SuppressWarnings("unchecked")
+		Iterator<Resource> resources = (Iterator<Resource>) result;
+		assertTrue(resources.hasNext());
+		assertEquals(TEST_PATH, resources.next().getPath());
+
+		log.info("Test successful!");
+	}
+}

Modified: sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestGetResourceTag.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestGetResourceTag.java?rev=1479945&r1=1479944&r2=1479945&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestGetResourceTag.java (original)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestGetResourceTag.java Tue May  7 15:33:36 2013
@@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory;
 
 /**
  * Unit Tests for the Class GetResourceTag.
+ * 
  * @see org.apache.sling.scripting.jsp.taglib.GetResourceTag
  */
 public class TestGetResourceTag {
@@ -42,7 +43,8 @@ public class TestGetResourceTag {
 	private MockResource resource;
 	private MockPageContext pageContext;
 	private static final String VAR_KEY = "resource";
-	private static final String TEST_PATH = "/content";
+	private static final String TEST_ABSOLUTE_PATH = "/content";
+	private static final String TEST_RELATIVE_PATH = "test";
 	private static final String TEST_NON_PATH = "/content/page";
 
 	/**
@@ -54,9 +56,14 @@ public class TestGetResourceTag {
 		log.info("init");
 
 		final MockResourceResolver resolver = new MockResourceResolver();
-		resource = new MockResource(resolver, TEST_PATH, "test");
+
+		resource = new MockResource(resolver, TEST_ABSOLUTE_PATH, "test");
 		resolver.addResource(resource);
 
+		MockResource child = new MockResource(resolver, TEST_ABSOLUTE_PATH
+				+ "/" + TEST_RELATIVE_PATH, "test");
+		resolver.addResource(child);
+
 		getResourceTag = new GetResourceTag() {
 			protected ResourceResolver getResourceResolver() {
 				return resolver;
@@ -70,19 +77,39 @@ public class TestGetResourceTag {
 	}
 
 	/**
-	 * Tests using a 'good' path.
+	 * Tests using an absolute path.
+	 */
+	@Test
+	public void testAbsolutePath() {
+		log.info("testAbsolutePath");
+
+		getResourceTag.setVar(VAR_KEY);
+		getResourceTag.setPath(TEST_ABSOLUTE_PATH);
+		getResourceTag.doEndTag();
+		Object result = pageContext.getAttribute(VAR_KEY);
+		assertNotNull(result);
+		assertTrue(result instanceof Resource);
+		assertEquals(TEST_ABSOLUTE_PATH, ((Resource) result).getPath());
+
+		log.info("Test successful!");
+	}
+
+	/**
+	 * Tests using an relative path.
 	 */
 	@Test
-	public void testGoodPath() {
-		log.info("testGoodPath");
+	public void testRelativePath() {
+		log.info("testRelativePath");
 
 		getResourceTag.setVar(VAR_KEY);
-		getResourceTag.setPath(TEST_PATH);
+		getResourceTag.setBase(resource);
+		getResourceTag.setPath(TEST_RELATIVE_PATH);
 		getResourceTag.doEndTag();
 		Object result = pageContext.getAttribute(VAR_KEY);
 		assertNotNull(result);
 		assertTrue(result instanceof Resource);
-		assertEquals(TEST_PATH, ((Resource) result).getPath());
+		assertEquals(TEST_ABSOLUTE_PATH + "/" + TEST_RELATIVE_PATH,
+				((Resource) result).getPath());
 
 		log.info("Test successful!");
 	}

Modified: sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestSlingFunctions.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestSlingFunctions.java?rev=1479945&r1=1479944&r2=1479945&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestSlingFunctions.java (original)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestSlingFunctions.java Tue May  7 15:33:36 2013
@@ -20,16 +20,23 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
 
+import org.apache.sling.api.adapter.Adaptable;
 import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.commons.testing.sling.MockResource;
 import org.apache.sling.commons.testing.sling.MockResourceResolver;
 import org.junit.Before;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
+/**
+ * Unit Tests for the Class SlingFunctions.
+ * @see org.apache.sling.scripting.jsp.taglib.SlingFunctions
+ */
 public class TestSlingFunctions {
 
 	private static final Logger log = LoggerFactory
@@ -45,7 +52,18 @@ public class TestSlingFunctions {
 	public void init() {
 		log.info("init");
 
-		resolver = new MockResourceResolver();
+		resolver = new MockResourceResolver(){
+			@Override
+		    public Iterator<Resource> findResources(String query, String language) {
+				if (query.equals("query") && language.equals("language")) {
+					List<Resource> resources = new ArrayList<Resource>();
+					resources.add(resource);
+					return resources.iterator();
+				} else {
+					return null;
+				}
+		    }
+		};
 		resource = new MockResource(resolver, TEST_PATH, "test");
 		resolver.addResource(resource);
 		MockResource child1 = new MockResource(resolver, TEST_PATH + "/child1",
@@ -67,6 +85,43 @@ public class TestSlingFunctions {
 
 		log.info("Tests successful!");
 	}
+	
+
+	@Test
+	public void testFindResources() throws ClassNotFoundException {
+		log.info("testFindResources");
+
+		Iterator<Resource> resources = SlingFunctions.findResources(resolver, "query", "language");
+		assertNotNull(resources);
+		assertTrue(resources.hasNext());
+		assertEquals(resource, resources.next());
+
+		log.info("Tests successful!");
+	}
+
+	@Test
+	public void testAdaptTo() throws ClassNotFoundException {
+		log.info("testAdaptTo");
+
+		Adaptable adaptable = SlingFunctions.getResource(resolver, TEST_PATH);
+		Object adapted = SlingFunctions.adaptTo(adaptable,
+				ValueMap.class.getCanonicalName());
+		assertNotNull(adapted);
+		assertTrue(adapted instanceof ValueMap);
+
+		log.info("Tests successful!");
+	}
+
+	@Test
+	public void testGetRelativeResource() {
+		log.info("testGetRelativeResource");
+		Resource parent = SlingFunctions.getResource(resolver, TEST_PATH);
+		Resource child = SlingFunctions.getRelativeResource(parent, "child1");
+		assertNotNull(child);
+		assertEquals(TEST_PATH + "/child1", child.getPath());
+
+		log.info("Tests successful!");
+	}
 
 	@Test
 	public void testListChildResources() {



Mime
View raw message