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

The following examples show how to use javax.portlet.PortletRequest#getPreferences() . 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: PreferenceCommonTest.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
protected TestResult checkGetPreferenceNames(PortletRequest request) {
    TestResult result = new TestResult();
    result.setDescription("Ensure returned enumeration is valid.");
    result.setSpecPLT("14.1");

    PortletPreferences preferences = request.getPreferences();
    Map<String, String[]> prefMap = preferences.getMap();
    boolean hasAll = true;
    for (Enumeration<String> en = preferences.getNames(); 
    		en.hasMoreElements(); ) {
        if (!prefMap.containsKey(en.nextElement())) {
            hasAll = false;
            break;
        }
    }

    if (hasAll) {
    	result.setReturnCode(TestResult.PASSED);
    } else {
    	result.setReturnCode(TestResult.FAILED);
    	result.setResultMessage("At least one name is not found "
    			+ "in the preference map.");
    }
    return result;
}
 
Example 2
Source File: PreferenceCommonTest.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
protected TestResult checkSetPreferencesReturnsFirst(PortletRequest request) {
    TestResult result = new TestResult();
    result.setDescription("Ensure the first value set to a given "
    		+ "preference is returned first by PortletPreferences.getValue().");
    result.setSpecPLT("14.1");

    PortletPreferences preferences = request.getPreferences();
    try {
        preferences.setValues("TEST", new String[] { "FIRST", "SECOND" });
    } catch (ReadOnlyException ex) {
    	TestUtils.failOnException("Unable to set preference values.", ex, result);
    	return result;
    }

    String value = preferences.getValue("TEST", DEF_VALUE);
    if (value != null && value.equals("FIRST")) {
    	result.setReturnCode(TestResult.PASSED);
    } else {
    	TestUtils.failOnAssertion("preference value", value, "FIRST", result);
    }
    return result;
}
 
Example 3
Source File: PreferenceCommonTest.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
/**
 * Private method that checks if a preference is not defined or has no
 * value in <code>portlet.xml</code>, the default values are returned.
 * @param request  the portlet request.
 * @param preferenceName  the preference name which is not defined or has no
 *        value in <code>portlet.xml</code>.
 * @return the test result.
 */
private TestResult doCheckDefaultPreference(PortletRequest request,
                                            String preferenceName) {
	TestResult result = new TestResult();
	result.setDescription("Ensure proper default is returned when "
			+ "a non-existing/value-undefined preference is requested.");
	result.setSpecPLT("14.1");

	PortletPreferences preferences = request.getPreferences();
	String value =  preferences.getValue(preferenceName, DEF_VALUE);
	String[] values = preferences.getValues(preferenceName,
	                                        new String[] { DEF_VALUE });
	if (DEF_VALUE.equals(value)
			&& values != null && values.length == 1
			&& DEF_VALUE.equals(values[0])) {
		result.setReturnCode(TestResult.PASSED);
	} else if (!DEF_VALUE.equals(value)) {
		TestUtils.failOnAssertion("preference value", value, DEF_VALUE, result);
	} else {
		TestUtils.failOnAssertion("preference values",
		                          values,
		                          new String[] { DEF_VALUE },
		                          result);
	}
	return result;
}
 
Example 4
Source File: PreferenceCommonTest.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
protected TestResult checkSetPreferenceNull(PortletRequest request) {
    TestResult result = new TestResult();
    result.setDescription("Ensure a preference value can be set to null.");
    result.setSpecPLT("14.1");

    PortletPreferences preferences = request.getPreferences();
    try {
        preferences.setValue("TEST", null);
    } catch (ReadOnlyException ex) {
    	TestUtils.failOnException("Unable to set preference value.", ex, result);
        return result;
    }

    String value = preferences.getValue("TEST", DEF_VALUE);
    // see PLUTO-609: behavioral change!
    if (null == value) {
        result.setReturnCode(TestResult.PASSED);
    } else {
        TestUtils.failOnAssertion("preference value", value, null, result);
    }
    return result;
}
 
