Example usage for javax.servlet ServletRequest getParameter

List of usage examples for javax.servlet ServletRequest getParameter

Introduction

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

Prototype

public String getParameter(String name);

Source Link

Document

Returns the value of a request parameter as a String, or null if the parameter does not exist.

Usage

From source file:com.doculibre.constellio.filters.SetCharacterEncodingFilter.java

private static String lookupCharSet(ServletRequest request) {
    String charSet;/* www  .  j a  va  2 s  .  c  om*/
    String cs = request.getParameter("cs");
    if (StringUtils.isNotBlank(cs)) {
        if ("Utf8".equalsIgnoreCase(cs) || CharSetUtils.UTF_8.equalsIgnoreCase(cs)) {
            charSet = CharSetUtils.UTF_8;
        } else if ("Iso".equalsIgnoreCase(cs) || CharSetUtils.ISO_8859_1.equalsIgnoreCase(cs)) {
            charSet = CharSetUtils.ISO_8859_1;
        } else {
            try {
                Charset.forName(cs);
                charSet = cs;
            } catch (UnsupportedCharsetException e) {
                charSet = null;
            }
        }
    } else {
        charSet = null;
    }
    return charSet;
}

From source file:org.rhq.enterprise.gui.util.WebUtility.java

public static int getOptionalIntRequestParameter(ServletRequest request, String name, int defaultValue) {
    String value = request.getParameter(name);
    return ((value != null) && (value.length() > 0)) ? Integer.parseInt(value) : defaultValue;
}

From source file:com.redhat.rhn.frontend.taglibs.list.ListTagHelper.java

/**
 * returns true if the list that is being filtered upon is allowed to
 * to treat the parent as an element (always true for normal list)
 * @param request the request to look in
 * @param uniqueName the unique (hashed) name for the list
 * @return true if the parent can be treated as an element.
 *///from   w w w  .j a v  a2s .c  om
public static boolean isParentAnElement(ServletRequest request, String uniqueName) {
    return ListTagUtil.toBoolean(request.getParameter(ListTagUtil.makeParentIsAnElementLabel(uniqueName)));
}

From source file:com.redhat.rhn.frontend.taglibs.list.ListTagHelper.java

/**
 * returns the value that the list is being filtered upon.  (null if not being filtered)
 * @param request the request to look in
 * @param uniqueName the unique (hashed) name for the list
 * @return the filter value/*from  ww  w  .j  ava 2s  . c  o  m*/
 */
public static String getFilterValue(ServletRequest request, String uniqueName) {

    String newValue = request.getParameter(ListTagUtil.makeFilterValueByLabel(uniqueName));
    String oldValue = request.getParameter(ListTagUtil.makeOldFilterValueByLabel(uniqueName));

    String clicked = request.getParameter(ListTagUtil.makeFilterNameByLabel(uniqueName));

    if (clicked == null) {
        if (oldValue != null && !oldValue.equals("null")) {
            return StringEscapeUtils.escapeHtml(oldValue);
        }
        return "";
    }
    return StringEscapeUtils.escapeHtml(newValue);
}

From source file:com.redhat.rhn.frontend.taglibs.list.decorators.PageSizeDecorator.java

/**
 * returns the page size/*from   w  w w . ja v a 2s . c  o  m*/
 * @param request the http  servlet request
 * @param listName the name of the list
 * @return selected page size or -1 if none was selected.
 */
public static int getSelectedPageSize(ServletRequest request, String listName) {
    if (pageWidgetSelected(request, listName)) {
        return Integer.valueOf(request.getParameter(makePageSizeLabel(listName)));
    }
    return -1;
}

From source file:dk.netarkivet.harvester.webinterface.EventHarvestUtil.java

/**
 * Adds a bunch of configurations to a given PartialHarvest. For full definitions of the parameters, see
 * Definitions-add-event-seeds.jsp. For each seed in the list, the following steps are taken: 1) The domain is
 * parsed out of the seed. If no such domain is known, it is created with the usual defaults. 2) For each domain, a
 * configuration with the name <harvestDefinition>_<orderTemplate>_<maxBytes>Bytes is created
 * unless it already exists. The configuration uses orderTemplate, and the specified maxBytes. If maxBytes is
 * unspecified, its default value is used. The configuration is added to the harvest specified by the
 * harvestDefinition argument. 3) For each domain, a seedlist with the name
 * <harvestDefinition>_<orderTemplate>_<maxBytes>Bytes is created if it does not already exist and
 * the given url is added to it. This seedlist is the only seedlist associated with the configuration of the same
 * name.//  w  ww  .  j  a v  a 2 s  .  c o  m
 *
 * @param context the current JSP context
 * @param i18n the translation information to use in this context
 * @param eventHarvestName The name of the partial harvest to which these seeds are to be added
 * @throws ForwardedToErrorPage If maxBytes is not a number, or if any of the seeds is badly formatted such that no
 * domain name can be parsed from it, or if orderTemplate is not given or unknown.
 */
