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

📄 collectionwizardservlet.java

📁 dspace 用j2ee架构的一个数字图书馆.开源程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * CollectionWizardServlet.java * * Version: $Revision: 1.21 $ * * Date: $Date: 2005/11/16 21:40:50 $ * * 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.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.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.Collection;import org.dspace.content.Community;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.eperson.EPerson;import org.dspace.eperson.Group;/** * Collection creation wizard UI *  * @author Robert Tansley * @version $Revision: 1.21 $ */public class CollectionWizardServlet extends DSpaceServlet{    /** Initial questions page */    public final static int INITIAL_QUESTIONS = 1;    /** Basic information page */    public final static int BASIC_INFO = 2;    /** Permissions pages */    public final static int PERMISSIONS = 3;    /** Default item page */    public final static int DEFAULT_ITEM = 4;    /** Summary page */    public final static int SUMMARY = 5;    /** Permissions page for who gets read permissions on new items */    public final static int PERM_READ = 10;    /** Permissions page for submitters */    public final static int PERM_SUBMIT = 11;    /** Permissions page for workflow step 1 */    public final static int PERM_WF1 = 12;    /** Permissions page for workflow step 2 */    public final static int PERM_WF2 = 13;    /** Permissions page for workflow step 3 */    public final static int PERM_WF3 = 14;    /** Permissions page for collection administrators */    public final static int PERM_ADMIN = 15;    /** Logger */    private static Logger log = Logger.getLogger(CollectionWizardServlet.class);    protected void doDSGet(Context context, HttpServletRequest request,            HttpServletResponse response) throws ServletException, IOException,            SQLException, AuthorizeException    {        /*         * For GET, all we should really get is a community_id parameter (DB ID         * of community to add collection to). doDSPost handles this         */        doDSPost(context, request, response);    }    protected void doDSPost(Context context, HttpServletRequest request,            HttpServletResponse response) throws ServletException, IOException,            SQLException, AuthorizeException    {        /*         * For POST, we expect from the form:         *          * community_id DB ID if it was a 'create a new collection' button press         *          * OR         *          * collection_id DB ID of collection we're dealing with stage Stage         * we're at (from constants above)         */        // First, see if we have a multipart request        // (the 'basic info' page which might include uploading a logo)        String contentType = request.getContentType();        if ((contentType != null)                && (contentType.indexOf("multipart/form-data") != -1))        {            // This is a multipart request, so it's a file upload            processBasicInfo(context, request, response);            return;        }        int communityID = UIUtil.getIntParameter(request, "community_id");        if (communityID > -1)        {            // We have a community ID, "create new collection" button pressed            Community c = Community.find(context, communityID);            if (c == null)            {                log.warn(LogManager.getHeader(context, "integrity_error",                        UIUtil.getRequestLogInfo(request)));                JSPManager.showIntegrityError(request, response);                return;            }            // Create the collection            Collection newCollection = c.createCollection();            request.setAttribute("collection", newCollection);            if (AuthorizeManager.isAdmin(context))            {                // set a variable to show all buttons                request.setAttribute("admin_button", new Boolean(true));            }            JSPManager.showJSP(request, response,                    "/dspace-admin/wizard-questions.jsp");            context.complete();        }        else        {            // Collection already created, dealing with one of the wizard pages            int collectionID = UIUtil.getIntParameter(request, "collection_id");            int stage = UIUtil.getIntParameter(request, "stage");            // Get the collection            Collection collection = Collection.find(context, collectionID);            // Put it in request attributes, as most JSPs will need it            request.setAttribute("collection", collection);            if (collection == null)            {                log.warn(LogManager.getHeader(context, "integrity_error",                        UIUtil.getRequestLogInfo(request)));                JSPManager.showIntegrityError(request, response);                return;            }            // All pages will need this attribute            request.setAttribute("collection.id", String.valueOf(collection                    .getID()));            switch (stage)            {            case INITIAL_QUESTIONS:                processInitialQuestions(context, request, response, collection);                break;            case PERMISSIONS:                processPermissions(context, request, response, collection);                break;            case DEFAULT_ITEM:                processDefaultItem(context, request, response, collection);                break;            default:                log.warn(LogManager.getHeader(context, "integrity_error",                        UIUtil.getRequestLogInfo(request)));                JSPManager.showIntegrityError(request, response);            }        }    }    /**     * Process input from initial questions page     *      * @param context     *            DSpace context     * @param request     *            HTTP request     * @param response     *            HTTP response     * @param collection     *            Collection we're editing     */    private void processInitialQuestions(Context context,            HttpServletRequest request, HttpServletResponse response,            Collection collection) throws SQLException, ServletException,            IOException, AuthorizeException    {        Group anonymousGroup = Group.find(context, 0);        // "Public read" checkbox. Only need to do anything        // if it's not checked.        if (!UIUtil.getBoolParameter(request, "public_read"))        {            // Remove anonymous default policies for new items            AuthorizeManager.removePoliciesActionFilter(context, collection,                    Constants.DEFAULT_ITEM_READ);            AuthorizeManager.removePoliciesActionFilter(context, collection,                    Constants.DEFAULT_BITSTREAM_READ);        }        // Some people authorised to submit        if (UIUtil.getBoolParameter(request, "submitters"))        {            // Create submitters group            Group g = collection.createSubmitters();        }        // Check for the workflow steps        for (int i = 1; i <= 3; i++)        {            if (UIUtil.getBoolParameter(request, "workflow" + i))            {                // should have workflow step i                Group g = collection.createWorkflowGroup(i);            }        }        // Check for collection administrators        if (UIUtil.getBoolParameter(request, "admins"))        {            // Create administrators group            Group g = collection.createAdministrators();        }        // Default item stuff?        if (UIUtil.getBoolParameter(request, "default.item"))        {            collection.createTemplateItem();        }        // Need to set a name so that the indexer won't throw an exception        collection.setMetadata("name", "");        collection.update();        // Now display "basic info" screen        JSPManager.showJSP(request, response,                "/dspace-admin/wizard-basicinfo.jsp");        context.complete();    }    /**     * Process input from one of the permissions pages     *      * @param context     *            DSpace context     * @param request     *            HTTP request     * @param response     *            HTTP response     * @param collection     *            Collection we're editing     */    private void processPermissions(Context context,            HttpServletRequest request, HttpServletResponse response,            Collection collection) throws SQLException, ServletException,            IOException, AuthorizeException    {        // Which permission are we dealing with?        int permission = UIUtil.getIntParameter(request, "permission");        // First, we deal with the special case of the MIT group...        if (UIUtil.getBoolParameter(request, "mitgroup"))        {            Group mitGroup = Group.findByName(context, "MIT Users");            int action;            if (permission == PERM_READ)            {                // assign default item and bitstream read to mitGroup                AuthorizeManager.addPolicy(context, collection,                        Constants.DEFAULT_ITEM_READ, mitGroup);                AuthorizeManager.addPolicy(context, collection,                        Constants.DEFAULT_BITSTREAM_READ, mitGroup);            }            else            {                // Must be submit                AuthorizeManager.addPolicy(context, collection, Constants.ADD,                        mitGroup);            }        }        //We need to add the selected people to the group.        // First, get the relevant group        Group g = null;        switch (permission)        {        case PERM_READ:            // Actually need to create a group for this.            g = Group.create(context);            // Name it according to our conventions            g                    .setName("COLLECTION_" + collection.getID()                            + "_DEFAULT_ITEM_READ");

⌨️ 快捷键说明

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