001: /*
002: * WorkspaceServlet.java
003: *
004: * Version: $Revision: 1520 $
005: *
006: * Date: $Date: 2006-05-26 09:14:03 -0500 (Fri, 26 May 2006) $
007: *
008: * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
009: * Institute of Technology. All rights reserved.
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions are
013: * met:
014: *
015: * - Redistributions of source code must retain the above copyright
016: * notice, this list of conditions and the following disclaimer.
017: *
018: * - Redistributions in binary form must reproduce the above copyright
019: * notice, this list of conditions and the following disclaimer in the
020: * documentation and/or other materials provided with the distribution.
021: *
022: * - Neither the name of the Hewlett-Packard Company nor the name of the
023: * Massachusetts Institute of Technology nor the names of their
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038: * DAMAGE.
039: */
040:
041: package org.dspace.app.webui.servlet;
042:
043: import java.io.IOException;
044: import java.sql.SQLException;
045: import java.util.Date;
046: import javax.servlet.ServletException;
047: import javax.servlet.http.HttpServletRequest;
048: import javax.servlet.http.HttpServletResponse;
049:
050: import org.apache.log4j.Logger;
051:
052: import org.dspace.app.webui.util.JSPManager;
053: import org.dspace.app.webui.util.UIUtil;
054: import org.dspace.authorize.AuthorizeException;
055: import org.dspace.authorize.AuthorizeManager;
056: import org.dspace.content.Item;
057: import org.dspace.content.WorkspaceItem;
058: import org.dspace.core.Constants;
059: import org.dspace.core.Context;
060: import org.dspace.core.LogManager;
061: import org.dspace.storage.rdbms.TableRow;
062:
063: /**
064: * Servlet for handling the workspace item
065: *
066: * @author Richard Jones
067: * @version $Revision: 1520 $
068: */
069: public class WorkspaceServlet extends DSpaceServlet {
070:
071: /** log4j category */
072: private static Logger log = Logger
073: .getLogger(WorkspaceServlet.class);
074:
075: protected void doDSGet(Context c, HttpServletRequest request,
076: HttpServletResponse response) throws ServletException,
077: IOException, SQLException, AuthorizeException {
078: // just pass all requests to the same place.
079: doDSPost(c, request, response);
080: }
081:
082: protected void doDSPost(Context c, HttpServletRequest request,
083: HttpServletResponse response) throws ServletException,
084: IOException, SQLException, AuthorizeException {
085:
086: String button = UIUtil.getSubmitButton(request, "submit_error");
087:
088: // direct the request to the relevant set of methods
089: if (button.equals("submit_open")) {
090: showMainPage(c, request, response);
091: } else if (button.equals("submit_cancel")) {
092: goToMyDSpace(c, request, response);
093: } else if (button.equals("submit_error")) {
094: showErrorPage(c, request, response);
095: }
096: }
097:
098: /**
099: * Show error page if nothing has been <code>POST</code>ed to servlet
100: *
101: * @param context the context of the request
102: * @param request the servlet request
103: * @param response the servlet response
104: */
105: private void showErrorPage(Context context,
106: HttpServletRequest request, HttpServletResponse response)
107: throws ServletException, IOException, SQLException,
108: AuthorizeException {
109: int wsItemID = UIUtil.getIntParameter(request, "workspace_id");
110:
111: log.error(LogManager.getHeader(context,
112: "Workspace Item View Failed", "workspace_item_id="
113: + wsItemID));
114:
115: JSPManager
116: .showJSP(request, response, "/workspace/ws-error.jsp");
117: }
118:
119: /**
120: * Return the user to the mydspace servlet
121: *
122: * @param context the context of the request
123: * @param request the servlet request
124: * @param response the servlet response
125: */
126: private void goToMyDSpace(Context context,
127: HttpServletRequest request, HttpServletResponse response)
128: throws ServletException, IOException, SQLException,
129: AuthorizeException {
130: response.sendRedirect(response.encodeRedirectURL(request
131: .getContextPath()
132: + "/mydspace"));
133: }
134:
135: /**
136: * show the workspace item home page
137: *
138: * @param context the context of the request
139: * @param request the servlet request
140: * @param response the servlet response
141: */
142: private void showMainPage(Context context,
143: HttpServletRequest request, HttpServletResponse response)
144: throws ServletException, IOException, SQLException,
145: AuthorizeException {
146: // get the values out of the request
147: int wsItemID = UIUtil.getIntParameter(request, "workspace_id");
148:
149: // get the workspace item
150: WorkspaceItem wsItem = WorkspaceItem.find(context, wsItemID);
151:
152: // Ensure the user has authorisation
153: Item item = wsItem.getItem();
154: AuthorizeManager.authorizeAction(context, item, Constants.READ);
155:
156: log.info(LogManager.getHeader(context, "View Workspace Item",
157: "workspace_item_id=" + wsItemID));
158:
159: // set the attributes for the JSP
160: request.setAttribute("wsItem", wsItem);
161:
162: JSPManager.showJSP(request, response, "/workspace/ws-main.jsp");
163: }
164:
165: }
|