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

The following examples show how to use javax.portlet.PortletRequest#getPortletMode() . 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: SaveConfigurationPublisher.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Given the request at input, gets the name of the reference publisher,driving
 * the execution into the correct jsp page, or jsp error page, if any error occurred.
 * 
 * @param requestContainer The object containing all request information
 * @param responseContainer The object containing all response information
 * 
 * @return A string representing the name of the correct publisher, which will
 * call the correct jsp reference.
 */
public String getPublisherName(RequestContainer requestContainer, ResponseContainer responseContainer) {

	//SourceBean serviceRequest = requestContainer.getServiceRequest();
	EMFErrorHandler errorHandler = responseContainer.getErrorHandler();
	if (errorHandler.isOKBySeverity(EMFErrorSeverity.ERROR)) {
		PortletRequest portletRequest = PortletAccess.getPortletRequest();
		PortletMode mode = portletRequest.getPortletMode(); 
		if (PortletMode.EDIT.equals(mode)) return "saveConfiguration";
		if (PortletMode.HELP.equals(mode)) return "saveConfiguration";
		else return "saveConfigurationLoop";
	}
	else
		return new String("error");
}
 
Example 2
Source File: AnnotationMethodHandlerAdapter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public Method resolveHandlerMethod(PortletRequest request) throws PortletException {
	Map<RequestMappingInfo, Method> targetHandlerMethods = new LinkedHashMap<RequestMappingInfo, Method>();
	for (Method handlerMethod : getHandlerMethods()) {
		RequestMappingInfo mappingInfo = this.mappings.get(handlerMethod);
		if (mappingInfo.match(request)) {
			Method oldMappedMethod = targetHandlerMethods.put(mappingInfo, handlerMethod);
			if (oldMappedMethod != null && oldMappedMethod != handlerMethod) {
				throw new IllegalStateException("Ambiguous handler methods mapped for portlet mode '" +
						request.getPortletMode() + "': {" + oldMappedMethod + ", " + handlerMethod +
						"}. If you intend to handle the same mode in multiple methods, then factor " +
						"them out into a dedicated handler class with that mode mapped at the type level!");
			}
		}
	}
	if (!targetHandlerMethods.isEmpty()) {
		if (targetHandlerMethods.size() == 1) {
			return targetHandlerMethods.values().iterator().next();
		}
		else {
			RequestMappingInfo bestMappingMatch = null;
			for (RequestMappingInfo mapping : targetHandlerMethods.keySet()) {
				if (bestMappingMatch == null) {
					bestMappingMatch = mapping;
				}
				else {
					if (mapping.isBetterMatchThan(bestMappingMatch)) {
						bestMappingMatch = mapping;
					}
				}
			}
			return targetHandlerMethods.get(bestMappingMatch);
		}
	}
	else {
		throw new NoHandlerFoundException("No matching handler method found for portlet request", request);
	}
}
 
Example 3
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 4
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;
	}
}
 
Example 5
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 6
Source File: DefaultAnnotationHandlerMapping.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Uses the current PortletMode as lookup key.
 */
@Override
protected PortletMode getLookupKey(PortletRequest request) throws Exception {
	return request.getPortletMode();
}
 
Example 7
Source File: PortletModeHandlerMapping.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Uses the current PortletMode as lookup key.
 */
@Override
protected PortletMode getLookupKey(PortletRequest request) throws Exception {
	return request.getPortletMode();
}
 
Example 8
Source File: NoHandlerFoundException.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor for NoHandlerFoundException.
 * @param msg the detail message
 * @param request the current portlet request,
 * for further context to be included in the exception message
 */
public NoHandlerFoundException(String msg, PortletRequest request) {
	super(msg + ": mode '" + request.getPortletMode() +
			"', phase '" + request.getAttribute(PortletRequest.LIFECYCLE_PHASE) +
			"', parameters " + StylerUtils.style(request.getParameterMap()));
}