com.feilong.servlet.http.RequestUtilTemp.java Source code

Java tutorial

Introduction

Here is the source code for com.feilong.servlet.http.RequestUtilTemp.java

Source

/*
 * Copyright (C) 2008 feilong
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.feilong.servlet.http;

import static org.apache.commons.lang3.StringUtils.EMPTY;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;

import com.feilong.core.net.ParamUtil;

import static com.feilong.core.URIComponents.FRAGMENT;
import static com.feilong.core.Validator.isNotNullOrEmpty;
import static com.feilong.core.Validator.isNullOrEmpty;

/**
 *
 * @author <a href="http://feitianbenyue.iteye.com/">feilong</a>
 * @since 1.4.0
 */
public class RequestUtilTemp {

    /**
     * ?.
     * 
     * <p>
     * <span style="color:red">:url?,?,???</span>
     * </p>
     * 
     * <p>
     * :({@link javax.servlet.ServletRequest#getParameter(String)},URI?,??)
     * </p>
     * 
     * @param request
     *            
     * @param paramName
     *            ???
     * @return ?
     * @deprecated ??
     */
    @Deprecated
    public static String getParameterAsItIsDecode(HttpServletRequest request, String paramName) {
        String returnValue = null;
        String queryString = request.getQueryString();
        if (isNotNullOrEmpty(queryString)) {
            Map<String, String> map = ParamUtil.toSingleValueMap(queryString, null);
            return map.get(paramName);
        }
        return returnValue;
    }

    /**
     * ??,null,.
     * 
     * @param request
     *            ?
     * @param paramName
     *            the param name
     * @return ??,null,
     * @deprecated ???
     */
    @Deprecated
    public static String getParameterWithTrim(HttpServletRequest request, String paramName) {
        String returnValue = RequestUtil.getParameter(request, paramName);
        if (isNotNullOrEmpty(returnValue)) {
            return returnValue.trim();
        }
        return returnValue;
    }

    /**
     * ??,sendDirect #,???.
     * 
     * @param request
     *            the request
     * @param paramName
     *            the param name
     * @return ??,sendDirect #,???
     * @deprecated ??
     */
    @Deprecated
    public static String getParameterWithoutSharp(HttpServletRequest request, String paramName) {
        String returnValue = RequestUtil.getParameter(request, paramName);
        if (isNotNullOrEmpty(returnValue)) {
            if (StringUtils.contains(returnValue, FRAGMENT)) {
                returnValue = substring(returnValue, null, FRAGMENT);
            }
        }
        return returnValue;
    }

    /**
     * [?]: <code>startString</code> ? <code>endString</code> .
     * 
     * <p>
     * ?<code>startString</code>,???<code>endString</code>.
     * </p>
     * 
     * @param text
     *            
     * @param startString
     *            ,null?
     * @param endString
     *            ?
     * @return  <code>text</code> nullempty, {@link StringUtils#EMPTY}<br>
     *         isNullOrEmpty(startString), text.substring(0, text.indexOf(endString))
     * @see org.apache.commons.lang3.StringUtils#substringBetween(String, String, String)
     */
    public static String substring(final String text, final String startString, final String endString) {
        return isNullOrEmpty(text) ? EMPTY
                : text.substring(isNullOrEmpty(startString) ? 0 : text.indexOf(startString),
                        text.indexOf(endString));
    }
}