Example 5
Source File: PreferenceCommonTest.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
protected TestResult checkSetPreferenceSingleValue(PortletRequest request) {
    TestResult result = new TestResult();
    result.setDescription("Ensure a single preference value can be set.");
    result.setSpecPLT("14.1");

    PortletPreferences preferences = request.getPreferences();
    try {
        preferences.setValue("TEST", "TEST_VALUE");
    } catch (ReadOnlyException ex) {
    	TestUtils.failOnException("Unable to set preference value.", ex, result);
        return result;
    }

    String value = preferences.getValue("TEST", DEF_VALUE);
    if (value != null && value.equals("TEST_VALUE")) {
    	result.setReturnCode(TestResult.PASSED);
    } else {
    	TestUtils.failOnAssertion("preference value", value, "TEST_VALUE", result);
    }
    return result;
}
 
Example 6
Source File: PreferenceCommonTest.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
protected TestResult checkSetPreferenceMultiValues(PortletRequest request) {
    TestResult result = new TestResult();
    result.setDescription("Ensure multiple preference values can be set.");
    result.setSpecPLT("14.1");

    PortletPreferences preferences = request.getPreferences();
    try {
        preferences.setValues("TEST", new String[] {"ONE", "ANOTHER"});
    } catch (ReadOnlyException ex) {
    	TestUtils.failOnException("Unable to set preference values.", ex, result);
    	return result;
    }

    String[] values = preferences.getValues("TEST", new String[] { DEF_VALUE });
    if (values != null && values.length == 2
    		&& values[0].equals("ONE") && values[1].equals("ANOTHER")) {
    	result.setReturnCode(TestResult.PASSED);
    } else if (values == null) {
    	TestUtils.failOnAssertion("preference values",
    	                          values,
    	                          new String[] { "ONE", "ANOTHER" },
    	                          result);
    } else if (values.length != 2) {
    	TestUtils.failOnAssertion("length of preference values",
    	                          String.valueOf(values.length),
    	                          String.valueOf(2),
    	                          result);
    } else {
    	TestUtils.failOnAssertion("preference values",
    	                          values,
    	                          new String[] { "ONE", "ANOTHER" },
    	                          result);
    }
    return result;
}
 
Example 7
Source File: SimpleRSSPortlet.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Helper to check if a preference is locked (ie readonly). This may be set by a channel config to restrict access.
 * 
 * @param request
 * @return
 */
private boolean isPrefLocked(PortletRequest request, String prefName) {
	PortletPreferences prefs = request.getPreferences();
	try {
		return prefs.isReadOnly(prefName);
	} catch (IllegalArgumentException e){
		log.debug("Preference does not exist: " + prefName);
		return false;
	}
}
 
Example 8
Source File: IMSBLTIPortlet.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public String getCorrectProperty(PortletRequest request, String propName, String defaultValue)
{
	Placement placement = ToolManager.getCurrentPlacement();
	String propertyName = placement.getToolId() + "." + propName;
	String propValue = ServerConfigurationService.getString(propertyName,null);
	if ( propValue != null && propValue.trim().length() > 0 ) {
		log.debug("Sakai.home {}={}", propName, propValue);
		return propValue;
	}

	Properties config = placement.getConfig();
	propValue = getSakaiProperty(config, "imsti."+propName);
	if ( propValue != null && "true".equals(config.getProperty("final."+propName)) )
	{
		log.debug("Frozen {} ={}", propName, propValue);
		return propValue;
	}

	PortletPreferences prefs = request.getPreferences();
	propValue = prefs.getValue("imsti."+propName, null);
	if ( propValue != null ) {
		log.debug("Portlet {} ={}", propName, propValue);
		return propValue;
	}

	propValue = getSakaiProperty(config, "imsti."+propName);
	if ( propValue != null ) {
		log.debug("Tool {} ={}", propName, propValue);
		return propValue;
	}

	if ( defaultValue != null ) {
		log.debug("Default {} ={}", propName, defaultValue);
		return defaultValue;
	}
	log.debug("Fell through {}", propName);
	return null;
}
 
