KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > core > contentPage > CallAssignContentPageRolesAction


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.webapp.action.core.contentPage;
17
18 import com.blandware.atleap.common.Constants;
19 import com.blandware.atleap.model.core.ContentPage;
20 import com.blandware.atleap.model.core.Role;
21 import com.blandware.atleap.service.core.PageManager;
22 import com.blandware.atleap.service.core.RoleManager;
23 import com.blandware.atleap.webapp.action.core.BaseAction;
24 import com.blandware.atleap.webapp.form.core.SelectRolesForm;
25 import com.blandware.atleap.webapp.util.core.WebappConstants;
26 import org.apache.struts.action.ActionForm;
27 import org.apache.struts.action.ActionForward;
28 import org.apache.struts.action.ActionMapping;
29 import org.apache.struts.action.ActionMessage;
30 import org.apache.struts.action.ActionMessages;
31
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import java.util.List JavaDoc;
37
38 /**
39  * <p>Returns page with two lists to reassign roles to content page
40  * </p>
41  * <p><a HREF="CallAssignContentPageRolesAction.java.htm"><i>View Source</i></a></p>
42  * <p/>
43  *
44  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
45  * @version $Revision: 1.9 $ $Date: 2006/03/11 10:08:52 $
46  * @struts.action path="/core/contentPage/callAssignRoles"
47  * name="selectRolesForm"
48  * validate="false"
49  * roles="core-contentPage-assignRoles"
50  * @struts.action-forward name="assignRoles"
51  * path=".core.contentPage.assignRoles"
52  * @struts.action-forward name="listContentPages"
53  * path="/core/contentPage/list.do"
54  * redirect="true"
55  */

56 public final class CallAssignContentPageRolesAction extends BaseAction {
57     /**
58      * @param mapping The ActionMapping used to select this instance
59      * @param form The optional ActionForm bean for this request (if any)
60      * @param request The HTTP request we are proceeding
61      * @param response The HTTP response we are creating
62      * @return an ActionForward instance describing where and how
63      * control should be forwarded, or null if response
64      * has already been completed
65      */

66     public ActionForward execute(ActionMapping mapping, ActionForm form,
67                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
68
69         Long JavaDoc contentPageId = null;
70         if ( request.getParameter("contentPageId") != null ) {
71             contentPageId = Long.valueOf(request.getParameter("contentPageId"));
72         } else if ( request.getAttribute(WebappConstants.CONTENT_PAGE_ID_KEY) != null ) {
73             contentPageId = (Long JavaDoc) request.getAttribute(WebappConstants.CONTENT_PAGE_ID_KEY);
74         } else {
75             if ( log.isWarnEnabled() ) {
76                 log.warn("Missing content page ID. Returning to list...");
77             }
78             return mapping.findForward("listContentPages");
79         }
80
81         request.getSession().setAttribute(WebappConstants.CONTENT_PAGE_ID_KEY, contentPageId);
82
83         SelectRolesForm selectRolesForm = (SelectRolesForm) form;
84         PageManager pageManager = (PageManager) getBean(Constants.PAGE_MANAGER_BEAN);
85         ContentPage contentPage = pageManager.retrieveContentPage(contentPageId);
86
87         if ( contentPage == null ) {
88             // content page not found. it might be deleted by someone else
89
ActionMessages errors = new ActionMessages();
90             errors.add("contentPageNotFound", new ActionMessage("core.contentPage.errors.notFound"));
91             saveErrors(request, errors);
92             return mapping.findForward("listContentPages");
93         }
94
95         selectRolesForm.setVersion(contentPage.getVersion().toString());
96
97         List JavaDoc contentPageRoles = new ArrayList JavaDoc();
98         for ( Iterator JavaDoc i = contentPage.getRoles().iterator(); i.hasNext(); ) {
99             Role role = (Role) i.next();
100             contentPageRoles.add(role);
101         }
102
103         RoleManager roleManager = (RoleManager) getBean(Constants.ROLE_MANAGER_BEAN);
104         List JavaDoc availableRoles = roleManager.listRoles(null).asList();
105         List JavaDoc allRoles = new ArrayList JavaDoc(availableRoles);
106         availableRoles.removeAll(contentPageRoles);
107
108         selectRolesForm.setAvailableRolesList(availableRoles);
109         selectRolesForm.setSelectedRolesList(contentPageRoles);
110
111         request.setAttribute("allRoles", allRoles);
112
113         // save transaction token in request
114
saveToken(request);
115         return mapping.findForward("assignRoles");
116     }
117 }
Popular Tags