use of org.apereo.portal.layout.om.IStylesheetParameterDescriptor in project uPortal by Jasig.
the class StylesheetUserPreferencesServiceImpl method populateStylesheetParameters.
@Override
public <P extends Populator<String, String>> P populateStylesheetParameters(HttpServletRequest request, PreferencesScope prefScope, P stylesheetParameters) {
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> sessionStylesheetParameters;
final HttpSession session = request.getSession(false);
if (session == null) {
sessionStylesheetParameters = null;
} else {
sessionStylesheetParameters = PortalWebUtils.getMapSessionAttribute(session, STYLESHEET_PARAMETERS_KEY + stylesheetPreferencesKey.toString(), false);
}
final Map<String, String> requestStylesheetParameters = PortalWebUtils.getMapRequestAttribute(request, STYLESHEET_PARAMETERS_KEY + stylesheetPreferencesKey.toString(), false);
//Try getting each stylesheet parameter to populate the Map
for (final IStylesheetParameterDescriptor stylesheetParameterDescriptor : stylesheetDescriptor.getStylesheetParameterDescriptors()) {
final String name = stylesheetParameterDescriptor.getName();
final String value;
final Scope scope = stylesheetParameterDescriptor.getScope();
switch(scope) {
case PERSISTENT:
{
if (stylesheetUserPreferences == null) {
value = null;
break;
}
value = stylesheetUserPreferences.getStylesheetParameter(name);
break;
}
case SESSION:
{
if (sessionStylesheetParameters == null) {
value = null;
break;
}
value = sessionStylesheetParameters.get(name);
break;
}
case REQUEST:
{
if (requestStylesheetParameters == null) {
value = null;
break;
}
value = requestStylesheetParameters.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, stylesheetParameterDescriptor.getDefaultValue())) {
this.removeStylesheetParameter(request, prefScope, name);
continue;
}
stylesheetParameters.put(name, value);
}
return stylesheetParameters;
}
Aggregations