001: /*
002: * (C) Copyright 2000 - 2006 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: package com.nabhinc.portal.processor;
020:
021: import java.io.IOException;
022: import java.io.Writer;
023:
024: import javax.servlet.ServletException;
025: import javax.servlet.http.HttpServletRequest;
026: import javax.servlet.http.HttpServletResponse;
027:
028: import com.nabhinc.portal.core.PortalConstants;
029: import com.nabhinc.portal.core.SessionCache;
030: import com.nabhinc.portal.model.CompositeRenderable;
031: import com.nabhinc.portal.model.NavigationalLayout;
032: import com.nabhinc.portal.model.PortalApplication;
033: import com.nabhinc.portal.model.PortalApplicationView;
034: import com.nabhinc.portal.model.PortalConfiguration;
035: import com.nabhinc.portal.model.PortalPageState;
036: import com.nabhinc.portal.model.PortletWindow;
037: import com.nabhinc.portal.model.Renderable;
038:
039: // Adds a portlet to a column in RenderableMap
040: /**
041: * Adds a new option
042: *
043: * @author Padmanabh Dabke
044: * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
045: */
046: public class AddOptionProcessor extends EditPagePortalActionProcessor {
047: public static final String OPTION_TYPE_PARAM = "option_type";
048:
049: public static final String URL_PARAM = "option_url";
050:
051: public static final String LABEL_PARAM = "option_label";
052:
053: public static final String LEVEL_PARAM = "option_level";
054:
055: public static final String ADD_TYPE_HEADER = "add_header";
056:
057: public static final String ADD_TYPE_URL = "add_url";
058:
059: public static final String ADD_TYPE_RENDERABLE = "add_content";
060:
061: public static final String PORTLET_NAME_PARAM = "portlet_name";
062:
063: public void process(HttpServletRequest request,
064: HttpServletResponse response, SessionCache sCache,
065: PortalApplicationView portalAppView,
066: PortalPageState pageState, int startIndex,
067: String[] portalParams, String displayMode,
068: String targetWindowId, boolean isAJAXRequest)
069: throws ServletException, IOException {
070:
071: if (!isAJAXRequest) {
072: response.sendRedirect(pageState.getPageURL());
073: return;
074: } else if (request.getParameter("is_submit") == null) {
075: request.getRequestDispatcher("/admin/new_option.jsp")
076: .forward(request, response);
077: return;
078: }
079:
080: String portletName = request.getParameter(PORTLET_NAME_PARAM);
081: String colId = request.getParameter("renderable_id");
082: CompositeRenderable targetR = (CompositeRenderable) pageState.portalPage
083: .getRenderable(colId);
084: Renderable r = null;
085: String optionLabel = request.getParameter(LABEL_PARAM);
086: if (request.getParameter(ADD_TYPE_HEADER) != null) {
087: ((NavigationalLayout) targetR).addHeader(optionLabel);
088: } else if (request.getParameter(ADD_TYPE_URL) != null) {
089: ((NavigationalLayout) targetR).addExternalLink(optionLabel,
090: request.getParameter(URL_PARAM));
091: } else {
092: if (portletName.endsWith(".jsp")) {
093: PortalApplication portalApp = portalAppView
094: .getPortalApplication();
095: try {
096: r = PortalConfiguration.getInstance()
097: .getRenderableForTemplate(portletName);
098: } catch (Exception e) {
099: throw new ServletException(
100: "Failed to create a composite renderable instance.",
101: e);
102: }
103: r.setTemplate(portletName);
104: targetR.addContent(r, optionLabel);
105: r.computeTemplatePath(request.getSession()
106: .getServletContext(), portalApp.getPath(),
107: portalApp.getTheme());
108: r.setPortalPage(pageState.portalPage);
109:
110: } else {
111: PortletWindow pWindow = new PortletWindow(
112: pageState.portalPage, portletName);
113: PortalApplication portalApp = portalAppView
114: .getPortalApplication();
115: // Must add content before invoking computeTemplatePath since
116: // the parent container sets the template.
117: targetR.addContent(pWindow, optionLabel);
118: pWindow.computeTemplatePath(request.getSession()
119: .getServletContext(), portalApp.getPath(),
120: portalApp.getTheme());
121: r = pWindow;
122: }
123: }
124:
125: if (isAJAXRequest) {
126: Writer w = response.getWriter();
127: if (r == null) {
128: w.write("ok");
129: } else {
130: request
131: .setAttribute(
132: PortalConstants.CURRENT_RENDERABLE_ATTRIBUTE,
133: r);
134: w.write("<div id=\"");
135: w.write(PortalConstants.PORTLET_NODE_ID_PREFIX);
136: w.write(r.getNumericId());
137: w.write("\">");
138: w.flush();
139: request.getRequestDispatcher(r.getTemplatePath())
140: .include(request, response);
141: w.flush();
142: w.write("</div>");
143: }
144: } else {
145: ViewProcessor.getInstance().process(request, response,
146: sCache, portalAppView, pageState, startIndex,
147: portalParams, displayMode, targetWindowId,
148: isAJAXRequest);
149: }
150: }
151: }
|