⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 edititemservlet.java

📁 dspace 用j2ee架构的一个数字图书馆.开源程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * EditItemServlet.java * * Version: $Revision: 1.21 $ * * Date: $Date: 2006/03/16 19:36:58 $ * * 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.admin;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.Collections;import java.util.Enumeration;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.StringTokenizer;import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.log4j.Logger;import org.dspace.app.webui.servlet.DSpaceServlet;import org.dspace.app.webui.util.FileUploadRequest;import org.dspace.app.webui.util.JSPManager;import org.dspace.app.webui.util.UIUtil;import org.dspace.authorize.AuthorizeException;import org.dspace.authorize.AuthorizeManager;import org.dspace.content.Bitstream;import org.dspace.content.BitstreamFormat;import org.dspace.content.Bundle;import org.dspace.content.Collection;import org.dspace.content.DSpaceObject;import org.dspace.content.FormatIdentifier;import org.dspace.content.Item;import org.dspace.content.MetadataField;import org.dspace.content.MetadataSchema;import org.dspace.core.Constants;import org.dspace.core.Context;import org.dspace.core.LogManager;import org.dspace.handle.HandleManager;import org.dspace.search.DSIndexer;import org.dspace.license.CreativeCommons;/** * Servlet for editing and deleting (expunging) items *  * @author Robert Tansley * @version $Revision: 1.21 $ */public class EditItemServlet extends DSpaceServlet{    /** User wants to delete (expunge) an item */    public static final int START_DELETE = 1;    /** User confirms delete (expunge) of item */    public static final int CONFIRM_DELETE = 2;    /** User updates item */    public static final int UPDATE_ITEM = 3;    /** User starts withdrawal of item */    public static final int START_WITHDRAW = 4;    /** User confirms withdrawal of item */    public static final int CONFIRM_WITHDRAW = 5;    /** User reinstates a withdrawn item */    public static final int REINSTATE = 6;    /** Logger */    private static Logger log = Logger.getLogger(EditCommunitiesServlet.class);    protected void doDSGet(Context context, HttpServletRequest request,            HttpServletResponse response) throws ServletException, IOException,            SQLException, AuthorizeException    {        /*         * GET with no parameters displays "find by handle/id" form parameter         * item_id -> find and edit item with internal ID item_id parameter         * handle -> find and edit corresponding item if internal ID or Handle         * are invalid, "find by handle/id" form is displayed again with error         * message         */        int internalID = UIUtil.getIntParameter(request, "item_id");        String handle = request.getParameter("handle");        boolean showError = false;        // See if an item ID or Handle was passed in        Item itemToEdit = null;        if (internalID > 0)        {            itemToEdit = Item.find(context, internalID);            showError = (itemToEdit == null);        }        else if ((handle != null) && !handle.equals(""))        {            // resolve handle            DSpaceObject dso = HandleManager.resolveToObject(context, handle);            // make sure it's an ITEM            if ((dso != null) && (dso.getType() == Constants.ITEM))            {                itemToEdit = (Item) dso;                showError = false;            }            else            {                showError = true;            }        }        // Show edit form if appropriate        if (itemToEdit != null)        {            // now check to see if person can edit item            checkEditAuthorization(context, itemToEdit);            showEditForm(context, request, response, itemToEdit);        }        else        {            if (showError)            {                request.setAttribute("invalid.id", new Boolean(true));            }            JSPManager.showJSP(request, response, "/tools/get-item-id.jsp");        }    }    protected void doDSPost(Context context, HttpServletRequest request,            HttpServletResponse response) throws ServletException, IOException,            SQLException, AuthorizeException    {        // First, see if we have a multipart request (uploading a new bitstream)        String contentType = request.getContentType();        if ((contentType != null)                && (contentType.indexOf("multipart/form-data") != -1))        {            // This is a multipart request, so it's a file upload            processUploadBitstream(context, request, response);            return;        }        /*         * Then we check for a "cancel" button - if it's been pressed, we simply         * return to the "find by handle/id" page         */        if (request.getParameter("submit_cancel") != null)        {            JSPManager.showJSP(request, response, "/tools/get-item-id.jsp");            return;        }        /*         * Respond to submitted forms. Each form includes an "action" parameter         * indicating what needs to be done (from the constants above.)         */        int action = UIUtil.getIntParameter(request, "action");        Item item = Item.find(context, UIUtil.getIntParameter(request,                "item_id"));         String handle = HandleManager.findHandle(context, item);        // now check to see if person can edit item        checkEditAuthorization(context, item);        request.setAttribute("item", item);        request.setAttribute("handle", handle);        switch (action)        {        case START_DELETE:            // Show "delete item" confirmation page            JSPManager.showJSP(request, response,                    "/tools/confirm-delete-item.jsp");            break;        case CONFIRM_DELETE:            // Delete the item - if "cancel" was pressed this would be            // picked up above            // FIXME: Don't know if this does all it should - remove Handle?            Collection[] collections = item.getCollections();            // Remove item from all the collections it's in            for (int i = 0; i < collections.length; i++)            {                collections[i].removeItem(item);            }            JSPManager.showJSP(request, response, "/tools/get-item-id.jsp");            context.complete();            break;        case UPDATE_ITEM:            processUpdateItem(context, request, response, item);            break;        case START_WITHDRAW:            // Show "withdraw item" confirmation page            JSPManager.showJSP(request, response,                    "/tools/confirm-withdraw-item.jsp");            break;        case CONFIRM_WITHDRAW:            // Withdraw the item            item.withdraw();            JSPManager.showJSP(request, response, "/tools/get-item-id.jsp");            context.complete();            break;        case REINSTATE:            item.reinstate();            JSPManager.showJSP(request, response, "/tools/get-item-id.jsp");            context.complete();            break;        default:            // Erm... weird action value received.            log.warn(LogManager.getHeader(context, "integrity_error", UIUtil                    .getRequestLogInfo(request)));            JSPManager.showIntegrityError(request, response);        }    }    /**     * Throw an exception if user isn't authorized to edit this item     *      * @param context     * @param item     */    private void checkEditAuthorization(Context c, Item item)            throws AuthorizeException, java.sql.SQLException    {        if (!item.canEdit())        {            int userID = 0;            // first, check if userid is set            if (c.getCurrentUser() != null)            {                userID = c.getCurrentUser().getID();            }            // show an error or throw an authorization exception            throw new AuthorizeException("EditItemServlet: User " + userID                    + " not authorized to edit item " + item.getID());        }    }    /**     * Show the item edit form for a particular item     *      * @param context     *            DSpace context     * @param request     *            the HTTP request containing posted info     * @param response     *            the HTTP response     * @param item     *            the item     */    private void showEditForm(Context context, HttpServletRequest request,            HttpServletResponse response, Item item) throws ServletException,            IOException, SQLException, AuthorizeException    {        if ( request.getParameter("cc_license_url") != null )        {        	// set or replace existing CC license        	CreativeCommons.setLicense( context, item,                   request.getParameter("cc_license_url") );        	context.commit();        }          // Get the handle, if any        String handle = HandleManager.findHandle(context, item);        // Collections

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -