Search in sources :

Example 6 with IStylesheetDescriptor

use of org.apereo.portal.layout.om.IStylesheetDescriptor in project uPortal by Jasig.

the class JpaStylesheetDescriptorDaoTest method testStylesheetUserPreferencesDao.

@Test
public void testStylesheetUserPreferencesDao() throws Exception {
    final long ssdId = this.execute(new Callable<Long>() {

        @Override
        public Long call() throws Exception {
            final IStylesheetDescriptor stylesheetDescriptor = stylesheetDescriptorDao.createStylesheetDescriptor("columns", "classpath:/layout/struct/columns.xsl");
            final long id = stylesheetDescriptor.getId();
            assertNotSame(-1, id);
            return id;
        }
    });
    final IPerson person = mock(IPerson.class);
    when(person.getID()).thenReturn(1);
    final IUserProfile userProfile = mock(IUserProfile.class);
    when(userProfile.getProfileId()).thenReturn(1);
    final long supId = this.execute(new Callable<Long>() {

        @Override
        public Long call() throws Exception {
            final IStylesheetDescriptor stylesheetDescriptor = stylesheetDescriptorDao.getStylesheetDescriptor(ssdId);
            final IStylesheetUserPreferences stylesheetUserPreferences = stylesheetUserPreferencesDao.createStylesheetUserPreferences(stylesheetDescriptor, person, userProfile);
            assertNotNull(stylesheetUserPreferences);
            stylesheetUserPreferences.setStylesheetParameter("activeTab", "1");
            stylesheetUserPreferences.setLayoutAttribute("u1l1n1", "deletable", "false");
            stylesheetUserPreferencesDao.storeStylesheetUserPreferences(stylesheetUserPreferences);
            return stylesheetUserPreferences.getId();
        }
    });
    this.execute(new Callable<Long>() {

        @Override
        public Long call() throws Exception {
            final IStylesheetUserPreferences stylesheetUserPreferences = stylesheetUserPreferencesDao.getStylesheetUserPreferences(supId);
            assertNotNull(stylesheetUserPreferences);
            assertEquals(Collections.singletonMap("activeTab", "1"), stylesheetUserPreferences.populateStylesheetParameters(new MapPopulator<String, String>()).getMap());
            assertEquals(Collections.singletonMap("deletable", "false"), stylesheetUserPreferences.populateLayoutAttributes("u1l1n1", new MapPopulator<String, String>()).getMap());
            return null;
        }
    });
    this.execute(new Callable<Long>() {

        @Override
        public Long call() throws Exception {
            final IStylesheetDescriptor stylesheetDescriptor = stylesheetDescriptorDao.getStylesheetDescriptor(ssdId);
            final IStylesheetUserPreferences stylesheetUserPreferences = stylesheetUserPreferencesDao.getStylesheetUserPreferences(stylesheetDescriptor, person, userProfile);
            assertNotNull(stylesheetUserPreferences);
            assertEquals(Collections.singletonMap("activeTab", "1"), stylesheetUserPreferences.populateStylesheetParameters(new MapPopulator<String, String>()).getMap());
            assertEquals(Collections.singletonMap("deletable", "false"), stylesheetUserPreferences.populateLayoutAttributes("u1l1n1", new MapPopulator<String, String>()).getMap());
            stylesheetUserPreferencesDao.deleteStylesheetUserPreferences(stylesheetUserPreferences);
            return null;
        }
    });
}
Also used : IPerson(org.apereo.portal.security.IPerson) IUserProfile(org.apereo.portal.IUserProfile) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor) IStylesheetUserPreferences(org.apereo.portal.layout.om.IStylesheetUserPreferences) MapPopulator(org.apereo.portal.utils.MapPopulator) Test(org.junit.Test) BasePortalJpaDaoTest(org.apereo.portal.test.BasePortalJpaDaoTest)

Example 7 with IStylesheetDescriptor

use of org.apereo.portal.layout.om.IStylesheetDescriptor in project uPortal by Jasig.

the class UrlNodeSyntaxHelperRegistryImpl method getUrlNodeSyntaxHelperForStylesheet.

