javax.portlet.WindowState Java Examples

The following examples show how to use javax.portlet.WindowState. 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: PreferencesActionController.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
@ActionMethod(portletName = "portlet1", actionName = "submitPreferences")
@CsrfProtected
public void submitPreferences(ActionRequest actionRequest, ActionResponse actionResponse) {

	ResourceBundle resourceBundle = portletConfig.getResourceBundle(actionRequest.getLocale());

	models.put("preferences", new Preferences(datePattern));

	Set<ParamError> bindingErrors = bindingResult.getAllErrors();

	if (bindingErrors.isEmpty()) {

		try {
			portletPreferences.setValue("datePattern", datePattern);
			portletPreferences.store();
			actionResponse.setPortletMode(PortletMode.VIEW);
			actionResponse.setWindowState(WindowState.NORMAL);
			models.put("globalInfoMessage", resourceBundle.getString("your-request-processed-successfully"));
		}
		catch (Exception e) {
			models.put("globalErrorMessage", resourceBundle.getString("an-unexpected-error-occurred"));
			logger.error(e.getMessage(), e);
		}
	}
}
 
Example #2
Source File: Utils.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
public boolean checkEqualStateAwareResponse(
      StateAwareResponse injectedPortletArtifact,
      StateAwareResponse stateAwareResponse) {
   if (injectedPortletArtifact.equals(stateAwareResponse)) {
      return true;
   }
   PortletMode injectedPortletMode = injectedPortletArtifact
         .getPortletMode();
   PortletMode portletPortletMode = stateAwareResponse.getPortletMode();
   WindowState injectedWindowState = injectedPortletArtifact
         .getWindowState();
   WindowState portletWindowState = stateAwareResponse.getWindowState();
   MutableRenderParameters injectedMutableRenderParams = injectedPortletArtifact
         .getRenderParameters();
   MutableRenderParameters portletMutableRenderParams = stateAwareResponse
         .getRenderParameters();
   if (checkEqualResponses(injectedPortletArtifact, stateAwareResponse)
         && injectedPortletMode.equals(portletPortletMode)
         && injectedWindowState.equals(portletWindowState)
         && checkEqualParameters(injectedMutableRenderParams,
               portletMutableRenderParams)) {
      return true;
   } else {
      return false;
   }
}
 
Example #3
Source File: SimplePortletStateEncoderTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public void testEncodeDecode()
{
	PortletState state = new PortletState("id");
	state.setAction(true);
	state.setSecure(true);
	state.setWindowState(WindowState.MAXIMIZED);
	state.setPortletMode(PortletMode.EDIT);

	String uriSafe = encoder.encode(state);
	PortletState read = encoder.decode(uriSafe);
	assertEquals(state.getId(), read.getId());
	assertEquals(state.isAction(), read.isAction());
	assertEquals(state.isSecure(), read.isSecure());
	assertEquals(state.getWindowState(), read.getWindowState());
	assertEquals(state.getPortletMode(), read.getPortletMode());
}
 
Example #4
Source File: PortletStateTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public void testSerialization() throws IOException, ClassNotFoundException
{
	PortletState state = new PortletState("id");
	state.setPortletMode(PortletMode.VIEW);
	state.setWindowState(WindowState.MAXIMIZED);

	ByteArrayOutputStream bao = new ByteArrayOutputStream();
	ObjectOutputStream out = new ObjectOutputStream(bao);

	out.writeObject(state);

	ByteArrayInputStream bai = new ByteArrayInputStream(bao.toByteArray());
	ObjectInputStream in = new ObjectInputStream(bai);
	PortletState alter = (PortletState) in.readObject();

	assertEquals(state, alter);

}
 
Example #5
Source File: PortletStateTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public void testSerialization() throws IOException, ClassNotFoundException
{
	PortletState state = new PortletState("id");
	state.setPortletMode(PortletMode.VIEW);
	state.setWindowState(WindowState.MAXIMIZED);

	ByteArrayOutputStream bao = new ByteArrayOutputStream();
	ObjectOutputStream out = new ObjectOutputStream(bao);

	out.writeObject(state);

	ByteArrayInputStream bai = new ByteArrayInputStream(bao.toByteArray());
	ObjectInputStream in = new ObjectInputStream(bai);
	PortletState alter = (PortletState) in.readObject();

	assertEquals(state, alter);

}
 
Example #6
Source File: IsMaximizedTag.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
public int doStartTag() throws JspException {
    PortalRequestContext portalEnv = PortalRequestContext.getContext(
            (HttpServletRequest) pageContext.getRequest());

    PortalURL portalURL = portalEnv.getRequestedPortalURL();

    // Check if someone else is maximized. If yes, don't show content.
    Map windowStates = portalURL.getWindowStates();
    for (Iterator it = windowStates.values().iterator(); it.hasNext();) {
        WindowState windowState = (WindowState) it.next();
        if (WindowState.MAXIMIZED.equals(windowState)) {
            pageContext.setAttribute(var, Boolean.TRUE);
            break;
        }
    }
    return SKIP_BODY;
}
 
