001: /*
002: * (C) Copyright 2000 - 2003 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019:
020: package com.nabhinc.portal.model;
021:
022: import javax.portlet.ActionRequest;
023: import javax.xml.bind.Unmarshaller;
024: import javax.xml.bind.annotation.XmlRootElement;
025:
026: import com.nabhinc.util.StringUtil;
027:
028: /**
029: * Represents a Web page layout in which there is a menu of portlets.
030: *
031: * @author Padmanabh Dabke
032: * (c) 2002 Nabh Information Systems, Inc. All Rights Reserved.
033: */
034: @XmlRootElement(name="menu")
035: public class MenuLayout extends NavigationalLayout {
036:
037: public MenuLayout() {
038: init();
039: }
040:
041: public MenuLayout(PortalPage p) {
042: super (p);
043: init();
044: }
045:
046: private void init() {
047: setTemplate("menu.jsp");
048: this .bprComponentTemplate = "menu_content.jsp";
049: }
050:
051: /**
052: * Modify the contents of this layout based on the form data submitted
053: * via HttpServletRequest.
054: * Creation date: (4/8/2002 11:06:14 PM)
055: * @param req javax.servlet.http.HttpServletRequest
056: */
057: @SuppressWarnings("unchecked")
058: public void modify(ActionRequest req) {
059:
060: int deleteIndex = -1;
061: int updownIndex = -1;
062: NavigationOption[] oldOptions = navOptions;
063: NavigationOption temp = null;
064:
065: /*
066: * Case 1: User is reordering the menu options.
067: */
068:
069: for (int i = 0; i < navOptions.length; i++) {
070: if (req.getParameter("upoption" + i) != null)
071: updownIndex = i;
072: }
073:
074: if (updownIndex != -1) {
075: if (updownIndex == 0 || updownIndex >= navOptions.length)
076: return;
077: temp = navOptions[updownIndex];
078: navOptions[updownIndex] = navOptions[updownIndex - 1];
079: navOptions[updownIndex - 1] = temp;
080: return;
081:
082: }
083:
084: updownIndex = -1;
085: for (int i = 0; i < navOptions.length; i++) {
086: if (req.getParameter("downoption" + i) != null)
087: updownIndex = i;
088: }
089:
090: if (updownIndex != -1) {
091: if (updownIndex > navOptions.length - 2)
092: return;
093: temp = navOptions[updownIndex];
094: navOptions[updownIndex] = navOptions[updownIndex + 1];
095: navOptions[updownIndex + 1] = temp;
096: return;
097:
098: }
099:
100: /*
101: * Case 2: User is attempting to delete a menu option.
102: */
103:
104: for (int i = 0; i < navOptions.length; i++) {
105: if (req.getParameter("deleteoption" + i) != null)
106: deleteIndex = i;
107: }
108:
109: if (deleteIndex != -1) {
110: try {
111: if (deleteIndex > -1 && deleteIndex < navOptions.length) {
112: navOptions = new NavigationOption[oldOptions.length - 1];
113:
114: for (int i = 0; i < deleteIndex; i++) {
115: navOptions[i] = oldOptions[i];
116: }
117:
118: for (int i = deleteIndex; i < navOptions.length; i++) {
119: navOptions[i] = oldOptions[i + 1];
120: }
121: }
122: setRowIndex(this .rowIndex);
123: } catch (Exception ex) {
124: }
125:
126: return;
127: }
128:
129: String action = req.getParameter("action");
130: int portletIndex = -1;
131: try {
132: portletIndex = Integer.parseInt(req
133: .getParameter("portletindex"));
134: } catch (Exception ex) {
135: }
136:
137: if ("hidetitle".equals(action)) {
138: if (portletIndex != -1)
139: navOptions[portletIndex].renderable
140: .setTitleShown(false);
141: return;
142: } else if ("showtitle".equals(action)) {
143: if (portletIndex != -1)
144: navOptions[portletIndex].renderable.setTitleShown(true);
145: return;
146: } else if ("hideborder".equals(action)) {
147: if (portletIndex != -1)
148: navOptions[portletIndex].renderable.setBorderWidth(0);
149: return;
150: } else if ("showborder".equals(action)) {
151: if (portletIndex != -1)
152: navOptions[portletIndex].renderable.setBorderWidth(1);
153: return;
154: }
155: /*
156: * Case 3: User is trying to add a menu option.
157: */
158:
159: if (req.getParameter("addoption") != null) {
160: NavigationOption newOption = new NavigationOption();
161: String pName = req.getParameter("newportlet");
162: String label = req.getParameter("newlabel");
163: String url = req.getParameter("newurl");
164:
165: if (label == null || label.trim().equals(""))
166: label = "sb.portal.menu_layout.option.no_label";
167: newOption.label = label;
168:
169: if (StringUtil.isNullOrEmpty(pName)) {
170: if (StringUtil.isNotNullOrEmpty(url)) {
171: newOption.url = url;
172: newOption.type = NavigationOption.OPTION_TYPE_URL;
173: } else {
174: return;
175: }
176: } else if ("com.nabhinc.portal.menu_header".equals(pName)) {
177: newOption.type = NavigationOption.OPTION_TYPE_HEADER;
178: } else {
179: newOption.type = NavigationOption.OPTION_TYPE_PORTLET;
180: newOption.renderable = createRenderable(pName, req,
181: "main_border", "main_title");
182: }
183:
184: navOptions = new NavigationOption[oldOptions.length + 1];
185: for (int i = 0; i < oldOptions.length; i++) {
186: navOptions[i] = oldOptions[i];
187: }
188: navOptions[oldOptions.length] = newOption;
189:
190: return;
191: }
192:
193: /*
194: * Case 4: User is trying to save
195: */
196: String newPageName = req.getParameter("pagename");
197: if (newPageName != null && (!newPageName.trim().equals(""))) {
198: getPortalPage().setName(newPageName.trim());
199: }
200:
201: try {
202: int rs = Integer.parseInt(req.getParameter("refresh"));
203: setRefreshSeconds(rs);
204: } catch (Exception ex) {
205: setRefreshSeconds(-1);
206: }
207:
208: /*
209: * Case 4a: User is trying to modify a label
210: */
211:
212: for (int i = 0; i < navOptions.length; i++) {
213: String temp2 = req.getParameter("label" + i);
214: if (temp2 != null && (!temp2.trim().equals("")))
215: navOptions[i].label = temp2;
216: }
217:
218: }
219:
220: public String getLayoutType() {
221: return "menu";
222: }
223:
224: // It seems like Sun's JAXB implementation does not pick up the afterUnmarshal
225: // method on a superclass. As a result, we have to define it here, even though
226: // it is not adding anything to the superclass implementation :-(
227: public void afterUnmarshal(Unmarshaller um, Object parent) {
228: super.afterUnmarshal(um, parent);
229: }
230:
231: }
|