Author: cziegeler
Date: Mon Feb 23 19:39:36 2009
New Revision: 747110

URL: http://svn.apache.org/viewvc?rev=747110&view=rev
Log:
SLING-590 - Add a new scription variable "properties" which points by default 
to resource.adaptTo(ValueMap.class). The name of the variable can be 
overwritten as well as the class for the adaptTo can be changed to Map.

Modified:
    incubator/sling/trunk/bundles/scripting/jsp-taglib/pom.xml
    
incubator/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/DefineObjectsTEI.java
    
incubator/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/DefineObjectsTag.java
    
incubator/sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/taglib.tld

Modified: incubator/sling/trunk/bundles/scripting/jsp-taglib/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/scripting/jsp-taglib/pom.xml?rev=747110&r1=747109&r2=747110&view=diff
==============================================================================
--- incubator/sling/trunk/bundles/scripting/jsp-taglib/pom.xml (original)
+++ incubator/sling/trunk/bundles/scripting/jsp-taglib/pom.xml Mon Feb 23 
19:39:36 2009
@@ -63,7 +63,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.api</artifactId>
-            <version>2.0.2-incubator</version>
+            <version>2.0.3-incubator-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>

Modified: 
incubator/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/DefineObjectsTEI.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/DefineObjectsTEI.java?rev=747110&r1=747109&r2=747110&view=diff
==============================================================================
--- 
incubator/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/DefineObjectsTEI.java
 (original)
+++ 
incubator/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/DefineObjectsTEI.java
 Mon Feb 23 19:39:36 2009
@@ -18,6 +18,8 @@
 
 import static 
org.apache.sling.scripting.jsp.taglib.DefineObjectsTag.DEFAULT_LOG_NAME;
 import static 
org.apache.sling.scripting.jsp.taglib.DefineObjectsTag.DEFAULT_NODE_NAME;
+import static 
org.apache.sling.scripting.jsp.taglib.DefineObjectsTag.DEFAULT_PROPERTIES_IS_VALUE_MAP;
+import static 
org.apache.sling.scripting.jsp.taglib.DefineObjectsTag.DEFAULT_PROPERTIES_NAME;
 import static 
org.apache.sling.scripting.jsp.taglib.DefineObjectsTag.DEFAULT_REQUEST_NAME;
 import static 
org.apache.sling.scripting.jsp.taglib.DefineObjectsTag.DEFAULT_RESOURCE_NAME;
 import static 
org.apache.sling.scripting.jsp.taglib.DefineObjectsTag.DEFAULT_RESOURCE_RESOLVER_NAME;
@@ -26,6 +28,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 import javax.jcr.Node;
 import javax.servlet.jsp.tagext.TagData;
@@ -36,6 +39,7 @@
 import org.apache.sling.api.SlingHttpServletResponse;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.api.scripting.SlingScriptHelper;
 import org.slf4j.Logger;
 
@@ -87,6 +91,18 @@
      */
     public static final String ATTR_LOG_NAME = "logName";
 
+    /**
+     * The name of the tag attribute used to define the name of the properties 
map
+     * scripting variable (value is "propertiesName").
+     */
+    public static final String ATTR_PROPERTIES_NAME = "propertiesName";
+
+    /**
+     * The name of the tag attribute used to define the class of the properties
+     * scripting variable (value is "propertiesIsValueMap").
+     */
+    public static final String ATTR_PROPERTIES_IS_VALUE_MAP_NAME = 
"propertiesIsValueMap";
+
     private static final String SLING_REQUEST_CLASS = 
SlingHttpServletRequest.class.getName();
 
     private static final String SLING_RESPONSE_CLASS = 
SlingHttpServletResponse.class.getName();
@@ -129,6 +145,22 @@
         addVar(varInfos, data, ATTR_LOG_NAME,
                 DEFAULT_LOG_NAME, LOG_CLASS);
 