@Override
public IUrlNodeSyntaxHelper getUrlNodeSyntaxHelperForStylesheet(final int stylesheetDescriptorId) {
    final IStylesheetDescriptor stylesheetDescriptor = this.stylesheetDescriptorDao.getStylesheetDescriptor(stylesheetDescriptorId);
    if (stylesheetDescriptor == null) {
        throw new IllegalArgumentException("No IStylesheetDescriptor found for id: " + stylesheetDescriptorId);
    }
    final String themeUrlSyntaxHelperName = stylesheetDescriptor.getUrlNodeSyntaxHelperName();
    if (themeUrlSyntaxHelperName != null) {
        return this.getUrlNodeSyntaxHelper(themeUrlSyntaxHelperName);
    }
    return null;
}
Also used : IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor)

Example 8 with IStylesheetDescriptor

use of org.apereo.portal.layout.om.IStylesheetDescriptor 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 9 with IStylesheetDescriptor

use of org.apereo.portal.layout.om.IStylesheetDescriptor 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 10 with IStylesheetDescriptor

use of org.apereo.portal.layout.om.IStylesheetDescriptor in project uPortal by Jasig.

the class StylesheetAttributeSource method getAdditionalAttributes.

@Override
public final Iterator<Attribute> getAdditionalAttributes(HttpServletRequest request, HttpServletResponse response, StartElement event) {
    final IStylesheetDescriptor stylesheetDescriptor = this.getStylesheetDescriptor(request);
    final PreferencesScope stylesheetPreferencesScope = this.getStylesheetPreferencesScope(request);
    final Collection<Attribute> attributes = new LinkedList<Attribute>();
    for (final ILayoutAttributeDescriptor layoutAttributeDescriptor : stylesheetDescriptor.getLayoutAttributeDescriptors()) {
        final Set<String> targetElementNames = layoutAttributeDescriptor.getTargetElementNames();
        final QName eventName = event.getName();
        final String localEventName = eventName.getLocalPart();
        if (targetElementNames.contains(localEventName)) {
            final Attribute subscribeIdAttr = event.getAttributeByName(IUserLayoutManager.ID_ATTR_NAME);
            final String subscribeId = subscribeIdAttr.getValue();
            final String name = layoutAttributeDescriptor.getName();
            String value = this.stylesheetUserPreferencesService.getLayoutAttribute(request, stylesheetPreferencesScope, subscribeId, name);
            if (value == null) {
                value = layoutAttributeDescriptor.getDefaultValue();
            }
            if (value != null) {
                if (this.shouldDoSpelEvaluationForAttributeValue(value)) {
                    final ServletWebRequest webRequest = new ServletWebRequest(request, response);
                    value = this.doSpelEvaluationForAttributeValue(webRequest, value);
                }
                if (value != null) {
                    final Attribute attribute = xmlEventFactory.createAttribute(name, value);
                    attributes.add(attribute);
                }
            }
        }
    }
    return attributes.iterator();
}
Also used : Attribute(javax.xml.stream.events.Attribute) QName(javax.xml.namespace.QName) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor) PreferencesScope(org.apereo.portal.layout.IStylesheetUserPreferencesService.PreferencesScope) ILayoutAttributeDescriptor(org.apereo.portal.layout.om.ILayoutAttributeDescriptor) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) LinkedList(java.util.LinkedList)

Aggregations

IStylesheetDescriptor (org.apereo.portal.layout.om.IStylesheetDescriptor)31 IStylesheetUserPreferences (org.apereo.portal.layout.om.IStylesheetUserPreferences)15 Scope (org.apereo.portal.layout.om.IStylesheetData.Scope)11 IStylesheetParameterDescriptor (org.apereo.portal.layout.om.IStylesheetParameterDescriptor)10 Map (java.util.Map)7 ILayoutAttributeDescriptor (org.apereo.portal.layout.om.ILayoutAttributeDescriptor)7 Transactional (org.springframework.transaction.annotation.Transactional)6 ConcurrentMap (java.util.concurrent.ConcurrentMap)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 WindowState (javax.portlet.WindowState)4 HttpSession (javax.servlet.http.HttpSession)4 IUserProfile (org.apereo.portal.IUserProfile)4 IOutputPropertyDescriptor (org.apereo.portal.layout.om.IOutputPropertyDescriptor)4 IPerson (org.apereo.portal.security.IPerson)4 IUserInstance (org.apereo.portal.user.IUserInstance)4 MapPopulator (org.apereo.portal.utils.MapPopulator)4 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)3 PreferencesScope (org.apereo.portal.layout.IStylesheetUserPreferencesService.PreferencesScope)3 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)3