Example 9
Source File: PreferenceCommonTest.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
/**
 * Check (xci) SPEC 91, PLT 14.1: Preferences values are not modified
 * if the values in the Map are altered.
 */
protected TestResult checkPreferenceValueNotModified(PortletRequest request) {
	TestResult result = new TestResult();
	result.setDescription("Preferences values are not modified if "
			+ "the values in the returned preference Map are altered.");
	result.setSpecPLT("14.1");

	PortletPreferences preferences = request.getPreferences();
    if (LOG.isDebugEnabled()) {
    	LOG.debug("Original Preferences:");
    	logPreferences(preferences);
    }

    // Modify the returned preference map.
	Map<String, String[]> prefMap = preferences.getMap();
	String[] values = (String[]) prefMap.get(PREF_NAME);
	String originalValue = null;
	String modifiedValue = "Value modified in preferences map.";
	if (values != null && values.length == 1) {
		originalValue = values[0];
		values[0] = modifiedValue;
	}

	// Check if the value held by portlet preferences is modified.
    if (LOG.isDebugEnabled()) {
    	LOG.debug("Modified Preferences:");
    	logPreferences(preferences);
    }
	String newValue = preferences.getValue(PREF_NAME, DEF_VALUE);
	if (newValue != null && newValue.equals(originalValue)) {
		result.setReturnCode(TestResult.PASSED);
	} else {
		result.setReturnCode(TestResult.FAILED);
		result.setResultMessage("Preference value modified according to "
				+ "the preference map.");
	}
	return result;
}
 
Example 10
Source File: ChannelUtilities.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Gets the preference value.
 *
 * @param requestContainer
 *            the request container
 * @param preferenceName
 *            the preference name
 * @param defaultValue
 *            the default value
 *
 * @return the preference value
 */
public static String getPreferenceValue(RequestContainer requestContainer, String preferenceName, String defaultValue) {
	String prefValue = defaultValue;
	try {
		// get mode of execution
		String channelType = requestContainer.getChannelType();
		String sbiMode = null;
		if ("PORTLET".equalsIgnoreCase(channelType))
			sbiMode = "PORTLET";
		else
			sbiMode = "WEB";
		// based on mode get spago object and url builder
		if (sbiMode.equalsIgnoreCase("WEB")) {
			SourceBean request = requestContainer.getServiceRequest();
			Object prefValueObj = request.getAttribute(preferenceName);
			if (prefValueObj != null)
				prefValue = prefValueObj.toString();
			else
				prefValue = defaultValue;
		} else if (sbiMode.equalsIgnoreCase("PORTLET")) {
			PortletRequest portReq = getPortletRequest();
			PortletPreferences prefs = portReq.getPreferences();
			prefValue = prefs.getValue(preferenceName, defaultValue);
		}
	} catch (Exception e) {
		SpagoBITracer.major(SpagoBIConstants.NAME_MODULE, ChannelUtilities.class.getName(), "getPreferenceValue", "Error while recovering preference value",
				e);
		prefValue = defaultValue;
	}
	return prefValue;
}
 
Example 11
Source File: PreferenceCommonTest.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
protected TestResult checkGetPreferences(PortletRequest request) {
    TestResult result = new TestResult();
    result.setDescription("Ensure that preferences defined "
    		+ "in the deployment descriptor may be retrieved.");
    result.setSpecPLT("14.1");

    PortletPreferences preferences = request.getPreferences();
    String value = preferences.getValue(PREF_NAME, DEF_VALUE);
    if (value != null && value.equals(PREF_VALUE)) {
    	result.setReturnCode(TestResult.PASSED);
    } else {
    	TestUtils.failOnAssertion("preference value", value, PREF_VALUE, result);
    }
    return result;
}
 
