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

The following examples show how to use javax.portlet.PortletRequest#getParameter() . 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: ComplexPortletApplicationContext.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public void doSomething(PortletRequest request) throws Exception {
	if (request.getParameter("fail") != null) {
		throw new ModelAndViewDefiningException(new ModelAndView("failed-modelandview"));
	}
	if (request.getParameter("access") != null) {
		throw new IllegalAccessException("portlet-illegalaccess");
	}
	if (request.getParameter("binding") != null) {
		throw new PortletRequestBindingException("portlet-binding");
	}
	if (request.getParameter("generic") != null) {
		throw new Exception("portlet-generic");
	}
	if (request.getParameter("runtime") != null) {
		throw new RuntimeException("portlet-runtime");
	}
	throw new IllegalArgumentException("illegal argument");
}
 
Example 2
Source File: PortletModeParameterHandlerMapping.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a lookup key that combines the current PortletMode and the current
 * value of the specified parameter.
 * @see javax.portlet.PortletRequest#getPortletMode()
 * @see #setParameterName
 */
@Override
protected PortletModeParameterLookupKey getLookupKey(PortletRequest request) throws Exception {
	PortletMode mode = request.getPortletMode();
	String parameter = request.getParameter(this.parameterName);
	return new PortletModeParameterLookupKey(mode, parameter);
}
 
Example 3
Source File: RenderParameterTest.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
protected TestResult checkRenderParameterValue(PortletRequest request) {
    TestResult result = new TestResult();
    result.setDescription("Ensure that render parameters set in action "
    		+ "response are available in the following render request.");

    String value = request.getParameter(RENDER_KEY);
    if (RENDER_VALUE.equals(value)) {
    	result.setReturnCode(TestResult.PASSED);
    } else {
    	TestUtils.failOnAssertion("parameter", value, RENDER_VALUE, result);
    }
    return result;
}
 
Example 4
Source File: RenderParameterTest.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
protected TestResult checkActionParametersNotHere(PortletRequest request) {
    TestResult result = new TestResult();
    result.setDescription("Ensure that action parameters are not available "
    		+ "in the following render request.");

    String value = request.getParameter(ACTION_KEY);
    if (value == null) {
    	result.setReturnCode(TestResult.PASSED);
    } else {
    	TestUtils.failOnAssertion("parameter", value, null, result);
    }
    return result;
}
 
Example 5
Source File: TestPortlet.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the current test ID.
 * @param request  the portlet request.
 * @return the current test ID.
 */
private String getTestId(PortletRequest request) {

    String testId = request.getParameter("testId");
    String prevTestId = request.getParameter("previousTestId");
    String nextTestId = request.getParameter("nextTestId");

    // If none of the parameters are available, return null.
    if ((testId == null || testId.trim().length() == 0)
            && nextTestId == null && prevTestId == null
            && tests.size() > 0) {
        return null;
    }

    // Retrieve the test which is next to the previous test.
    else if (testId == null && prevTestId != null) {
        int previousTestIdInt = Integer.parseInt(prevTestId);
        if (previousTestIdInt >= testConfigs.size() - 1) {
            testId = "0";
        } else {
            testId = String.valueOf(previousTestIdInt + 1);
        }
    }

    // Retrieve the test which is previous to the next test.
    else if (testId == null && nextTestId != null) {
        int nextTestIdInt = Integer.parseInt(nextTestId);
        if (nextTestIdInt <= 0) {
            testId = String.valueOf(testConfigs.size()-1);
        } else {
            testId = String.valueOf(nextTestIdInt - 1);
        }
    }

    // Return the current test ID.
    return testId;
}
 
Example 6
Source File: PortletRequestUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Get a boolean parameter, with a fallback value. Never throws an exception.
 * Can pass a distinguished value as default to enable checks of whether it was supplied.
 * <p>Accepts "true", "on", "yes" (any case) and "1" as values for true;
 * treats every other non-empty value as false (i.e. parses leniently).
 * @param request current portlet request
 * @param name the name of the parameter
 * @param defaultVal the default value to use as fallback
 */
public static boolean getBooleanParameter(PortletRequest request, String name, boolean defaultVal) {
	if (request.getParameter(name) == null) {
		return defaultVal;
	}
	try {
		return getRequiredBooleanParameter(request, name);
	}
	catch (PortletRequestBindingException ex) {
		return defaultVal;
	}
}
 
Example 7
Source File: PortletRequestUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Get a double parameter, with a fallback value. Never throws an exception.
 * Can pass a distinguished value as default to enable checks of whether it was supplied.
 * @param request current portlet request
 * @param name the name of the parameter
 * @param defaultVal the default value to use as fallback
 */
