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.core;
022:
023: import java.io.Serializable;
024:
025: import javax.portlet.PortletException;
026: import javax.portlet.PortletURL;
027: import javax.portlet.RenderRequest;
028: import javax.portlet.RenderResponse;
029:
030: /**
031: * Represents a navigation node associated with a render type. The node can
032: * optionally have an id parameter and a name parameter. These parameters are
033: * used in creating a link that points to the corresponding render type.
034: *
035: * @author Padmanabh Dabke
036: * (c) 2004 Nabh Information Systems, Inc. All Rights Reserved.
037: */
038: public class NavigationNode implements Serializable {
039: /**
040: *
041: */
042: private static final long serialVersionUID = -4671105869971437564L;
043: public static final int LINK_TYPE_RENDER = 0;
044: public static final int LINK_TYPE_ACTION = 1;
045: private int nnLinkTypeCode = LINK_TYPE_RENDER;
046: private String nnLabel = null;
047: private String nnIdParam = null;
048: private String nnNameParam = null;
049: private String nnRequestType = null;
050: private boolean nnResetPath = false;
051:
052: public NavigationNode() {
053:
054: }
055:
056: public NavigationNode(String label, String idParam,
057: String nameParam, String linkType, String reqType)
058: throws PortletException {
059: if (label == null || label.equals("")) {
060: throw new PortletException(
061: "Missing required attribute label in NavigationNode config.");
062: }
063: nnLabel = label;
064: nnIdParam = idParam;
065: nnNameParam = nameParam;
066: nnRequestType = reqType;
067:
068: if ("".equals(nnIdParam))
069: nnIdParam = null;
070: if ("".equals(nnNameParam))
071: nnNameParam = null;
072: if ("".equals(nnRequestType))
073: nnRequestType = null;
074: if ("action".equals(linkType))
075: nnLinkTypeCode = LINK_TYPE_ACTION;
076:
077: }
078:
079: public String getRequestType() {
080: return nnRequestType;
081: }
082:
083: public void setRequestType(String reqType) {
084: nnRequestType = reqType;
085: }
086:
087: public String getLinkType() {
088: if (nnLinkTypeCode == LINK_TYPE_RENDER) {
089: return "render";
090: } else {
091: return "action";
092: }
093: }
094:
095: public void setLinkType(String linkType) {
096: if ("action".equals(linkType))
097: nnLinkTypeCode = LINK_TYPE_ACTION;
098: }
099:
100: public String getLabel() {
101: return nnLabel;
102: }
103:
104: public void setLabel(String label) {
105: nnLabel = label;
106: }
107:
108: public String getIdParam() {
109: return nnIdParam;
110: }
111:
112: public void setIdParam(String param) {
113: nnIdParam = param;
114: }
115:
116: public String getNameParam() {
117: return nnNameParam;
118: }
119:
120: public void setNameParam(String param) {
121: nnNameParam = param;
122: }
123:
124: public boolean isResetPath() {
125: return nnResetPath;
126: }
127:
128: public void setResetPath(boolean flag) {
129: nnResetPath = flag;
130: }
131:
132: public PortletURL createURL(RenderRequest request,
133: RenderResponse response) {
134: PortletURL url = null;
135: if (nnLinkTypeCode == LINK_TYPE_RENDER) {
136: url = response.createRenderURL();
137: } else {
138: url = response.createActionURL();
139: }
140:
141: if (nnRequestType != null) {
142: url.setParameter(Constants.REQUEST_TYPE_PARAM,
143: nnRequestType);
144: }
145: if (nnIdParam != null) {
146: url
147: .setParameter(nnIdParam, request
148: .getParameter(nnIdParam));
149: }
150: if (nnNameParam != null) {
151: url.setParameter(nnNameParam, request
152: .getParameter(nnNameParam));
153: }
154: url.setParameter(Constants.POP_NODES_PARAM, "true");
155: return url;
156: }
157: }
|