Java Code Examples for javax.portlet.PortletRequest#getParameterNames()

The following examples show how to use javax.portlet.PortletRequest#getParameterNames() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PortletUtils.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Return a map containing all parameters with the given prefix.
 * Maps single values to String and multiple values to String array.
 * <p>For example, with a prefix of "spring_", "spring_param1" and
 * "spring_param2" result in a Map with "param1" and "param2" as keys.
 * <p>Similar to portlet
 * {@link javax.portlet.PortletRequest#getParameterMap()},
 * but more flexible.
 * @param request portlet request in which to look for parameters
 * @param prefix the beginning of parameter names
 * (if this is {@code null} or the empty string, all parameters will match)
 * @return map containing request parameters <b>without the prefix</b>,
 * containing either a String or a String array as values
 * @see javax.portlet.PortletRequest#getParameterNames
 * @see javax.portlet.PortletRequest#getParameterValues
 * @see javax.portlet.PortletRequest#getParameterMap
 */
public static Map<String, Object> getParametersStartingWith(PortletRequest request, String prefix) {
	Assert.notNull(request, "Request must not be null");
	Enumeration<String> paramNames = request.getParameterNames();
	Map<String, Object> params = new TreeMap<String, Object>();
	if (prefix == null) {
		prefix = "";
	}
	while (paramNames != null && paramNames.hasMoreElements()) {
		String paramName = 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;
}
 
Example 2
Source File: PortletUtils.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Return the target page specified in the request.
 * @param request current portlet request
 * @param paramPrefix the parameter prefix to check for
 * (e.g. "_target" for parameters like "_target1" or "_target2")
 * @param currentPage the current page, to be returned as fallback
 * if no target page specified
 * @return the page specified in the request, or current page if not found
 */
public static int getTargetPage(PortletRequest request, String paramPrefix, int currentPage) {
	Enumeration<String> paramNames = request.getParameterNames();
	while (paramNames.hasMoreElements()) {
		String paramName = paramNames.nextElement();
		if (paramName.startsWith(paramPrefix)) {
			for (int i = 0; i < WebUtils.SUBMIT_IMAGE_SUFFIXES.length; i++) {
				String suffix = WebUtils.SUBMIT_IMAGE_SUFFIXES[i];
				if (paramName.endsWith(suffix)) {
					paramName = paramName.substring(0, paramName.length() - suffix.length());
				}
			}
			return Integer.parseInt(paramName.substring(paramPrefix.length()));
		}
	}
	return currentPage;
}
 
Example 3
Source File: AdapterPortlet.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Handle simple form.
 *
 * @param request
 *            the request
 * @param requestContext
 *            the request context
 *
 * @throws SourceBeanException
 *             the source bean exception
 */
private void handleSimpleForm(PortletRequest request, RequestContextIFace requestContext) throws SourceBeanException {
	SourceBean serviceRequest = requestContext.getServiceRequest();
	Enumeration names = request.getParameterNames();
	while (names.hasMoreElements()) {
		String parameterName = (String) names.nextElement();
		String[] parameterValues = request.getParameterValues(parameterName);
		if (parameterValues != null)
			for (int i = 0; i < parameterValues.length; i++)
				serviceRequest.setAttribute(parameterName, parameterValues[i]);
	} // while (names.hasMoreElements())
}
 
Example 4
Source File: AdapterPortlet.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
    * Handle simple form.
    * 
    * @param request the request
    * @param requestContext the request context
    * 
    * @throws SourceBeanException the source bean exception
    */
   private void handleSimpleForm(PortletRequest request, RequestContextIFace requestContext) throws SourceBeanException {
   	SourceBean serviceRequest = requestContext.getServiceRequest();
   	Enumeration names = request.getParameterNames();
       while (names.hasMoreElements()) {
           String parameterName = (String) names.nextElement();
           String[] parameterValues =
               request.getParameterValues(parameterName);
           if (parameterValues != null)
               for (int i = 0; i < parameterValues.length; i++)
                   serviceRequest.setAttribute(
                       parameterName,
                       parameterValues[i]);
       } // while (names.hasMoreElements())
}
 
Example 5
Source File: AdapterPortlet.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
private void handleSimpleForm(PortletRequest request, RequestContextIFace requestContext) throws SourceBeanException {
	SourceBean serviceRequest = requestContext.getServiceRequest();
	Enumeration names = request.getParameterNames();
	while (names.hasMoreElements()) {
		String parameterName = (String) names.nextElement();
		String[] parameterValues = request.getParameterValues(parameterName);
		if (parameterValues != null)
			for (int i = 0; i < parameterValues.length; i++)
				serviceRequest.setAttribute(parameterName, parameterValues[i]);
	} // while (names.hasMoreElements())
}
 
Example 6
Source File: DispatcherPortlet.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Expose the given action exception to the given response.
 * @param request current portlet request
 * @param response current portlet response
 * @param ex the action exception (may also come from an event phase)
 */
protected void exposeActionException(PortletRequest request, StateAwareResponse response, Exception ex) {
	// Copy all parameters unless overridden in the action handler.
	Enumeration<String> paramNames = request.getParameterNames();
	while (paramNames.hasMoreElements()) {
		String paramName = paramNames.nextElement();
		String[] paramValues = request.getParameterValues(paramName);
		if (paramValues != null && !response.getRenderParameterMap().containsKey(paramName)) {
			response.setRenderParameter(paramName, paramValues);
		}
	}
	response.setRenderParameter(ACTION_EXCEPTION_RENDER_PARAMETER, ex.toString());
	request.getPortletSession().setAttribute(ACTION_EXCEPTION_SESSION_ATTRIBUTE, ex);
}
 
Example 7
Source File: RenderParameterTest.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
protected TestResult checkParameterNames(PortletRequest request) {
    TestResult result = new TestResult();
    result.setDescription("Ensure that render request returns the correct "
    		+ "parameter names enumeration.");

    boolean hasActionParameter = false;
    boolean hasRenderParameter = false;
    for (Enumeration<String> en = request.getParameterNames();
    		en.hasMoreElements(); ) {
        String name = en.nextElement();
        if (ACTION_KEY.equals(name)) {
        	hasActionParameter = true;
        }
        if (RENDER_KEY.equals(name)) {
        	hasRenderParameter = true;
        }
    }

    if (!hasActionParameter && hasRenderParameter) {
    	result.setReturnCode(TestResult.PASSED);
    } else {
    	result.setReturnCode(TestResult.FAILED);
        StringBuffer buffer = new StringBuffer();
        if (!hasRenderParameter) {
        	buffer.append("Render parameter not found. ");
        }
        if (!hasActionParameter) {
        	buffer.append("Action parameter found. ");
        }
        result.setResultMessage(buffer.toString());
    }
    return result;
}