public static void addConfigurations(PageContext context, I18n i18n, String eventHarvestName) {
    ArgumentNotValid.checkNotNull(context, "PageContext context");
    ArgumentNotValid.checkNotNull(i18n, "I18n i18n");
    ArgumentNotValid.checkNotNull(eventHarvestName, "String eventHarvestName");

    HTMLUtils.forwardOnMissingParameter(context, Constants.SEEDS_PARAM);
    ServletRequest request = context.getRequest();

    // If no seeds are specified, just return
    String seeds = request.getParameter(Constants.SEEDS_PARAM);
    if (seeds == null || seeds.trim().length() == 0) {
        return;
    }
    // split the seeds up into individual seeds
    // Note: Matches any sort of newline (unix/mac/dos), but won't get empty
    // lines, which is fine for this purpose

    Set<String> seedSet = new HashSet<String>();
    for (String seed : seeds.split("[\n\r]+")) {
        seedSet.add(seed);
    }

    HTMLUtils.forwardOnEmptyParameter(context, Constants.ORDER_TEMPLATE_PARAM);
    String orderTemplate = request.getParameter(Constants.ORDER_TEMPLATE_PARAM);
    // Check that order template exists
    if (!TemplateDAO.getInstance().exists(orderTemplate)) {
        HTMLUtils.forwardWithErrorMessage(context, i18n, "errormsg;harvest.template.0.does.not.exist",
                orderTemplate);
        throw new ForwardedToErrorPage("The orderTemplate with name '" + orderTemplate + "' does not exist!");
    }

    // Check that numerical parameters are meaningful and replace null or
    // empty with default values
    long maxBytes = HTMLUtils.parseOptionalLong(context, Constants.MAX_BYTES_PARAM,
            dk.netarkivet.harvester.datamodel.Constants.DEFAULT_MAX_BYTES);
    long maxObjectsL = HTMLUtils.parseOptionalLong(context, Constants.MAX_OBJECTS_PARAM,
            dk.netarkivet.harvester.datamodel.Constants.DEFAULT_MAX_OBJECTS);
    int maxObjects = (int) maxObjectsL;
    // All parameters are valid, so call method
    try {
        PartialHarvest eventHarvest = (PartialHarvest) HarvestDefinitionDAO.getInstance()
                .getHarvestDefinition(eventHarvestName);
        eventHarvest.addSeeds(seedSet, orderTemplate, maxBytes, maxObjects);
    } catch (Exception e) {
        HTMLUtils.forwardWithErrorMessage(context, i18n, "errormsg;error.adding.seeds.to.0", eventHarvestName,
                e);
        throw new ForwardedToErrorPage("Error while adding seeds", e);
    }
}

From source file:com.googlecode.jtiger.modules.ecside.filter.ECSideFilter.java

public static String getExportFileName(ServletRequest servletRequest) {
    String fileName = servletRequest.getParameter(ECSideConstants.EASY_DATA_EXPORT_FILENAME);
    if (StringUtils.isBlank(fileName)) {
        fileName = "excel.xls";
    }//from  ww  w  .j ava 2s  . co m
    return StringUtils.isNotBlank(fileName) ? fileName : null;
}

From source file:io.wcm.sling.commons.request.RequestParam.java

/**
 * @param request Servlet request/*from w  w  w . j av a 2 s  .  c  o m*/
 * @return Checks if form encoding parameter is set
 */
private static boolean hasFormEncodingParam(ServletRequest request) {
    return StringUtils.isNotEmpty(request.getParameter(PARAMETER_FORMENCODING));
}

From source file:org.opencms.file.history.CmsHistoryResourceHandler.java

/**
 * Appends the <code>version</code> parameter to the URI if needed.<p>
 * //from   w ww  . j a  v  a2s.  c  o  m
 * @param uri the resource URI
 * @param req the current request
 * 
 * @return the same URI, with additional parameters in case of a historical request
 */
public static String getHistoryResourceURI(String uri, ServletRequest req) {

    String histUri = uri;
    if (CmsHistoryResourceHandler.isHistoryRequest(req)) {
        String version = req.getParameter(CmsHistoryResourceHandler.PARAM_VERSION);
        histUri = CmsRequestUtil.appendParameter(uri, CmsHistoryResourceHandler.PARAM_VERSION, version);
    }
    return histUri;
}

From source file:org.rhq.enterprise.gui.util.WebUtility.java

public static String getRequiredRequestParameter(ServletRequest request, String name) {
    logWarningIfParameterHasMultipleValues(request, name);
    String value = request.getParameter(name);
    if (value == null) {
        throw new ParameterNotFoundException("Required request parameter '" + name + "' does not exist.");
    }// w  w  w .j  av  a 2 s . c om

    return value;
}