Author: sshyrkov
Date: Thu Nov 15 20:52:48 2007
New Revision: 19171
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D19171&repname=
=3Djahia
Log:
Jahia Include Tag handler: initial version
Added:
branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/inclu=
de/
branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/inclu=
de/IncludeTag.java
branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/inclu=
de/ParamTag.java
Modified:
branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/data/beans/Te=
mplatePathResolverBean.java
branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/WEB-INF/etc/taglibs/j=
ahia-html.tld
branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/WEB-INF/var/shared_te=
mplates/basic.jar
branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/WEB-INF/var/shared_te=
mplates/custom_v1.jar
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=3D19171&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 Thu Nov 15 20:52:48 2007
@@ -82,7 +82,19 @@
* the unchanged path, if it is not found
*/
public Object get(Object key) {
- String path =3D (String) key;
+ return lookup((String) key);
+ }
+
+ /**
+ * Resolves the specified path (which is related to the root folder of=
the
+ * template set) into the actual path, considering template set inheri=
tance.
+ * =
+ * @param path
+ * the resource path to resolve
+ * @return the resolved path (context related) to the requested resour=
ce or
+ * the unchanged path, if it is not found
+ */
+ public String lookup(String path) {
String resolvedPath =3D resolvePath(path);
=
return resolvedPath !=3D null ? resolvedPath : path;
Added: branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/in=
clude/IncludeTag.java
URL: https://svndev.jahia.net/websvn/filedetails.php?path=3D/branches/JAHIA=
-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/include/IncludeTag.java=
&rev=3D19171&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 (added)
+++ branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/inclu=
de/IncludeTag.java Thu Nov 15 20:52:48 2007
@@ -0,0 +1,143 @@
+/*
+ * 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 java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+
+import javax.servlet.jsp.JspTagException;
+import javax.servlet.jsp.PageContext;
+
+import org.apache.taglibs.standard.tag.common.core.ImportSupport;
+import org.jahia.bin.Jahia;
+import org.jahia.data.beans.JahiaBean;
+import org.jahia.data.beans.TemplatePathResolverBean;
+import org.jahia.params.ProcessingContext;
+import org.jahia.services.templates.JahiaTemplateManagerService;
+
+/**
+ * Tag handler for looking up a resource in the template set hierarchy, st=
arting
+ * from the current template set root folder, then the parent template set=
and
+ * so on.
+ * =
+ * <pre>
+ * Consider the following example:
+ * =
+ * We have:
+ * 1) 'Basic templates' set with the root folder 'basic'
+ * 2) 'Custom templates v1' set with the root folder 'custom_v1'. T=
his template set extends the 'Basic templates'
+ * 3) Our current virtual site uses the 'Custom templates' template=
set
+ * =
+ * In one of our templates we make a call to this tag as follows:
+ * ...
+ * <jahia:include page=3D"common/header.jsp">
+ * <jahia:param name=3D"a" value=3D"1"=
/>
+ * <jahia:param name=3D"b" value=3D"test&qu=
ot;/>
+ * </jahia:include>
+ * ...
+ * =
+ * The result will be as follows, if:
+ * 1) the 'header.jsp' is found under custom_v1/common/header.jsp
+ * =
+ * <jsp:include page=3D"/jsp/jahia/templates/custom_v1/=
common/header.jsp">
+ * <jsp:param name=3D"a" value=3D"1"/&=
gt;
+ * <jsp:param name=3D"b" value=3D"test"=
;/>
+ * </jsp:include>
+ * =
+ * 2) the 'header.jsp' is found under basic/common/header.jsp (in =
the parent template set)
+ * =
+ * <jsp:include page=3D"/jsp/jahia/templates/basic/comm=
on/header.jsp">
+ * <jsp:param name=3D"a" value=3D"1"/&=
gt;
+ * <jsp:param name=3D"b" value=3D"test"=
;/>
+ * </jsp:include>
+ * =
+ * 3) the 'header.jsp' is not found --> the path remains unchang=
ed
+ * =
+ * <jsp:include page=3D"common/header.jsp">
+ * <jsp:param name=3D"a" value=3D"1"/&=
gt;
+ * <jsp:param name=3D"b" value=3D"test"=
;/>
+ * </jsp:include>
+ * </pre>
+ * =
+ * @author Sergiy Shyrkov
+ * @see JahiaTemplateManagerService
+ */
+public class IncludeTag extends ImportSupport {
+
+ /**
+ * Adds a parameters to the list.
+ * =
+ * @param name
+ * the name of the parameter
+ * @param value
+ * parameter value
+ */
+ public void addParameter(String name, String value) {
+ try {
+ super.addParameter(name, URLEncoder.encode(value, pageContext
+ .getResponse().getCharacterEncoding() !=3D null ? page=
Context
+ .getResponse().getCharacterEncoding() : Jahia.getSetti=
ngs()
+ .getDefaultResponseBodyEncoding()));
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalArgumentException(e);
+ }
+
+ }
+
+ private 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;
+ }
+
+ private TemplatePathResolverBean getTemplatePathResolver()
+ throws JspTagException {
+ TemplatePathResolverBean resolverBean =3D null;
+ JahiaBean jahiaBean =3D (JahiaBean) pageContext.getAttribute("jahi=
a",
+ PageContext.REQUEST_SCOPE);
+ if (jahiaBean !=3D null) {
+ resolverBean =3D jahiaBean.getIncludes().getTemplatePath();
+ } else {
+ ProcessingContext ctx =3D (ProcessingContext) pageContext
+ .getAttribute("org.jahia.data.JahiaParams",
+ PageContext.REQUEST_SCOPE);
+ if (ctx !=3D null && ctx.getSite() !=3D null) {
+ resolverBean =3D new TemplatePathResolverBean(ctx.getSite()
+ .getTemplatePackageName());
+ }
+ }
+
+ if (resolverBean =3D=3D null) {
+ throw new JspTagException(
+ "Unable to find any Jahia site related information");
+ }
+
+ return resolverBean;
+ }
+
+ public void setPage(String page) throws JspTagException {
+ this.url =3D getResolvedPath(page);
+ }
+}
Added: branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/in=
clude/ParamTag.java
URL: https://svndev.jahia.net/websvn/filedetails.php?path=3D/branches/JAHIA=
-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/include/ParamTag.java&r=
ev=3D19171&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/ParamTag.java (added)
+++ branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/taglibs/inclu=
de/ParamTag.java Thu Nov 15 20:52:48 2007
@@ -0,0 +1,77 @@
+/*
+ * 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.jsp.JspException;
+import javax.servlet.jsp.JspTagException;
+import javax.servlet.jsp.tagext.TagSupport;
+
+/**
+ * Tag handler for used in conjunction with [EMAIL PROTECTED] IncludeTag} to
pass
+ * additional parameters.
+ * =
+ * @author Sergiy Shyrkov
+ * @see IncludeTag
+ */
+public class ParamTag extends TagSupport {
+
+ private String name;
+
+ private String value;
+
+ /**
+ * Initializes an instance of this class.
+ */
+ public ParamTag() {
+ super();
+ init();
+ }
+
+ @Override
+ public int doStartTag() throws JspException {
+ IncludeTag includeTag =3D (IncludeTag) findAncestorWithClass(this,
+ IncludeTag.class);
+ if (includeTag =3D=3D null)
+ throw new JspTagException(
+ "ParamTag must be nested inside IncludeTag");
+
+ includeTag.addParameter(name, value);
+
+ return SKIP_BODY;
+ }
+
+ private void init() {
+ name =3D null;
+ value =3D null;
+ }
+
+ @Override
+ public void release() {
+ init();
+ super.release();
+ }
+
+ public void setName(String name) {
+ this.name =3D name;
+ }
+
+ public void setValue(String value) {
+ this.value =3D value;
+ }
+
+}
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=3D19171=
&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 Thu Nov 15 20:52:48 2007
@@ -644,4 +644,30 @@
<tagclass>org.jahia.taglibs.html.links.FileManagerLinkTag</tagclas=
s>
<info>Generates a full link to the Ajax filemanager</info>
</tag>
-</taglib>
+
+ <tag>
+ <name>include</name>
+ <tagclass>org.jahia.taglibs.include.IncludeTag</tagclass>
+ <info>Custom jsp:include implementation that resolves the specifie=
d template path considering template set inheritance</info>
+ <attribute>
+ <name>page</name>
+ <required>true</required>
+ <rtexprvalue>true</rtexprvalue>
+ </attribute>
+ </tag>
+ <tag>
+ <name>param</name>
+ <tagclass>org.jahia.taglibs.include.ParamTag</tagclass>
+ <info>Custom jsp:param implementation that is used in conjunction =
with 'include' to pass additional parameters</info>
+ <attribute>
+ <name>name</name>
+ <required>true</required>
+ <rtexprvalue>true</rtexprvalue>
+ </attribute>
+ <attribute>
+ <name>value</name>
+ <required>true</required>
+ <rtexprvalue>true</rtexprvalue>
+ </attribute>
+ </tag>
+</taglib>
\ No newline at end of file
Modified: branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/WEB-INF/var/sha=
red_templates/basic.jar
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-INCLUD=
E-TAG-BRANCH/core/src/webapp/WEB-INF/var/shared_templates/basic.jar&rev=3D1=
9171&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
Binary files - no diff available.
Modified: branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/WEB-INF/var/sha=
red_templates/custom_v1.jar
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-INCLUD=
E-TAG-BRANCH/core/src/webapp/WEB-INF/var/shared_templates/custom_v1.jar&rev=
=3D19171&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
Binary files - no diff available.
_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list