Author: sshyrkov
Date: Mon Jan 21 17:42:14 2008
New Revision: 19555

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D19555&repname=
=3Djahia
Log:
Adde <jahiaHtml:executeSuper/> tag to call the parent (iverriden) JSP when =
using <jahiaHtml:include/> tag

Added:
    branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/inclu=
de/ExecuteSuperTag.java
Modified:
    branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/data/beans/Te=
mplatePathResolverBean.java
    branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/services/temp=
lates/JahiaTemplateManagerService.java
    branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/inclu=
de/IncludeTag.java
    branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/WEB-INF/etc/taglibs/j=
ahia-html.tld

Modified: branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/data/be=
ans/TemplatePathResolverBean.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-INCLUD=
E-TAG-BRANCH/core/src/java/org/jahia/data/beans/TemplatePathResolverBean.ja=
va&rev=3D19555&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/data/beans/Te=
mplatePathResolverBean.java (original)
+++ branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/data/beans/Te=
mplatePathResolverBean.java Mon Jan 21 17:42:14 2008
@@ -101,6 +101,23 @@
     }
 =

     /**
+     * Looks up the overriden JSP (from the parent template package) by the
+     * specified servlet path name (current JSP path) or <code>null</code>=
 if
+     * not found.
+     * =

+     * @param jspPath
+     *            current JSP path
+     * @return the overriden JSP (from the parent template package) by the
+     *         specified servlet path name (current JSP path) or
+     *         <code>null</code> if not found
+     */
+    public String lookupOverriden(String jspPath) {
+        return ServicesRegistry.getInstance().getJahiaTemplateManagerServi=
ce()
+                .resolveOverridenResourcePathByServletPath(jspPath,
+                        templatePackageName);
+    }
+    =

