request.setAttribute("next.query", "order=oldestfirst&top="
request.setAttribute("next.query", "order=oldestfirst&amp;top="
    protected void doDSGet(Context context, HttpServletRequest request,            HttpServletResponse response) throws ServletException, IOException,            SQLException, AuthorizeException    {        // We will resolve the HTTP request parameters into a scope        BrowseScope scope = new BrowseScope(context);        // Will need to know whether to highlight the "focus" point        boolean highlight = false;        // Build up log information        String logInfo = "";        // For browse by date, we'll need to work out the URL query string to        // use when the user swaps the ordering, so that they stay at the same        // point in the index        String flipOrderingQuery = "";        // Grab HTTP request parameters        String focus = request.getParameter("focus");        String startsWith = request.getParameter("starts_with");        String top = request.getParameter("top");        String bottom = request.getParameter("bottom");        // The following three are specific to browsing items by date        String month = request.getParameter("month");        String year = request.getParameter("year");        String order = request.getParameter("order");        // For browse by date: oldest item first?        boolean oldestFirst = false;        if ((order != null) && order.equalsIgnoreCase("oldestfirst"))        {            oldestFirst = true;        }        if (browseDates && (year != null) && !year.equals("")                && ((startsWith == null) || startsWith.equals("")))        {            // We're browsing items by date, the user hasn't typed anything            // into the "year" text box, and they've selected a year from            // the drop-down list. From this we work out where to start            // the browse.            startsWith = year;            if ((month != null) & !month.equals("-1"))            {                // They've selected a month as well                if (month.length() == 1)                {                    // Ensure double-digit month number                    month = "0" + month;                }                startsWith = year + "-" + month;            }        }        // Set the scope according to the parameters passed in        if (focus != null)        {            // ----------------------------------------------            // Browse should start at a specified focus point            // ----------------------------------------------            if (browseAuthors)            {                // For browsing authors, focus is just a text value                scope.setFocus(focus);            }            else            {                // For browsing items by title or date, focus is a Handle                Item item = (Item) HandleManager                        .resolveToObject(context, focus);                if (item == null)                {                    // Handle is invalid one. Show an error.                    JSPManager.showInvalidIDError(request, response, focus,                            Constants.ITEM);                    return;                }                scope.setFocus(item);            }            // Will need to highlight the focus            highlight = true;            logInfo = "focus=" + focus + ",";            if (browseDates)            {                // if the date order is flipped, we'll keep the same focus                flipOrderingQuery = "focus="                        + URLEncoder.encode(focus, Constants.DEFAULT_ENCODING)                        + "&";            }        }        else if (startsWith != null)        {            // ----------------------------------------------            // Start the browse using user-specified text            // ----------------------------------------------            if (browseDates)            {                // if the date order is flipped, we'll keep the same focus                flipOrderingQuery = "starts_with="                        + URLEncoder.encode(startsWith,                                Constants.DEFAULT_ENCODING) + "&";                /*                 * When the user is browsing with the most recent items first,                 * the browse code algorithm doesn't quite do what some people                 * might expect. For example, if in the index there are entries:                 *                  * Mar-2000 15-Feb-2000 6-Feb-2000 15-Jan-2000                 *                  * and the user has selected "Feb 2000" as the start point for                 * the browse, the browse algorithm will start at the first                 * point in that index *after* "Feb 2000". "Feb 2000" would                 * appear in the index above between 6-Feb-2000 and 15-Jan-2000.                 * So, the browse code in this case will start the browse at                 * "15-Jan-2000". This isn't really what users are likely to                 * want: They're more likely to want the browse to start at the                 * first Feb 2000 date, i.e. 15-Feb-2000. A similar scenario                 * occurs when the user enters just a year. Our quick hack to                 * produce this behaviour is to add "-32" to the startsWith                 * variable, when sorting with most recent items first. This                 * means the browse code starts at the topmost item in the index                 * that matches the user's input, rather than the point in the                 * index where the user's input would appear.                 */                if (!oldestFirst)                {                    startsWith = startsWith + "-32";                }            }            scope.setFocus(startsWith);            highlight = true;            logInfo = "starts_with=" + startsWith + ",";        }        else if ((top != null) || (bottom != null))        {            // ----------------------------------------------            // Paginating: put specified entry at top or bottom            // ----------------------------------------------            // Use a single value and a boolean to simplify the code below            String val = bottom;            boolean isTop = false;            if (top != null)            {                val = top;                isTop = true;            }            if (browseAuthors)            {                // Value will be a text value for author browse                scope.setFocus(val);            }            else            {                // Value is Handle if we're browsing items by title or date                Item item = (Item) HandleManager.resolveToObject(context, val);                if (item == null)                {                    // Handle is invalid one. Show an error.                    JSPManager.showInvalidIDError(request, response, focus,                            Constants.ITEM);                    return;                }                scope.setFocus(item);            }            // This entry appears at the top or bottom, and so needs to have            // 0 or 20 entries shown before it            scope.setNumberBefore(isTop ? 0 : 20);            logInfo = (isTop ? "top" : "bottom") + "=" + val + ",";            if (browseDates)            {                // If the date order is flipped, we'll flip the table upside                // down - i.e. the top will become the bottom and the bottom                // the top.                if (top != null)                {                    flipOrderingQuery = "bottom="                            + URLEncoder                                    .encode(top, Constants.DEFAULT_ENCODING)                            + "&";                }                else                {                    flipOrderingQuery = "top="                            + URLEncoder.encode(bottom,                                    Constants.DEFAULT_ENCODING) + "&";                }            }        }        // ----------------------------------------------        // If none of the above apply, no positioning parameters        // set - use start of index        // ----------------------------------------------        // Are we in a community or collection?        Community community = UIUtil.getCommunityLocation(request);        Collection collection = UIUtil.getCollectionLocation(request);        if (collection != null)        {            logInfo = logInfo + ",collection_id=" + collection.getID() + ",";            scope.setScope(collection);        }        else if (community != null)        {            logInfo = logInfo + ",community_id=" + community.getID() + ",";            scope.setScope(community);        }        BrowseInfo browseInfo;        // Query the browse index        if (browseAuthors)        {            browseInfo = Browse.getAuthors(scope);        }        else if (browseDates)        {            browseInfo = Browse.getItemsByDate(scope, oldestFirst);        }        else        {            browseInfo = Browse.getItemsByTitle(scope);        }        // Write log entry        String what = "title";        if (browseAuthors)        {            what = "author";        }        else if (browseDates)        {            what = "date";        }        log.info(LogManager.getHeader(context, "browse_" + what, logInfo                + "results=" + browseInfo.getResultCount()));        if (browseInfo.getResultCount() == 0)        {            // No results!            request.setAttribute("community", community);            request.setAttribute("collection", collection);            JSPManager.showJSP(request, response, "/browse/no-results.jsp");        }        else        {            // Work out what the query strings will be for the previous            // and next pages            if (!browseInfo.isFirst())            {                // Not the first page, so we'll need a "previous page" button                // The top entry of the current page becomes the bottom                // entry of the "previous page"                String s;                if (browseAuthors)                {                    s = (browseInfo.getStringResults())[0];                }                else                {                    Item firstItem = (browseInfo.getItemResults())[0];                    s = firstItem.getHandle();                }                if (browseDates && oldestFirst)                {                    // For browsing by date, oldest first, we need                    // to add the ordering parameter                    request.setAttribute("previous.query",                            "order=oldestfirst&bottom="                                    + URLEncoder.encode(s,                                            Constants.DEFAULT_ENCODING));                }                else                {                    request.setAttribute("previous.query", "bottom="                            + URLEncoder.encode(s, Constants.DEFAULT_ENCODING));                }            }            if (!browseInfo.isLast())            {                // Not the last page, so we'll need a "next page" button                // The bottom entry of the current page will be the top                // entry in the next page                String s;                if (browseAuthors)                {                    String[] authors = browseInfo.getStringResults();                    s = authors[authors.length - 1];                }                else                {                    Item[] items = browseInfo.getItemResults();                    Item lastItem = items[items.length - 1];                    s = lastItem.getHandle();                }                if (browseDates && oldestFirst)                {                    // For browsing by date, oldest first, we need                    // to add the ordering parameter                    request.setAttribute("next.query", "order=oldestfirst&top="                            + URLEncoder.encode(s, Constants.DEFAULT_ENCODING));                }                else                {                    request.setAttribute("next.query", "top="                            + URLEncoder.encode(s, Constants.DEFAULT_ENCODING));                }            }            // Set appropriate attributes and forward to results page            request.setAttribute("community", community);            request.setAttribute("collection", collection);            request.setAttribute("browse.info", browseInfo);            request.setAttribute("highlight", new Boolean(highlight));            if (browseAuthors)            {                JSPManager.showJSP(request, response, "/browse/authors.jsp");            }            else if (browseDates)            {                request.setAttribute("oldest.first", new Boolean(oldestFirst));                request.setAttribute("flip.ordering.query", flipOrderingQuery);                JSPManager.showJSP(request, response,                        "/browse/items-by-date.jsp");            }            else            {                JSPManager.showJSP(request, response,                        "/browse/items-by-title.jsp");            }        }    }