Example usage for javax.servlet ServletRequest getParameterValues

List of usage examples for javax.servlet ServletRequest getParameterValues

Introduction

In this page you can find the example usage for javax.servlet ServletRequest getParameterValues.

Prototype

public String[] getParameterValues(String name);

Source Link

Document

Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.

Usage

From source file:org.itboys.commons.utils.servlet.Servlets.java

/**
 * ???Request Parameters, copy from spring.
 * /*ww w  . j  av a 2 s .c om*/
 * Parameter???.
 * 
 * m2
 */
@SuppressWarnings({ "rawtypes" })
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
    Validate.notNull(request, "Request must not be null");
    Enumeration paramNames = request.getParameterNames();
    Map<String, Object> params = new HashMap<String, Object>();
    if (prefix == null) {
        prefix = "";
    }
    while (paramNames != null && paramNames.hasMoreElements()) {
        String paramName = (String) paramNames.nextElement();
        if ("".equals(prefix) || paramName.startsWith(prefix)) {
            String unprefixed = paramName.substring(prefix.length());
            String[] values = request.getParameterValues(paramName);
            if (values == null || values.length == 0) {
                // Do nothing, no values found at all.
            } else if (values.length > 1) {
                params.put(unprefixed, values);
            } else {
                params.put(unprefixed, values[0]);
            }
        }
    }
    return params;
}

From source file:org.jahia.data.viewhelper.principal.PrincipalViewHelper.java

/**
 * Get the user search result from the parameter form given by the request.
 * If the form is not in the request then all the Jahia users will be search.
 *
 * @param request the request that should contain the HTML formular with the
 *                following fields :/*  w  w w. j av a  2s .c o m*/
 *                - searchString
 *                - searchIn
 *                - properties
 *                - storedOn
 *                - providers
 * @return a Properties object that contain the search criterium
 */
public static Set<JCRUserNode> getSearchResult(ServletRequest request) {

    String searchString = request.getParameter("searchString");
    final String searchIn = request.getParameter("searchIn");
    final String[] searchInProps = request.getParameterValues("properties");
    final String storedOn = request.getParameter("storedOn");
    final String[] providers = request.getParameterValues("providers");

    return getSearchResult(searchIn, null, searchString, searchInProps, storedOn, providers);
}

From source file:org.jahia.data.viewhelper.principal.PrincipalViewHelper.java

/**
 * Get the group search result from the parameter form given by the request.
 * If the form is not in the request then all the Jahia groups will be search.
 *
 * @param request the request that should contain the HTML formular with the
 *                following fields :/*from   w ww  .  jav a2s . c o  m*/
 *                - searchString
 *                - searchIn
 *                - properties
 *                - storedOn
 *                - providers
 * @param siteKey  The site ID containing the principal to search
 * @return a Properties object that contain the search criterium
 */
public static Set<JCRGroupNode> getGroupSearchResult(ServletRequest request, String siteKey) {

    String searchString = request.getParameter("searchString");
    final String searchIn = request.getParameter("searchIn");
    final String[] searchInProps = request.getParameterValues("properties");
    final String storedOn = request.getParameter("storedOn");
    final String[] providers = request.getParameterValues("providers");

    return getGroupSearchResult(searchIn, siteKey, searchString, searchInProps, storedOn, providers);
}

From source file:org.mitre.medj.WebUtils.java

/**
 *  Retrieves a list of parameters from a passed request in comma delimited
 *  format. If the parameter is not found, an NPE is thrown.
 *
 * @param  req                       Request object to look in
 * @param  name                      the name of the field from the html
 *      form/*from  ww w .j  av  a  2 s .c o  m*/
 * @return                           the value from the html form
 *      corresponding to the name parameter
 * @exception  NullPointerException  thrown if the name was not in the html
 *      form
 */
public static String getRequiredParameterValues(ServletRequest req, String name) throws NullPointerException {
    String[] values = req.getParameterValues(name);

    if (values == null) {
        throw new NullPointerException("This form requires a \"" + name
                + "\" parameter, which was missing from the submitted request.");
    }

    StringBuffer ret = new StringBuffer();

    for (int i = 0; i < values.length; i++) {
        if (i > 0) {
            ret.append(",");
        }
        ret.append(values[i]);
    }
    return ret.toString();
}

From source file:org.mitre.medj.WebUtils.java

