KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > core > contentResource > CallUpdateContentResourceAction


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.contentResource;
17
18 import com.blandware.atleap.webapp.action.core.BaseAction;
19 import com.blandware.atleap.webapp.util.core.WebappConstants;
20 import org.apache.struts.action.ActionForm;
21 import org.apache.struts.action.ActionForward;
22 import org.apache.struts.action.ActionMapping;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26
27 /**
28  * <p>Returns page with form to update content resource
29  * </p>
30  * <p><a HREF="CallUpdateContentResourceAction.java.htm"><i>View Source</i></a></p>
31  * <p/>
32  *
33  * @author Andrey Grebnev <a HREF="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
34  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
35  * @version $Revision: 1.16 $ $Date: 2006/03/10 17:10:21 $
36  * @struts.action name="uploadContentResourceForm"
37  * path="/core/contentResource/callUpdate"
38  * scope="request"
39  * input="listContentResources"
40  * validate="false"
41  * roles="core-contentResource-update, core-contentResource-view"
42  * @struts.action-forward name="updateContentResource"
43  * path=".core.contentResource.update"
44  * @struts.action-forward name="listContentResources"
45  * path="/core/contentResource/list.do"
46  * redirect="true"
47  */

48 public final class CallUpdateContentResourceAction extends BaseAction {
49
50     /**
51      * @param mapping The ActionMapping used to select this instance
52      * @param form The optional ActionForm bean for this request (if any)
53      * @param request The HTTP request we are proceeding
54      * @param response The HTTP response we are creating
55      * @return an ActionForward instance describing where and how
56      * control should be forwarded, or null if response
57      * has already been completed
58      */

59     public ActionForward execute(ActionMapping mapping, ActionForm form,
60                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
61         if ( isCancelled(request) ) {
62             resetToken(request);
63             return mapping.findForward("listContentResources");
64         }
65
66         if (!request.isUserInRole("core-contentResource-update")) {
67             response.sendError(HttpServletResponse.SC_FORBIDDEN);
68             return null;
69         }
70
71         Long JavaDoc contentResourceId = null;
72         if ( request.getParameter("id") != null ) {
73             contentResourceId = Long.valueOf(request.getParameter("id"));
74         } else if ( request.getSession().getAttribute(WebappConstants.CONTENT_RESOURCE_ID_KEY) != null ) {
75             contentResourceId = (Long JavaDoc) request.getSession().getAttribute(WebappConstants.CONTENT_RESOURCE_ID_KEY);
76         } else {
77             if ( log.isWarnEnabled() ) {
78                 log.warn("Missing content resource ID");
79             }
80             return mapping.findForward("listContentResources");
81         }
82
83         //put into session because the form with file field does not populate id if some error is occurred e.g. big file size
84
request.getSession().setAttribute(WebappConstants.CONTENT_RESOURCE_ID_KEY, contentResourceId);
85         saveToken(request);
86         return mapping.findForward("updateContentResource");
87     }
88 }
Popular Tags