public static double getDoubleParameter(PortletRequest request, String name, double defaultVal) {
	if (request.getParameter(name) == null) {
		return defaultVal;
	}
	try {
		return getRequiredDoubleParameter(request, name);
	}
	catch (PortletRequestBindingException ex) {
		return defaultVal;
	}
}
 
Example 8
Source File: PortletRequestUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Get a float parameter, with a fallback value. Never throws an exception.
 * Can pass a distinguished value as default to enable checks of whether it was supplied.
 * @param request current portlet request
 * @param name the name of the parameter
 * @param defaultVal the default value to use as fallback
 */
public static float getFloatParameter(PortletRequest request, String name, float defaultVal) {
	if (request.getParameter(name) == null) {
		return defaultVal;
	}
	try {
		return getRequiredFloatParameter(request, name);
	}
	catch (PortletRequestBindingException ex) {
		return defaultVal;
	}
}
 
Example 9
Source File: PortletRequestUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Get a long parameter, with a fallback value. Never throws an exception.
 * Can pass a distinguished value as default to enable checks of whether it was supplied.
 * @param request current portlet request
 * @param name the name of the parameter
 * @param defaultVal the default value to use as fallback
 */
public static long getLongParameter(PortletRequest request, String name, long defaultVal) {
	if (request.getParameter(name) == null) {
		return defaultVal;
	}
	try {
		return getRequiredLongParameter(request, name);
	}
	catch (PortletRequestBindingException ex) {
		return defaultVal;
	}
}
 
Example 10
Source File: PortletRequestUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Get an int parameter, with a fallback value. Never throws an exception.
 * Can pass a distinguished value as default to enable checks of whether it was supplied.
 * @param request current portlet request
 * @param name the name of the parameter
 * @param defaultVal the default value to use as fallback
 */
public static int getIntParameter(PortletRequest request, String name, int defaultVal) {
	if (request.getParameter(name) == null) {
		return defaultVal;
	}
	try {
		return getRequiredIntParameter(request, name);
	}
	catch (PortletRequestBindingException ex) {
		return defaultVal;
	}
}
 
Example 11
Source File: PortletUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Return the full name of a specific input type="submit" parameter
 * if it was sent in the request, either via a button (directly with name)
 * or via an image (name + ".x" or name + ".y").
 * @param request current portlet request
 * @param name name of the parameter
 * @return the actual parameter name with suffix if needed - null if not present
 * @see org.springframework.web.util.WebUtils#SUBMIT_IMAGE_SUFFIXES
 */
public static String getSubmitParameter(PortletRequest request, String name) {
	Assert.notNull(request, "Request must not be null");
	if (request.getParameter(name) != null) {
		return name;
	}
	for (int i = 0; i < WebUtils.SUBMIT_IMAGE_SUFFIXES.length; i++) {
		String suffix = WebUtils.SUBMIT_IMAGE_SUFFIXES[i];
		String parameter = name + suffix;
		if (request.getParameter(parameter) != null) {
			return parameter;
		}
	}
	return null;
}
 
Example 12
Source File: ParameterHandlerMapping.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Uses the value of the specified parameter as lookup key.
 * @see #setParameterName
 */
@Override
protected String getLookupKey(PortletRequest request) throws Exception {
	return request.getParameter(this.parameterName);
}
 
Example 13
Source File: AddlEnvironmentTests_SPEC2_18_Sessions_invalidate2.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
protected void processTCKReq(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

  PortletRequest portletReq = (PortletRequest) request.getAttribute("javax.portlet.request");
  PortletResponse portletResp = (PortletResponse) request.getAttribute("javax.portlet.response");
  PortletSession portletSession = portletReq.getPortletSession();
  

  PrintWriter writer = ((MimeResponse) portletResp).getWriter();

  JSR286SpecTestCaseDetails tcd = new JSR286SpecTestCaseDetails();

  /* TestCase: V2AddlEnvironmentTests_SPEC2_18_Sessions_httpSession5 */
  /* Details: "If the PortletSession object is invalidated by a */
  /* portlet, the portlet container must invalidate the associated */
  /* HttpSession object" */
  {
     String tcid = portletReq.getParameter(BUTTON_PARAM_NAME);
     if (tcid == null || !tcid.equals(V2ADDLENVIRONMENTTESTS_SPEC2_18_SESSIONS_HTTPSESSION5)) {
        
        // generate test link 
        
        PortletURL rurl = ((MimeResponse)portletResp).createRenderURL();
        rurl.setParameter(BUTTON_PARAM_NAME, V2ADDLENVIRONMENTTESTS_SPEC2_18_SESSIONS_HTTPSESSION5);
        TestLink tl = new TestLink(V2ADDLENVIRONMENTTESTS_SPEC2_18_SESSIONS_HTTPSESSION5, rurl);
        tl.writeTo(writer);
     } else {
        
        // perform test
        
        TestResult result = tcd.getTestResultFailed(V2ADDLENVIRONMENTTESTS_SPEC2_18_SESSIONS_HTTPSESSION5);
        portletSession.invalidate();
        if (!request.isRequestedSessionIdValid()) {
          result.setTcSuccess(true);
        } else {
          result.appendTcDetail("Failed because session is not invalidated.");
        }
        result.writeTo(writer);
     }
  }
  
}
 
