KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > deprecated > taglibs > field > page > IfNotPageInPathTag


1 package org.jahia.deprecated.taglibs.field.page;
2
3 import java.io.IOException JavaDoc;
4 import java.util.Enumeration JavaDoc;
5
6 import javax.servlet.ServletRequest JavaDoc;
7 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
8
9 import org.jahia.data.JahiaData;
10 import org.jahia.exceptions.JahiaException;
11 import org.jahia.services.pages.JahiaPage;
12 import org.jahia.utils.JahiaConsole;
13
14
15 /**
16  * Class IfNotPageInPathTag : evaluates the body only if the given page is not in the
17  * path of the current page.
18  * This tag must be enclosed inside a PageField tag.
19  * This tag is the "else" part of the "IfPageInPath" tag.
20  *
21  * @author Jerome Tamiotti
22  */

23 public class IfNotPageInPathTag extends BodyTagSupport JavaDoc {
24
25     public int doStartTag() {
26
27         // looks for the enclosing PageField tag
28
PageFieldTag parent = (PageFieldTag) findAncestorWithClass(this, PageFieldTag.class);
29         if (parent == null) {
30             return SKIP_BODY;
31         }
32         JahiaPage thePage = parent.getPage();
33         if (thePage != null) {
34
35             ServletRequest JavaDoc request = pageContext.getRequest();
36             JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData");
37             // loops through the current path
38
try {
39                 Enumeration JavaDoc thePath = jData.page().getPagePath(jData.params().getOperationMode(), jData.params().getUser());
40                 while (thePath.hasMoreElements()) {
41                     JahiaPage aPage = (JahiaPage) thePath.nextElement();
42                     if (aPage.getID() == thePage.getID()) {
43                         return SKIP_BODY;
44                     }
45                 }
46             } catch (JahiaException je) {
47                 JahiaConsole.println("IfNotPageInPathTag: doStartTag ",je.toString());
48             }
49             return EVAL_BODY_BUFFERED;
50         } else {
51             return SKIP_BODY;
52         }
53     }
54
55
56     public int doAfterBody() {
57         try {
58             bodyContent.writeOut(bodyContent.getEnclosingWriter());
59         } catch (IOException JavaDoc ioe) {
60             JahiaConsole.println("IfNotPageInPathTag: doAfterBody ",ioe.toString());
61         }
62         return SKIP_BODY;
63     }
64
65 }
66
Popular Tags