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

📄 gdatarequest.java

📁 一套java版本的搜索引擎源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        return retval < 0 ? DEFAULT_ITEMS_PER_PAGE : retval;    }    /**     * Start index represents the number of the first entry of the query -     * result. The order depends on the query. Is the query a search query the     * this value will be assigned to the score in a common feed query the value     * will be assigned to the update time of the entries.     *      * @return - the requested start index     */    public int getStartIndex() {        String startIndex = this.request.getParameter(START_INDEX_NEXT_PAGE_PARAMETER);        if (startIndex == null)            return DEFAULT_START_INDEX;        int retval = -1;        try {            retval = new Integer(startIndex).intValue();        } catch (Exception e) {            LOG.warn("Start-index could not be parsed - not an integer - " + e.getMessage());        }        return retval < 0 ? DEFAULT_START_INDEX : retval;    }    /**     * The self id is the feeds <i>href</i> pointing to the requested resource     *      * @return - the self id     */    public String getSelfId() {        StringBuilder builder = new StringBuilder();        builder.append(buildRequestIDString(false));        builder.append("?");        builder.append(getQueryString());        return builder.toString();    }        /**       * The previous id is the feeds <i>href</i> pointing to the previous result of the requested resource     *      * @return - the self id     */    public String getPreviousId(){                int startIndex = getStartIndex();        if(startIndex == DEFAULT_START_INDEX )            return null;        StringBuilder builder = new StringBuilder();        builder.append(buildRequestIDString(false));        startIndex = startIndex-getItemsPerPage();        builder.append(getPreparedQueryString(startIndex<1?DEFAULT_START_INDEX:startIndex));        return builder.toString();    }          private String getPreparedQueryString(int startIndex){        String queryString = this.request.getQueryString();        String startIndexValue = this.request.getParameter(START_INDEX_NEXT_PAGE_PARAMETER);        String maxResultsValue = this.request.getParameter(ITEMS_PER_PAGE_PARAMETER);                StringBuilder builder = new StringBuilder("?");        if(maxResultsValue == null){            builder.append(ITEMS_PER_PAGE_PARAMETER).append("=").append(DEFAULT_ITEMS_PER_PAGE);            builder.append("&");        }        if(startIndexValue== null){            builder.append(START_INDEX_NEXT_PAGE_PARAMETER).append("=");            builder.append(Integer.toString(startIndex));            if(queryString!=null){                builder.append("&");                builder.append(queryString);            }        }else{            builder.append(queryString.replaceAll("start-index=[\\d]*",START_INDEX_NEXT_PAGE_PARAMETER+"="+Integer.toString(startIndex)));        }        return builder.toString();    }    /**     * The <i>href</i> id of the next page of the requested resource.     *      * @return the id of the next page     */    public String getNextId() {        int startIndex = getStartIndex();        StringBuilder builder = new StringBuilder();        builder.append(buildRequestIDString(false));        startIndex = startIndex+getItemsPerPage();        builder.append(getPreparedQueryString(startIndex));        return builder.toString();    }    private String buildRequestIDString(boolean endingSlash) {        StringBuilder builder = new StringBuilder("http://");        builder.append(this.request.getHeader("Host"));        builder.append(this.request.getRequestURI());        if (!endingSlash && builder.charAt(builder.length() - 1) == '/')            builder.setLength(builder.length() - 1);        if (endingSlash && builder.charAt(builder.length() - 1) != '/')            builder.append("/");        return builder.toString();    }    /**     * This will return the current query string including all parameters.     * Additionally the <code>max-resul</code> parameter will be added if not     * specified.     * <p>     * <code>max-resul</code> indicates the number of results returned to the     * client. The default value is 25.     * </p>     *      * @return - the query string including all parameters     */    public String getQueryString() {        String retVal = this.request.getQueryString();        if (this.request.getParameter(ITEMS_PER_PAGE_PARAMETER) != null)            return retVal;        String tempString = (retVal == null ? ITEMS_PER_PAGE_PARAMETER + "="                + DEFAULT_ITEMS_PER_PAGE : "&" + ITEMS_PER_PAGE_PARAMETER + "="                + DEFAULT_ITEMS_PER_PAGE);        return retVal == null ? tempString : retVal + tempString;    }    /**     * This enum represents the OutputFormat of the GDATA Server     *      * @author Simon Willnauer     *      */    public static enum OutputFormat {        /**         * Output format ATOM. ATOM is the default response format.         */        ATOM,        /**         * Output format RSS         */        RSS,        /**         * Output format html if user defined xsl style sheet is present          */        HTML    }    /**     * Returns the requested path including the domain name and the requested     * resource <i>http://www.apache.org/path/resource/</i>     *      * @return the context path     */    public String getContextPath() {        if (this.contextPath == null)            this.contextPath = buildRequestIDString(true);        return this.contextPath;    }    /**     * Indicates the request type     *      * @author Simon Willnauer     *      */    public enum GDataRequestType {        /**         * Type FeedRequest         */        GET,        /**         * Type UpdateRequest         */        UPDATE,        /**         * Type DeleteRequest         */        DELETE,        /**         * Type InsertRequest         */        INSERT    }    /**     * {@link GDataRequestType}     *      * @return the current request type     */    public GDataRequestType getType() {        return this.type;    }    /**     * If the request is a {@link GDataRequestType#GET} request and there is no     * entry id specified, the requested resource is a feed.     *      * @return - <code>true</code> if an only if the requested resource is a     *         feed     */    public boolean isFeedRequested() {        return this.isFeedRequest ;    }    /**     * * If the request is a {@link GDataRequestType#GET} request and there is     * an entry id specified, the requested resource is an entry.     *      * @return - <code>true</code> if an only if the requested resource is an     *         entry     */    public boolean isEntryRequested() {        return !this.isFeedRequested();    }    /**     * @return - <code>true</code> if an only if the user request is a search request, otherwise <code>false</code>     */    public boolean isSearchRequested(){        return this.isSearchRequest;    }    /**     * @return the configuration for this request     */    public ProvidedService getConfigurator() {        return this.configurator;    }    /**     * @return - Returns the Internet Protocol (IP) address of the client or     *         last proxy that sent the request.     */    public String getRemoteAddress() {        return this.request.getRemoteAddr();    }    /**     * @return - the value for the send auth token. The auth token will be send     *         as a request <tt>Authentication</tt> header.     */    public String getAuthToken() {        String token = this.request.getHeader(HTTP_HEADER_AUTH);        if (token == null)            return null;        token = token.substring(token.indexOf("=") + 1);        return token;    }    /**     * @return - Returns an array containing all of the Cookie objects the     *         client sent with underlying HttpServletRequest.     */    public Cookie[] getCookies() {        return this.request.getCookies();    }    /**     * @return - the cookie set instead of the authentication token or     *         <code>null</code> if no auth cookie is set     */    public Cookie getAuthCookie() {        Cookie[] cookies = this.request.getCookies();        if (cookies == null)            return null;        for (int i = 0; i < cookies.length; i++) {            if (cookies[i].getName().equals(AuthenticationController.TOKEN_KEY))                return cookies[i];        }        return null;    }    /**     * @return - the date string of the <tt>If-Modified-Since</tt> HTTP     *         request header, or null if header is not set     */    public String getModifiedSince() {        return this.request.getHeader(HTTP_HEADER_IF_MODIFIED_SINCE);    }    /**     * @return - the underlying HttpServletRequest     */    public HttpServletRequest getHttpServletRequest() {        return this.request;    }        protected String getTranslatedQuery(){        return this.translatedSearchQuery;    } }

⌨️ 快捷键说明

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