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

📄 handleservlet.java

📁 dspace 用j2ee架构的一个数字图书馆.开源程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            scope.setTotal(5);            List items = Browse.getLastSubmitted(scope);            // Get titles and URLs to item pages            String[] itemTitles = getItemTitles(items);            String[] itemLinks = getItemURLs(context, items);            // is the user a COMMUNITY_EDITOR?            if (community.canEditBoolean())            {                // set a variable to create an edit button                request.setAttribute("editor_button", new Boolean(true));            }            // can they add to this community?            if (AuthorizeManager.authorizeActionBoolean(context, community,                    Constants.ADD))            {                // set a variable to create an edit button                request.setAttribute("add_button", new Boolean(true));            }            // can they remove from this community?            if (AuthorizeManager.authorizeActionBoolean(context, community,                    Constants.REMOVE))            {                // set a variable to create an edit button                request.setAttribute("remove_button", new Boolean(true));            }            // Forward to community home page            request.setAttribute("last.submitted.titles", itemTitles);            request.setAttribute("last.submitted.urls", itemLinks);            request.setAttribute("community", community);            request.setAttribute("collections", collections);            request.setAttribute("subcommunities", subcommunities);            JSPManager.showJSP(request, response, "/community-home.jsp");        }    }    /**     * Show a collection 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     * @param collection     *            the collection     */    private void collectionHome(Context context, HttpServletRequest request,            HttpServletResponse response, Community community,            Collection collection) throws ServletException, IOException,            SQLException, AuthorizeException    {        // Handle click on a browse or search button        if (!handleButton(request, response, collection.getHandle()))        {            // Will need to know whether to commit to DB            boolean updated = false;            // No search or browse button pressed, check for            if (request.getParameter("submit_subscribe") != null)            {                // Subscribe button pressed.                // Only registered can subscribe, so redirect unless logged in.                if (context.getCurrentUser() == null &&                    !Authenticate                            .startAuthentication(context, request, response))                    return;                else                {                    Subscribe.subscribe(context, context.getCurrentUser(),                            collection);                    updated = true;                }            }            else if (request.getParameter("submit_unsubscribe") != null)            {                Subscribe.unsubscribe(context, context.getCurrentUser(),                        collection);                updated = true;            }            // display collection home page            log.info(LogManager.getHeader(context, "view_collection",                    "collection_id=" + collection.getID()));            // Find the 5 last submitted items            BrowseScope scope = new BrowseScope(context);            scope.setScope(collection);            scope.setTotal(5);            List items = Browse.getLastSubmitted(scope);            // Get titles and URLs to item pages            String[] itemTitles = getItemTitles(items);            String[] itemLinks = getItemURLs(context, items);            // Is the user logged in/subscribed?            EPerson e = context.getCurrentUser();            boolean subscribed = false;            if (e != null)            {                subscribed = Subscribe.isSubscribed(context, e, collection);                // is the user a COLLECTION_EDITOR?                if (collection.canEditBoolean())                {                    // set a variable to create an edit button                    request.setAttribute("editor_button", new Boolean(true));                }                // can they admin this collection?                if (AuthorizeManager.authorizeActionBoolean(context,                        collection, Constants.COLLECTION_ADMIN))                {                    request.setAttribute("admin_button", new Boolean(true));                    // give them a button to manage submitter list                    // what group is the submitter?                    Group group = collection.getSubmitters();                    if (group != null)                    {                        request.setAttribute("submitters", group);                    }                }                // can they submit to this collection?                if (AuthorizeManager.authorizeActionBoolean(context,                        collection, Constants.ADD))                {                    request                            .setAttribute("can_submit_button",                                    new Boolean(true));                }                else                {                    request.setAttribute("can_submit_button",                            new Boolean(false));                }            }            // Forward to collection home page            request.setAttribute("last.submitted.titles", itemTitles);            request.setAttribute("last.submitted.urls", itemLinks);            request.setAttribute("collection", collection);            request.setAttribute("community", community);            request.setAttribute("logged.in", new Boolean(e != null));            request.setAttribute("subscribed", new Boolean(subscribed));            JSPManager.showJSP(request, response, "/collection-home.jsp");            if (updated)            {                context.complete();            }        }    }    /**     * Check to see if a browse or search button has been pressed on a community     * or collection home page. If so, redirect to the appropriate URL.     *      * @param request     *            HTTP request     * @param response     *            HTTP response     * @param handle     *            Handle of the community/collection home page     *      * @return true if a browse/search button was pressed and the user was     *         redirected     */    private boolean handleButton(HttpServletRequest request,            HttpServletResponse response, String handle) throws IOException    {        String button = UIUtil.getSubmitButton(request, "");        String location = request.getParameter("location");        String prefix = "/";        String url = null;        if (location == null)        {            return false;        }        /*         * Work out the "prefix" to which to redirect If "/", scope is all of         * DSpace, so prefix is "/" If prefix is a handle, scope is a community         * or collection, so "/handle/1721.x/xxxx/" is the prefix.         */        if (!location.equals("/"))        {            prefix = "/handle/" + location + "/";        }        if (button.equals("submit_titles"))        {            // Redirect to browse by title            url = request.getContextPath() + prefix + "browse-title";        }        else if (button.equals("submit_authors"))        {            // Redirect to browse authors            url = request.getContextPath() + prefix + "browse-author";        }        else if (button.equals("submit_subjects"))        {            // Redirect to browse by date            url = request.getContextPath() + prefix + "browse-subject";        }        else if (button.equals("submit_dates"))        {            // Redirect to browse by date            url = request.getContextPath() + prefix + "browse-date";        }        else if (button.equals("submit_search")                || (request.getParameter("query") != null))        {            /*             * Have to check for search button and query - in some browsers,             * typing a query into the box and hitting return doesn't produce a             * submit button parameter. Redirect to appropriate search page             */            url = request.getContextPath()                    + prefix                    + "simple-search?query="                    + URLEncoder.encode(request.getParameter("query"),                            Constants.DEFAULT_ENCODING);        }        // If a button was pressed, redirect to appropriate page        if (url != null)        {            response.sendRedirect(response.encodeRedirectURL(url));            return true;        }        return false;    }    /**     * Utility method to obtain the titles for the Items in the given list.     *      * @param List     *            of Items     * @return array of corresponding titles     */    private String[] getItemTitles(List items)    {        String[] titles = new String[items.size()];        for (int i = 0; i < items.size(); i++)        {            Item item = (Item) items.get(i);            // FIXME: Should probably check for preferred language?            DCValue[] titlesForThis = item.getDC("title", null, Item.ANY);            // Just use the first title, if any            if (titlesForThis.length == 0)            {                // No title at all!                titles[i] = null;            }            else            {                // Use first title                titles[i] = titlesForThis[0].value;            }        }        return titles;    }    /**     * Utility method obtain URLs for the most recent items     *      * @param context     *            DSpace context     * @param items     *            the items to get URLs for     * @return an array of URLs (in Strings) corresponding to those items     */    private String[] getItemURLs(Context context, List items)            throws SQLException    {        String[] urls = new String[items.size()];        for (int i = 0; i < items.size(); i++)        {            Item item = (Item) items.get(i);            urls[i] = "/handle/" + item.getHandle();        }        return urls;    }    /**     * Utility method to produce a list of parent communities for a given     * community, ending with the passed community, if include is true. If     * commmunity is top-level, the array will be empty, or contain only the     * passed community, if include is true. The array is ordered highest level     * to lowest     */    private Community[] getParents(Community c, boolean include)            throws SQLException    {        // Find all the "parent" communities for the community        Community[] parents = c.getAllParents();        // put into an array in reverse order        int revLength = include ? (parents.length + 1) : parents.length;        Community[] reversedParents = new Community[revLength];        int index = parents.length - 1;        for (int i = 0; i < parents.length; i++)        {            reversedParents[i] = parents[index - i];        }        if (include)        {            reversedParents[revLength - 1] = c;        }        return reversedParents;    }}

⌨️ 快捷键说明

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