+    /**
      * Resolves the specified path (which is related to the root folder of=
 the
      * template set) into the actual path, considering template set inheri=
tance.
      * =


Modified: branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/service=
s/templates/JahiaTemplateManagerService.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-INCLUD=
E-TAG-BRANCH/core/src/java/org/jahia/services/templates/JahiaTemplateManage=
rService.java&rev=3D19555&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/services/temp=
lates/JahiaTemplateManagerService.java (original)
+++ branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/services/temp=
lates/JahiaTemplateManagerService.java Mon Jan 21 17:42:14 2008
@@ -391,6 +391,55 @@
         return resolveResourcePath(resource,
                 getTemplatePackage(templatePackageName));
     }
+    =

+    /**
+     * Returns the overriden resource path (related to the Web context),
+     * resolved using template package inheritance or <code>null</code>, in
+     * case the specifiied resource can not found. I.e. it returns the res=
ource
+     * that is overriden by the specified resource in any of the parent te=
mpalte
+     * sets.
+     * =

+     * @see org.jahia.taglibs.include.ExecuteSuperTag
+     * @param jspServletPath
+     *            the resource name or path related to the template pckage=
 root
+     *            folder
+     * @param templatePackageName
+     *            template set name of the current site
+     * @return the overriden resource path (related to the Web context),
+     *         resolved using template package inheritance or <code>null</=
code>,
+     *         in case the specifiied resource can not found
+     */
+    public String resolveOverridenResourcePathByServletPath(String jspServ=
letPath,
+            String templatePackageName) {
+
+        if (null =3D=3D jspServletPath || null =3D=3D templatePackageName)=
 {
+            throw new IllegalArgumentException(
+                    "Either servletPath, templatePackageName or both are n=
ull");
+        }
+
+        String path =3D null;
+
+        JahiaTemplatesPackage currentPkg =3D getTemplatePackage(templatePa=
ckageName);
+        if (currentPkg !=3D null) {
+            JahiaTemplatesPackage foundPackage =3D null;
+            String resource =3D null;
+            for (String pkgName : currentPkg.getHierarchy()) {
+                JahiaTemplatesPackage pkg =3D getTemplatePackage(pkgName);
+                String rootFolder =3D pkg.getRootFolderPath();
+                if (jspServletPath.startsWith(rootFolder)) {
+                    // found the template package
+                    foundPackage =3D pkg;
+                    resource =3D jspServletPath.substring(rootFolder.lengt=
h());
+                    break;
+                }
+            }
+            if (foundPackage !=3D null && foundPackage.getExtends() !=3D n=
ull) {
+                path =3D resolveResourcePath(resource, foundPackage.getExt=
ends());
+            }
+        }
+
+        return path;
+    }
 =

     public void serializeTemplateDeploymentDescriptor(
             JahiaTemplatesPackage pkg, Writer writer)

Added: branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/in=
clude/ExecuteSuperTag.java
URL: https://svndev.jahia.net/websvn/filedetails.php?path=3D/branches/JAHIA=
-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/include/ExecuteSuperTag=
.java&rev=3D19555&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/inclu=
de/ExecuteSuperTag.java (added)
+++ branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/inclu=
de/ExecuteSuperTag.java Mon Jan 21 17:42:14 2008
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2002-2007 Jahia Ltd
+ *
+ * Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (J=
CDDL), =

+ * Version 1.0 (the "License"), or (at your option) any later version; you=
 may =

+ * not use this file except in compliance with the License. You should hav=
e =

+ * received a copy of the License along with this program; if not, you may=
 obtain =

+ * a copy of the License at =

+ *
+ *  http://www.jahia.org/license/
+ *
+ * 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.jahia.taglibs.include;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspTagException;
+
+/**
+ * Tag handler for executing a JSP with the same name as the current one f=
rom
+ * the parent template set. Consider this tag as an equivalent of the Java
+ * constructor overriding:
+ * =

+ * <pre>
+ * public class Child extends Parent {
+ * =

+ *     public Child() {
+ *         super();
+ *         // initialization of this instance
+ *     }
+ * }
+ * </pre>
+ * =

+ * This tag does the same as the call <code>super()</code> in the example
+ * above.
+ * =

+ * @author Sergiy Shyrkov
+ */
+public class ExecuteSuperTag extends IncludeTag {
+
+    private boolean found;
+
+    @Override
+    public int doEndTag() throws JspException {
+        return found ? super.doEndTag() : EVAL_PAGE;
+    }
+
+    @Override
+    public int doStartTag() throws JspException {
+        found =3D false;
+        HttpServletRequest request =3D (HttpServletRequest) pageContext
+                .getRequest();
+        String jspPath =3D (String) (request
+                .getAttribute("javax.servlet.include.servlet_path") !=3D n=
ull ? request
+                .getAttribute("javax.servlet.include.servlet_path")
+                : request.getServletPath());
+
+        if (jspPath !=3D null) {
+            String path =3D getTemplatePathResolver().lookupOverriden(jspP=
ath);
+            if (path !=3D null) {
+                this.url =3D path;
+                found =3D true;
+            }
+        }
+
+        return found ? super.doStartTag() : SKIP_BODY;
+    }
+
+    protected String getResolvedPath(String page) throws JspTagException {
+        String lookupPath =3D page;
+        int questionMarkPosition =3D page.indexOf('?');
+        // path includes parameters?
+        if (questionMarkPosition !=3D -1) {
+            // get path to '?'
+            lookupPath =3D page.substring(0, questionMarkPosition);
+        }
+        String resolvedPath =3D getTemplatePathResolver().lookup(lookupPat=
h);
+        return questionMarkPosition !=3D -1 ? resolvedPath
+                + page.substring(questionMarkPosition) : resolvedPath;
+    }
+
+}

Modified: branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs=
/include/IncludeTag.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-INCLUD=
E-TAG-BRANCH/core/src/java/org/jahia/taglibs/include/IncludeTag.java&rev=3D=
19555&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/inclu=
de/IncludeTag.java (original)
+++ branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/inclu=
de/IncludeTag.java Mon Jan 21 17:42:14 2008
@@ -99,7 +99,7 @@
 =

     }
 =

-    private String getResolvedPath(String page) throws JspTagException {
+    protected String getResolvedPath(String page) throws JspTagException {
         String lookupPath =3D page;
         int questionMarkPosition =3D page.indexOf('?');
         // path includes parameters?
@@ -112,7 +112,7 @@
                 + page.substring(questionMarkPosition) : resolvedPath;
     }
 =

-    private TemplatePathResolverBean getTemplatePathResolver()
+    protected TemplatePathResolverBean getTemplatePathResolver()
             throws JspTagException {
         TemplatePathResolverBean resolverBean =3D null;
         JahiaBean jahiaBean =3D (JahiaBean) pageContext.getAttribute("jahi=
a",

Modified: branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/WEB-INF/etc/tag=
libs/jahia-html.tld
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-INCLUD=
E-TAG-BRANCH/core/src/webapp/WEB-INF/etc/taglibs/jahia-html.tld&rev=3D19555=
&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/WEB-INF/etc/taglibs/j=
ahia-html.tld (original)
+++ branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/WEB-INF/etc/taglibs/j=
ahia-html.tld Mon Jan 21 17:42:14 2008
@@ -711,6 +711,12 @@
             <rtexprvalue>true</rtexprvalue>
         </attribute>
     </tag>
+    <tag>
+        <name>executeSuper</name>
+        <tagclass>org.jahia.taglibs.include.ExecuteSuperTag</tagclass>
+        <info>Used to call the overriden JSP from the parent set. Does not=
hing, if it is not found.
+        </info>
+    </tag>
 =

     <tag>
         <name>remove-html-tags</name>

_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list

Reply via email to