📄 submitservlet.java
字号:
/* * SubmitServlet.java * * Version: $Revision: 1.42 $ * * Date: $Date: 2005/11/16 21:40:52 $ * * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts * Institute of Technology. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * - Neither the name of the Hewlett-Packard Company nor the name of the * Massachusetts Institute of Technology nor the names of their * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. */package org.dspace.app.webui.servlet;import java.io.BufferedInputStream;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.sql.SQLException;import java.util.ArrayList;import java.util.LinkedList;import java.util.List;import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.log4j.Logger;import org.dspace.app.webui.util.DCInput;import org.dspace.app.webui.util.DCInputsReader;import org.dspace.app.webui.util.FileUploadRequest;import org.dspace.app.webui.util.JSPManager;import org.dspace.app.webui.util.SubmissionInfo;import org.dspace.app.webui.util.UIUtil;import org.dspace.authorize.AuthorizeException;import org.dspace.content.Bitstream;import org.dspace.content.BitstreamFormat;import org.dspace.content.Bundle;import org.dspace.content.Collection;import org.dspace.content.Community;import org.dspace.content.DCDate;import org.dspace.content.DCPersonName;import org.dspace.content.DCSeriesNumber;import org.dspace.content.DCValue;import org.dspace.content.FormatIdentifier;import org.dspace.content.Item;import org.dspace.content.MetadataField;import org.dspace.content.WorkspaceItem;import org.dspace.core.ConfigurationManager;import org.dspace.core.Constants;import org.dspace.core.Context;import org.dspace.core.LogManager;import org.dspace.eperson.EPerson;import org.dspace.license.CreativeCommons;import org.dspace.workflow.WorkflowItem;import org.dspace.workflow.WorkflowManager;/** * Submission servlet for DSpace. Handles the initial submission of items, as * well as the editing of items further down the line. * <p> * Whenever the submit servlet receives a GET request, this is taken to indicate * the start of a fresh new submission, where no collection has been selected, * and the submission process is started from scratch. * <p> * All other interactions happen via POSTs. Part of the post will normally be a * (hidden) "step" parameter, which will correspond to the form that the user * has just filled out. If this is absent, step 0 (select collection) is * assumed, meaning that it's simple to place "Submit to this collection" * buttons on collection home pages. * <p> * According to the step number of the incoming form, the values posted from the * form are processed (using the process* methods), and the item updated as * appropriate. The servlet then forwards control of the request to the * appropriate JSP (from jsp/submit) to render the next stage of the process or * an error if appropriate. Each of these JSPs may require that attributes be * passed in. Check the comments at the top of a JSP to see which attributes are * needed. All submit-related forms require a properly initialised * SubmissionInfo object to be present in the the "submission.info" attribute. * This holds the core information relevant to the submission, e.g. the item, * personal workspace or workflow item, the submitting "e-person", and the * target collection. * <p> * When control of the request reaches a JSP, it is assumed that all checks, * interactions with the database and so on have been performed and that all * necessary information to render the form is in memory. e.g. The * SubmitFormInfo object passed in must be correctly filled out. Thus the JSPs * do no error or integrity checking; it is the servlet's responsibility to * ensure that everything is prepared. The servlet is fairly diligent about * ensuring integrity at each step. * <p> * Each step has an integer constant defined below. The main sequence of the * submission procedure always runs from 0 upwards, until SUBMISSION_COMPLETE. * Other, not-in-sequence steps (such as the cancellation screen and the * "previous version ID verification" screen) have numbers much higher than * SUBMISSION_COMPLETE. These conventions allow the progress bar component of * the submission forms to render the user's progress through the process. * * @author Robert Tansley * @version $Revision: 1.42 $ */public class SubmitServlet extends DSpaceServlet{ // Steps in the submission process /** Selection collection step */ public static final int SELECT_COLLECTION = 0; /** Ask initial questions about the submission step */ public static final int INITIAL_QUESTIONS = 1; /** Edit DC metadata first page step */ public static final int EDIT_METADATA_1 = 2; /** Edit DC metadata last page step * Current value allows up to 6 distinct pages. * If more are needed, renumber this value and those * that follow it (up to SUBMISSION_COMPLETE), but * note that the progress bar will stretch badly beyond 6. */ public static final int EDIT_METADATA_2 = 7; /** * Upload files step. Note this doesn't correspond to an actual page, since * the upload file step consists of a number of pages with no definite * order. This is just used for the progress bar. */ public static final int UPLOAD_FILES = 8; /** Review submission step */ public static final int REVIEW_SUBMISSION = 9; /** optional CC license step */ public static final int CC_LICENSE = 10; /** Grant (deposit) license step */ public static final int GRANT_LICENSE = 11; /** Submission completed step */ public static final int SUBMISSION_COMPLETE = 12; // Steps which aren't part of the main sequence, but rather // short "diversions" are given high step numbers. The main sequence // is defined as being steps 0 to SUBMISSION_COMPLETE. /** Cancellation of a submission */ public static final int SUBMISSION_CANCELLED = 101; /** List of uploaded files */ public static final int FILE_LIST = 102; /** Choose file page */ public static final int CHOOSE_FILE = 103; /** File format page */ public static final int GET_FILE_FORMAT = 104; /** Error uploading file */ public static final int UPLOAD_ERROR = 105; /** Change file description page */ public static final int CHANGE_FILE_DESCRIPTION = 106; /** * Verify pruning of extra files, titles, dates as a result of changing an * answer to one of the initial questions */ public static final int VERIFY_PRUNE = 107; /** log4j logger */ private static Logger log = Logger.getLogger(SubmitServlet.class); /** hash of all submission forms details */ private DCInputsReader inputsReader; public SubmitServlet() throws ServletException { // read configurable submissions forms data inputsReader = new DCInputsReader(); } protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { /* * Possible GET parameters: * * resume= <workspace_item_id> - Resumes submitting the given workspace * item * * workflow= <workflow_id> - Starts editing the given workflow item in * workflow mode * * With no parameters, A GET starts a new submission. What happens * depends on the context of the user (where they are.) If they're not * in a community or collection, they can choose any collection from the * list of all collections. If they're in a community, the list of * collections they can choose from will be limited to those within the * current community. If the user has selected a collection, a new * submission will be started in that collection. */ String workspaceID = request.getParameter("resume"); if (workspaceID != null) { try { WorkspaceItem wi = WorkspaceItem.find(context, Integer .parseInt(workspaceID)); SubmissionInfo si = new SubmissionInfo(); si.submission = wi; doStep(context, request, response, si, INITIAL_QUESTIONS); } catch (NumberFormatException nfe) { log.warn(LogManager.getHeader(context, "bad_workspace_id", "bad_id=" + workspaceID)); JSPManager.showInvalidIDError(request, response, workspaceID, -1); } return; } String workflowID = request.getParameter("workflow"); if (workflowID != null) { try { WorkflowItem wi = WorkflowItem.find(context, Integer .parseInt(workflowID)); SubmissionInfo si = new SubmissionInfo(); si.submission = wi; doStep(context, request, response, si, INITIAL_QUESTIONS); } catch (NumberFormatException nfe) { log.warn(LogManager.getHeader(context, "bad_workflow_id", "bad_id=" + workflowID)); JSPManager .showInvalidIDError(request, response, workflowID, -1); } return; } Community com = UIUtil.getCommunityLocation(request); Collection col = UIUtil.getCollectionLocation(request); if (col != null) { // In a collection, skip the "choose selection" stage // Create a workspace item WorkspaceItem wi = WorkspaceItem.create(context, col, true); // Proceed to first step SubmissionInfo si = new SubmissionInfo(); si.submission = wi; doStep(context, request, response, si, INITIAL_QUESTIONS); context.complete(); } else { Collection[] collections; if (com != null) { // In a community. Show collections in that community only. collections = Collection.findAuthorized(context, com, Constants.ADD); } else { // Show all collections collections = Collection.findAuthorized(context, null, Constants.ADD); } log.info(LogManager.getHeader(context, "select_collection", "")); request.setAttribute("collections", collections); JSPManager.showJSP(request, response, "/submit/select-collection.jsp"); } } protected void doDSPost(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException { // First of all, we need to work out if this is a multipart request // The file upload page uses those String contentType = request.getContentType(); if ((contentType != null) && (contentType.indexOf("multipart/form-data") != -1)) { // This is a multipart request, so it's a file upload processChooseFile(context, request, response); return; } // First get the step int step = UIUtil.getIntParameter(request, "step"); // select collection is a special case - no submissioninfo object // If no step was given, we also assume "select collection" // (Submit button on collection home page or elsewhere) if ((step == SELECT_COLLECTION) || (step == -1)) { processSelectCollection(context, request, response); return; } // Get submission info SubmissionInfo subInfo = getSubmissionInfo(context, request); if (subInfo == null) { /* * Work around for problem where people select "is a thesis", see * the error page, and then use their "back" button thinking they * can start another submission - it's been removed so the ID in the * form is invalid. If we detect the "removed_thesis" attribute we * display a friendly message instead of an integrity error. */ if (request.getSession().getAttribute("removed_thesis") != null) { request.getSession().removeAttribute("removed_thesis"); JSPManager.showJSP(request, response, "/submit/thesis-removed-workaround.jsp"); return; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -