Search in sources :

Example 11 with WindowState

use of javax.portlet.WindowState in project uPortal by Jasig.

the class WindowStateSettingsStAXComponent method getEventReader.

/* (non-Javadoc)
     * @see org.apereo.portal.rendering.PipelineComponent#getEventReader(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
@Override
public PipelineEventReader<XMLEventReader, XMLEvent> getEventReader(HttpServletRequest request, HttpServletResponse response) {
    final PipelineEventReader<XMLEventReader, XMLEvent> pipelineEventReader = this.wrappedComponent.getEventReader(request, response);
    final XMLEventReader eventReader = pipelineEventReader.getEventReader();
    final IStylesheetDescriptor stylesheetDescriptor = stylesheetAttributeSource.getStylesheetDescriptor(request);
    final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
    final XMLEventReader filteredEventReader;
    if (portalRequestInfo.getTargetedPortletWindowId() == null) {
        final IStylesheetParameterDescriptor defaultWindowStateParam = stylesheetDescriptor.getStylesheetParameterDescriptor("dashboardForcedWindowState");
        if (defaultWindowStateParam != null) {
            // Set all window states to the specified default
            final WindowState windowState = PortletUtils.getWindowState(defaultWindowStateParam.getDefaultValue());
            filteredEventReader = new SinglePortletWindowStateSettingXMLEventReader(request, eventReader, windowState);
        } else {
            // Make sure there aren't any portlets in a "targeted" window state
            filteredEventReader = new NonTargetedPortletWindowStateSettingXMLEventReader(request, eventReader);
        }
    } else {
        // Not mobile, don't bother filtering
        filteredEventReader = eventReader;
    }
    final Map<String, String> outputProperties = pipelineEventReader.getOutputProperties();
    return new PipelineEventReaderImpl<XMLEventReader, XMLEvent>(filteredEventReader, outputProperties);
}
Also used : WindowState(javax.portlet.WindowState) IStylesheetParameterDescriptor(org.apereo.portal.layout.om.IStylesheetParameterDescriptor) IPortalRequestInfo(org.apereo.portal.url.IPortalRequestInfo) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader) FilteringXMLEventReader(org.apereo.portal.xml.stream.FilteringXMLEventReader) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor)

Example 12 with WindowState

use of javax.portlet.WindowState in project uPortal by Jasig.

the class XsltPortalUrlProviderTest method testPortletUrlById.

@Test
public void testPortletUrlById() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final IPortletWindowId portletWindowId = new MockPortletWindowId("w1");
    when(portalUrlProvider.getPortalUrlBuilderByLayoutNode(request, "foo", UrlType.RENDER)).thenReturn(portalUrlBuilder);
    when(portalUrlBuilder.getPortletUrlBuilder(portletWindowId)).thenReturn(portletUrlBuilder);
    when(portalUrlBuilder.getUrlString()).thenReturn("/uPortal/home/normal/render.uP?layoutUrl");
    when(portletWindowRegistry.getOrCreateDefaultPortletWindowByLayoutNodeId(request, "foo")).thenReturn(portletWindow);
    when(portletWindow.getPortletWindowId()).thenReturn(portletWindowId);
    final Transformer transformer = xslTemplate.newTransformer();
    transformer.setParameter(XsltPortalUrlProvider.XSLT_PORTAL_URL_PROVIDER, xsltPortalUrlProvider);
    transformer.setParameter("CURRENT_REQUEST", request);
    // xsl template mode to use
    transformer.setParameter("TEST", "portletUrlById");
    // set up configuration in the transformer impl
    final StringWriter resultWriter = new StringWriter();
    transformer.transform(xmlSource, new StreamResult(resultWriter));
    verify(portalUrlBuilder).addParameter("pageNum", "42");
    verify(portalUrlBuilder).getPortletUrlBuilder(portletWindowId);
    verify(portalUrlBuilder).getUrlString();
    verifyNoMoreInteractions(portalUrlBuilder);
    verify(portletUrlBuilder).setWindowState(new WindowState("maximized"));
    verify(portletUrlBuilder).addParameter("tmp", "blah");
    verify(portletUrlBuilder).setCopyCurrentRenderParameters(false);
    verifyNoMoreInteractions(portletUrlBuilder);
    final String result = resultWriter.getBuffer().toString();
    logger.debug(result);
    XMLUnit.setIgnoreWhitespace(true);
    Diff d = new Diff(expected, result);
    assertTrue("Transformation result differs from what's expected" + d, d.similar());
}
Also used : WindowState(javax.portlet.WindowState) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) Diff(org.custommonkey.xmlunit.Diff) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) Test(org.junit.Test)

Example 13 with WindowState

use of javax.portlet.WindowState in project uPortal by Jasig.

the class XsltPortalUrlProviderTest method testMultiPortletUrlById.

@Test
public void testMultiPortletUrlById() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final IPortletWindowId portletWindowId = new MockPortletWindowId("w1");
    final IPortletWindow portletWindow2 = mock(IPortletWindow.class);
    final IPortletWindowId portletWindowId2 = new MockPortletWindowId("w2");
    final IPortletUrlBuilder portletUrlBuilder2 = mock(IPortletUrlBuilder.class);
    when(portalUrlProvider.getPortalUrlBuilderByLayoutNode(request, "foo", UrlType.RENDER)).thenReturn(portalUrlBuilder);
    when(portalUrlBuilder.getPortletUrlBuilder(portletWindowId)).thenReturn(portletUrlBuilder);
    when(portalUrlBuilder.getUrlString()).thenReturn("/uPortal/home/normal/render.uP?layoutUrl");
    when(portletWindowRegistry.getOrCreateDefaultPortletWindowByLayoutNodeId(request, "foo")).thenReturn(portletWindow);
    when(portletWindow.getPortletWindowId()).thenReturn(portletWindowId);
    when(portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(request, "my-portlet")).thenReturn(portletWindow2);
    when(portletWindow2.getPortletWindowId()).thenReturn(portletWindowId2);
    when(portalUrlBuilder.getPortletUrlBuilder(portletWindowId2)).thenReturn(portletUrlBuilder2);
    final Transformer transformer = xslTemplate.newTransformer();
    transformer.setParameter(XsltPortalUrlProvider.XSLT_PORTAL_URL_PROVIDER, xsltPortalUrlProvider);
    transformer.setParameter("CURRENT_REQUEST", request);
    // xsl template mode to use
    transformer.setParameter("TEST", "multiPortletUrlById");
    // set up configuration in the transformer impl
    final StringWriter resultWriter = new StringWriter();
    transformer.transform(xmlSource, new StreamResult(resultWriter));
    verify(portalUrlBuilder).addParameter("pageNum", "42");
    verify(portalUrlBuilder).getPortletUrlBuilder(portletWindowId);
    verify(portalUrlBuilder).getPortletUrlBuilder(portletWindowId2);
    verify(portalUrlBuilder).getUrlString();
    verifyNoMoreInteractions(portalUrlBuilder);
    verify(portletUrlBuilder).addParameter("tmp", "blah");
    verify(portletUrlBuilder).setCopyCurrentRenderParameters(false);
    verifyNoMoreInteractions(portletUrlBuilder);
    verify(portletUrlBuilder2).setWindowState(new WindowState("minimized"));
    verify(portletUrlBuilder2).addParameter("event", "param");
    verify(portletUrlBuilder2).setCopyCurrentRenderParameters(false);
    verifyNoMoreInteractions(portletUrlBuilder2);
    final String result = resultWriter.getBuffer().toString();
    logger.debug(result);
    XMLUnit.setIgnoreWhitespace(true);
    Diff d = new Diff(expected, result);
    assertTrue("Transformation result differs from what's expected" + d, d.similar());
}
Also used : WindowState(javax.portlet.WindowState) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) Diff(org.custommonkey.xmlunit.Diff) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) Test(org.junit.Test)

Example 14 with WindowState

use of javax.portlet.WindowState in project uPortal by Jasig.

the class PortletEntityImpl method getWindowStates.

@Override
public Map<Long, WindowState> getWindowStates() {
    final Map<Long, WindowState> simpleWindowStates = new LinkedHashMap<Long, WindowState>();
    synchronized (this.windowStates) {
        for (Map.Entry<StylesheetDescriptorImpl, WindowState> windowStateEntry : windowStates.entrySet()) {
            final StylesheetDescriptorImpl stylesheetDescriptor = windowStateEntry.getKey();
            final long stylesheetDescriptorId = stylesheetDescriptor.getId();
            final WindowState windowState = windowStateEntry.getValue();
            simpleWindowStates.put(stylesheetDescriptorId, windowState);
        }
    }
    return Collections.unmodifiableMap(simpleWindowStates);
}
Also used : WindowState(javax.portlet.WindowState) StylesheetDescriptorImpl(org.apereo.portal.layout.dao.jpa.StylesheetDescriptorImpl) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 15 with WindowState

use of javax.portlet.WindowState in project uPortal by Jasig.

the class PortletWindowRegistryImpl method initializePortletWindowData.

/**
 * Initializes a newly created {@link PortletWindow}, the default implementation sets up the
 * appropriate {@link WindowState} and {@link javax.portlet.PortletMode}
 */
protected void initializePortletWindowData(HttpServletRequest request, PortletWindowData portletWindowData) {
    final IStylesheetDescriptor stylesheetDescriptor = getThemeStylesheetDescriptor(request);
    final IPortletEntityId portletEntityId = portletWindowData.getPortletEntityId();
    final IPortletEntity portletEntity = this.portletEntityRegistry.getPortletEntity(request, portletEntityId);
    final WindowState entityWindowState = portletEntity.getWindowState(stylesheetDescriptor);
    if (persistentWindowStates.contains(entityWindowState)) {
        portletWindowData.setWindowState(entityWindowState);
    } else if (entityWindowState != null) {
        // Set of persistent window states must have changed, nuke the old value
        this.logger.warn("PortletEntity.windowState=" + entityWindowState + " but that state is not in the set of persistent WindowStates. PortletEntity.windowState will be set to null");
        portletEntity.setWindowState(stylesheetDescriptor, null);
        this.portletEntityRegistry.storePortletEntity(request, portletEntity);
    }
}
Also used : WindowState(javax.portlet.WindowState) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId)

Aggregations

WindowState (javax.portlet.WindowState)19 PortletMode (javax.portlet.PortletMode)11 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)10 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)7 Map (java.util.Map)4 IStylesheetDescriptor (org.apereo.portal.layout.om.IStylesheetDescriptor)4 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)4 List (java.util.List)3 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Transformer (javax.xml.transform.Transformer)2 StreamResult (javax.xml.transform.stream.StreamResult)2 DelegateState (org.apereo.portal.api.portlet.DelegateState)2 DelegationRequest (org.apereo.portal.api.portlet.DelegationRequest)2 MockPortletWindowId (org.apereo.portal.mock.portlet.om.MockPortletWindowId)2 IPerson (org.apereo.portal.security.IPerson)2 IPortalRequestInfo (org.apereo.portal.url.IPortalRequestInfo)2