/**
   *  Retrieves a list of parameters from a passed request in comma delimited
   *  format. If the parameter is not found, an NPE is thrown.
   */*from   w w w . ja v a 2  s.  c om*/
   * @param  req                       Request object to look in
   * @param  name                      the name of the field from the html
   *      form
   * @return                           the value from the html form
   *      corresponding to the name parameter
   * @exception  NullPointerException  thrown if the name was not in the html
   *      form
   */
public static String getOptionalParameterValues(ServletRequest req, String name) throws NullPointerException {
    String[] values = req.getParameterValues(name);

    if (values == null) {
        return "";
    }

    StringBuffer ret = new StringBuffer();

    for (int i = 0; i < values.length; i++) {
        if (i > 0) {
            ret.append(",");
        }
        ret.append(values[i]);
    }
    return ret.toString();
}

From source file:org.nimbustools.messaging.query.security.QueryAuthenticationFilter.java

private void appendCanonicalQueryString_v2(ServletRequest request, StringBuilder buf) {
    final Set<String> sortedKeys = new TreeSet<String>();
    final Enumeration paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
        String param = (String) paramNames.nextElement();

        // don't include signature in canonical query string
        if (!param.equals(this.signatureParameter)) {
            sortedKeys.add(param);/*  www  .  j  a  v a  2 s.c o m*/
        }
    }
    boolean first = true;
    for (String key : sortedKeys) {
        String[] values = request.getParameterValues(key);

        for (String val : values) {
            if (first) {
                first = false;
            } else {
                buf.append('&');
            }

            buf.append(urlEncode(key)).append('=');
            buf.append(urlEncode(val));
        }
    }
}

From source file:org.nimbustools.messaging.query.security.QueryAuthenticationFilter.java

private static String getExactlyOneParameter(ServletRequest request, String paramName) {
    String[] values = request.getParameterValues(paramName);
    if (values == null || values.length != 1) {
        throw new QueryException(QueryError.InvalidArgument,
                "Request must have exactly one " + paramName + " parameter");
    }/*from w  w w.j  a  v  a 2s .  co m*/
    return values[0];
}

From source file:org.nimbustools.messaging.query.security.QueryAuthenticationFilter.java

private static String getAtMostOneParameter(ServletRequest request, String paramName) {

    String[] values = request.getParameterValues(paramName);
    if (values == null || values.length == 0) {
        return null;
    }//from w  w w.j a  v a 2 s  . c  o  m
    if (values.length > 1) {
        throw new QueryException(QueryError.InvalidArgument,
                "Request must have at most one " + paramName + " parameter");
    }
    return values[0];
}

From source file:org.pushio.datacenter.ctrl.util.Servlets.java

/**
 * ???Request Parameters, copy from spring WebUtils.
 * //from w w w.j  a v  a2 s. c  o m
 * Parameter???.
 */
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
    Validate.notNull(request, "Request must not be null");
    Enumeration paramNames = request.getParameterNames();
    Map<String, Object> params = new TreeMap<String, Object>();
    if (prefix == null) {
        prefix = "";
    }
    if ((paramNames != null)) {
        while (paramNames.hasMoreElements()) {
            String paramName = (String) paramNames.nextElement();
            if ("".equals(prefix) || paramName.startsWith(prefix)) {
                String unprefixed = paramName.substring(prefix.length());
                String[] values = request.getParameterValues(paramName);
                if ((values == null) || (values.length == 0)) {
                    // Do nothing, no values found at all.
                } else if (values.length > 1) {
                    params.put(unprefixed, values);
                } else {
                    params.put(unprefixed, values[0]);
                }
            }
        }
    }
    return params;
}

From source file:org.rhq.enterprise.gui.legacy.util.RequestUtils.java

public static String dumpRequestParamsToString(ServletRequest request, boolean html) {
    StringBuffer output = new StringBuffer();
    if (html) {/*from  w  w w. ja  v  a  2s.  co  m*/
        output.append("<ol>\n");
    }

    for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
        String key = (String) e.nextElement();
        String[] values = request.getParameterValues(key);
        if (html) {
            output.append("<li>");
        }

        output.append("'" + key + "' = ");
        for (int i = 0; i < (values.length - 1); i++) {
            output.append("'" + values[i] + "', ");
        }

        output.append("'" + values[values.length - 1] + "'");
        output.append("\n");
    }

    if (html) {
        output.append("</ol>\n");
    }

    return output.toString();
}