Example 14
Source File: PortletRequestUtils.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Get a Float parameter, or {@code null} if not present.
 * Throws an exception if it the parameter value isn't a number.
 * @param request current portlet request
 * @param name the name of the parameter
 * @return the Float value, or {@code null} if not present
 * @throws PortletRequestBindingException a subclass of PortletException,
 * so it doesn't need to be caught
 */
public static Float getFloatParameter(PortletRequest request, String name)
		throws PortletRequestBindingException {

	if (request.getParameter(name) == null) {
		return null;
	}
	return getRequiredFloatParameter(request, name);
}
 
Example 15
Source File: PortletRequestUtils.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Get a Double parameter, or {@code null} if not present.
 * Throws an exception if it the parameter value isn't a number.
 * @param request current portlet request
 * @param name the name of the parameter
 * @return the Double value, or {@code null} if not present
 * @throws PortletRequestBindingException a subclass of PortletException,
 * so it doesn't need to be caught
 */
public static Double getDoubleParameter(PortletRequest request, String name)
		throws PortletRequestBindingException {

	if (request.getParameter(name) == null) {
		return null;
	}
	return getRequiredDoubleParameter(request, name);
}
 
Example 16
Source File: PortletRequestUtils.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Get a Boolean parameter, or {@code null} if not present.
 * Throws an exception if it the parameter value isn't a boolean.
 * <p>Accepts "true", "on", "yes" (any case) and "1" as values for true;
 * treats every other non-empty value as false (i.e. parses leniently).
 * @param request current portlet request
 * @param name the name of the parameter
 * @return the Boolean value, or {@code null} if not present
 * @throws PortletRequestBindingException a subclass of PortletException,
 * so it doesn't need to be caught
 */
public static Boolean getBooleanParameter(PortletRequest request, String name)
		throws PortletRequestBindingException {

	if (request.getParameter(name) == null) {
		return null;
	}
	return (getRequiredBooleanParameter(request, name));
}
 
Example 17
Source File: PortletRequestUtils.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Get a Long parameter, or {@code null} if not present.
 * Throws an exception if it the parameter value isn't a number.
 * @param request current portlet request
 * @param name the name of the parameter
 * @return the Long value, or {@code null} if not present
 * @throws PortletRequestBindingException a subclass of PortletException,
 * so it doesn't need to be caught
 */
public static Long getLongParameter(PortletRequest request, String name)
		throws PortletRequestBindingException {

	if (request.getParameter(name) == null) {
		return null;
	}
	return getRequiredLongParameter(request, name);
}
 
Example 18
Source File: PortletRequestUtils.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Get a String parameter, or {@code null} if not present.
 * Throws an exception if it the parameter value is empty.
 * @param request current portlet request
 * @param name the name of the parameter
 * @return the String value, or {@code null} if not present
 * @throws PortletRequestBindingException a subclass of PortletException,
 * so it doesn't need to be caught
 */
public static String getStringParameter(PortletRequest request, String name)
		throws PortletRequestBindingException {

	if (request.getParameter(name) == null) {
		return null;
	}
	return getRequiredStringParameter(request, name);
}
 
Example 19
Source File: PortletRequestUtils.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Get an Integer parameter, or {@code null} if not present.
 * Throws an exception if it the parameter value isn't a number.
 * @param request current portlet request
 * @param name the name of the parameter
 * @return the Integer value, or {@code null} if not present
 * @throws PortletRequestBindingException a subclass of PortletException,
 * so it doesn't need to be caught
 */
public static Integer getIntParameter(PortletRequest request, String name)
		throws PortletRequestBindingException {

	if (request.getParameter(name) == null) {
		return null;
	}
	return getRequiredIntParameter(request, name);
}
 
Example 20
Source File: PortletRequestUtils.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Get a String parameter, with a fallback value. Never throws an exception.
 * Can pass a distinguished value to default to enable checks of whether it was supplied.
 * @param request current portlet request
 * @param name the name of the parameter
 * @param defaultVal the default value to use as fallback
 */
public static String getStringParameter(PortletRequest request, String name, String defaultVal) {
	String val = request.getParameter(name);
	return (val != null ? val : defaultVal);
}