Example 12
Source File: SimpleRSSPortlet.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Helper to check if a preference is locked (ie readonly). This may be set by a channel config to restrict access.
 * 
 * @param request
 * @return
 */
private boolean isPrefLocked(PortletRequest request, String prefName) {
	PortletPreferences prefs = request.getPreferences();
	try {
		return prefs.isReadOnly(prefName);
	} catch (IllegalArgumentException e){
		log.debug("Preference does not exist: " + prefName);
		return false;
	}
}
 
Example 13
Source File: IMSBLTIPortlet.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public String getCorrectProperty(PortletRequest request, String propName, String defaultValue)
{
	Placement placement = ToolManager.getCurrentPlacement();
	String propertyName = placement.getToolId() + "." + propName;
	String propValue = ServerConfigurationService.getString(propertyName,null);
	if ( propValue != null && propValue.trim().length() > 0 ) {
		log.debug("Sakai.home {}={}", propName, propValue);
		return propValue;
	}

	Properties config = placement.getConfig();
	propValue = getSakaiProperty(config, "imsti."+propName);
	if ( propValue != null && "true".equals(config.getProperty("final."+propName)) )
	{
		log.debug("Frozen {} ={}", propName, propValue);
		return propValue;
	}

	PortletPreferences prefs = request.getPreferences();
	propValue = prefs.getValue("imsti."+propName, null);
	if ( propValue != null ) {
		log.debug("Portlet {} ={}", propName, propValue);
		return propValue;
	}

	propValue = getSakaiProperty(config, "imsti."+propName);
	if ( propValue != null ) {
		log.debug("Tool {} ={}", propName, propValue);
		return propValue;
	}

	if ( defaultValue != null ) {
		log.debug("Default {} ={}", propName, defaultValue);
		return defaultValue;
	}
	log.debug("Fell through {}", propName);
	return null;
}
 
Example 14
Source File: SaveConfigurationModule.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Service.
 * 
 * @param request the request
 * @param response the response
 * 
 * @throws Exception the exception
 * 
 * @see it.eng.spago.dispatching.action.AbstractHttpAction#service(it.eng.spago.base.SourceBean, it.eng.spago.base.SourceBean)
 */

public void service(SourceBean request, SourceBean response) throws Exception {
       
	List attributes = request.getContainedAttributes();
	PortletRequest portReq = PortletUtilities.getPortletRequest();
	PortletPreferences pref = portReq.getPreferences();
	String prefPrefix = "PORTLET_PREF_";
	Iterator it = attributes.iterator();
	while (it.hasNext()) {
		SourceBeanAttribute attribute = (SourceBeanAttribute) it.next();
		String key = attribute.getKey();
		if (key != null && key.startsWith(prefPrefix)) {
			String prefName = key.substring(prefPrefix.length());
			String prefValues = (String) attribute.getValue();
			String[] values = prefValues.split(",");
			pref.setValues(prefName, values);
		}
	}
	pref.store();
	/*
	SessionContainer session = getRequestContainer().getSessionContainer();
	RequestContainer requestContainer = this.getRequestContainer();
	PortletRequest portReq = PortletUtilities.getPortletRequest();
	PortletPreferences pref = portReq.getPreferences();
	String lang = (String)request.getAttribute("language");
	String[] codesLang = lang.split(",");
	pref.setValues("language", codesLang);
	pref.store();
	SessionContainer permanentContainer = session.getPermanentContainer();
	permanentContainer.setAttribute("AF_LANGUAGE", codesLang[0]);
	permanentContainer.setAttribute("AF_COUNTRY", codesLang[1]);
	*/
}
 
