KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > bridge > jsp > taglib > tree > LeafConstraintsTag


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.tree;
11
12 import javax.servlet.jsp.JspTagException JavaDoc;
13
14 import org.mmbase.bridge.*;
15 import org.mmbase.storage.search.*;
16 import org.mmbase.bridge.jsp.taglib.containers.*;
17 import org.mmbase.bridge.jsp.taglib.util.*;
18 import org.mmbase.bridge.jsp.taglib.*;
19 import org.mmbase.bridge.util.*;
20
21 /**
22  * Sub-tag of tree container. Is itself a Query container. It makes it possible to set the 'search constraints on a tree'.
23  * Search constraints do not change the actual tree, but only the 'leaves'. So, it is kind of constraint only valid on the leaves.
24  * This makes it possible to easily search through a tree of objects.
25  *
26  * @author Michiel Meeuwissen
27  * @since MMBase-1.8
28  * @version $Id: LeafConstraintsTag.java,v 1.6 2006/03/14 17:56:24 michiel Exp $
29  */

30 public class LeafConstraintsTag extends ContextReferrerTag implements NodeQueryContainer, QueryContainerReferrer {
31
32     private static final int ON_TEMPLATE = 1;
33     private static final int ON_TRUNK = 2;
34     private Attribute container = Attribute.NULL;
35     private Attribute onAttribute = Attribute.NULL;
36     private int on = 1;
37     private NodeQuery trunkClone;
38
39     protected GrowingTreeList tree;
40
41     public void setContainer(String JavaDoc c) throws JspTagException JavaDoc {
42         container = getAttribute(c);
43     }
44
45     public void setOn(String JavaDoc c) throws JspTagException JavaDoc {
46         onAttribute = getAttribute(c);
47     }
48
49     public Query getQuery() {
50         return getNodeQuery();
51     }
52     public NodeQuery getNodeQuery() {
53         switch(on) {
54         case ON_TRUNK:
55             if (trunkClone == null) {
56                 trunkClone = (NodeQuery) tree.getLeafQuery().clone();
57                 trunkClone.setConstraint(null);
58             }
59             return trunkClone;
60         case ON_TEMPLATE:
61         default: return tree.getLeafTemplate();
62         }
63     }
64
65     public Cloud getCloudVar() throws JspTagException JavaDoc {
66         return getQuery().getCloud();
67     }
68
69
70     public int doStartTag() throws JspTagException JavaDoc {
71
72         String JavaDoc o = onAttribute.getString(this);
73         if ("".equals(o)) {
74             on = ON_TEMPLATE;
75         } else if ("template".equals(o)) {
76             on = ON_TEMPLATE;
77         } else if ("trunk".equals(o)) {
78             on = ON_TRUNK;
79         } else {
80             throw new JspTagException JavaDoc("Unknown value for 'on' attribute '" + o + "' (known are 'template' and 'trunk')");
81         }
82         tree = ((TreeContainerTag) findParentTag(TreeContainerTag.class, (String JavaDoc) container.getValue(this), true)).getTree();
83         return EVAL_BODY;
84     }
85
86     public int doAfterBody() throws JspTagException JavaDoc {
87         if(trunkClone != null) {
88             tree.setLeafConstraint(trunkClone.getConstraint());
89         }
90         // for garbage collection:
91
tree = null;
92         trunkClone = null;
93         if (EVAL_BODY == EVAL_BODY_BUFFERED) {
94             try {
95                 if (bodyContent != null) {
96                     bodyContent.writeOut(bodyContent.getEnclosingWriter());
97                 }
98             } catch (java.io.IOException JavaDoc ioe){
99                 throw new JspTagException JavaDoc(ioe.toString());
100             }
101         }
102         return SKIP_BODY;
103     }
104
105 }
106
Popular Tags