Search in sources :

Example 6 with WindowState

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

the class PortletEntityRegistryImpl method createPersistentEntity.

protected IPortletEntity createPersistentEntity(final IPortletEntity portletEntity, final IPortletEntityId wrapperPortletEntityId) {
    final IPortletDefinitionId portletDefinitionId = portletEntity.getPortletDefinitionId();
    final String layoutNodeId = portletEntity.getLayoutNodeId();
    final int userId = portletEntity.getUserId();
    IPortletEntity persistentEntity = this.portletEntityDao.getPortletEntity(layoutNodeId, userId);
    if (persistentEntity != null) {
        this.logger.warn("A persistent portlet entity already exists: " + persistentEntity + ". The data from the passed in entity will be copied to the persistent entity: " + portletEntity);
    } else {
        persistentEntity = this.portletEntityDao.createPortletEntity(portletDefinitionId, layoutNodeId, userId);
    }
    //Copy over preferences to avoid modifying any part of the interim entity by reference
    final List<IPortletPreference> existingPreferences = portletEntity.getPortletPreferences();
    final List<IPortletPreference> persistentPreferences = persistentEntity.getPortletPreferences();
    //Only do the copy if the List objects are not the same instance
    if (persistentPreferences != existingPreferences) {
        persistentPreferences.clear();
        for (final IPortletPreference preference : existingPreferences) {
            persistentPreferences.add(new PortletPreferenceImpl(preference));
        }
    }
    //Copy over WindowStates
    final Map<Long, WindowState> windowStates = portletEntity.getWindowStates();
    for (Map.Entry<Long, WindowState> windowStateEntry : windowStates.entrySet()) {
        final Long stylesheetDescriptorId = windowStateEntry.getKey();
        final IStylesheetDescriptor stylesheetDescriptor = stylesheetDescriptorDao.getStylesheetDescriptor(stylesheetDescriptorId);
        final WindowState windowState = windowStateEntry.getValue();
        persistentEntity.setWindowState(stylesheetDescriptor, windowState);
    }
    this.portletEntityDao.updatePortletEntity(persistentEntity);
    return persistentEntity;
}
Also used : WindowState(javax.portlet.WindowState) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor) Map(java.util.Map) ConcurrentMap(java.util.concurrent.ConcurrentMap) PortletPreferenceImpl(org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl)

Example 7 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 8 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 9 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 10 with WindowState

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

the class ParentUrlTag method doEndTag.

@Override
public int doEndTag() throws JspException {
    final RenderPortletTag renderPortletTag = (RenderPortletTag) TagSupport.findAncestorWithClass(this, RenderPortletTag.class);
    if (this.windowState != null) {
        final WindowState state = PortletUtils.getWindowState(this.windowState);
        renderPortletTag.setParentUrlState(state);
    }
    if (this.portletMode != null) {
        final PortletMode mode = PortletUtils.getPortletMode(this.portletMode);
        renderPortletTag.setParentUrlMode(mode);
    }
    renderPortletTag.setParentUrlParameters(this.parameters);
    return EVAL_PAGE;
}
Also used : WindowState(javax.portlet.WindowState) PortletMode(javax.portlet.PortletMode)

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