incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1428328 - in /sling/trunk/bundles/scripting/jsp-taglib: ./ src/main/java/org/apache/sling/scripting/jsp/taglib/ src/main/resources/META-INF/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/sli...
Date Thu, 03 Jan 2013 13:18:49 GMT
Author: bdelacretaz
Date: Thu Jan  3 13:18:49 2013
New Revision: 1428328

URL: http://svn.apache.org/viewvc?rev=1428328&view=rev
Log:
SLING-2648 - new resource access JSP tags, contributed by Dan Klco, thanks!

Added:
    sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/AdaptObjectTag.java
    sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/GetPropertyTag.java
    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/ListChildrenTag.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/
    sling/trunk/bundles/scripting/jsp-taglib/src/test/java/
    sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/
    sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/
    sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/
    sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/
    sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/
    sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/
    sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/MockPageContext.java
    sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestAdaptObjectTag.java
    sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestGetPropertyTag.java
    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/TestListChildrenTag.java
    sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestSlingFunctions.java
Modified:
    sling/trunk/bundles/scripting/jsp-taglib/pom.xml

Modified: sling/trunk/bundles/scripting/jsp-taglib/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/pom.xml?rev=1428328&r1=1428327&r2=1428328&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/pom.xml (original)
+++ sling/trunk/bundles/scripting/jsp-taglib/pom.xml Thu Jan  3 13:18:49 2013
@@ -98,5 +98,25 @@
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>
+	
+        <!-- Testing Dependencies -->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jmock</groupId>
+            <artifactId>jmock-junit4</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.testing</artifactId>
+            <version>2.0.12</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>

Added: sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/AdaptObjectTag.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/AdaptObjectTag.java?rev=1428328&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/AdaptObjectTag.java (added)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/AdaptObjectTag.java Thu Jan  3 13:18:49 2013
@@ -0,0 +1,145 @@
+/*
+ * 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 javax.servlet.jsp.tagext.TagSupport;
+
+import org.apache.sling.api.adapter.Adaptable;
+import org.apache.sling.api.scripting.SlingBindings;
+import org.apache.sling.api.scripting.SlingScriptHelper;
+import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tag for adapting adaptables to classes.
+ * 
+ * @author dklco
+ */
+public class AdaptObjectTag extends TagSupport {
+
+	private static final Logger log = LoggerFactory
+			.getLogger(AdaptObjectTag.class);
+	private static final long serialVersionUID = -1945089681840552408L;
+	private Adaptable adaptable;
+	private String adaptTo;
+	private String var;
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
+	 */
+	@Override
+	public int doEndTag() {
+		log.trace("doEndTag");
+
+		ClassLoader classLoader = getClassLoader();
+		log.debug("Adapting adaptable " + adaptable + " to class " + adaptTo);
+
+		if (adaptable != null) {
+			Object adapted = null;
+			try {
+				Class<?> adaptToClass = classLoader.loadClass(adaptTo);
+				adapted = adaptable.adaptTo(adaptToClass);
+			} catch (ClassNotFoundException e) {
+				log.warn("Unable to retrieve class " + adaptTo, e);
+			}
+
+			log.debug("Saving " + adapted + " to variable " + var);
+			pageContext.setAttribute(var, adapted);
+		} else {
+			log.warn("Null adaptable specified");
+		}
+
+		return EVAL_PAGE;
+	}
+
+	/**
+	 * Get the adaptable object to be adapted.
+	 * 
+	 * @return the adaptable
+	 */
+	public Adaptable getAdaptable() {
+		return adaptable;
+	}
+
+	/**
+	 * Gets the class name to adapt the adaptable to.
+	 * 
+	 * @return the class to adapt to
+	 */
+	public String getAdaptTo() {
+		return adaptTo;
+	}
+
+	/**
+	 * Method for retrieving the classloader from the OSGi console.
+	 * 
+	 * @return the classloader
+	 */
+	protected ClassLoader getClassLoader() {
+		final SlingBindings bindings = (SlingBindings) pageContext.getRequest()
+				.getAttribute(SlingBindings.class.getName());
+		final SlingScriptHelper scriptHelper = bindings.getSling();
+		final DynamicClassLoaderManager dynamicClassLoaderManager = scriptHelper
+				.getService(DynamicClassLoaderManager.class);
+		final ClassLoader classLoader = dynamicClassLoaderManager
+				.getDynamicClassLoader();
+		return classLoader;
+	}
+
+	/**
+	 * Gets the variable name to save the resulting object to.
+	 * 
+	 * @return the variable name
+	 */
+	public String getVar() {
+		return var;
+	}
+
+	/**
+	 * Sets the adaptable object to be adapted.
+	 * 
+	 * @param adaptable
+	 *            the object to adapt
+	 */
+	public void setAdaptable(Adaptable adaptable) {
+		this.adaptable = adaptable;
+	}
+
+	/**
+	 * Sets the class name to adapt the adaptable to.
+	 * 
+	 * @param adaptTo
+	 *            the class to adapt to
+	 */
+	public void setAdaptTo(String adaptTo) {
+		this.adaptTo = adaptTo;
+	}
+
+	/**
+	 * Gets the variable name to save the resulting object to.
+	 * 
+	 * @param var
+	 *            the variable name
+	 */
+	public void setVar(String var) {
+		this.var = var;
+	}
+
+}