Example 15
Source File: PreferenceCommonTest.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
protected TestResult checkResetPreferenceToDefault(PortletRequest request) {
	TestResult result = new TestResult();
	result.setDescription("Ensure preferences are properly reset.");
	result.setSpecPLT("14.1");

    PortletPreferences preferences = request.getPreferences();
    boolean setOccured = false;
    boolean resetOccured = false;

    try {
    	// Set new value to overwrite the default value.
        preferences.setValue(PREF_NAME, NEW_VALUE);
        String value = preferences.getValue(PREF_NAME, DEF_VALUE);
        if (NEW_VALUE.equals(value)) {
            setOccured = true;
        }
        // Reset the preference so that default value is restored.
        preferences.reset(PREF_NAME);
        value =  preferences.getValue(PREF_NAME, DEF_VALUE);
        if (PREF_VALUE.equals(value)) {
            resetOccured = true;
        }
    } catch (ReadOnlyException ex) {
    	TestUtils.failOnException("Unable to set preference value.", ex, result);
    	return result;
    }

    // Everything is OK.
    if (setOccured && resetOccured) {
    	result.setReturnCode(TestResult.PASSED);
    }
    // Error occurred when setting or storing preferences.
    else if (!setOccured) {
    	result.setReturnCode(TestResult.WARNING);
    	result.setResultMessage("A function upon which the reset test "
    			+ "depends failed to execute as expected. "
    			+ "Check the other test results in this test suite.");
    }
    // Error occurred when resetting preference.
    else {
    	result.setReturnCode(TestResult.FAILED);
    	result.setResultMessage("Preferences value was not successfully reset after store");
    }
    return result;
}
 
Example 16
Source File: PreferenceCommonTest.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
protected TestResult checkResetPreferenceWithoutDefault(PortletRequest request) {
	TestResult result = new TestResult();
    result.setDescription("Ensure preferences are properly reset (removed) "
    		+ "when the default value is not defined.");
    result.setSpecPLT("14.1");

    PortletPreferences preferences = request.getPreferences();
    boolean setOccured = false;
    boolean resetOccured = false;

    try {
    	// Set preference value to overwrite the original (null).
        preferences.setValue(BOGUS_KEY, NEW_VALUE);
        String value = preferences.getValue(BOGUS_KEY, DEF_VALUE);
        if (NEW_VALUE.equals(value)) {
            setOccured = true;
        }
        // Reset preference value to null.
        preferences.reset(BOGUS_KEY);
        value =  preferences.getValue(BOGUS_KEY, DEF_VALUE);
        if (DEF_VALUE.equals(value)) {
            resetOccured = true;
        }
    } catch (ReadOnlyException ex) {
    	TestUtils.failOnException("Unable to set preference value.", ex, result);
    	return result;
    }

    // Everything is OK.
    if (setOccured && resetOccured) {
    	result.setReturnCode(TestResult.PASSED);
    }
    // Error occurred when setting or storing preferences.
    else if (!setOccured) {
    	result.setReturnCode(TestResult.WARNING);
    	result.setResultMessage("A function upon which the reset test "
    			+ "depends failed to execute as expected. "
    			+ "Check the other test results in this test suite.");
    }
    // Error occurred when resetting preference value.
    else {
    	result.setReturnCode(TestResult.FAILED);
    	result.setResultMessage("Preferences value was not successfully "
    			+ "reset after store.");
    }
    return result;
}
 
