incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r581686 - in /incubator/sling/trunk/scripting-jsp-taglib/src/main: java/org/apache/sling/scripting/jsp/taglib/IncludeTagHandler.java resources/META-INF/taglib.tld
Date Wed, 03 Oct 2007 18:55:22 GMT
Author: fmeschbe
Date: Wed Oct  3 11:55:21 2007
New Revision: 581686

URL: http://svn.apache.org/viewvc?rev=581686&view=rev
Log:
SLING-34 Extend sling:include tag to allow for path specification and optional flushing

Modified:
    incubator/sling/trunk/scripting-jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/IncludeTagHandler.java
    incubator/sling/trunk/scripting-jsp-taglib/src/main/resources/META-INF/taglib.tld

Modified: incubator/sling/trunk/scripting-jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/IncludeTagHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting-jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/IncludeTagHandler.java?rev=581686&r1=581685&r2=581686&view=diff
==============================================================================
--- incubator/sling/trunk/scripting-jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/IncludeTagHandler.java
(original)
+++ incubator/sling/trunk/scripting-jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/IncludeTagHandler.java
Wed Oct  3 11:55:21 2007
@@ -18,13 +18,13 @@
 
 import java.io.IOException;
 
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
 import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.BodyContent;
 import javax.servlet.jsp.tagext.TagSupport;
 
-import org.apache.sling.component.Component;
-import org.apache.sling.component.ComponentException;
 import org.apache.sling.component.ComponentRequest;
-import org.apache.sling.component.ComponentRequestDispatcher;
 import org.apache.sling.component.ComponentResponse;
 import org.apache.sling.component.Content;
 import org.apache.sling.scripting.jsp.util.JspComponentResponseWrapper;
@@ -43,9 +43,15 @@
     /** default log */
     private static final Logger log = LoggerFactory.getLogger(IncludeTagHandler.class);
 
+    /** flush argument */
+    private boolean flush = false;
+
     /** content argument */
     private Content content;
 
+    /** path argument */
+    private String path;
+
     /**
      * Called after the body has been processed.
      *
@@ -55,29 +61,59 @@
         log.debug("IncludeTagHandler.doEndTag");
 
         // only try to include, if there is anything to include !!
-        if (this.content != null) {
+        ComponentRequest request = TagUtil.getRequest(pageContext);
+        RequestDispatcher dispatcher = null;
+        if (content != null) {
             // get the request dispatcher for the content object
-            Component component = TagUtil.getComponent(this.pageContext);
-            ComponentRequestDispatcher crd = component.getComponentContext().getRequestDispatcher(this.content);
+            dispatcher = request.getRequestDispatcher(content);
+            path = content.getPath();
+
+        } else if (path != null) {
+            // ensure the child path is absolute and assign the result to path
+            if (!path.startsWith("/")) {
+                path = request.getContent().getPath() + "/" + path;
+            }
+
+            // get the request dispatcher for the (relative) path
+            dispatcher = request.getRequestDispatcher(path);
+        }
+
+        try {
+
+            // optionally flush
+            if (flush && !(pageContext.getOut() instanceof BodyContent)) {
+                // might throw an IOException of course
+                pageContext.getOut().flush();
+            }
 
             // include the rendered content
-            try {
-                ComponentRequest request = TagUtil.getRequest(this.pageContext);
-                ComponentResponse response = new JspComponentResponseWrapper(this.pageContext);
-                crd.include(request, response);
-            } catch (IOException ioe) {
-                throw new JspException("Error including " + this.content, ioe);
-            } catch (ComponentException ce) {
-                throw new JspException("Error including " + this.content, TagUtil.getRootCause(ce));
+            if (dispatcher != null) {
+                ComponentResponse response = new JspComponentResponseWrapper(
+                    pageContext);
+                dispatcher.include(request, response);
+            } else {
+                TagUtil.log(log, pageContext, "No content to include...", null);
             }
-        } else {
-            TagUtil.log(log, this.pageContext, "No content to include...", null);
+
+        } catch (IOException ioe) {
+            throw new JspException("Error including " + path, ioe);
+        } catch (ServletException ce) {
+            throw new JspException("Error including " + path,
+                TagUtil.getRootCause(ce));
         }
 
         return EVAL_PAGE;
     }
 
+    public void setFlush(boolean flush) {
+        this.flush = flush;
+    }
+
     public void setContent(Content content) {
         this.content = content;
+    }
+
+    public void setPath(String path) {
+        this.path = path;
     }
 }

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=581686&r1=581685&r2=581686&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 Wed
Oct  3 11:55:21 2007
@@ -1,21 +1,21 @@
 <?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.
+    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"
@@ -37,10 +37,37 @@
         </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 Content object to include in the current request
+                processing. Either content or path must be specified. If
+                both are specified, the Content takes precedences.
+            </description>
             <name>content</name>
-            <required>true</required>
+            <required>false</required>
             <rtexprvalue>true</rtexprvalue>
             <type>org.apache.sling.component.Content</type>
+        </attribute>
+        <attribute>
+            <description>
+                The path to the Content object to include in the current
+                request processing. If this path is relative it is
+                appended to the path of the current Content whose
+                Component is including the given Content. Either content
+                or path must be specified. If both are specified, the
+                Content takes precedences.
+            </description>
+            <name>path</name>
+            <required>false</required>
+            <rtexprvalue>true</rtexprvalue>
         </attribute>
     </tag>
 



Mime
View raw message