001: /*
002: * (C) Copyright 2004 Nabh Information Systems, Inc.
003: *
004: * All copyright notices regarding Nabh's products MUST remain
005: * intact in the scripts and in the outputted HTML.
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021: package com.nabhinc.portlet.mvcportlet.taglib;
022:
023: import java.util.Vector;
024:
025: import javax.portlet.RenderRequest;
026: import javax.portlet.RenderResponse;
027: import javax.servlet.ServletRequest;
028: import javax.servlet.jsp.JspException;
029: import javax.servlet.jsp.JspWriter;
030: import javax.servlet.jsp.tagext.TagSupport;
031:
032: import com.nabhinc.portlet.mvcportlet.core.Constants;
033: import com.nabhinc.portlet.mvcportlet.core.ControllerPortletConfig;
034: import com.nabhinc.portlet.mvcportlet.core.NavigationNodeState;
035: import com.nabhinc.portlet.mvcportlet.core.RenderConfig;
036: import com.nabhinc.util.StringUtil;
037:
038: /**
039: * Navigation node tag (displayed as a link).
040: *
041: * @author Padmanabh Dabke
042: * (c) 2004 Nabh Information Systems, Inc. All Rights Reserved.
043: */
044: public class NavTag extends TagSupport {
045: private String rutNodeDelimiter = " » ";
046: private String rutNameDelimiter = ": ";
047: private String rutStyle = null;
048: private String rutStyleClass = null;
049: private String rutTitle = null;
050:
051: public void release() {
052: super .release();
053: rutNodeDelimiter = " » ";
054: rutNameDelimiter = ": ";
055: rutStyle = null;
056: rutStyleClass = null;
057: rutTitle = null;
058: }
059:
060: /**
061: * Returns the delimiter between navigation nodes.
062: * @return
063: */
064: public String getNodeDelimiter() {
065: return rutNodeDelimiter;
066: }
067:
068: /**
069: * Sets the delimiter between navigation nodes.
070: * Default is <code>&nbsp;&raquo;&nbsp;</code>
071: * @param delim
072: */
073: public void setNodeDelimiter(String delim) {
074: rutNodeDelimiter = delim;
075: }
076:
077: /**
078: * Returns the delimiter between navigation node's label and param name.
079: * @return
080: */
081: public String getNameDelimiter() {
082: return rutNameDelimiter;
083: }
084:
085: /**
086: * Sets the delimiter between the navigation node's label and param name.
087: * Default is <code>:&nbsp;</code>
088: * @param delim
089: */
090: public void setNameDelimiter(String delim) {
091: rutNameDelimiter = delim;
092: }
093:
094: /**
095: * @return Returns the inline CSS style.
096: */
097: public String getStyle() {
098: return rutStyle;
099: }
100:
101: /**
102: * @param style Inline stylesheet to set.
103: */
104: public void setStyle(String style) {
105: rutStyle = style;
106: }
107:
108: /**
109: * @return Returns the stylesheet class.
110: */
111: public String getStyleClass() {
112: return rutStyleClass;
113: }
114:
115: /**
116: * Sets the stylesheet class name
117: * @param styleClass The stylesheet class to set.
118: */
119: public void setStyleClass(String styleClass) {
120: rutStyleClass = styleClass;
121: }
122:
123: /**
124: * Returns the title text (text displayed in a tool tip)
125: * @return The title text .
126: */
127: public String getTitle() {
128: return rutTitle;
129: }
130:
131: /**
132: * Sets the title text that serves as text to be displayed in a tool tip.
133: * @param title The title text to set.
134: */
135: public void setTitle(String title) {
136: rutTitle = title;
137: }
138:
139: public int doStartTag() throws JspException {
140:
141: try {
142: ServletRequest sRequest = pageContext.getRequest();
143: RenderResponse response = (RenderResponse) sRequest
144: .getAttribute("javax.portlet.response");
145: RenderRequest request = (RenderRequest) sRequest
146: .getAttribute("javax.portlet.request");
147: RenderConfig rConfig = (RenderConfig) request
148: .getAttribute(Constants.RENDER_CONFIG_ATTRIB);
149: ControllerPortletConfig config = (ControllerPortletConfig) request
150: .getAttribute(Constants.PORTLET_CONFIG_ATTRIB);
151: String pMode = request.getPortletMode().toString()
152: .toLowerCase();
153: // NavigationNode[] nav = rConfig.getNavigationNodes();
154: Vector navVec = (Vector) request.getPortletSession()
155: .getAttribute(Constants.NAV_PATH_ATTRIB + pMode);
156: if (navVec == null || navVec.size() == 0)
157: return SKIP_BODY;
158:
159: JspWriter out = pageContext.getOut();
160: int num = navVec.size() - 1;
161: for (int i = 0; i < num; i++) {
162: NavigationNodeState node = (NavigationNodeState) navVec
163: .elementAt(i);
164: // PortletURL url = node.createURL(request, response);
165: out.print("<a href=\"");
166: out.print(node.getRenderURL());
167: out.print("\" ");
168:
169: if (rutTitle != null) {
170: out.print("title=\"");
171: out.print(rutTitle);
172: out.print("\" ");
173: }
174:
175: if (rutStyle != null) {
176: out.print("style=\"");
177: out.print(rutStyle);
178: out.print("\" ");
179: }
180:
181: if (rutStyleClass != null) {
182: out.print("class=\"");
183: out.print(rutStyleClass);
184: out.print("\" ");
185: }
186: out.print(">");
187: out.print(config.getLocalizedMessage(node.getLabel(),
188: request));
189: //String nameParam = node.getNameParam();
190: //if (nameParam != null) {
191: // out.print(rutNameDelimiter);
192: // out.print(request.getParameter(nameParam));
193: //}
194: String instanceLabel = node.getInstanceLabel();
195: if (StringUtil.isNotNullOrEmpty(instanceLabel)) {
196: out.print(rutNameDelimiter);
197: out.print(instanceLabel);
198: }
199: out.print("</a>");
200: out.print(rutNodeDelimiter);
201: }
202: NavigationNodeState node = (NavigationNodeState) navVec
203: .elementAt(navVec.size() - 1);
204: out.print(config.getLocalizedMessage(node.getLabel(),
205: request));
206: String instanceLabel = node.getInstanceLabel();
207: if (StringUtil.isNotNullOrEmpty(instanceLabel)) {
208: out.print(rutNameDelimiter);
209: out.print(instanceLabel);
210: }
211:
212: } catch (Exception ex) {
213: throw new JspException(ex);
214: }
215:
216: return SKIP_BODY;
217: }
218:
219: public int doEndTag() {
220: return EVAL_PAGE;
221: }
222:
223: }
|