You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2008/05/08 14:10:49 UTC

svn commit: r654501 - in /incubator/sling/trunk/scripting: jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/ jsp-taglib/src/main/resources/META-INF/ jsp/src/main/java/org/apache/sling/scripting/jsp/ jsp/src/main/java/org/apache/sling/scri...

Author: cziegeler
Date: Thu May  8 05:10:48 2008
New Revision: 654501

URL: http://svn.apache.org/viewvc?rev=654501&view=rev
Log:
SLING-247: Clean up providing script variables, add log.

Modified:
    incubator/sling/trunk/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/DefineObjectsTEI.java
    incubator/sling/trunk/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/DefineObjectsTag.java
    incubator/sling/trunk/scripting/jsp-taglib/src/main/resources/META-INF/taglib.tld
    incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
    incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletWrapperAdapter.java
    incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/util/TagUtil.java

Modified: incubator/sling/trunk/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/DefineObjectsTEI.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/DefineObjectsTEI.java?rev=654501&r1=654500&r2=654501&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/DefineObjectsTEI.java (original)
+++ incubator/sling/trunk/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/DefineObjectsTEI.java Thu May  8 05:10:48 2008
@@ -16,6 +16,7 @@
  */
 package org.apache.sling.scripting.jsp.taglib;
 
+import static org.apache.sling.scripting.jsp.taglib.DefineObjectsTag.DEFAULT_LOG_NAME;
 import static org.apache.sling.scripting.jsp.taglib.DefineObjectsTag.DEFAULT_MAPPED_OBJECT_NAME;
 import static org.apache.sling.scripting.jsp.taglib.DefineObjectsTag.DEFAULT_NODE_NAME;
 import static org.apache.sling.scripting.jsp.taglib.DefineObjectsTag.DEFAULT_REQUEST_NAME;
@@ -37,6 +38,7 @@
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.scripting.SlingScriptHelper;
+import org.slf4j.Logger;
 
 /**
  * This class defines the scripting variables that are created by the
@@ -92,9 +94,15 @@
      */
     public static final String ATTR_RESOURCE_RESOLVER_NAME = "resourceResolverName";
 
-    private static final String RENDER_REQUEST_CLASS = SlingHttpServletRequest.class.getName();
+    /**
+     * The name of the tag attribute used to define the name of the
+     * logger scripting variable (value is "logName").
+     */
+    public static final String ATTR_LOG_NAME = "logName";
 
-    private static final String RENDER_RESPONSE_CLASS = SlingHttpServletResponse.class.getName();
+    private static final String SLING_REQUEST_CLASS = SlingHttpServletRequest.class.getName();
+
+    private static final String SLING_RESPONSE_CLASS = SlingHttpServletResponse.class.getName();
 
     private static final String RESOURCE_CLASS = Resource.class.getName();
 
@@ -104,6 +112,8 @@
 
     private static final String SLING_CLASS = SlingScriptHelper.class.getName();
 
+    private static final String LOG_CLASS = Logger.class.getName();
+
     /**
      * Returns an Array of <code>VariableInfo</code> objects describing
      * scripting variables.
@@ -115,9 +125,9 @@
         List<VariableInfo> varInfos = new ArrayList<VariableInfo>();
 
         addVar(varInfos, data, ATTR_REQUEST_NAME, DEFAULT_REQUEST_NAME,
-            RENDER_REQUEST_CLASS);
+            SLING_REQUEST_CLASS);
         addVar(varInfos, data, ATTR_RESPONSE_NAME, DEFAULT_RESPONSE_NAME,
-            RENDER_RESPONSE_CLASS);
+            SLING_RESPONSE_CLASS);
 
         addVar(varInfos, data, ATTR_RESOURCE_NAME, DEFAULT_RESOURCE_NAME,
             RESOURCE_CLASS);
@@ -134,6 +144,9 @@
         addVar(varInfos, data, ATTR_SLING_NAME,
             DEFAULT_SLING_NAME, SLING_CLASS);
 
+        addVar(varInfos, data, ATTR_LOG_NAME,
+                DEFAULT_LOG_NAME, LOG_CLASS);
+
         return varInfos.toArray(new VariableInfo[varInfos.size()]);
 
     }

Modified: incubator/sling/trunk/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/DefineObjectsTag.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/DefineObjectsTag.java?rev=654501&r1=654500&r2=654501&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/DefineObjectsTag.java (original)
+++ incubator/sling/trunk/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/DefineObjectsTag.java Thu May  8 05:10:48 2008
@@ -17,14 +17,12 @@
 package org.apache.sling.scripting.jsp.taglib;
 
 import javax.jcr.Node;
+import javax.script.Bindings;
 import javax.servlet.jsp.tagext.TagSupport;
 
-import org.apache.sling.api.SlingHttpServletRequest;
-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.scripting.SlingBindings;
 import org.apache.sling.api.scripting.SlingScriptHelper;
-import org.apache.sling.scripting.jsp.util.TagUtil;
 
 /**
  */
