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:
023: import javax.servlet.ServletException;
024: import javax.servlet.http.HttpServletRequest;
025: import javax.servlet.http.HttpServletResponse;
026:
027: import com.nabhinc.condition.AlwaysTrue;
028: import com.nabhinc.condition.Condition;
029: import com.nabhinc.portal.api.EntityLockedException;
030: import com.nabhinc.portal.api.PortalInformationStore;
031: import com.nabhinc.portal.api.PortalInformationStoreLocator;
032: import com.nabhinc.portal.core.PortalEventMonitor;
033: import com.nabhinc.portal.core.PortalConstants;
034: import com.nabhinc.portal.core.PortalUtil;
035: import com.nabhinc.portal.core.SessionCache;
036: import com.nabhinc.portal.model.PortalApplication;
037: import com.nabhinc.portal.model.PortalApplicationView;
038: import com.nabhinc.portal.model.PortalConfiguration;
039: import com.nabhinc.portal.model.PortalPageState;
040: import com.nabhinc.util.StringUtil;
041: import com.nabhinc.ws.core.WebServiceSecurityException;
042:
043: /**
044: *
045: *
046: * @author Padmanabh Dabke
047: * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
048: */
049: public class EditPortalAppProcessor extends
050: AdminAppPortalActionProcessor {
051: public void process(HttpServletRequest request,
052: HttpServletResponse response, SessionCache sCache,
053: PortalApplicationView portalAppView,
054: PortalPageState pageState, int startIndex,
055: String[] portalParams, String displayMode,
056: String targetWindowId, boolean isAJAXRequest)
057: throws ServletException, IOException {
058:
059: String errorMessage = "";
060: if (!isAJAXRequest) {
061: response.sendRedirect(pageState.getPageURL());
062: return;
063: } else if (request.getParameter("is_submit") == null) {
064: request.getRequestDispatcher("/admin/edit_portal_app.jsp")
065: .forward(request, response);
066: return;
067: }// else {
068: PortalApplication portalApp = portalAppView
069: .getPortalApplication();
070: String appTitle = request
071: .getParameter(PortalConstants.TITLE_PARAM);
072: if (StringUtil.isNotNullOrEmpty(appTitle))
073: portalApp.setTitle(appTitle);
074:
075: String appTagline = request
076: .getParameter(PortalConstants.TAGLINE_PARAM);
077: if (StringUtil.isNotNullOrEmpty(appTagline))
078: portalApp.setTagline(appTagline);
079:
080: String appTheme = request
081: .getParameter(PortalConstants.THEME_PARAM);
082: if (StringUtil.isNotNullOrEmpty(appTheme)) {
083: portalApp.setTheme(appTheme);
084: PortalUtil.setTemplatePaths(portalApp, request);
085: }
086:
087: if (request.getParameter(PortalConstants.REMOVE_PASSWORD_PARAM) != null) {
088: portalApp.setPassword(null);
089: }
090: String password = request
091: .getParameter(PortalConstants.PASSWORD_PARAM);
092: if (StringUtil.isNotNullOrEmpty(password)) {
093: portalApp.setPassword(password);
094: }
095:
096: String editPerm = request
097: .getParameter(PortalConstants.EDIT_PERM_TYPE_PARAM);
098: if (StringUtil.isNotNullOrEmpty(editPerm)) {
099: try {
100: portalApp.setEditPermission(PortalUtil.createCondition(
101: request, editPerm,
102: PortalConstants.EDIT_ROLES_PARAM,
103: PortalConstants.EDIT_USERS_PARAM));
104: } catch (IllegalArgumentException ex) {
105: errorMessage += "- Edit Permission: " + ex.getMessage()
106: + "\n";
107: }
108: }
109: String viewPerm = request
110: .getParameter(PortalConstants.VIEW_PERM_TYPE_PARAM);
111: if (StringUtil.isNotNullOrEmpty(viewPerm)) {
112: Condition oldCondition = portalApp.getViewPermission();
113: try {
114: portalApp.setViewPermission(PortalUtil.createCondition(
115: request, viewPerm,
116: PortalConstants.VIEW_ROLES_PARAM,
117: PortalConstants.VIEW_USERS_PARAM));
118: Condition newCondition = portalApp.getViewPermission();
119: boolean oldFlag = oldCondition != null
120: && (!(oldCondition instanceof AlwaysTrue));
121: boolean newFlag = newCondition != null
122: && (!(newCondition instanceof AlwaysTrue));
123: if (oldFlag != newFlag) {
124: PortalEventMonitor monitor = PortalConfiguration
125: .getInstance().getEventMonitor();
126: if (monitor != null)
127: monitor.viewPermissionChanged(portalApp
128: .getPath());
129: }
130: } catch (IllegalArgumentException ex) {
131: errorMessage += "- View Permission: " + ex.getMessage()
132: + "\n";
133: }
134: }
135: String dPerm = request
136: .getParameter(PortalConstants.DELETE_PERM_TYPE_PARAM);
137: if (StringUtil.isNotNullOrEmpty(dPerm)) {
138: try {
139: portalApp.setDeletePermission(PortalUtil
140: .createCondition(request, dPerm,
141: PortalConstants.DELETE_ROLES_PARAM,
142: PortalConstants.DELETE_USERS_PARAM));
143: } catch (IllegalArgumentException ex) {
144: errorMessage += "- Delete Permission: "
145: + ex.getMessage() + "\n";
146: }
147: }
148: String cPerm = request
149: .getParameter(PortalConstants.CREATE_PSITE_PERM_TYPE_PARAM);
150: if (StringUtil.isNotNullOrEmpty(cPerm)) {
151: try {
152: portalApp
153: .setCreatePsitePermission(PortalUtil
154: .createCondition(
155: request,
156: cPerm,
157: PortalConstants.CREATE_PSITE_ROLES_PARAM,
158: PortalConstants.CREATE_PSITE_USERS_PARAM));
159: } catch (IllegalArgumentException ex) {
160: errorMessage += "- Create Permission: "
161: + ex.getMessage() + "\n";
162: }
163: }
164:
165: String logoPath = request
166: .getParameter(PortalConstants.LOGO_IMAGE_PARAM);
167: if (StringUtil.isNotNullOrEmpty(logoPath)) {
168: portalApp.setLogo(logoPath.trim());
169: } else {
170: portalApp.setLogo(null);
171: }
172:
173: String headerStyle = request
174: .getParameter(PortalConstants.HEADER_STYLE_PARAM);
175: if (StringUtil
176: .isNotNullOrEmpty(PortalConstants.HEADER_STYLE_PARAM)) {
177: portalApp.setHeaderStyle(headerStyle.trim());
178: } else {
179: portalApp.setHeaderStyle("");
180: }
181:
182: if (StringUtil.isNullOrEmpty(request
183: .getParameter(PortalConstants.DISPLAY_TITLE_PARAM))) {
184: portalApp.setDisplayTitle(false);
185: } else {
186: portalApp.setDisplayTitle(true);
187: }
188:
189: String memberStr = request
190: .getParameter(PortalConstants.MEMBERS_PARAM);
191: String[] members = null;
192: if (StringUtil.isNotNullOrEmpty(memberStr)) {
193: members = StringUtil.split(memberStr, "\n \t\r");
194: }
195:
196: if (!"".equals(errorMessage)) {
197: response.getWriter().write(
198: "Errors occurred:\n" + errorMessage);
199: return;
200: }
201:
202: try {
203: PortalInformationStore store = PortalInformationStoreLocator
204: .getPortalInformationStore();
205: store.setPortalApplicationMembers(portalApp.getPath(),
206: members);
207: if (request.getParameter(PortalConstants.LOCK_PSITE_PARAM) != null) {
208: store.lockPortalApplication(portalApp.getPath());
209: } else if (request
210: .getParameter(PortalConstants.UNLOCK_PSITE_PARAM) != null) {
211: store.unlockPortalApplication(portalApp.getPath());
212: }
213:
214: } catch (WebServiceSecurityException e) {
215: } catch (EntityLockedException e) {
216: // TODO Auto-generated catch block
217: e.printStackTrace();
218: }
219: response.getWriter().write("ok");
220: /*if (! oldTheme.equals(appTheme)) */
221: // PortalUtil.redirectRequest(pageState.getPageURL(), response, isAJAXRequest);
222: //}
223: }
224:
225: }
|