Search in sources :

Example 11 with IStylesheetParameterDescriptor

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;
}
Also used : IStylesheetParameterDescriptor(org.apereo.portal.layout.om.IStylesheetParameterDescriptor) Scope(org.apereo.portal.layout.om.IStylesheetData.Scope) HttpSession(javax.servlet.http.HttpSession) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor) IStylesheetUserPreferences(org.apereo.portal.layout.om.IStylesheetUserPreferences)

Aggregations

IStylesheetParameterDescriptor (org.apereo.portal.layout.om.IStylesheetParameterDescriptor)11 IStylesheetDescriptor (org.apereo.portal.layout.om.IStylesheetDescriptor)10 Scope (org.apereo.portal.layout.om.IStylesheetData.Scope)5 IStylesheetUserPreferences (org.apereo.portal.layout.om.IStylesheetUserPreferences)5 ILayoutAttributeDescriptor (org.apereo.portal.layout.om.ILayoutAttributeDescriptor)3 IOutputPropertyDescriptor (org.apereo.portal.layout.om.IOutputPropertyDescriptor)3 Transactional (org.springframework.transaction.annotation.Transactional)3 PreferencesScope (org.apereo.portal.layout.IStylesheetUserPreferencesService.PreferencesScope)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 WindowState (javax.portlet.WindowState)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1 XMLEventReader (javax.xml.stream.XMLEventReader)1 XMLEvent (javax.xml.stream.events.XMLEvent)1 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)1 IUserProfile (org.apereo.portal.IUserProfile)1 IStylesheetDescriptorDao (org.apereo.portal.layout.dao.IStylesheetDescriptorDao)1 IStylesheetUserPreferencesDao (org.apereo.portal.layout.dao.IStylesheetUserPreferencesDao)1 LayoutAttributeDescriptorImpl (org.apereo.portal.layout.dao.jpa.LayoutAttributeDescriptorImpl)1