Example 17
Source File: AnnotationMethodHandlerAdapter.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
protected Object resolveStandardArgument(Class<?> parameterType, NativeWebRequest webRequest)
		throws Exception {

	PortletRequest request = webRequest.getNativeRequest(PortletRequest.class);
	PortletResponse response = webRequest.getNativeResponse(PortletResponse.class);

	if (PortletRequest.class.isAssignableFrom(parameterType) ||
			MultipartRequest.class.isAssignableFrom(parameterType)) {
		Object nativeRequest = webRequest.getNativeRequest(parameterType);
		if (nativeRequest == null) {
			throw new IllegalStateException(
					"Current request is not of type [" + parameterType.getName() + "]: " + request);
		}
		return nativeRequest;
	}
	else if (PortletResponse.class.isAssignableFrom(parameterType)) {
		Object nativeResponse = webRequest.getNativeResponse(parameterType);
		if (nativeResponse == null) {
			throw new IllegalStateException(
					"Current response is not of type [" + parameterType.getName() + "]: " + response);
		}
		return nativeResponse;
	}
	else if (PortletSession.class.isAssignableFrom(parameterType)) {
		return request.getPortletSession();
	}
	else if (PortletPreferences.class.isAssignableFrom(parameterType)) {
		return request.getPreferences();
	}
	else if (PortletMode.class.isAssignableFrom(parameterType)) {
		return request.getPortletMode();
	}
	else if (WindowState.class.isAssignableFrom(parameterType)) {
		return request.getWindowState();
	}
	else if (PortalContext.class.isAssignableFrom(parameterType)) {
		return request.getPortalContext();
	}
	else if (Principal.class.isAssignableFrom(parameterType)) {
		return request.getUserPrincipal();
	}
	else if (Locale.class == parameterType) {
		return request.getLocale();
	}
	else if (InputStream.class.isAssignableFrom(parameterType)) {
		if (!(request instanceof ClientDataRequest)) {
			throw new IllegalStateException("InputStream can only get obtained for Action/ResourceRequest");
		}
		return ((ClientDataRequest) request).getPortletInputStream();
	}
	else if (Reader.class.isAssignableFrom(parameterType)) {
		if (!(request instanceof ClientDataRequest)) {
			throw new IllegalStateException("Reader can only get obtained for Action/ResourceRequest");
		}
		return ((ClientDataRequest) request).getReader();
	}
	else if (OutputStream.class.isAssignableFrom(parameterType)) {
		if (!(response instanceof MimeResponse)) {
			throw new IllegalStateException("OutputStream can only get obtained for Render/ResourceResponse");
		}
		return ((MimeResponse) response).getPortletOutputStream();
	}
	else if (Writer.class.isAssignableFrom(parameterType)) {
		if (!(response instanceof MimeResponse)) {
			throw new IllegalStateException("Writer can only get obtained for Render/ResourceResponse");
		}
		return ((MimeResponse) response).getWriter();
	}
	else if (Event.class == parameterType) {
		if (!(request instanceof EventRequest)) {
			throw new IllegalStateException("Event can only get obtained from EventRequest");
		}
		return ((EventRequest) request).getEvent();
	}
	return super.resolveStandardArgument(parameterType, webRequest);
}
 
Example 18
Source File: DefineObjectsTag286.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
/**
 * Processes the <CODE>defineObjects</CODE> tag.
 * @return <CODE>SKIP_BODY</CODE>
 */
public int doStartTag() throws JspException {
	
	ServletRequest servletRequest = pageContext.getRequest();
	
	PortletRequest portletRequest = 
		(PortletRequest) servletRequest.getAttribute(Constants.PORTLET_REQUEST);
	
	PortletResponse portletResponse = 
		(PortletResponse) servletRequest.getAttribute(Constants.PORTLET_RESPONSE);
	
	PortletConfig portletConfig = 
		(PortletConfig) servletRequest.getAttribute(Constants.PORTLET_CONFIG);
	
	PortletSession portletSession = portletRequest.getPortletSession(false);
	
	Map<String, Object> portletSessionScope = null;
	if(portletSession != null){
		portletSessionScope = (Map<String, Object>)portletSession.getAttributeMap();// getMap();
	}
	else{
		portletSessionScope = new HashMap<String, Object>();
	}
	
	PortletPreferences portletPreferences = portletRequest.getPreferences();
	
	Map<String, String[]> portletPreferencesValues = null;
	if(portletPreferences != null){
		portletPreferencesValues = portletPreferences.getMap();
	}
	else{
		portletPreferencesValues = new HashMap<String, String[]>();
	}
	
	// set attributes render and request
	setPortletRequestResponseAttribute(portletRequest, portletResponse);
	
	// set attribute portletConfig
	setAttribute(portletConfig, "portletConfig");
	
	// set attribute portletSession
	setAttribute(portletSession, "portletSession");
	
	//set attribute portletSession
	setAttribute(portletSessionScope, "portletSessionScope");
	
	// set attribute portletPreferences
	setAttribute(portletPreferences, "portletPreferences");
	
	// set attribute portletPreferences
	setAttribute(portletPreferencesValues, "portletPreferencesValues");    	
	
    return SKIP_BODY;
}
 
