Source code: com/RuntimeCollective/webapps/tag/TreeBreadcrumbTag.java
1 /* $Header: /home/CVS/rjp/src/com/RuntimeCollective/webapps/tag/TreeBreadcrumbTag.java,v 1.4 2003/09/30 15:13:18 joe Exp $
2 * $Revision: 1.4 $
3 * $Date: 2003/09/30 15:13:18 $
4 *
5 * ====================================================================
6 *
7 * Josephine : http://www.runtime-collective.com/josephine/index.html
8 *
9 * Copyright (C) 2003 Runtime Collective
10 *
11 * This product includes software developed by the
12 * Apache Software Foundation (http://www.apache.org/).
13 *
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 */
29
30 package com.RuntimeCollective.webapps.tag;
31
32 import com.RuntimeCollective.webapps.bean.EntityBean;
33 import com.RuntimeCollective.webapps.bean.TreeExtension;
34 import com.RuntimeCollective.webapps.RuntimeParameters;
35 import com.RuntimeCollective.webapps.tag.TagUtils;
36
37 import java.io.IOException;
38 import java.io.PrintStream;
39 import javax.servlet.jsp.JspWriter;
40 import javax.servlet.jsp.PageContext;
41 import javax.servlet.jsp.JspException;
42 import javax.servlet.jsp.JspTagException;
43 import javax.servlet.jsp.tagext.Tag;
44 import javax.servlet.jsp.tagext.TagSupport;
45 import javax.servlet.http.HttpServletRequest;
46 import javax.servlet.http.HttpServletResponse;
47
48 import org.apache.struts.action.Action;
49 import org.apache.struts.util.RequestUtils;
50 import org.apache.struts.taglib.html.BaseHandlerTag;
51
52 /**
53 * View the breadcrumb trail for a given TreeExtension.
54 * <p>
55 * This JSP tag takes the following attributes:
56 * <ul>
57 * <li> <code>name</code> - the name under which the TreeExtension is stored. </li>
58 * <li> <code>scope</code> - the scope under which the TreeExtension is stored [Optional]. </li>
59 * <li> <code>property</code> - if the TreeExtension is not stored in "name", but in "name.property" [Optional].</li>
60 * <li> <code>displayProperty</code> - the property to use to render each TreeExtension.getEntityBean() in the breadcrumb, defaults to "name".</li>
61 * <li> <code>displayPath</code> - the path to use to render the links in the breadcrumb (eg "/viewNode.jsp?id="), only relevent if asLinks is set to true [Optional].</li>
62 * <li> <code>asLinks</code> - whether the breadcrumb items are links to pages or not, default to false [Optional].</li>
63 * <li> <code>styleClass</code> - a CSS style type to use [Optional].</li>
64 * </ul>
65 *
66 * @version $Id: TreeBreadcrumbTag.java,v 1.4 2003/09/30 15:13:18 joe Exp $
67 */
68 public class TreeBreadcrumbTag extends BaseHandlerTag {
69
70 // == Properties ===================================================
71
72 protected String name = null;
73 public String getName() { return this.name; }
74 public void setName(String name) { this.name = name; }
75
76 protected String property = null;
77 public String getProperty() { return this.property; }
78 public void setProperty(String property) { this.property = property; }
79
80 protected String scope = null;
81 public String getScope() { return this.scope; }
82 public void setScope(String scope) { this.scope = scope; }
83
84 protected String displayProperty = "name";
85 public String getDisplayProperty() { return this.displayProperty; }
86 public void setDisplayProperty(String displayProperty) { this.displayProperty = displayProperty; }
87
88 protected String displayPath = "";
89 public String getDisplayPath() { return this.displayPath; }
90 public void setDisplayPath(String displayPath) { this.displayPath = displayPath; }
91
92 protected boolean asLinks = false;
93 public boolean getAsLinks() { return this.asLinks; }
94 public void setAsLinks(boolean asLinks) { this.asLinks = asLinks; }
95
96 protected String styleClass = null;
97 public String getStyleClass() { return this.styleClass; }
98 public void setStyleClass(String styleClass) { this.styleClass = styleClass; }
99
100
101
102 // == Tag methods ==================================
103
104 public int doStartTag() throws JspException {
105
106 // get the TreeExtension
107 TreeExtension ext = (TreeExtension) RequestUtils.lookup(pageContext, name, property, scope);
108 if (ext == null)
109 throw new JspTagException("Could not find the TreeExtension.");
110
111 // get the breadcrumb
112 String breadcrumb = ext.getBreadcrumb(pageContext, getDisplayProperty(), getDisplayPath(), getAsLinks(), getStyleClass());
113
114 // Construct a response
115 HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
116 try {
117 pageContext.getOut().println(breadcrumb);
118 } catch (IOException e) {
119 throw new JspTagException("I/O Exception " + e.getMessage() );
120 }
121
122 return SKIP_BODY;
123 }
124
125 public void release() {
126 super.release();
127 }
128 }