Added: sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/GetPropertyTag.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/GetPropertyTag.java?rev=1428328&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/GetPropertyTag.java (added)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/GetPropertyTag.java Thu Jan  3 13:18:49 2013
@@ -0,0 +1,194 @@
+/*
+ * 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 javax.servlet.jsp.tagext.TagSupport;
+
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.api.scripting.SlingBindings;
+import org.apache.sling.api.scripting.SlingScriptHelper;
+import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tag for retrieving a property from a ValueMap.
+ * 
+ * @author dklco
+ */
+public class GetPropertyTag extends TagSupport {
+
+	private static final Logger log = LoggerFactory
+			.getLogger(GetPropertyTag.class);
+	private static final long serialVersionUID = -1945089681840552408L;
+	private ValueMap properties;
+	private String key;
+	private Object defaultValue;
+	private String returnClass;
+	private String var;
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
+	 */
+	@Override
+	public int doEndTag() {
+		log.trace("doEndTag");
+
+		Object value = null;
+		if(properties != null){
+			if (this.defaultValue != null) {
+				value = properties.get(key, defaultValue);
+			} else if (returnClass != null && returnClass.trim().length() != 0) {
+				ClassLoader classLoader = getClassLoader();
+				
+				log.debug("Returning value as type: " + returnClass);
+				try {
+					Class<?> clazz = classLoader.loadClass(returnClass);
+					value = properties.get(key, clazz);
+				} catch (ClassNotFoundException cnfe) {
+					log.warn("Unable to find class: " + returnClass, cnfe);
+				}
+			} else {
+				value = properties.get(key);
+			}
+		}else{
+			if (this.defaultValue != null) {
+				value = defaultValue;
+			}
+		}
+
+		log.debug("Saving " + value + " to variable " + var);
+		pageContext.setAttribute(var, value);
+
+		return EVAL_PAGE;
+	}
+
+	/**
+	 * Method for retrieving the classloader from the OSGi console.
+	 * 
+	 * @return the classloader
+	 */
+	protected ClassLoader getClassLoader() {
+		final SlingBindings bindings = (SlingBindings) pageContext.getRequest()
+				.getAttribute(SlingBindings.class.getName());
+		final SlingScriptHelper scriptHelper = bindings.getSling();
+		final DynamicClassLoaderManager dynamicClassLoaderManager = scriptHelper
+				.getService(DynamicClassLoaderManager.class);
+		final ClassLoader classLoader = dynamicClassLoaderManager
+				.getDynamicClassLoader();
+		return classLoader;
+	}
+
+	/**
+	 * Gets the default value to return if no value exists for the key. If
+	 * specified, this takes precedence over returnClass.
+	 * 
+	 * @return the default value
+	 */
+	public Object getDefaultValue() {
+		return defaultValue;
+	}
+
+	/**
+	 * Gets key to retrieve the value from from the ValueMap.
+	 * 
+	 * @return the key
+	 */
+	public String getKey() {
+		return key;
+	}
+
+	/**
+	 * Gets the ValueMap from which to retrieve the value.
+	 * 
+	 * @return the ValueMap of properties
+	 */
+	public ValueMap getProperties() {
+		return properties;
+	}
+
+	/**
+	 * Gets the name of class into which to coerce the returned value.
+	 * 
+	 * @return the class name
+	 */
+	public String getReturnClass() {
+		return returnClass;
+	}
+
+	/**
+	 * Gets the variable name to which to save the value
+	 * 
+	 * @return the variable name
+	 */
+	public String getVar() {
+		return var;
+	}
+
+	/**
+	 * Sets the default value to return if no value exists for the key. If
+	 * specified, this takes precedence over returnClass.
+	 * 
+	 * @param defaultValue
+	 *            the default value
+	 */
+	public void setDefaultValue(Object defaultValue) {
+		this.defaultValue = defaultValue;
+	}
+
+	/**
+	 * Sets the key to retrieve the value from from the ValueMap.
+	 * 
+	 * @param key
+	 *            the key
+	 */
+	public void setKey(String key) {
+		this.key = key;
+	}
+
+	/**
+	 * Sets the ValueMap from which to retrieve the value.
+	 * 
+	 * @param properties
+	 *            the ValueMap of properties
+	 */
+	public void setProperties(ValueMap properties) {
+		this.properties = properties;
+	}
+
+	/**
+	 * Sets the name of class into which to coerce the returned value.
+	 * 
+	 * @param returnClass
+	 *            the class name
+	 */
+	public void setReturnClass(String returnClass) {
+		this.returnClass = returnClass;
+	}
+
+	/**
+	 * Sets the variable name to which to save the value.
+	 * 
+	 * @param var
+	 *            the variable name
+	 */
+	public void setVar(String var) {
+		this.var = var;
+	}
+}
\ No newline at end of file