@@ -66,10 +64,10 @@
     public static final String DEFAULT_MAPPED_OBJECT_NAME = "object";
 
     /**
-     * Default name for the scripting variable referencing the current
-     * <code>ResourceResolver</code> (value is "resourceResolver").
+     * Default name for the scripting variable referencing the log
+     * <code>org.slf4j.Logger</code> (value is "log").
      */
-    public static final String DEFAULT_RESOURCE_RESOLVER_NAME = "resourceResolver";
+    public static final String DEFAULT_LOG_NAME = "log";
 
     /**
      * Default name for the scripting variable referencing the current
@@ -77,6 +75,12 @@
      */
     public static final String DEFAULT_SLING_NAME = "sling";
 
+    /**
+     * Default name for the scripting variable referencing the current
+     * <code>ResourceResolver</code> (value is "resourceResolver").
+     */
+    public static final String DEFAULT_RESOURCE_RESOLVER_NAME = "resourceResolver";
+
     private String requestName = DEFAULT_REQUEST_NAME;
 
     private String responseName = DEFAULT_RESPONSE_NAME;
@@ -89,10 +93,12 @@
 
     private String mappedObjectClass = null;
 
-    private String resourceResolverName = DEFAULT_RESOURCE_RESOLVER_NAME;
-
     private String slingName = DEFAULT_SLING_NAME;
 
+    private String logName = DEFAULT_LOG_NAME;
+
+    private String resourceResolverName = DEFAULT_RESOURCE_RESOLVER_NAME;
+
     /**
      * Default constructor.
      */
@@ -105,27 +111,25 @@
      * <li><code>SlingHttpServletRequest</code>
      * <li><code>SlingHttpServletResponse</code>
      * <li>current <code>Resource</code>