Example #7
Source File: AbstractHandlerExceptionResolver.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Check whether this resolver is supposed to apply to the given handler.
 * <p>The default implementation checks against the specified mapped handlers
 * and handler classes, if any, and also checks the window state (according
 * to the "renderWhenMinimize" property).
 * @param request current portlet request
 * @param handler the executed handler, or {@code null} if none chosen at the
 * time of the exception (for example, if multipart resolution failed)
 * @return whether this resolved should proceed with resolving the exception
 * for the given request and handler
 * @see #setMappedHandlers
 * @see #setMappedHandlerClasses
 */
protected boolean shouldApplyTo(PortletRequest request, Object handler) {
	// If the portlet is minimized and we don't want to render then return null.
	if (WindowState.MINIMIZED.equals(request.getWindowState()) && !this.renderWhenMinimized) {
		return false;
	}
	// Check mapped handlers...
	if (handler != null) {
		if (this.mappedHandlers != null && this.mappedHandlers.contains(handler)) {
			return true;
		}
		if (this.mappedHandlerClasses != null) {
			for (Class<?> mappedClass : this.mappedHandlerClasses) {
				if (mappedClass.isInstance(handler)) {
					return true;
				}
			}
		}
	}
	// Else only apply if there are no explicit handler mappings.
	return (this.mappedHandlers == null && this.mappedHandlerClasses == null);
}
 
Example #8
Source File: AbstractController.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public ModelAndView handleRenderRequest(RenderRequest request, RenderResponse response) throws Exception {
	// If the portlet is minimized and we don't want to render then return null.
	if (WindowState.MINIMIZED.equals(request.getWindowState()) && !this.renderWhenMinimized) {
		return null;
	}

	// Delegate to PortletContentGenerator for checking and preparing.
	checkAndPrepare(request, response);

	// Execute in synchronized block if required.
	if (this.synchronizeOnSession) {
		PortletSession session = request.getPortletSession(false);
		if (session != null) {
			Object mutex = PortletUtils.getSessionMutex(session);
			synchronized (mutex) {
				return handleRenderRequestInternal(request, response);
			}
		}
	}

	return handleRenderRequestInternal(request, response);
}
 
Example #9
Source File: PreferencesActionController.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
@ActionMethod(portletName = "portlet1", actionName = "submitPreferences")
@CsrfProtected
public void submitPreferences(ActionRequest actionRequest, ActionResponse actionResponse) {

	ResourceBundle resourceBundle = portletConfig.getResourceBundle(actionRequest.getLocale());

	models.put("preferences", new Preferences(datePattern));

	Set<ParamError> bindingErrors = bindingResult.getAllErrors();

	if (bindingErrors.isEmpty()) {

		try {
			portletPreferences.setValue("datePattern", datePattern);
			portletPreferences.store();
			actionResponse.setPortletMode(PortletMode.VIEW);
			actionResponse.setWindowState(WindowState.NORMAL);
			models.put("globalInfoMessage", resourceBundle.getString("your-request-processed-successfully"));
		}
		catch (Exception e) {
			models.put("globalErrorMessage", resourceBundle.getString("an-unexpected-error-occurred"));
			logger.error(e.getMessage(), e);
		}
	}
}
 
Example #10
Source File: SimpleMappingExceptionResolverTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void defaultNoRenderWhenMinimized() {
	exceptionResolver.setDefaultErrorView(DEFAULT_VIEW);
	request.setWindowState(WindowState.MINIMIZED);
	ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException);
	assertNull("Should not render when WindowState is MINIMIZED", mav);
}
 
Example #11
Source File: StateAwareResponseImpl.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
public void setWindowState(WindowState windowState)
      throws WindowStateException {
   ArgumentUtility.validateNotNull("windowState", windowState);
   if (isWindowStateAllowed(windowState)) {
      checkSetStateChanged();
      responseContext.setWindowState(windowState);
   } else {
      throw new WindowStateException("Can't set this WindowState",
            windowState);
   }
}
 
Example #12
Source File: PortletRequestWrapperChecker.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isWindowStateAllowed(WindowState state) {
   String meth = "isWindowStateAllowed";
   Object[] args = { state };
   boolean ret = true;
   retVal = ret;
   checkArgs(meth, args);
   return ret;
}
 
Example #13
Source File: EventResponseWrapperChecker.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@Override
public WindowState getWindowState() {
   String meth = "getWindowState";
   Object[] args = {};
   WindowState ret = WindowState.NORMAL;
   retVal = ret;
   checkArgs(meth, args);
   return ret;
}
 
