KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > app > webui > servlet > WorkspaceServlet


1 /*
2  * WorkspaceServlet.java
3  *
4  * Version: $Revision: 1.3 $
5  *
6  * Date: $Date: 2006/05/26 14:13:04 $
7  *
8  * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
9  * Institute of Technology. All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are
13  * met:
14  *
15  * - Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * - Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution.
21  *
22  * - Neither the name of the Hewlett-Packard Company nor the name of the
23  * Massachusetts Institute of Technology nor the names of their
24  * contributors may be used to endorse or promote products derived from
25  * this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38  * DAMAGE.
39  */

40
41 package org.dspace.app.webui.servlet;
42
43 import java.io.IOException JavaDoc;
44 import java.sql.SQLException JavaDoc;
45 import java.util.Date JavaDoc;
46 import javax.servlet.ServletException JavaDoc;
47 import javax.servlet.http.HttpServletRequest JavaDoc;
48 import javax.servlet.http.HttpServletResponse JavaDoc;
49
50 import org.apache.log4j.Logger;
51
52 import org.dspace.app.webui.util.JSPManager;
53 import org.dspace.app.webui.util.UIUtil;
54 import org.dspace.authorize.AuthorizeException;
55 import org.dspace.authorize.AuthorizeManager;
56 import org.dspace.content.Item;
57 import org.dspace.content.WorkspaceItem;
58 import org.dspace.core.Constants;
59 import org.dspace.core.Context;
60 import org.dspace.core.LogManager;
61 import org.dspace.storage.rdbms.TableRow;
62
63 /**
64  * Servlet for handling the workspace item
65  *
66  * @author Richard Jones
67  * @version $Revision: 1.3 $
68  */

69 public class WorkspaceServlet extends DSpaceServlet
70 {
71     
72     /** log4j category */
73     private static Logger log = Logger.getLogger(WorkspaceServlet.class);
74     
75     protected void doDSGet(Context c,
76         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
77         throws ServletException JavaDoc, IOException JavaDoc, SQLException JavaDoc, AuthorizeException
78     {
79         // just pass all requests to the same place.
80
doDSPost(c, request, response);
81     }
82     
83     protected void doDSPost(Context c,
84         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
85         throws ServletException JavaDoc, IOException JavaDoc, SQLException JavaDoc, AuthorizeException
86     {
87         
88         String JavaDoc button = UIUtil.getSubmitButton(request, "submit_error");
89         
90         // direct the request to the relevant set of methods
91
if (button.equals("submit_open"))
92         {
93             showMainPage(c, request, response);
94         }
95         else if (button.equals("submit_cancel"))
96         {
97             goToMyDSpace(c, request, response);
98         }
99         else if (button.equals("submit_error"))
100         {
101             showErrorPage(c, request, response);
102         }
103     }
104     
105     
106     /**
107      * Show error page if nothing has been <code>POST</code>ed to servlet
108      *
109      * @param context the context of the request
110      * @param request the servlet request
111      * @param response the servlet response
112      */

113     private void showErrorPage(Context context,
114         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
115         throws ServletException JavaDoc, IOException JavaDoc, SQLException JavaDoc, AuthorizeException
116     {
117         int wsItemID = UIUtil.getIntParameter(request, "workspace_id");
118         
119         log.error(LogManager.getHeader(context,
120             "Workspace Item View Failed",
121             "workspace_item_id="+wsItemID));
122         
123         JSPManager.showJSP(request, response, "/workspace/ws-error.jsp");
124     }
125     
126     /**
127      * Return the user to the mydspace servlet
128      *
129      * @param context the context of the request
130      * @param request the servlet request
131      * @param response the servlet response
132      */

133     private void goToMyDSpace(Context context,
134         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
135         throws ServletException JavaDoc, IOException JavaDoc, SQLException JavaDoc, AuthorizeException
136     {
137         response.sendRedirect(response.encodeRedirectURL(
138                 request.getContextPath() + "/mydspace"));
139     }
140     
141     
142     /**
143      * show the workspace item home page
144      *
145      * @param context the context of the request
146      * @param request the servlet request
147      * @param response the servlet response
148      */

149     private void showMainPage(Context context,
150         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
151         throws ServletException JavaDoc, IOException JavaDoc, SQLException JavaDoc, AuthorizeException
152     {
153         // get the values out of the request
154
int wsItemID = UIUtil.getIntParameter(request, "workspace_id");
155         
156         // get the workspace item
157
WorkspaceItem wsItem = WorkspaceItem.find(context, wsItemID);
158         
159         // Ensure the user has authorisation
160
Item item = wsItem.getItem();
161         AuthorizeManager.authorizeAction(context, item, Constants.READ);
162         
163         log.info(LogManager.getHeader(context,
164             "View Workspace Item",
165             "workspace_item_id="+wsItemID));
166         
167         // set the attributes for the JSP
168
request.setAttribute("wsItem", wsItem);
169         
170         JSPManager.showJSP(request, response, "/workspace/ws-main.jsp");
171     }
172     
173 }
174
Popular Tags