use of org.apereo.portal.layout.om.ILayoutAttributeDescriptor 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.ILayoutAttributeDescriptor in project uPortal by Jasig.
the class StylesheetUserPreferencesServiceImpl method setLayoutAttribute.
@Transactional
@Override
public String setLayoutAttribute(HttpServletRequest request, PreferencesScope prefScope, String nodeId, String name, String value) {
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 set layout attribute {}={} on node with ID=\"{}\" but no such stylesheet parameter is defined in stylesheet descriptor {}. It will be ignored.", new Object[] { name, value, nodeId, stylesheetDescriptor.getName() });
return null;
}
if (this.compareValues(value, layoutAttributeDescriptor.getDefaultValue())) {
// Value matches the default value, remove the attribute
return this.removeLayoutAttribute(request, prefScope, nodeId, name);
}
final IStylesheetUserPreferences distributedStylesheetUserPreferences = this.getDistributedStylesheetUserPreferences(request, prefScope);
if (distributedStylesheetUserPreferences != null) {
final String defaultValue = distributedStylesheetUserPreferences.getLayoutAttribute(nodeId, name);
if (this.compareValues(value, defaultValue)) {
// Value matches the DLM preferences value, remove the value
return this.removeLayoutAttribute(request, prefScope, nodeId, name);
}
}
final Scope scope = this.getWriteScope(request, prefScope, stylesheetPreferencesKey, layoutAttributeDescriptor);
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.setLayoutAttribute(nodeId, name, value);
this.stylesheetUserPreferencesDao.storeStylesheetUserPreferences(stylesheetUserPreferences);
return oldValue;
}
default:
{
// Determine the mutex to use for accessing the nodeAttributes map
final Object mutex;
switch(scope) {
case REQUEST:
{
mutex = PortalWebUtils.getRequestAttributeMutex(request);
break;
}
case SESSION:
{
final HttpSession session = request.getSession();
mutex = WebUtils.getSessionMutex(session);
break;
}
default:
{
mutex = new Object();
break;
}
}
// Get/Create the nodeAttributes map
Map<String, String> nodeAttributes;
synchronized (mutex) {
nodeAttributes = this.getDataValue(request, stylesheetPreferencesKey, scope, LAYOUT_ATTRIBUTES_KEY, nodeId);
if (nodeAttributes == null) {
nodeAttributes = new ConcurrentHashMap<>();
this.putDataValue(request, stylesheetPreferencesKey, scope, LAYOUT_ATTRIBUTES_KEY, nodeId, nodeAttributes);
}
}
return nodeAttributes.put(name, value);
}
}
}
use of org.apereo.portal.layout.om.ILayoutAttributeDescriptor in project uPortal by Jasig.
the class StylesheetDescriptorImporterExporter method convert.
/**
* Convert the {@link IStylesheetDescriptor} to an {@link ExternalStylesheetDescriptor}.
*
* @param stylesheetDescriptor
* @return converted object, never null
*/
protected ExternalStylesheetDescriptor convert(IStylesheetDescriptor stylesheetDescriptor) {
final ExternalStylesheetDescriptor externalStylesheetDescriptor = new ExternalStylesheetDescriptor();
externalStylesheetDescriptor.setName(stylesheetDescriptor.getName());
externalStylesheetDescriptor.setUrlSyntaxHelper(stylesheetDescriptor.getUrlNodeSyntaxHelperName());
externalStylesheetDescriptor.setDescription(stylesheetDescriptor.getDescription());
externalStylesheetDescriptor.setUri(stylesheetDescriptor.getStylesheetResource());
final Collection<IOutputPropertyDescriptor> outputPropertyDescriptors = stylesheetDescriptor.getOutputPropertyDescriptors();
final List<ExternalOutputPropertyDescriptor> extOutputPropertyDescriptors = externalStylesheetDescriptor.getOutputProperties();
for (final IOutputPropertyDescriptor outputPropertyDescriptor : outputPropertyDescriptors) {
final ExternalOutputPropertyDescriptor extOutputPropertyDescriptor = new ExternalOutputPropertyDescriptor();
copyProperties(outputPropertyDescriptor, extOutputPropertyDescriptor);
extOutputPropertyDescriptors.add(extOutputPropertyDescriptor);
}
Collections.sort(extOutputPropertyDescriptors, ExternalStylesheetDataNameComparator.INSTANCE);
final Collection<IStylesheetParameterDescriptor> stylesheetParameterDescriptors = stylesheetDescriptor.getStylesheetParameterDescriptors();
final List<ExternalStylesheetParameterDescriptor> extStylesheetParameterDescriptors = externalStylesheetDescriptor.getStylesheetParameters();
for (final IStylesheetParameterDescriptor stylesheetParameterDescriptor : stylesheetParameterDescriptors) {
final ExternalStylesheetParameterDescriptor extStylesheetParameterDescriptor = new ExternalStylesheetParameterDescriptor();
copyProperties(stylesheetParameterDescriptor, extStylesheetParameterDescriptor);
extStylesheetParameterDescriptors.add(extStylesheetParameterDescriptor);
}
Collections.sort(extStylesheetParameterDescriptors, ExternalStylesheetDataNameComparator.INSTANCE);
final Collection<ILayoutAttributeDescriptor> layoutAttributeDescriptors = stylesheetDescriptor.getLayoutAttributeDescriptors();
final List<ExternalLayoutAttributeDescriptor> extLayoutAttributeDescriptors = externalStylesheetDescriptor.getLayoutAttributes();
for (final ILayoutAttributeDescriptor layoutAttributeDescriptor : layoutAttributeDescriptors) {
final ExternalLayoutAttributeDescriptor extLayoutAttributeDescriptor = new ExternalLayoutAttributeDescriptor();
copyProperties(layoutAttributeDescriptor, extLayoutAttributeDescriptor);
extLayoutAttributeDescriptor.getTargetElements().addAll(layoutAttributeDescriptor.getTargetElementNames());
extLayoutAttributeDescriptors.add(extLayoutAttributeDescriptor);
}
Collections.sort(extLayoutAttributeDescriptors, ExternalStylesheetDataNameComparator.INSTANCE);
return externalStylesheetDescriptor;
}
use of org.apereo.portal.layout.om.ILayoutAttributeDescriptor in project uPortal by Jasig.
the class StylesheetAttributeSourceForSpELVariablesTest method layoutAttributeFoundForName.
private void layoutAttributeFoundForName(final String layoutAttributeName, final String defaultValue) {
final ILayoutAttributeDescriptor layoutAttributeDescriptor = mock(ILayoutAttributeDescriptor.class);
this.layoutAttributeDescriptorReturnsTargetElementNames(layoutAttributeDescriptor, this.localEventName);
this.layoutAttributeDescriptors.add(layoutAttributeDescriptor);
given(layoutAttributeDescriptor.getName()).willReturn(layoutAttributeName);
given(layoutAttributeDescriptor.getDefaultValue()).willReturn(defaultValue);
}
Aggregations