Added: 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=1428328&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/GetResourceTag.java (added)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/GetResourceTag.java Thu Jan  3 13:18:49 2013
@@ -0,0 +1,112 @@
+/*
+ * 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 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 retrieving a resource based a path.
+ * 
+ * @author dklco
+ */
+public class GetResourceTag extends TagSupport {
+
+	private static final Logger log = LoggerFactory
+			.getLogger(GetResourceTag.class);
+	private static final long serialVersionUID = -1945089681840552408L;
+	private String path;
+	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);
+
+		log.debug("Saving " + resource + " to variable " + var);
+		pageContext.setAttribute(var, resource);
+
+		return EVAL_PAGE;
+	}
+
+	/**
+	 * 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;
+	}
+
+	/**
+	 * Get the path of the resource to retrieve.
+	 * 
+	 * @return the path
+	 */
+	public String getPath() {
+		return path;
+	}
+
+	/**
+	 * Gets the variable name to which to save the list of children.
+	 * 
+	 * @return the variable name
+	 */
+	public String getVar() {
+		return var;
+	}
+
+	/**
+	 * Set the path of the resource to retrieve.
+	 * 
+	 * @param path
+	 *            the path
+	 */
+	public void setPath(String path) {
+		this.path = path;
+	}
+
+	/**
+	 * 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;
+	}
+}
\ No newline at end of file

Added: sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/ListChildrenTag.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/ListChildrenTag.java?rev=1428328&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/ListChildrenTag.java (added)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/ListChildrenTag.java Thu Jan  3 13:18:49 2013
@@ -0,0 +1,100 @@
+/*
+ * 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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tag for listing the children of a Resource. The children will be returned as
+ * an Iterator<Resource> in the specified variable.
+ * 
+ * @author dklco
+ */
+public class ListChildrenTag extends TagSupport {
+
+	private static final Logger log = LoggerFactory
+			.getLogger(ListChildrenTag.class);
+	private static final long serialVersionUID = -1945089681840552408L;
+	private Resource resource;
+	private String var;
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
+	 */
+	@Override
+	public int doEndTag() {
+		log.trace("doEndTag");
+
+		log.debug("Listing the children of resource: " + resource);
+
+		Iterator<Resource> children = null;
+		if (resource != null) {
+			children = resource.listChildren();
+		}
+
+		log.debug("Saving to variable " + var);
+		pageContext.setAttribute(var, children);
+
+		return EVAL_PAGE;
+	}
+
+	/**
+	 * Gets the resource of which to list the children.
+	 * 
+	 * @return the Sling Resource
+	 */
+	public Resource getResource() {
+		return resource;
+	}
+
+	/**
+	 * Gets the variable name to which to save the list of children.
+	 * 
+	 * @return the variable name
+	 */
+	public String getVar() {
+		return var;
+	}
+
+	/**
+	 * Sets the resource of which to list the children.
+	 * 
+	 * @param resource
+	 *            the Sling Resource
+	 */
+	public void setResource(Resource resource) {
+		this.resource = resource;
+	}
+
+	/**
+	 * 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;
+	}
+}
\ No newline at end of file

Added: 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=1428328&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/SlingFunctions.java (added)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/SlingFunctions.java Thu Jan  3 13:18:49 2013
@@ -0,0 +1,69 @@
+/*
+ * 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 org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class containing the TagLib Functions for Sling.
+ * 
+ * @author dklco
+ */
+public class SlingFunctions {
+
+	/**
+	 * The SLF4J Logger.
+	 */
+	private static final Logger log = LoggerFactory
+			.getLogger(SlingFunctions.class);
+
+	/**
+	 * Method allow for the retrieval of resources.
+	 * 
+	 * @param resolver
+	 *            the current resource resolver
+	 * @param path
+	 *            the path of the resource to retrieve
+	 * @return
+	 */
+	public static final Resource getResource(ResourceResolver resolver, String path) {
+		return resolver.getResource(path);
+	}
+
+	/**
+	 * Method for allowing the invocation of the Sling Resource listChildren
+	 * method.
+	 * 
+	 * @param resource
+	 *            the resource of which to list the children
+	 * @return the children of the resource
+	 * @see org.apache.sling.api.resource.Resource#listChildren()
+	 */
+	public static final Iterator<Resource> listChildResources(Resource resource) {
+		log.trace("listChildren");
+		if (resource != null) {
+			return resource.listChildren();
+		} else {
+			return null;
+		}
+	}
+}

Added: 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=1428328&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/taglib13.tld (added)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/taglib13.tld Thu Jan  3 13:18:49 2013
@@ -0,0 +1,492 @@
+<?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>
+
+	<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>
+
+	<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>
+
+    <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>
+</taglib>

Added: sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/MockPageContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/MockPageContext.java?rev=1428328&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/MockPageContext.java (added)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/MockPageContext.java Thu Jan  3 13:18:49 2013
@@ -0,0 +1,161 @@
+package org.apache.sling.scripting.jsp.taglib;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpSession;
+import javax.servlet.jsp.JspWriter;
+import javax.servlet.jsp.PageContext;
+import javax.servlet.jsp.el.ExpressionEvaluator;
+import javax.servlet.jsp.el.VariableResolver;
+
+public class MockPageContext extends PageContext {
+
+	private Map<String, Object> attributes = new HashMap<String, Object>();
+
+	@Override
+	public void forward(String arg0) throws ServletException, IOException {
+		throw new java.lang.UnsupportedOperationException();
+	}
+
+	@Override
+	public Exception getException() {
+		throw new java.lang.UnsupportedOperationException();
+	}
+
+	@Override
+	public Object getPage() {
+		throw new java.lang.UnsupportedOperationException();
+	}
+
+	@Override
+	public ServletRequest getRequest() {
+		throw new java.lang.UnsupportedOperationException();
+	}
+
+	@Override
+	public ServletResponse getResponse() {
+		throw new java.lang.UnsupportedOperationException();
+	}
+
+	@Override
+	public ServletConfig getServletConfig() {
+		throw new java.lang.UnsupportedOperationException();
+	}
+
+	@Override
+	public ServletContext getServletContext() {
+		throw new java.lang.UnsupportedOperationException();
+	}
+
+	@Override
+	public HttpSession getSession() {
+		throw new java.lang.UnsupportedOperationException();
+	}
+
+	@Override
+	public void handlePageException(Exception arg0) throws ServletException,
+			IOException {
+		throw new java.lang.UnsupportedOperationException();
+	}
+
+	@Override
+	public void handlePageException(Throwable arg0) throws ServletException,
+			IOException {
+		throw new java.lang.UnsupportedOperationException();
+	}
+
+	@Override
+	public void include(String arg0) throws ServletException, IOException {
+		throw new java.lang.UnsupportedOperationException();
+	}
+
+	@Override
+	public void include(String arg0, boolean arg1) throws ServletException,
+			IOException {
+		throw new java.lang.UnsupportedOperationException();
+	}
+
+	@Override
+	public void initialize(Servlet arg0, ServletRequest arg1,
+			ServletResponse arg2, String arg3, boolean arg4, int arg5,
+			boolean arg6) throws IOException, IllegalStateException,
+			IllegalArgumentException {
+		throw new java.lang.UnsupportedOperationException();
+	}
+
+	@Override
+	public void release() {
+		throw new java.lang.UnsupportedOperationException();
+	}
+
+	@Override
+	public Object findAttribute(String key) {
+		return attributes.get(key);
+	}
+
+	@Override
+	public Object getAttribute(String key) {
+		return attributes.get(key);
+	}
+
+	@Override
+	public Object getAttribute(String key, int arg1) {
+		return attributes.get(key);
+	}
+
+	@SuppressWarnings("rawtypes")
+	@Override
+	public Enumeration getAttributeNamesInScope(int arg0) {
+		throw new java.lang.UnsupportedOperationException();
+	}
+
+	@Override
+	public int getAttributesScope(String arg0) {
+		throw new java.lang.UnsupportedOperationException();
+	}
+
+	@Override
+	public ExpressionEvaluator getExpressionEvaluator() {
+		throw new java.lang.UnsupportedOperationException();
+	}
+
+	@Override
+	public JspWriter getOut() {
+		throw new java.lang.UnsupportedOperationException();
+	}
+
+	@Override
+	public VariableResolver getVariableResolver() {
+		throw new java.lang.UnsupportedOperationException();
+	}
+
+	@Override
+	public void removeAttribute(String arg0) {
+		attributes.remove(arg0);
+	}
+
+	@Override
+	public void removeAttribute(String arg0, int arg1) {
+		attributes.remove(arg0);
+	}
+
+	@Override
+	public void setAttribute(String arg0, Object arg1) {
+		attributes.put(arg0, arg1);
+	}
+
+	@Override
+	public void setAttribute(String arg0, Object arg1, int arg2) {
+		attributes.put(arg0, arg1);
+	}
+
+}

Added: sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestAdaptObjectTag.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestAdaptObjectTag.java?rev=1428328&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestAdaptObjectTag.java (added)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestAdaptObjectTag.java Thu Jan  3 13:18:49 2013
@@ -0,0 +1,109 @@
+/*
+ * 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.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.sling.api.resource.ResourceResolver;
+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 AdaptObject.
+ * 
+ * @author dklco
+ * @see org.apache.sling.scripting.jsp.taglib.AdaptObjectTag
+ */
+public class TestAdaptObjectTag {
+
+	private static final Logger log = LoggerFactory
+			.getLogger(TestAdaptObjectTag.class);
+	private AdaptObjectTag adaptObjectTag;
+	private MockResource resource;
+	private MockPageContext pageContext;
+	private static final String VAR_KEY = "properties";
+
+	/**
+	 * Initializes the fields for this test.
+	 */
+	@SuppressWarnings("serial")
+	@Before
+	public void init() {
+		log.info("init");
+		adaptObjectTag = new AdaptObjectTag() {
+			protected ClassLoader getClassLoader() {
+				return TestAdaptObjectTag.class.getClassLoader();
+			}
+		};
+
+		pageContext = new MockPageContext();
+		adaptObjectTag.setPageContext(pageContext);
+
+		ResourceResolver resolver = new MockResourceResolver();
+		resource = new MockResource(resolver, "/", "test");
+		log.info("init Complete");
+	}
+
+	/**
+	 * Tests the adapt object Tag functionality.
+	 */
+	@Test
+	public void testAdaptObject() {
+		log.info("testAdaptObject");
+
+		log.info("Setting up tests");
+		adaptObjectTag.setAdaptable(resource);
+		adaptObjectTag.setAdaptTo(ValueMap.class.getCanonicalName());
+		adaptObjectTag.setVar(VAR_KEY);
+		adaptObjectTag.doEndTag();
+
+		log.info("Checking result");
+		Object result = pageContext.getAttribute(VAR_KEY);
+		assertNotNull(result);
+		assertTrue(result instanceof ValueMap);
+
+		log.info("Test successful!");
+	}
+
+	/**
+	 * Tests to ensure that a null result is returned if the class to adapt does
+	 * not exist.
+	 */
+	@Test
+	public void testMissingClass() {
+		log.info("testMissingClass");
+
+		log.info("Setting up tests");
+		adaptObjectTag.setAdaptable(resource);
+		adaptObjectTag.setAdaptTo("com.bad.class");
+		adaptObjectTag.setVar(VAR_KEY);
+		adaptObjectTag.doEndTag();
+
+		log.info("Checking result");
+		Object result = pageContext.getAttribute(VAR_KEY);
+		assertNull(result);
+
+		log.info("Test successful!");
+	}
+}

Added: sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestGetPropertyTag.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestGetPropertyTag.java?rev=1428328&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestGetPropertyTag.java (added)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestGetPropertyTag.java Thu Jan  3 13:18:49 2013
@@ -0,0 +1,106 @@
+/*
+ * 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 java.util.HashMap;
+
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.api.wrappers.ValueMapDecorator;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Unit Tests for the Class GetPropertyTag.
+ * 
+ * @author dklco
+ * @see org.apache.sling.scripting.jsp.taglib.GetPropertyTag
+ */
+public class TestGetPropertyTag {
+
+	private static final Logger log = LoggerFactory
+			.getLogger(TestGetPropertyTag.class);
+	private GetPropertyTag getPropertyTag;
+	private MockPageContext pageContext;
+	private static final String VAR_KEY = "value";
+	private static final String TEST_KEY = "key";
+	private static final String TEST_EMPTY_KEY = "key2";
+	private static final String TEST_VALUE = "Sling";
+
+	/**
+	 * Initializes the fields for this test.
+	 */
+	@SuppressWarnings("serial")
+	@Before
+	public void init() {
+		log.info("init");
+		getPropertyTag = new GetPropertyTag() {
+			protected ClassLoader getClassLoader() {
+				return TestGetPropertyTag.class.getClassLoader();
+			}
+		};
+
+		pageContext = new MockPageContext();
+		getPropertyTag.setPageContext(pageContext);
+	}
+
+	/**
+	 * Tests the adapt object Tag functionality.
+	 */
+	@Test
+	public void testAdaptObject() {
+		log.info("testAdaptObject");
+
+		log.info("Setting up tests");
+		ValueMap properties = new ValueMapDecorator(
+				new HashMap<String, Object>());
+		properties.put(TEST_KEY, TEST_VALUE);
+		getPropertyTag.setProperties(properties);
+		getPropertyTag.setVar(VAR_KEY);
+
+		log.info("Testing retrieving value with default value");
+		getPropertyTag.setDefaultValue(TEST_VALUE);
+		getPropertyTag.setKey(TEST_KEY);
+		getPropertyTag.doEndTag();
+		Object value = pageContext.getAttribute(VAR_KEY);
+		assertNotNull(value);
+		assertEquals(TEST_VALUE, value);
+		
+		log.info("Testing retrieving default value");
+		getPropertyTag.setDefaultValue(TEST_VALUE);
+		getPropertyTag.setKey(TEST_EMPTY_KEY);
+		getPropertyTag.doEndTag();
+		value = pageContext.getAttribute(VAR_KEY);
+		assertNotNull(value);
+		assertEquals(TEST_VALUE, value);
+
+		log.info("Testing retrieving value");
+		getPropertyTag.setDefaultValue(null);
+		getPropertyTag.setReturnClass(String.class.getCanonicalName());
+		getPropertyTag.setKey(TEST_KEY);
+		getPropertyTag.doEndTag();
+		value = pageContext.getAttribute(VAR_KEY);
+		assertNotNull(value);
+		assertEquals(TEST_VALUE, value);
+
+		log.info("Test successful!");
+	}
+}

Added: 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=1428328&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestGetResourceTag.java (added)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestGetResourceTag.java Thu Jan  3 13:18:49 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.assertNull;
+import static org.junit.Assert.assertTrue;
+
+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 GetResourceTag.
+ * 
+ * @author dklco
+ * @see org.apache.sling.scripting.jsp.taglib.GetResourceTag
+ */
+public class TestGetResourceTag {
+
+	private static final Logger log = LoggerFactory
+			.getLogger(TestGetResourceTag.class);
+	private GetResourceTag getResourceTag;
+	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_NON_PATH = "/content/page";
+
+	/**
+	 * Initializes the fields for this test.
+	 */
+	@SuppressWarnings("serial")
+	@Before
+	public void init() {
+		log.info("init");
+
+		final MockResourceResolver resolver = new MockResourceResolver();
+		resource = new MockResource(resolver, TEST_PATH, "test");
+		resolver.addResource(resource);
+
+		getResourceTag = new GetResourceTag() {
+			protected ResourceResolver getResourceResolver() {
+				return resolver;
+			}
+		};
+
+		pageContext = new MockPageContext();
+		getResourceTag.setPageContext(pageContext);
+
+		log.info("init Complete");
+	}
+
+	/**
+	 * Tests using a 'good' path.
+	 */
+	@Test
+	public void testGoodPath() {
+		log.info("testGoodPath");
+
+		getResourceTag.setVar(VAR_KEY);
+		getResourceTag.setPath(TEST_PATH);
+		getResourceTag.doEndTag();
+		Object result = pageContext.getAttribute(VAR_KEY);
+		assertNotNull(result);
+		assertTrue(result instanceof Resource);
+		assertEquals(TEST_PATH, ((Resource) result).getPath());
+
+		log.info("Test successful!");
+	}
+
+	/**
+	 * Tests to see what happens if a bad path is specified, this should just
+	 * return a null value instead of a resource.
+	 */
+	@Test
+	public void testBadPath() {
+		log.info("testBadPath");
+
+		getResourceTag.setVar(VAR_KEY);
+		getResourceTag.setPath(TEST_NON_PATH);
+		getResourceTag.doEndTag();
+		Object result = pageContext.getAttribute(VAR_KEY);
+		assertNull(result);
+
+		log.info("Test successful!");
+	}
+}

Added: sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestListChildrenTag.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestListChildrenTag.java?rev=1428328&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestListChildrenTag.java (added)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/test/java/org/apache/sling/scripting/jsp/taglib/TestListChildrenTag.java Thu Jan  3 13:18:49 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.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Iterator;
+
+import org.apache.sling.api.resource.Resource;
+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 ListChildrenTag.
+ * 
+ * @author dklco
+ * @see org.apache.sling.scripting.jsp.taglib.ListChildrenTag
+ */
+public class TestListChildrenTag {
+
+	private static final Logger log = LoggerFactory
+			.getLogger(TestListChildrenTag.class);
+	private ListChildrenTag listChildrenTag = new ListChildrenTag();
+	private MockResource resource;
+	private MockPageContext pageContext;
+	private static final String TEST_PATH = "/content";
+	private static final String VAR_KEY = "children";
+
+	/**
+	 * Initializes the fields for this test.
+	 */
+	@Before
+	public void init() {
+		log.info("init");
+
+		log.info("Creating Resource Structure");
+		final MockResourceResolver resolver = new MockResourceResolver();
+		resource = new MockResource(resolver, TEST_PATH, "test");
+		resolver.addResource(resource);
+		MockResource child1 = new MockResource(resolver, TEST_PATH + "/child1",
+				"test");
+		resolver.addResource(child1);
+		MockResource child2 = new MockResource(resolver, TEST_PATH + "/child2",
+				"test");
+		resolver.addResource(child2);
+
+		log.info("Adding page context");
+		pageContext = new MockPageContext();
+		listChildrenTag.setPageContext(pageContext);
+
+		log.info("init Complete");
+	}
+
+	/**
+	 * Tests to ensure the base ListChildren functionality works.
+	 */
+	@SuppressWarnings("unchecked")
+	@Test
+	public void testListChildren() {
+		log.info("testGoodPath");
+
+		listChildrenTag.setResource(resource);
+		listChildrenTag.setVar(VAR_KEY);
+		listChildrenTag.doEndTag();
+		Object result = pageContext.getAttribute(VAR_KEY);
+		assertNotNull(result);
+		assertTrue(result instanceof Iterator);
+		assertTrue(((Iterator<Resource>) result).hasNext());
+
+		log.info("Test successful!");
+	}
+
+	/**
+	 * Tests to see what happens if a null Resource is provided
+	 */
+	@Test
+	public void testNullResource() {
+		log.info("testNullResource");
+
+		listChildrenTag.setVar(VAR_KEY);
+		listChildrenTag.setResource(null);
+		listChildrenTag.doEndTag();
+		Object result = pageContext.getAttribute(VAR_KEY);
+		assertNull(result);
+
+		log.info("Test successful!");
+	}
+}

Added: 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=1428328&view=auto
==============================================================================
--- 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/test/java/org/apache/sling/scripting/jsp/taglib/TestSlingFunctions.java Thu Jan  3 13:18:49 2013
@@ -0,0 +1,81 @@
+/*
+ * 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.Iterator;
+
+import org.apache.sling.api.resource.Resource;
+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;
+
+public class TestSlingFunctions {
+
+	private static final Logger log = LoggerFactory
+			.getLogger(TestGetResourceTag.class);
+	private MockResource resource;
+	private MockResourceResolver resolver;
+	private static final String TEST_PATH = "/content";
+
+	/**
+	 * Initializes the fields for this test.
+	 */
+	@Before
+	public void init() {
+		log.info("init");
+
+		resolver = new MockResourceResolver();
+		resource = new MockResource(resolver, TEST_PATH, "test");
+		resolver.addResource(resource);
+		MockResource child1 = new MockResource(resolver, TEST_PATH + "/child1",
+				"test");
+		resolver.addResource(child1);
+		MockResource child2 = new MockResource(resolver, TEST_PATH + "/child2",
+				"test");
+		resolver.addResource(child2);
+
+		log.info("init Complete");
+	}
+
+	@Test
+	public void testGetResource() {
+		log.info("testGetResource");
+		Resource resource = SlingFunctions.getResource(resolver, TEST_PATH);
+		assertNotNull(resource);
+		assertEquals(TEST_PATH, resource.getPath());
+
+		log.info("Tests successful!");
+	}
+
+	@Test
+	public void testListChildResources() {
+		log.info("testListChildResources");
+		Iterator<Resource> children = SlingFunctions
+				.listChildResources(resource);
+		assertNotNull(children);
+		assertTrue(children.hasNext());
+
+		log.info("Tests successful!");
+	}
+}



Mime
View raw message