KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * ViewWorkspaceItemServlet.java
3  *
4  * Version: $Revision: 1.3 $
5  *
6  * Date: $Date: 2006/11/28 04:15:35 $
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 javax.servlet.ServletException JavaDoc;
45 import javax.servlet.http.HttpServletRequest JavaDoc;
46 import javax.servlet.http.HttpServletResponse JavaDoc;
47 import java.sql.SQLException JavaDoc;
48
49 import org.apache.log4j.Logger;
50
51 import org.dspace.authorize.AuthorizeException;
52 import org.dspace.authorize.AuthorizeManager;
53 import org.dspace.app.webui.util.JSPManager;
54 import org.dspace.app.webui.util.UIUtil;
55 import org.dspace.core.Constants;
56 import org.dspace.core.Context;
57 import org.dspace.core.LogManager;
58 import org.dspace.content.Collection;
59 import org.dspace.content.Item;
60 import org.dspace.content.WorkspaceItem;
61
62 /**
63  * Class to deal with viewing workspace items during the authoring process.
64  * Based heavily on the HandleServlet.
65  *
66  * @author Richard Jones
67  * @version $Revision: 1.3 $
68  */

69 public class ViewWorkspaceItemServlet
70     extends DSpaceServlet
71 {
72
73     /** log4j logger */
74     private static Logger log = Logger.getLogger(ViewWorkspaceItemServlet.class);
75
76     protected void doDSGet(Context c,
77         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
78         throws ServletException JavaDoc, IOException JavaDoc, SQLException JavaDoc, AuthorizeException
79     {
80         // pass all requests to the same place for simplicty
81
doDSPost(c, request, response);
82     }
83     
84     protected void doDSPost(Context c,
85         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
86         throws ServletException JavaDoc, IOException JavaDoc, SQLException JavaDoc, AuthorizeException
87     {
88         String JavaDoc button = UIUtil.getSubmitButton(request, "submit_error");
89         
90         if (button.equals("submit_view")
91             || button.equals("submit_full")
92             || button.equals("submit_simple"))
93         {
94             showMainPage(c, request, response);
95         } else {
96             showErrorPage(c, request, response);
97         }
98
99     }
100
101    /**
102      * show the workspace item home page
103      *
104      * @param context the context of the request
105      * @param request the servlet request
106      * @param response the servlet response
107      */

108     private void showMainPage(Context c,
109         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
110         throws ServletException JavaDoc, IOException JavaDoc, SQLException JavaDoc, AuthorizeException
111     {
112         // get the value from the request
113
int wsItemID = UIUtil.getIntParameter(request,"workspace_id");
114         
115         // get the workspace item, item and collections from the request value
116
WorkspaceItem wsItem = WorkspaceItem.find(c, wsItemID);
117         Item item = wsItem.getItem();
118         //Collection[] collections = item.getCollections();
119
Collection[] collections = {wsItem.getCollection()};
120         
121         // Ensure the user has authorisation
122
AuthorizeManager.authorizeAction(c, item, Constants.READ);
123         
124         log.info(LogManager.getHeader(c,
125             "View Workspace Item Metadata",
126             "workspace_item_id="+wsItemID));
127         
128         // Full or simple display?
129
boolean displayAll = false;
130         String JavaDoc button = UIUtil.getSubmitButton(request, "submit_simple");
131         if (button.equalsIgnoreCase("submit_full"))
132         {
133             displayAll = true;
134         }
135         
136         // FIXME: we need to synchronise with the handle servlet to use the
137
// display item JSP for both handled and un-handled items
138
// Set attributes and display
139
// request.setAttribute("wsItem", wsItem);
140
request.setAttribute("display.all", new Boolean JavaDoc(displayAll));
141         request.setAttribute("item", item);
142         request.setAttribute("collections", collections);
143         request.setAttribute("workspace_id", new Integer JavaDoc(wsItem.getID()));
144         
145         JSPManager.showJSP(request, response, "/display-item.jsp");
146     }
147     
148    /**
149      * Show error page if nothing has been <code>POST</code>ed to servlet
150      *
151      * @param context the context of the request
152      * @param request the servlet request
153      * @param response the servlet response
154      */

155     private void showErrorPage(Context context,
156         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
157         throws ServletException JavaDoc, IOException JavaDoc, SQLException JavaDoc, AuthorizeException
158     {
159         int wsItemID = UIUtil.getIntParameter(request,"workspace_id");
160         
161         log.error(LogManager.getHeader(context,
162             "View Workspace Item Metadata Failed",
163             "workspace_item_id="+wsItemID));
164         
165         JSPManager.showJSP(request, response, "/workspace/wsv-error.jsp");
166     }
167 }
168
Popular Tags