Example #14
Source File: ToolTips.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
static ToolTips forWindowState(WindowState state) {
    StringBuffer tip = new StringBuffer("");
    try {
        tip.append(BUNDLE.getString("tooltip.windowstate." + state));
    } catch (MissingResourceException e) {
        LOG.warn("No tooltip found for window state [" + state + "]", e);
    }
    return new ToolTips(tip.toString());
}
 
Example #15
Source File: AnnotationMethodHandlerAdapter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public boolean match(PortletRequest request) {
	if (!this.modes.isEmpty() && !this.modes.contains(request.getPortletMode())) {
		return false;
	}
	if (StringUtils.hasLength(this.phase) &&
			!this.phase.equals(request.getAttribute(PortletRequest.LIFECYCLE_PHASE))) {
		return false;
	}
	if (StringUtils.hasLength(this.value)) {
		if (this.phase.equals(PortletRequest.ACTION_PHASE) &&
				!this.value.equals(request.getParameter(ActionRequest.ACTION_NAME))) {
			return false;
		}
		else if (this.phase.equals(PortletRequest.RENDER_PHASE) &&
				!(new WindowState(this.value)).equals(request.getWindowState())) {
			return false;
		}
		else if (this.phase.equals(PortletRequest.RESOURCE_PHASE) &&
				!this.value.equals(((ResourceRequest) request).getResourceID())) {
			return false;
		}
		else if (this.phase.equals(PortletRequest.EVENT_PHASE)) {
			Event event = ((EventRequest) request).getEvent();
			if (!this.value.equals(event.getName()) && !this.value.equals(event.getQName().toString())) {
				return false;
			}
		}
	}
	return (PortletAnnotationMappingUtils.checkRequestMethod(this.methods, request) &&
			PortletAnnotationMappingUtils.checkParameters(this.params, request) &&
			PortletAnnotationMappingUtils.checkHeaders(this.headers, request));
}
 
Example #16
Source File: PreferencesActionController.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@ActionMethod(portletName = "portlet1", actionName = "reset")
@ValidateOnExecution(type = ExecutableType.NONE)
@CsrfProtected
public void resetPreferences(ActionRequest actionRequest, ActionResponse actionResponse) {

	ResourceBundle resourceBundle = portletConfig.getResourceBundle(actionRequest.getLocale());

	try {

		Enumeration<String> preferenceNames = portletPreferences.getNames();

		while (preferenceNames.hasMoreElements()) {
			String preferenceName = preferenceNames.nextElement();

			if (!portletPreferences.isReadOnly(preferenceName)) {
				portletPreferences.reset(preferenceName);
			}
		}

		portletPreferences.store();
		actionResponse.setPortletMode(PortletMode.VIEW);
		actionResponse.setWindowState(WindowState.NORMAL);
		models.put("globalInfoMessage", resourceBundle.getString("your-request-processed-successfully"));
	}
	catch (Exception e) {

		models.put("globalErrorMessage", resourceBundle.getString("an-unexpected-error-occurred"));

		logger.error(e.getMessage(), e);
	}
}
 
Example #17
Source File: ResourceRequestImpl.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@Override
public WindowState getWindowState() {
   if (ResourceURL.FULL.equals(getCacheability())) {
      return WindowState.UNDEFINED;
   }
   return super.getWindowState();
}
 
Example #18
Source File: SimpleMappingExceptionResolverTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void doRenderWhenMinimized() {
	exceptionResolver.setDefaultErrorView(DEFAULT_VIEW);
	exceptionResolver.setRenderWhenMinimized(true);
	request.setWindowState(WindowState.MINIMIZED);
	ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException);
	assertNotNull("ModelAndView should not be null", mav);
	assertEquals(DEFAULT_VIEW, mav.getViewName());
}
 
Example #19
Source File: PortletURLImpl.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
public void setWindowState(WindowState windowState)
      throws WindowStateException {
   ArgumentUtility.validateNotNull("windowState", windowState);
   if (isWindowStateAllowed(windowState)) {
      urlProvider.setWindowState(windowState);
   } else {
      throw new WindowStateException("Can't set this WindowState",
            windowState);
   }
}
 
Example #20
Source File: MockActionResponse.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void setWindowState(WindowState windowState) throws WindowStateException {
	if (this.redirectedUrl != null) {
		throw new IllegalStateException("Cannot set WindowState after sendRedirect has been called");
	}
	super.setWindowState(windowState);
	this.redirectAllowed = false;
}
 
Example #21
Source File: MockPortletURL.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void setWindowState(WindowState windowState) throws WindowStateException {
	if (!CollectionUtils.contains(this.portalContext.getSupportedWindowStates(), windowState)) {
		throw new WindowStateException("WindowState not supported", windowState);
	}
	this.windowState = windowState;
}
 
