001: /*
002: * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Portal/Sources/es/udc/mypersonalizer/portal/controller/actions/content/FindWorkspaceLayoutAction.java,v 1.1.1.1 2004/03/25 12:08:40 fbellas Exp $
003: * $Revision: 1.1.1.1 $
004: * $Date: 2004/03/25 12:08:40 $
005: *
006: * =============================================================================
007: *
008: * Copyright (c) 2003, The MyPersonalizer Development Group
009: * (http://www.tic.udc.es/~fbellas/mypersonalizer/index.html) at
010: * University Of A Coruna
011: * All rights reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions are met:
015: *
016: * - Redistributions of source code must retain the above copyright notice,
017: * this list of conditions and the following disclaimer.
018: *
019: * - Redistributions in binary form must reproduce the above copyright notice,
020: * this list of conditions and the following disclaimer in the documentation
021: * and/or other materials provided with the distribution.
022: *
023: * - Neither the name of the University Of A Coruna nor the names of its
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
028: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
029: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
030: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
031: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
032: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
033: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
034: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
035: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
036: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
037: * POSSIBILITY OF SUCH DAMAGE.
038: *
039: */
040:
041: package es.udc.mypersonalizer.portal.controller.actions.content;
042:
043: import java.util.ArrayList;
044: import java.util.HashMap;
045: import java.util.Iterator;
046: import java.util.List;
047: import java.util.Map;
048:
049: import javax.servlet.http.HttpServletRequest;
050: import javax.servlet.http.HttpServletResponse;
051:
052: import org.apache.struts.action.ActionErrors;
053: import org.apache.struts.action.ActionForm;
054: import org.apache.struts.action.ActionForward;
055: import org.apache.struts.action.ActionMapping;
056:
057: import es.udc.mypersonalizer.kernel.controller.actions.DefaultAction;
058: import es.udc.mypersonalizer.kernel.model.editors.EditorFactory;
059: import es.udc.mypersonalizer.kernel.model.editors.ServiceKeys;
060: import es.udc.mypersonalizer.kernel.model.editors.WorkspaceLayoutEditor;
061: import es.udc.mypersonalizer.kernel.model.repository.interfaces.WorkspaceLayout;
062: import es.udc.mypersonalizer.portal.controller.session.SessionManager;
063: import es.udc.mypersonalizer.portal.conventions.RequestAttributeNames;
064: import es.udc.mypersonalizer.portal.model.permissions.UserCredentials;
065: import es.udc.mypersonalizer.portal.view.content.WorkspaceLayoutView;
066:
067: /**
068: * This action performs a lookup for the current layout of services in the
069: * workspace, so that it can be changed by the user. This action does not call
070: * the model, as it takes the necessary information from the workspace layout
071: * data stored in the session.<p>
072: *
073: * This action requires a <tt>Success</tt> forward, which will usually point
074: * to the jsp page which will display the details of the layout to the user.<p>
075: *
076: * When successful, this action populates the request (before performing
077: * any <i>forward</i> operation) with the following data:
078: * <ul>
079: * <li><tt>servicesLayoutView</tt>: a {@link
080: * es.udc.mypersonalizer.portal.view.content.WorkspaceLayoutView}
081: * object.</li>
082: * </ul>
083: *
084: * @author Daniel Fernandez
085: * @since 1.0
086: */
087: public class FindWorkspaceLayoutAction extends DefaultAction {
088:
089: protected ActionForward doExecute(ActionMapping mapping,
090: ActionForm form, HttpServletRequest request,
091: HttpServletResponse response) throws Exception {
092:
093: ActionErrors errors = new ActionErrors();
094:
095: /*
096: * If there are no workspaces, this action cannot be executed.
097: */
098: if (!SessionManager.getUserHasWorkspaces(request)) {
099: throw new NoActiveWorkspacesException(
100: "Cannot change contents");
101: }
102:
103: /* We get the action parameters from the session manager */
104: UserCredentials userCredentials = SessionManager
105: .getUserCredentials(request);
106: WorkspaceLayout currentWorkspaceLayout = SessionManager
107: .getCurrentWorkspaceLayout(request);
108:
109: /* We create an editor */
110: EditorFactory editorFactory = EditorFactory.getInstance();
111: WorkspaceLayoutEditor workspaceLayoutEditor = editorFactory
112: .createWorkspaceLayoutEditor(currentWorkspaceLayout
113: .getProperty());
114:
115: Map serviceKeys = workspaceLayoutEditor.getServiceKeys();
116:
117: Map servicesLayout = new HashMap();
118:
119: /*
120: * Next we perform a simple operation: iterate the contents of
121: * the ServiceKeys Map in the workspace layout building
122: * simultaneously the Map object we need, which will only contain
123: * the service identifiers.
124: */
125: Iterator serviceKeysIter = serviceKeys.entrySet().iterator();
126: while (serviceKeysIter.hasNext()) {
127:
128: Map.Entry serviceKeysEntry = (Map.Entry) serviceKeysIter
129: .next();
130: Integer area = (Integer) serviceKeysEntry.getKey();
131: List servicesForArea = (List) serviceKeysEntry.getValue();
132: List servicesLayoutForArea = new ArrayList();
133:
134: Iterator servicesForAreaIter = servicesForArea.iterator();
135: while (servicesForAreaIter.hasNext()) {
136:
137: ServiceKeys currentServiceKeys = (ServiceKeys) servicesForAreaIter
138: .next();
139: servicesLayoutForArea
140: .add(currentServiceKeys.getServicePropertyKey()
141: .getServiceIdentifier());
142:
143: }
144:
145: servicesLayout.put(area.toString(), servicesLayoutForArea);
146:
147: }
148:
149: /* Finally, we create the view object. */
150: WorkspaceLayoutView workspaceLayoutView = new WorkspaceLayoutView(
151: servicesLayout);
152:
153: /* The services layout gets into the request */
154: request
155: .setAttribute(
156: RequestAttributeNames.WORKSPACE_LAYOUT_VIEW_ATTRIBUTE_NAME,
157: workspaceLayoutView);
158:
159: return mapping
160: .findForward(DefaultAction.ACTION_SUCCESS_FORWARD);
161: }
162:
163: }
|