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;
}
});
}
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;
}
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;
}
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);
}
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();
}
Aggregations