KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > bridge > jsp > taglib > pageflow > LeafFileTag


1 /*
2  
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5  
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8  
9  */

10 package org.mmbase.bridge.jsp.taglib.pageflow;
11
12 import org.mmbase.bridge.jsp.taglib.util.Attribute;
13 import javax.servlet.jsp.JspTagException JavaDoc;
14
15 import org.mmbase.util.logging.Logger;
16 import org.mmbase.util.logging.Logging;
17
18 /**
19  * Like IncludeTag, but an entire tree of files is being probed to find the one
20  * that has the most specified value.
21  *
22  * This is a taglib-implementation of the 'LEAFFILE' command.
23  * A full description of this command can be found in the mmbase-taglib.xml file.
24  *
25  * Note that the interesting functionality is implemented in the 'TreeHelper' class.
26  * @author Johannes Verelst
27  * @version $Id: LeafFileTag.java,v 1.15 2006/07/17 15:38:47 johannes Exp $
28  */

29
30 public class LeafFileTag extends UrlTag {
31     
32     private static final Logger log = Logging.getLoggerInstance(LeafFileTag.class);
33     protected Attribute objectList = Attribute.NULL;
34     protected TreeHelper th = new TreeHelper();
35
36     protected Attribute notFound = Attribute.NULL;
37
38     public void setNotfound(String JavaDoc n) throws JspTagException JavaDoc {
39         notFound = getAttribute(n);
40     }
41
42     public int doStartTag() throws JspTagException JavaDoc {
43         if (page == Attribute.NULL) {
44             throw new JspTagException JavaDoc("Attribute 'page' was not specified");
45         }
46         if (objectList == Attribute.NULL) {
47             throw new JspTagException JavaDoc("Attribute 'objectlist' was not specified");
48         }
49         return super.doStartTag();
50     }
51     protected String JavaDoc getPage() throws JspTagException JavaDoc {
52         String JavaDoc orgPage = super.getPage();
53         String JavaDoc leafPage = th.findLeafFile(orgPage, objectList.getString(this), pageContext.getSession());
54         if (log.isDebugEnabled()) {
55             log.debug("Retrieving page '" + leafPage + "'");
56         }
57
58         if (leafPage == null || "".equals(leafPage)) {
59             throw new JspTagException JavaDoc("Could not find page " + orgPage);
60         }
61
62         return leafPage;
63     }
64
65     public int doEndTag() throws JspTagException JavaDoc {
66         th.setCloud(getCloudVar());
67         int retval = super.doEndTag();
68         return retval;
69     }
70
71     public void doFinally() {
72         th.doFinally();
73         super.doFinally();
74     }
75     
76     public void setObjectlist(String JavaDoc p) throws JspTagException JavaDoc {
77         objectList = getAttribute(p);
78     }
79
80     protected String JavaDoc getUrl(boolean writeamp, boolean encode) throws JspTagException JavaDoc {
81         String JavaDoc url = "";
82         try {
83             url = super.getUrl(writeamp, encode);
84         } catch (JspTagException JavaDoc e) {
85             if (!notFound.getString(this).equals("skip")) {
86                 throw(e);
87             }
88         }
89         return url;
90     }
91     
92     // override to cancel
93
protected boolean doMakeRelative() {
94         log.debug("doMakeRelative() overridden!");
95         return false;
96     }
97 }
98
Popular Tags