-     * <li>current <code>Node</code> (if resource is a NodeProvider)
-     * <li>current <code>ResourceResolver</code>
+     * <li>current <code>Node</code> (if resource is adaptable to a node)
+     * <li>current <code>Logger</code>
      * <li>current <code>SlingScriptHelper</code>
      * </ul>
      *
      * @return always {@link #EVAL_PAGE}.
      */
     public int doEndTag() {
+        final Bindings bindings = (Bindings)pageContext.getRequest().getAttribute(Bindings.class.getName());
+        final SlingScriptHelper scriptHelper = (SlingScriptHelper)bindings.get(SlingBindings.SLING);
 
-        SlingHttpServletRequest req = TagUtil.getRequest(pageContext);
-        SlingHttpServletResponse res = TagUtil.getResponse(pageContext);
-        Resource resource = req.getResource();
-        ResourceResolver resourceResolver = TagUtil.getResourceResolver(pageContext);
-
-        pageContext.setAttribute(requestName, req);
-        pageContext.setAttribute(responseName, res);
+        pageContext.setAttribute(requestName, scriptHelper.getRequest());
+        pageContext.setAttribute(responseName, scriptHelper.getResponse());
+        final Resource resource = scriptHelper.getRequest().getResource();
         pageContext.setAttribute(resourceName, resource);
-        pageContext.setAttribute(resourceResolverName, resourceResolver);
-        pageContext.setAttribute(slingName, req.getAttribute(SlingScriptHelper.class.getName()));
-
-        Node node = resource.adaptTo(Node.class);
+        pageContext.setAttribute(resourceResolverName, scriptHelper.getRequest().getResourceResolver());
+        pageContext.setAttribute(slingName, scriptHelper);
+        pageContext.setAttribute(logName, bindings.get(SlingBindings.LOG));
+        final Node node = resource.adaptTo(Node.class);
         if (node != null) {
             pageContext.setAttribute(nodeName, node);
         }
@@ -167,11 +171,15 @@
         this.mappedObjectClass = name;
     }
 
-    public void setResourceResolverName(String name) {
-        this.resourceResolverName = name;
+    public void setLogName(String name) {
+        this.logName = name;
     }
 
     public void setSlingName(String name) {
         this.slingName = name;
     }
+
+    public void setResourceResolverName(String name) {
+        this.resourceResolverName = name;
+    }
 }

Modified: incubator/sling/trunk/scripting/jsp-taglib/src/main/resources/META-INF/taglib.tld
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp-taglib/src/main/resources/META-INF/taglib.tld?rev=654501&r1=654500&r2=654501&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jsp-taglib/src/main/resources/META-INF/taglib.tld (original)
+++ incubator/sling/trunk/scripting/jsp-taglib/src/main/resources/META-INF/taglib.tld Thu May  8 05:10:48 2008
@@ -22,14 +22,14 @@
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
     version="2.0">
 
-    <description>A tab library for Sling support</description>
+    <description>A supporting tab library for Apache Sling</description>
     <tlib-version>1.0</tlib-version>
     <short-name>sling</short-name>
     <uri>http://sling.apache.org/taglibs/sling/1.0</uri>
 
     <tag>
         <description>
-            Includes a Content rendering into the current page
+            Includes a resource rendering into the current page
         </description>
         <name>include</name>
         <tag-class>
@@ -47,9 +47,9 @@
         </attribute>
         <attribute>
             <description>
-                The Resource object to include in the current request
+                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.
+                both are specified, the resource takes precedences.
             </description>
             <name>resource</name>
             <required>false</required>
@@ -58,12 +58,12 @@
         </attribute>
         <attribute>
             <description>
-                The path to the Resource object to include in the current
+                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
-                Component is including the given Resource. Either resource
+                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.
+                resource takes precedences.
             </description>
             <name>path</name>
             <required>false</required>
@@ -73,10 +73,10 @@
             <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
+                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,
+                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>
@@ -119,6 +119,11 @@
             <rtexprvalue>false</rtexprvalue>
         </attribute>
         <attribute>
+            <name>logName</name>
+            <required>false</required>
+            <rtexprvalue>false</rtexprvalue>
+        </attribute>
+        <attribute>
             <name>mappedObjectName</name>
             <required>false</required>
             <rtexprvalue>false</rtexprvalue>

Modified: incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java?rev=654501&r1=654500&r2=654501&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java (original)
+++ incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java Thu May  8 05:10:48 2008
@@ -123,12 +123,12 @@
      * @throws SlingServletException
      * @throws SlingIOException
      */
-    private void callJsp(SlingScriptHelper scriptHelper) {
+    private void callJsp(Bindings bindings, SlingScriptHelper scriptHelper) {
 
         ioProvider.setRequestResourceResolver(scriptHelper.getRequest().getResourceResolver());
         try {
             JspServletWrapperAdapter jsp = getJspWrapperAdapter(scriptHelper);
-            jsp.service(scriptHelper);
+            jsp.service(bindings);
         } finally {
             ioProvider.resetRequestResourceResolver();
         }
@@ -271,7 +271,7 @@
             SlingScriptHelper scriptHelper = (SlingScriptHelper) props.get(SLING);
             if (scriptHelper != null) {
                 try {
-                    callJsp(scriptHelper);
+                    callJsp(props, scriptHelper);
                 } catch (Exception e) {
                     throw new ScriptException(e);
                 }

Modified: incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletWrapperAdapter.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletWrapperAdapter.java?rev=654501&r1=654500&r2=654501&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletWrapperAdapter.java (original)
+++ incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletWrapperAdapter.java Thu May  8 05:10:48 2008
@@ -18,15 +18,17 @@
 
 import java.io.IOException;
 
+import javax.script.Bindings;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.sling.api.SlingException;
 import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
 import org.apache.sling.api.SlingIOException;
 import org.apache.sling.api.SlingServletException;
-import org.apache.sling.api.scripting.SlingScriptHelper;
+import org.apache.sling.api.scripting.SlingBindings;
 import org.apache.sling.scripting.jsp.jasper.Constants;
 import org.apache.sling.scripting.jsp.jasper.JasperException;
 import org.apache.sling.scripting.jsp.jasper.Options;
@@ -45,18 +47,18 @@
     }
 
     /**
-     * @param scriptHelper
+     * @param bindings
      * @throws SlingIOException
      * @throws SlingServletException
      * @throws IllegalArgumentException if the Jasper Precompile controller
      *             request parameter has an illegal value.
      */
-    public void service(SlingScriptHelper scriptHelper) {
-        final SlingHttpServletRequest request = scriptHelper.getRequest();
-        final Object oldValue = request.getAttribute(SlingScriptHelper.class.getName());
+    public void service(Bindings bindings) {
+        final SlingHttpServletRequest request = (SlingHttpServletRequest) bindings.get(SlingBindings.REQUEST);
+        final Object oldValue = request.getAttribute(Bindings.class.getName());
         try {
-            request.setAttribute(SlingScriptHelper.class.getName(), scriptHelper);
-            service(request, scriptHelper.getResponse(), preCompile(request));
+            request.setAttribute(Bindings.class.getName(), bindings);
+            service(request, (SlingHttpServletResponse)bindings.get(SlingBindings.RESPONSE), preCompile(request));
         } catch (SlingException se) {
             // rethrow as is
             throw se;
@@ -65,7 +67,7 @@
         } catch (ServletException se) {
             throw new SlingServletException(se);
         } finally {
-            request.setAttribute(SlingScriptHelper.class.getName(), oldValue);
+            request.setAttribute(Bindings.class.getName(), oldValue);
         }
     }
 

Modified: incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/util/TagUtil.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/util/TagUtil.java?rev=654501&r1=654500&r2=654501&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/util/TagUtil.java (original)
+++ incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/util/TagUtil.java Thu May  8 05:10:48 2008
@@ -25,7 +25,6 @@
 
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.SlingHttpServletResponse;
-import org.apache.sling.api.resource.ResourceResolver;
 import org.slf4j.Logger;
 
 /**
@@ -112,13 +111,4 @@
 
         return (SlingHttpServletResponse) req;
     }
-
-    public static ResourceResolver getResourceResolver(PageContext pageContext) {
-        try {
-            SlingHttpServletRequest request = getRequest(pageContext);
-            return request.getResourceResolver();
-        } catch (ClassCastException cce) {
-            throw new IllegalStateException("resource resolver wrong class");
-        }
-    }
 }
\ No newline at end of file