KickJava   Java API By Example, From Geeks To Geeks.

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


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.image;
17
18 import com.blandware.atleap.common.Constants;
19 import com.blandware.atleap.model.core.ContentResource;
20 import com.blandware.atleap.service.core.ContentResourceManager;
21 import com.blandware.atleap.webapp.action.core.BaseAction;
22 import com.blandware.atleap.webapp.form.core.ImageForm;
23 import com.blandware.atleap.webapp.util.core.WebappConstants;
24 import org.apache.struts.action.ActionForm;
25 import org.apache.struts.action.ActionForward;
26 import org.apache.struts.action.ActionMapping;
27 import org.apache.struts.action.ActionMessage;
28 import org.apache.struts.action.ActionMessages;
29
30 import javax.servlet.http.HttpServletRequest JavaDoc;
31 import javax.servlet.http.HttpServletResponse JavaDoc;
32
33 /**
34  * <p>View image
35  * </p>
36  * <p><a HREF="ViewImageAction.java.htm"><i>View Source</i></a></p>
37  * <p/>
38  *
39  * @author Andrey Grebnev <a HREF="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
40  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
41  * @version $Revision: 1.7 $ $Date: 2006/03/10 17:10:23 $
42  * @struts.action path="/core/contentResource/image/view"
43  * name="imageForm"
44  * scope="request"
45  * input="listContentResources"
46  * validate="false"
47  * roles="core-contentResource-view"
48  * @struts.action-forward name="viewImage"
49  * path=".core.contentResource.image.view"
50  * @struts.action-forward name="listContentResources"
51  * path="/core/contentResource/list.do"
52  * redirect="true"
53  */

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

64     public ActionForward execute(ActionMapping mapping, ActionForm form,
65                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
66         resetToken(request);
67         ImageForm imageForm = (ImageForm) form;
68         Long JavaDoc contentResourceId = null;
69         if ( imageForm.getId() != null ) {
70             contentResourceId = Long.valueOf(imageForm.getId());
71         } else if ( request.getAttribute(WebappConstants.CONTENT_RESOURCE_ID_KEY) != null ) {
72             contentResourceId = (Long JavaDoc) request.getAttribute(WebappConstants.CONTENT_RESOURCE_ID_KEY);
73         } else {
74             if ( log.isWarnEnabled() ) {
75                 log.warn("Missing content resource ID");
76             }
77             return mapping.findForward("listContentResources");
78         }
79
80         ContentResourceManager contentResourceManager = (ContentResourceManager) getBean(Constants.CONTENT_RESOURCE_MANAGER_BEAN);
81         ContentResource image = contentResourceManager.retrieveContentImage(contentResourceId);
82
83         if ( image == null ) {
84             // image not found. it might be deleted by someone else
85
ActionMessages errors = new ActionMessages();
86             errors.add("imageNotFound", new ActionMessage("core.contentResource.image.errors.notFound"));
87             saveErrors(request, errors);
88             return mapping.findForward("listContentResources");
89         }
90
91         request.setAttribute("image", image);
92         return mapping.findForward("viewImage");
93     }
94 }
Popular Tags