Example 19
Source File: AnnotationMethodHandlerExceptionResolver.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Resolves standard method arguments. The default implementation handles {@link NativeWebRequest},
 * {@link ServletRequest}, {@link ServletResponse}, {@link HttpSession}, {@link Principal},
 * {@link Locale}, request {@link InputStream}, request {@link Reader}, response {@link OutputStream},
 * response {@link Writer}, and the given {@code thrownException}.
 * @param parameterType the method parameter type
 * @param webRequest the request
 * @param thrownException the exception thrown
 * @return the argument value, or {@link org.springframework.web.bind.support.WebArgumentResolver#UNRESOLVED}
 */
protected Object resolveStandardArgument(Class<?> parameterType, NativeWebRequest webRequest,
		Exception thrownException) throws Exception {

	if (parameterType.isInstance(thrownException)) {
		return thrownException;
	}
	else if (WebRequest.class.isAssignableFrom(parameterType)) {
		return webRequest;
	}

	PortletRequest request = webRequest.getNativeRequest(PortletRequest.class);
	PortletResponse response = webRequest.getNativeResponse(PortletResponse.class);

	if (PortletRequest.class.isAssignableFrom(parameterType)) {
		return request;
	}
	else if (PortletResponse.class.isAssignableFrom(parameterType)) {
		return response;
	}
	else if (PortletSession.class.isAssignableFrom(parameterType)) {
		return request.getPortletSession();
	}
	else if (PortletPreferences.class.isAssignableFrom(parameterType)) {
		return request.getPreferences();
	}
	else if (PortletMode.class.isAssignableFrom(parameterType)) {
		return request.getPortletMode();
	}
	else if (WindowState.class.isAssignableFrom(parameterType)) {
		return request.getWindowState();
	}
	else if (PortalContext.class.isAssignableFrom(parameterType)) {
		return request.getPortalContext();
	}
	else if (Principal.class.isAssignableFrom(parameterType)) {
		return request.getUserPrincipal();
	}
	else if (Locale.class == parameterType) {
		return request.getLocale();
	}
	else if (InputStream.class.isAssignableFrom(parameterType)) {
		if (!(request instanceof ClientDataRequest)) {
			throw new IllegalStateException("InputStream can only get obtained for Action/ResourceRequest");
		}
		return ((ClientDataRequest) request).getPortletInputStream();
	}
	else if (Reader.class.isAssignableFrom(parameterType)) {
		if (!(request instanceof ClientDataRequest)) {
			throw new IllegalStateException("Reader can only get obtained for Action/ResourceRequest");
		}
		return ((ClientDataRequest) request).getReader();
	}
	else if (OutputStream.class.isAssignableFrom(parameterType)) {
		if (!(response instanceof MimeResponse)) {
			throw new IllegalStateException("OutputStream can only get obtained for Render/ResourceResponse");
		}
		return ((MimeResponse) response).getPortletOutputStream();
	}
	else if (Writer.class.isAssignableFrom(parameterType)) {
		if (!(response instanceof MimeResponse)) {
			throw new IllegalStateException("Writer can only get obtained for Render/ResourceResponse");
		}
		return ((MimeResponse) response).getWriter();
	}
	else if (Event.class == parameterType) {
		if (!(request instanceof EventRequest)) {
			throw new IllegalStateException("Event can only get obtained from EventRequest");
		}
		return ((EventRequest) request).getEvent();
	}
	else {
		return WebArgumentResolver.UNRESOLVED;
	}
}