Example #22
Source File: MockPortalContext.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new MockPortalContext
 * with default PortletModes (VIEW, EDIT, HELP)
 * and default WindowStates (NORMAL, MAXIMIZED, MINIMIZED).
 * @see javax.portlet.PortletMode
 * @see javax.portlet.WindowState
 */
public MockPortalContext() {
	this.portletModes = new ArrayList<PortletMode>(3);
	this.portletModes.add(PortletMode.VIEW);
	this.portletModes.add(PortletMode.EDIT);
	this.portletModes.add(PortletMode.HELP);

	this.windowStates = new ArrayList<WindowState>(3);
	this.windowStates.add(WindowState.NORMAL);
	this.windowStates.add(WindowState.MAXIMIZED);
	this.windowStates.add(WindowState.MINIMIZED);
}
 
Example #23
Source File: PortletRequestImpl.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
/**
 * Determine whether or not the specified WindowState is allowed for this portlet.
 * 
 * @param state
 *           the state in question
 * @return true if the state is allowed.
 */
@Override
public boolean isWindowStateAllowed(WindowState state) {
   for (Enumeration<WindowState> en = portalContext.getSupportedWindowStates(); en.hasMoreElements();) {
      if (en.nextElement().toString().equalsIgnoreCase(state.toString())) {
         return true;
      }
   }
   return false;
}
 
Example #24
Source File: PortletState.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private void readObject(ObjectInputStream in) throws IOException,
		ClassNotFoundException
{

	id = in.readObject().toString();
	action = in.readBoolean();
	secure = in.readBoolean();
	parameters = (Map) in.readObject();
	portletMode = new PortletMode(in.readObject().toString());
	windowState = new WindowState(in.readObject().toString());

	log.debug("Deserializing PortletState [action={}]", action);

}
 
Example #25
Source File: PortletURLImpl.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
private boolean isWindowStateAllowed(WindowState state) {
   Enumeration<WindowState> supportedStates = portalContext
         .getSupportedWindowStates();
   while (supportedStates.hasMoreElements()) {
      if (supportedStates.nextElement().equals(state)) {
         return true;
      }
   }
   return false;
}
 
Example #26
Source File: EventRequestWrapperChecker.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@Override
public WindowState getWindowState() {
   String meth = "getWindowState";
   Object[] args = {};
   WindowState ret = WindowState.NORMAL;
   retVal = ret;
   checkArgs(meth, args);
   return ret;
}
 
Example #27
Source File: SakaiPortalContext.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public SakaiPortalContext()
{
	properties = new HashMap();
	modes = new ArrayList();
	states = new ArrayList();

	modes.add(PortletMode.VIEW);
	modes.add(PortletMode.HELP);
	modes.add(PortletMode.EDIT);

	states.add(WindowState.MAXIMIZED);
	states.add(WindowState.MINIMIZED);
	states.add(WindowState.NORMAL);
}
 
Example #28
Source File: ActionRequestWrapperChecker.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isWindowStateAllowed(WindowState state) {
   String meth = "isWindowStateAllowed";
   Object[] args = { state };
   boolean ret = true;
   retVal = ret;
   checkArgs(meth, args);
   return ret;
}
 
Example #29
Source File: MockActionResponse.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void setWindowState(WindowState windowState) throws WindowStateException {
	if (this.redirectedUrl != null) {
		throw new IllegalStateException("Cannot set WindowState after sendRedirect has been called");
	}
	super.setWindowState(windowState);
	this.redirectAllowed = false;
}
 
Example #30
Source File: PreferencesActionController.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@ActionMethod(portletName = "portlet1", actionName = "reset")
@ValidateOnExecution(type = ExecutableType.NONE)
@CsrfProtected
public void resetPreferences(ActionRequest actionRequest, ActionResponse actionResponse) {

	ResourceBundle resourceBundle = portletConfig.getResourceBundle(actionRequest.getLocale());

	try {

		Enumeration<String> preferenceNames = portletPreferences.getNames();

		while (preferenceNames.hasMoreElements()) {
			String preferenceName = preferenceNames.nextElement();

			if (!portletPreferences.isReadOnly(preferenceName)) {
				portletPreferences.reset(preferenceName);
			}
		}

		portletPreferences.store();
		actionResponse.setPortletMode(PortletMode.VIEW);
		actionResponse.setWindowState(WindowState.NORMAL);
		models.put("globalInfoMessage", resourceBundle.getString("your-request-processed-successfully"));
	}
	catch (Exception e) {

		models.put("globalErrorMessage", resourceBundle.getString("an-unexpected-error-occurred"));

		logger.error(e.getMessage(), e);
	}
}