+        Boolean isValueMap = DEFAULT_PROPERTIES_IS_VALUE_MAP;
+        final Object isValueMapObj = 
data.getAttribute(ATTR_PROPERTIES_IS_VALUE_MAP_NAME);
+        if ( isValueMapObj instanceof Boolean ) {
+            isValueMap = (Boolean)isValueMapObj;
+        }
+
+        final String propertiesClassName;
+        if ( isValueMap ) {
+            propertiesClassName = ValueMap.class.getName();
+        } else {
+            propertiesClassName = Map.class.getName();
+        }
+        addVar(varInfos, data, ATTR_PROPERTIES_NAME,
+                DEFAULT_PROPERTIES_NAME,
+                propertiesClassName);
+
         return varInfos.toArray(new VariableInfo[varInfos.size()]);
 
     }

Modified: 
incubator/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/DefineObjectsTag.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/DefineObjectsTag.java?rev=747110&r1=747109&r2=747110&view=diff
==============================================================================
--- 
incubator/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/DefineObjectsTag.java
 (original)
+++ 
incubator/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/DefineObjectsTag.java
 Mon Feb 23 19:39:36 2009
@@ -16,10 +16,13 @@
  */
 package org.apache.sling.scripting.jsp.taglib;
 
+import java.util.Map;
+
 import javax.jcr.Node;
 import javax.servlet.jsp.tagext.TagSupport;
 
 import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.api.scripting.SlingBindings;
 import org.apache.sling.api.scripting.SlingScriptHelper;
 
@@ -68,6 +71,18 @@
     public static final String DEFAULT_SLING_NAME = "sling";
 
     /**
+     * Default name for the scripting variable referencing the properties
+     * map (value is "properties").
+     */
+    public static final String DEFAULT_PROPERTIES_NAME = "properties";
+
+    /**
+     * Default name for the properties class information.
+     * (value is "true").
+     */
+    public static final Boolean DEFAULT_PROPERTIES_IS_VALUE_MAP = true;
+
+    /**
      * Default name for the scripting variable referencing the current
      * <code>ResourceResolver</code> (value is "resourceResolver").
      */
@@ -87,6 +102,10 @@
 
     private String resourceResolverName = DEFAULT_RESOURCE_RESOLVER_NAME;
 
+    private String propertiesName = DEFAULT_PROPERTIES_NAME;
+
+    private boolean propertiesIsValueMap = DEFAULT_PROPERTIES_IS_VALUE_MAP;
+
     /**
      * Default constructor.
      */
@@ -121,6 +140,18 @@
         if (node != null) {
             pageContext.setAttribute(nodeName, node);
         }
+        if ( this.propertiesIsValueMap ) {
+            final ValueMap vm = resource.adaptTo(ValueMap.class);
+            if ( vm != null ) {
+                pageContext.setAttribute(propertiesName, vm);
+            }
+        } else {
+            @SuppressWarnings("unchecked")
+            final Map map = resource.adaptTo(Map.class);
+            if ( map != null ) {
+                pageContext.setAttribute(propertiesName, map);
+            }
+        }
 
         return EVAL_PAGE;
     }
@@ -154,4 +185,12 @@
     public void setResourceResolverName(String name) {
         this.resourceResolverName = name;
     }
+
+    public void setPropertiesName(String name) {
+        this.propertiesName = name;
+    }
+
+    public void setPropertiesIsValueMap(boolean value) {
+        this.propertiesIsValueMap = value;
+    }
 }

Modified: 
incubator/sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/taglib.tld
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/taglib.tld?rev=747110&r1=747109&r2=747110&view=diff
==============================================================================
--- 
incubator/sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/taglib.tld
 (original)
+++ 
incubator/sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/taglib.tld
 Mon Feb 23 19:39:36 2009
@@ -234,6 +234,20 @@
             <required>false</required>
             <rtexprvalue>false</rtexprvalue>
         </attribute>
+        <attribute>
+            <name>propertiesName</name>
+            <required>false</required>
+            <rtexprvalue>false</rtexprvalue>
+        </attribute>
+        <attribute>
+            <description>
+                Should the properties variable be a value map or a map
+            </description>
+            <name>propertiesIsValueMap</name>
+            <required>false</required>
+            <rtexprvalue>true</rtexprvalue>
+            <type>boolean</type>
+        </attribute>
     </tag>
 
 </taglib>


Reply via email to