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

📄 handleservlet.java

📁 dspace 用j2ee架构的一个数字图书馆.开源程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * HandleServlet.java * * Version: $Revision: 1.21 $ * * Date: $Date: 2006/01/12 21:47:30 $ * * 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.IOException;import java.net.URLEncoder;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.util.Authenticate;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.browse.Browse;import org.dspace.browse.BrowseScope;import org.dspace.content.Collection;import org.dspace.content.Community;import org.dspace.content.DCValue;import org.dspace.content.DSpaceObject;import org.dspace.content.Item;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;import org.dspace.eperson.Subscribe;import org.dspace.handle.HandleManager;/** * Servlet for handling requests within a community or collection. The Handle is * extracted from the URL, e.g: <code>/community/1721.1/1234</code>. If there * is anything after the Handle, the request is forwarded to the appropriate * servlet. For example: * <P> * <code>/community/1721.1/1234/simple-search</code> * <P> * would be forwarded to <code>/simple-search</code>. If there is nothing * after the Handle, the community or collection home page is shown. * <P> * If the initial parameter " **FIXME** *  * @author Robert Tansley * @version $Revision: 1.21 $ */public class HandleServlet extends DSpaceServlet{    /** log4j category */    private static Logger log = Logger.getLogger(DSpaceServlet.class);    /** Is this servlet for dealing with collections? */    private boolean collections;    public void init()    {        // Sort out what we're dealing with default is titles        String param = getInitParameter("location");        collections = ((param != null) && param.equalsIgnoreCase("collections"));    }    protected void doDSGet(Context context, HttpServletRequest request,            HttpServletResponse response) throws ServletException, IOException,            SQLException, AuthorizeException    {        String handle = null;        String extraPathInfo = null;        DSpaceObject dso = null;        // Original path info, of the form "1721.x/1234"        // or "1721.x/1234/extra/stuff"        String path = request.getPathInfo();        if (path != null)        {            // substring(1) is to remove initial '/'            path = path.substring(1);            try            {                // Extract the Handle                int firstSlash = path.indexOf('/');                int secondSlash = path.indexOf('/', firstSlash + 1);                if (secondSlash != -1)                {                    // We have extra path info                    handle = path.substring(0, secondSlash);                    extraPathInfo = path.substring(secondSlash);                }                else                {                    // The path is just the Handle                    handle = path;                }            }            catch (NumberFormatException nfe)            {                // Leave handle as null            }        }        // Find out what the handle relates to        if (handle != null)        {            dso = HandleManager.resolveToObject(context, handle);        }        if (dso == null)        {            log.info(LogManager                    .getHeader(context, "invalid_id", "path=" + path));            JSPManager.showInvalidIDError(request, response, path, -1);            return;        }        // OK, we have a valid Handle. What is it?        if (dso.getType() == Constants.ITEM)        {            // Display the item page            displayItem(context, request, response, (Item) dso, handle);        }        else if (dso.getType() == Constants.COLLECTION)        {            Collection c = (Collection) dso;            // Store collection location in request            request.setAttribute("dspace.collection", c);            /*             * Find the "parent" community the collection, mainly for             * "breadcrumbs" FIXME: At the moment, just grab the first community             * the collection is in. This should probably be more context             * sensitive when we have multiple inclusion.             */            Community[] parents = c.getCommunities();            request.setAttribute("dspace.community", parents[0]);            /*             * Find all the "parent" communities for the collection for             * "breadcrumbs"             */            request.setAttribute("dspace.communities", getParents(parents[0],                    true));            // home page, or forward to another page?            if (extraPathInfo == null)            {                collectionHome(context, request, response, parents[0], c);            }            else            {                // Forward to another servlet                request.getRequestDispatcher(extraPathInfo).forward(request,                        response);            }        }        else if (dso.getType() == Constants.COMMUNITY)        {            Community c = (Community) dso;            // Store collection location in request            request.setAttribute("dspace.community", c);            /*             * Find all the "parent" communities for the community             */            request.setAttribute("dspace.communities", getParents(c, false));            // home page, or forward to another page?            if (extraPathInfo == null)            {                communityHome(context, request, response, c);            }            else            {                // Forward to another servlet                request.getRequestDispatcher(extraPathInfo).forward(request,                        response);            }        }        else        {            // Shouldn't happen. Log and treat as invalid ID            log.info(LogManager.getHeader(context,                    "Handle not an item, collection or community", "handle="                            + handle));            JSPManager.showInvalidIDError(request, response, path, -1);            return;        }    }    /**     * Show an item page     *      * @param context     *            Context object     * @param request     *            the HTTP request     * @param response     *            the HTTP response     * @param item     *            the item     * @param handle     *            the item's handle     */    private void displayItem(Context context, HttpServletRequest request,            HttpServletResponse response, Item item, String handle)            throws ServletException, IOException, SQLException,            AuthorizeException    {        // Tombstone?        if (item.isWithdrawn())        {            JSPManager.showJSP(request, response, "/tombstone.jsp");            return;        }        // Ensure the user has authorisation        AuthorizeManager.authorizeAction(context, item, Constants.READ);        log                .info(LogManager.getHeader(context, "view_item", "handle="                        + handle));        // show edit link        if (item.canEdit())        {            // set a variable to create an edit button            request.setAttribute("admin_button", new Boolean(true));        }        // Get the collections        Collection[] collections = item.getCollections();        // For the breadcrumbs, get the first collection and the first community        // that is in. FIXME: Not multiple-inclusion friendly--should be        // smarter, context-sensitive        request.setAttribute("dspace.collection", item.getOwningCollection());        Community[] comms = item.getOwningCollection().getCommunities();        request.setAttribute("dspace.community", comms[0]);        /*         * Find all the "parent" communities for the collection         */        request.setAttribute("dspace.communities", getParents(comms[0], true));        // Full or simple display?        boolean displayAll = false;        String modeParam = request.getParameter("mode");        if ((modeParam != null) && modeParam.equalsIgnoreCase("full"))        {            displayAll = true;        }        // Set attributes and display        request.setAttribute("display.all", new Boolean(displayAll));        request.setAttribute("item", item);        request.setAttribute("collections", collections);        JSPManager.showJSP(request, response, "/display-item.jsp");    }    /**     * Show a community home page, or deal with button press on home page     *      * @param context     *            Context object     * @param request     *            the HTTP request     * @param response     *            the HTTP response     * @param community     *            the community     */    private void communityHome(Context context, HttpServletRequest request,            HttpServletResponse response, Community community)            throws ServletException, IOException, SQLException    {        // Handle click on a browse or search button        if (!handleButton(request, response, community.getHandle()))        {            // No button pressed, display community home page            log.info(LogManager.getHeader(context, "view_community",                    "community_id=" + community.getID()));            // Get the collections within the community            Collection[] collections = community.getCollections();            // get any subcommunities of the community            Community[] subcommunities = community.getSubcommunities();            // Find the 5 last submitted items            BrowseScope scope = new BrowseScope(context);            scope.setScope(community);

⌨️ 快捷键说明

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