use of org.apereo.portal.layout.om.IStylesheetData.Scope in project uPortal by Jasig.
the class StylesheetUserPreferencesServiceImpl method setStylesheetParameter.
@Transactional
@Override
public String setStylesheetParameter(HttpServletRequest request, PreferencesScope prefScope, String name, String value) {
logger.trace("Setting stylesheet parameter {} with scope {} to {}.", name, prefScope, value);
final StylesheetPreferencesKey stylesheetPreferencesKey = this.getStylesheetPreferencesKey(request, prefScope);
final IStylesheetDescriptor stylesheetDescriptor = stylesheetPreferencesKey.stylesheetDescriptor;
final IStylesheetParameterDescriptor stylesheetParameterDescriptor = stylesheetDescriptor.getStylesheetParameterDescriptor(name);
if (stylesheetParameterDescriptor == null) {
logger.warn("Attempted to set stylesheet parameter {}={} but no such stylesheet parameter is defined in stylesheet descriptor {}. It will be ignored", new Object[] { name, value, stylesheetDescriptor.getName() });
return null;
}
if (this.compareValues(value, stylesheetParameterDescriptor.getDefaultValue())) {
return this.removeStylesheetParameter(request, prefScope, name);
}
final Scope scope = this.getWriteScope(request, prefScope, stylesheetPreferencesKey, stylesheetParameterDescriptor);
switch(scope) {
case PERSISTENT:
{
IStylesheetUserPreferences stylesheetUserPreferences = this.getStylesheetUserPreferences(request, stylesheetPreferencesKey);
if (stylesheetUserPreferences == null) {
stylesheetUserPreferences = this.stylesheetUserPreferencesDao.createStylesheetUserPreferences(stylesheetDescriptor, stylesheetPreferencesKey.person, stylesheetPreferencesKey.userProfile);
this.clearStylesheetUserPreferencesCache(request, stylesheetPreferencesKey);
}
final String oldValue = stylesheetUserPreferences.setStylesheetParameter(name, value);
this.stylesheetUserPreferencesDao.storeStylesheetUserPreferences(stylesheetUserPreferences);
return oldValue;
}
default:
{
return this.putDataValue(request, stylesheetPreferencesKey, scope, STYLESHEET_PARAMETERS_KEY, name, value);
}
}
}
use of org.apereo.portal.layout.om.IStylesheetData.Scope in project uPortal by Jasig.
the class StylesheetUserPreferencesServiceImpl method removeStylesheetParameter.
@Transactional
@Override
public String removeStylesheetParameter(HttpServletRequest request, PreferencesScope prefScope, String name) {
final StylesheetPreferencesKey stylesheetPreferencesKey = this.getStylesheetPreferencesKey(request, prefScope);
final IStylesheetDescriptor stylesheetDescriptor = stylesheetPreferencesKey.stylesheetDescriptor;
final IStylesheetParameterDescriptor stylesheetParameterDescriptor = stylesheetDescriptor.getStylesheetParameterDescriptor(name);
if (stylesheetParameterDescriptor == null) {
logger.warn("Attempted to remove stylesheet parameter {} but no such stylesheet parameter is defined in stylesheet descriptor {}. It will be ignored", new Object[] { name, stylesheetDescriptor.getName() });
return null;
}
final Scope scope = this.getWriteScope(request, prefScope, stylesheetPreferencesKey, stylesheetParameterDescriptor);
switch(scope) {
case PERSISTENT:
{
final IStylesheetUserPreferences stylesheetUserPreferences = this.getStylesheetUserPreferences(request, stylesheetPreferencesKey);
if (stylesheetUserPreferences == null) {
return null;
}
final String oldValue = stylesheetUserPreferences.removeStylesheetParameter(name);
this.stylesheetUserPreferencesDao.storeStylesheetUserPreferences(stylesheetUserPreferences);
return oldValue;
}
default:
{
return removeDataValue(request, stylesheetPreferencesKey, scope, STYLESHEET_PARAMETERS_KEY, name);
}
}
}
use of org.apereo.portal.layout.om.IStylesheetData.Scope in project uPortal by Jasig.
the class StylesheetUserPreferencesServiceImpl method getWriteScope.
protected final Scope getWriteScope(HttpServletRequest request, PreferencesScope prefScope, StylesheetPreferencesKey stylesheetPreferencesKey, IStylesheetData descriptor) {
final Scope scope = descriptor.getScope();
final boolean persistentScopeReadOnly = stylesheetPreferencesKey.person.isGuest();
if (persistentScopeReadOnly && Scope.PERSISTENT == scope) {
return Scope.SESSION;
}
return scope;
}
use of org.apereo.portal.layout.om.IStylesheetData.Scope in project uPortal by Jasig.
the class StylesheetUserPreferencesServiceImpl method getLayoutAttribute.
@Override
public String getLayoutAttribute(HttpServletRequest request, PreferencesScope prefScope, String nodeId, String name) {
final StylesheetPreferencesKey stylesheetPreferencesKey = this.getStylesheetPreferencesKey(request, prefScope);
final IStylesheetDescriptor stylesheetDescriptor = stylesheetPreferencesKey.stylesheetDescriptor;
final ILayoutAttributeDescriptor layoutAttributeDescriptor = stylesheetDescriptor.getLayoutAttributeDescriptor(name);
if (layoutAttributeDescriptor == null) {
logger.warn("Attempted to get layout attribute {} for ID=\"{}\" but no such stylesheet parameter is defined in stylesheet descriptor {}. Null will be returned", new Object[] { name, nodeId, stylesheetDescriptor.getName() });
return null;
}
// Load the default value
String defaultValue = null;
final IStylesheetUserPreferences distributedStylesheetUserPreferences = this.getDistributedStylesheetUserPreferences(request, prefScope);
if (distributedStylesheetUserPreferences != null) {
defaultValue = distributedStylesheetUserPreferences.getLayoutAttribute(nodeId, name);
// special handling for fragment owner
if (this.isFragmentOwnerStylesheetPreferencesKey(stylesheetPreferencesKey)) {
return defaultValue;
}
if (this.compareValues(defaultValue, layoutAttributeDescriptor.getDefaultValue())) {
// DLM attribute value matches the stylesheet descriptor default, remove the DLM
// value
distributedStylesheetUserPreferences.removeLayoutAttribute(nodeId, name);
defaultValue = null;
}
}
final String value;
final Scope scope = layoutAttributeDescriptor.getScope();
switch(scope) {
case PERSISTENT:
{
final IStylesheetUserPreferences stylesheetUserPreferences = this.getStylesheetUserPreferences(request, stylesheetPreferencesKey);
if (stylesheetUserPreferences == null) {
value = null;
break;
}
value = stylesheetUserPreferences.getLayoutAttribute(nodeId, name);
break;
}
default:
{
final Map<String, String> nodeAttributes = this.getDataValue(request, stylesheetPreferencesKey, scope, LAYOUT_ATTRIBUTES_KEY, nodeId);
if (nodeAttributes == null) {
value = null;
break;
}
value = nodeAttributes.get(name);
break;
}
}
if (value == null) {
return defaultValue;
}
if (!this.isFragmentOwnerStylesheetPreferencesKey(stylesheetPreferencesKey)) {
if (this.compareValues(value, layoutAttributeDescriptor.getDefaultValue()) || // Value is equal to stylesheet descriptor default
(defaultValue != null && this.compareValues(value, defaultValue))) {
// Value is equal to DLM stylesheet
// preferences default
// Remove the user's customized value
this.removeLayoutAttribute(request, prefScope, nodeId, name);
return null;
}
}
return value;
}
use of org.apereo.portal.layout.om.IStylesheetData.Scope in project uPortal by Jasig.
the class StylesheetUserPreferencesServiceImpl method populateOutputProperties.
@Override
public <P extends Populator<String, String>> P populateOutputProperties(HttpServletRequest request, PreferencesScope prefScope, P properties) {
final StylesheetPreferencesKey stylesheetPreferencesKey = this.getStylesheetPreferencesKey(request, prefScope);
final IStylesheetDescriptor stylesheetDescriptor = stylesheetPreferencesKey.stylesheetDescriptor;
// Get the scoped sources once
final IStylesheetUserPreferences stylesheetUserPreferences = this.getStylesheetUserPreferences(request, stylesheetPreferencesKey);
final Map<String, String> sessionOutputProperties;
final HttpSession session = request.getSession(false);
if (session == null) {
sessionOutputProperties = null;
} else {
sessionOutputProperties = PortalWebUtils.getMapSessionAttribute(session, OUTPUT_PROPERTIES_KEY + stylesheetPreferencesKey.toString(), false);
}
final Map<String, String> requestOutputProperties = PortalWebUtils.getMapRequestAttribute(request, OUTPUT_PROPERTIES_KEY + stylesheetPreferencesKey.toString(), false);
// Try getting each output property to populate the Properties
for (final IOutputPropertyDescriptor outputPropertyDescriptor : stylesheetDescriptor.getOutputPropertyDescriptors()) {
final String name = outputPropertyDescriptor.getName();
final String value;
final Scope scope = outputPropertyDescriptor.getScope();
switch(scope) {
case PERSISTENT:
{
if (stylesheetUserPreferences == null) {
value = null;
break;
}
value = stylesheetUserPreferences.getOutputProperty(name);
break;
}
case SESSION:
{
if (sessionOutputProperties == null) {
value = null;
break;
}
value = sessionOutputProperties.get(name);
break;
}
case REQUEST:
{
if (requestOutputProperties == null) {
value = null;
break;
}
value = requestOutputProperties.get(name);
break;
}
default:
{
value = null;
break;
}
}
// Don't add unset properties
if (value == null) {
continue;
}
// If the value is equal to the default value remove the property and return null
if (this.compareValues(value, outputPropertyDescriptor.getDefaultValue())) {
this.removeOutputProperty(request, prefScope, name);
continue;
}
properties.put(name, value);
}
return properties;
}
Aggregations