KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > crumb > CrumbsTag


1 package fr.improve.struts.taglib.layout.crumb;
2
3 import java.util.Iterator JavaDoc;
4
5 import javax.servlet.http.HttpServletRequest JavaDoc;
6 import javax.servlet.jsp.JspException JavaDoc;
7
8 import fr.improve.struts.taglib.layout.PanelTag;
9 import fr.improve.struts.taglib.layout.event.EndLayoutEvent;
10 import fr.improve.struts.taglib.layout.event.StartLayoutEvent;
11 import fr.improve.struts.taglib.layout.util.ICrumbRenderer;
12 import fr.improve.struts.taglib.layout.util.LayoutUtils;
13 import fr.improve.struts.taglib.layout.util.TagUtils;
14 /**
15  * Displays bread crumbs.
16  * @author: Jean-NoŽl Ribette
17  */

18 public class CrumbsTag extends PanelTag {
19     /**
20      * does the inner crumb tag need to display a crumb separator before displaying the crumb<br>
21      * false for the first crumb<br>
22      * true for the followers
23      */

24     protected boolean needSeparator = false;
25
26     /**
27      * the current crumb level calculated by counting the number of time needSeparator() is count.
28      * use to generate the css class to use for the crumbs
29      */

30     protected int level = 0;
31
32     /**
33      * the separator character<br>
34      * default: |
35      */

36     protected String JavaDoc separator = "|";
37
38     /**
39      * the css style clas to use if the sepatator is an image (in this case, the separator is defined as a background-image in the css file)
40      */

41      protected String JavaDoc separatorClass;
42      protected String JavaDoc separatorWidth;
43      protected String JavaDoc separatorHeight;
44      protected String JavaDoc separatorDivTag;
45      
46      /**
47       * If the crumbs should be taken in the context, name of the bean containing them.
48       */

49      protected String JavaDoc crumbsName;
50      protected String JavaDoc crumbsProperty;
51      
52     public int doEndLayoutTag() throws JspException JavaDoc {
53         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
54         if (crumbsName!=null && crumbsName.length()!=0) {
55             Iterator JavaDoc lc_iterator = LayoutUtils.getIterator(pageContext, crumbsName, crumbsProperty);
56             while (lc_iterator.hasNext()) {
57                 Crumb lc_crumb = (Crumb) lc_iterator.next();
58                 printCrumb(null, lc_crumb);
59             }
60         }
61         TagUtils.write(pageContext, buffer.toString());
62                         
63         ICrumbRenderer renderer = getSkin().getCrumbRenderer(getModel());
64         renderer.doEndCrumbs(pageContext, this);
65         
66         new EndLayoutEvent(this, null).send();
67         
68         // Reset the tag.
69
needSeparator = false;
70         level = 0;
71         
72         return EVAL_PAGE;
73     }
74     public int doStartLayoutTag() throws JspException JavaDoc {
75         new StartLayoutEvent(this, null).send();
76         ICrumbRenderer renderer = getSkin().getCrumbRenderer(getModel());
77         renderer.doStartCrumbs(pageContext, this);
78         return EVAL_BODY_INCLUDE;
79     }
80     public int getLevel() {
81         return level;
82     }
83     
84     /**
85      * Return the HTML crumb separator code.
86      * Only used by the default crumb renderer.
87      *
88      * @return java.lang.String
89      */

90     public java.lang.String JavaDoc getSeparator() {
91         if (separatorClass==null) return separator;
92         if (separatorDivTag==null) {
93             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
94             buffer.append("<div class=\"");
95             buffer.append(separatorClass);
96             buffer.append("\" width=\"");
97             buffer.append(separatorWidth);
98             buffer.append("\" height=\"");
99             buffer.append(separatorHeight);
100             buffer.append("\">&nbsp</div>");
101             separatorDivTag = buffer.toString();
102         }
103         return separatorDivTag;
104     }
105
106     /**
107      * Display a crumb.
108      * Use the crumb renderer to do that.
109      */

110     public void printCrumb(StringBuffer JavaDoc in_buffer, Crumb in_crumb) throws JspException JavaDoc {
111         ICrumbRenderer renderer = getSkin().getCrumbRenderer(getModel());
112         renderer.doRenderCrumb(pageContext, this, in_crumb);
113     }
114
115 /**
116  * Insert the method's description here.
117  * Creation date: (18/07/2001 14:38:59)
118  * @return java.lang.String
119  */

120 public java.lang.String JavaDoc getSeparatorClass() {
121     return separatorClass;
122 }
123 /**
124  * Insert the method's description here.
125  * Creation date: (18/07/2001 14:38:59)
126  * @return java.lang.String
127  */

128 public java.lang.String JavaDoc getSeparatorHeight() {
129     return separatorHeight;
130 }
131 /**
132  * Insert the method's description here.
133  * Creation date: (18/07/2001 14:38:59)
134  * @return java.lang.String
135  */

136 public java.lang.String JavaDoc getSeparatorWidth() {
137     return separatorWidth;
138 }
139     public boolean needSeparator() {
140         boolean value = needSeparator;
141         needSeparator = true;
142         level++;
143         return value;
144     }
145     public void release() {
146         super.release();
147         
148         needSeparator = false;
149         level = 0;
150         separatorClass = null;
151         separatorHeight = null;
152         separatorWidth = null;
153         separatorDivTag = null;
154         
155         crumbsName = null;
156         crumbsProperty = null;
157     }
158 /**
159  * Insert the method's description here.
160  * Creation date: (17/07/2001 17:01:10)
161  * @param newSeparator java.lang.String
162  */

163 public void setSeparator(java.lang.String JavaDoc newSeparator) {
164     separator = newSeparator;
165 }
166 /**
167  * Insert the method's description here.
168  * Creation date: (18/07/2001 14:38:59)
169  * @param newSeparatorClass java.lang.String
170  */

171 public void setSeparatorClass(java.lang.String JavaDoc newSeparatorClass) {
172     separatorClass = newSeparatorClass;
173 }
174 /**
175  * Insert the method's description here.
176  * Creation date: (18/07/2001 14:38:59)
177  * @param newSeparatorHeight java.lang.String
178  */

179 public void setSeparatorHeight(java.lang.String JavaDoc newSeparatorHeight) {
180     separatorHeight = newSeparatorHeight;
181 }
182 /**
183  * Insert the method's description here.
184  * Creation date: (18/07/2001 14:38:59)
185  * @param newSeparatorWidth java.lang.String
186  */

187 public void setSeparatorWidth(java.lang.String JavaDoc newSeparatorWidth) {
188     separatorWidth = newSeparatorWidth;
189 }
190     /**
191      * Gets the crumbsName.
192      * @return Returns a String
193      */

194     public String JavaDoc getCrumbsName() {
195         return crumbsName;
196     }
197
198     /**
199      * Sets the crumbsName.
200      * @param crumbsName The crumbsName to set
201      */

202     public void setCrumbsName(String JavaDoc crumbsName) {
203         this.crumbsName = crumbsName;
204     }
205
206     /**
207      * Gets the crumbsProperty.
208      * @return Returns a String
209      */

210     public String JavaDoc getCrumbsProperty() {
211         return crumbsProperty;
212     }
213
214     /**
215      * Sets the crumbsProperty.
216      * @param crumbsProperty The crumbsProperty to set
217      */

218     public void setCrumbsProperty(String JavaDoc crumbsProperty) {
219         this.crumbsProperty = crumbsProperty;
220     }
221
222 }
223
Popular Tags