/** * Gets the current page number from the query string "p" of the specified request. * * @param request the specified request * @return page number, returns {@code 1} as default */ public static int getPage(final HttpServletRequest request) { int ret = 1; final String p = request.getParameter("p"); if (Strings.isNumeric(p)) { try { ret = Integer.parseInt(p); } catch (final Exception e) { // ignored } } if (1 > ret) { ret = 1; } return ret; }
/** * Gets the current page number from the query string "p" of the specified request. * * @param request the specified request * @return page number, returns {@code 1} as default */ public static int getPage(final HttpServletRequest request) { int ret = 1; final String p = request.getParameter("p"); if (Strings.isNumeric(p)) { try { ret = Integer.parseInt(p); } catch (final Exception e) { // ignored } } if (1 > ret) { ret = 1; } return ret; }
/** * Gets the request page number from the specified path. * * @param path the specified path, see {@link #PAGINATION_PATH_PATTERN} for the details * @return page number, returns {@code 1} if the specified request URI can not convert to an number * @see #PAGINATION_PATH_PATTERN */ public static int getCurrentPageNum(final String path) { if (StringUtils.isBlank(path) || path.equals("/")) { return 1; } final String currentPageNumber = path.split("/")[0]; if (!Strings.isNumeric(currentPageNumber)) { return 1; } return Integer.valueOf(currentPageNumber); }
/** * Gets the request window size from the specified path. * * @param path the specified path, see {@link #PAGINATION_PATH_PATTERN} for the details * @return page number, returns {@value #DEFAULT_WINDOW_SIZE} if the specified request URI can not convert to an number * @see #PAGINATION_PATH_PATTERN */ public static int getWindowSize(final String path) { if (StringUtils.isBlank(path)) { return DEFAULT_WINDOW_SIZE; } final String[] parts = path.split("/"); if (2 >= parts.length) { return DEFAULT_WINDOW_SIZE; } final String windowSize = parts[2]; if (!Strings.isNumeric(windowSize)) { return DEFAULT_WINDOW_SIZE; } return Integer.valueOf(windowSize); } }
/** * Gets the request page size from the specified path. * * @param path the specified path, see {@link #PAGINATION_PATH_PATTERN} for the details * @return page number, returns {@value #DEFAULT_PAGE_SIZE} if the specified request URI can not convert to an number * @see #PAGINATION_PATH_PATTERN */ public static int getPageSize(final String path) { if (StringUtils.isBlank(path)) { return DEFAULT_PAGE_SIZE; } final String[] parts = path.split("/"); if (1 >= parts.length) { return DEFAULT_PAGE_SIZE; } final String pageSize = parts[1]; if (!Strings.isNumeric(pageSize)) { return DEFAULT_PAGE_SIZE; } return Integer.valueOf(pageSize); }