use of org.apereo.portal.layout.om.IStylesheetData.Scope in project uPortal by Jasig.
the class StylesheetDescriptorImporterExporter method importData.
/* (non-Javadoc)
* @see org.apereo.portal.io.xml.IDataImporterExporter#importData(java.lang.Object)
*/
@Transactional
@Override
public void importData(ExternalStylesheetDescriptor data) {
final String stylesheetName = data.getName();
final String uri = data.getUri();
IStylesheetDescriptor stylesheetDescriptor = this.stylesheetDescriptorDao.getStylesheetDescriptorByName(stylesheetName);
if (stylesheetDescriptor == null) {
stylesheetDescriptor = this.stylesheetDescriptorDao.createStylesheetDescriptor(stylesheetName, uri);
} else {
stylesheetDescriptor.setStylesheetResource(uri);
}
stylesheetDescriptor.setUrlNodeSyntaxHelperName(data.getUrlSyntaxHelper());
stylesheetDescriptor.setDescription(data.getDescription());
final List<ExternalOutputPropertyDescriptor> extOutputProperties = data.getOutputProperties();
final List<IOutputPropertyDescriptor> outputPropertyDescriptors = new ArrayList<IOutputPropertyDescriptor>(extOutputProperties.size());
for (final ExternalOutputPropertyDescriptor extOutputProperty : extOutputProperties) {
final String name = extOutputProperty.getName();
final Scope scope = Scope.valueOf(extOutputProperty.getScope().name());
final OutputPropertyDescriptorImpl outputPropertyDescriptor = new OutputPropertyDescriptorImpl(name, scope);
outputPropertyDescriptor.setDefaultValue(extOutputProperty.getDefaultValue());
outputPropertyDescriptor.setDescription(extOutputProperty.getDescription());
outputPropertyDescriptors.add(outputPropertyDescriptor);
}
stylesheetDescriptor.setOutputPropertyDescriptors(outputPropertyDescriptors);
final List<ExternalStylesheetParameterDescriptor> extStylesheetParameters = data.getStylesheetParameters();
final List<IStylesheetParameterDescriptor> stylesheetParameterDescriptors = new ArrayList<IStylesheetParameterDescriptor>(extOutputProperties.size());
for (final ExternalStylesheetParameterDescriptor extStylesheetParameter : extStylesheetParameters) {
final String name = extStylesheetParameter.getName();
final Scope scope = Scope.valueOf(extStylesheetParameter.getScope().name());
final StylesheetParameterDescriptorImpl stylesheetParameterDescriptor = new StylesheetParameterDescriptorImpl(name, scope);
stylesheetParameterDescriptor.setDefaultValue(extStylesheetParameter.getDefaultValue());
stylesheetParameterDescriptor.setDescription(extStylesheetParameter.getDescription());
stylesheetParameterDescriptors.add(stylesheetParameterDescriptor);
}
stylesheetDescriptor.setStylesheetParameterDescriptors(stylesheetParameterDescriptors);
final List<ExternalLayoutAttributeDescriptor> extLayoutAttributes = data.getLayoutAttributes();
final List<ILayoutAttributeDescriptor> layoutAttributeDescriptors = new ArrayList<ILayoutAttributeDescriptor>(extOutputProperties.size());
for (final ExternalLayoutAttributeDescriptor extLayoutAttribute : extLayoutAttributes) {
final String name = extLayoutAttribute.getName();
final Scope scope = Scope.valueOf(extLayoutAttribute.getScope().name());
final LayoutAttributeDescriptorImpl layoutAttributeDescriptor = new LayoutAttributeDescriptorImpl(name, scope);
layoutAttributeDescriptor.setDefaultValue(extLayoutAttribute.getDefaultValue());
layoutAttributeDescriptor.setDescription(extLayoutAttribute.getDescription());
layoutAttributeDescriptor.setTargetElementNames(new LinkedHashSet<String>(extLayoutAttribute.getTargetElements()));
layoutAttributeDescriptors.add(layoutAttributeDescriptor);
}
stylesheetDescriptor.setLayoutAttributeDescriptors(layoutAttributeDescriptors);
this.stylesheetDescriptorDao.updateStylesheetDescriptor(stylesheetDescriptor);
}
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 removeOutputProperty.
@Transactional
@Override
public String removeOutputProperty(HttpServletRequest request, PreferencesScope prefScope, String name) {
final StylesheetPreferencesKey stylesheetPreferencesKey = this.getStylesheetPreferencesKey(request, prefScope);
final IStylesheetDescriptor stylesheetDescriptor = stylesheetPreferencesKey.stylesheetDescriptor;
final IOutputPropertyDescriptor outputPropertyDescriptor = stylesheetDescriptor.getOutputPropertyDescriptor(name);
if (outputPropertyDescriptor == null) {
logger.warn("Attempted to remove output property '{}' but no such output property is defined in stylesheet descriptor '{}'. It will be ignored", new Object[] { name, stylesheetDescriptor.getName() });
return null;
}
final Scope scope = this.getWriteScope(request, prefScope, stylesheetPreferencesKey, outputPropertyDescriptor);
switch(scope) {
case PERSISTENT:
{
final IStylesheetUserPreferences stylesheetUserPreferences = this.getStylesheetUserPreferences(request, stylesheetPreferencesKey);
if (stylesheetUserPreferences == null) {
return null;
}
final String oldValue = stylesheetUserPreferences.removeOutputProperty(name);
this.stylesheetUserPreferencesDao.storeStylesheetUserPreferences(stylesheetUserPreferences);
this.clearStylesheetUserPreferencesCache(request, stylesheetPreferencesKey);
return oldValue;
}
default:
{
return removeDataValue(request, stylesheetPreferencesKey, scope, OUTPUT_PROPERTIES_KEY, name);
}
}
}
use of org.apereo.portal.layout.om.IStylesheetData.Scope in project uPortal by Jasig.
the class StylesheetUserPreferencesServiceImpl method getStylesheetParameter.
@Override
public String getStylesheetParameter(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 get stylesheet parameter '{}' but no such stylesheet parameter is defined in stylesheet descriptor '{}'. null will be returned", new Object[] { name, stylesheetDescriptor.getName() });
return null;
}
final String value;
final Scope scope = stylesheetParameterDescriptor.getScope();
switch(scope) {
case PERSISTENT:
{
final IStylesheetUserPreferences stylesheetUserPreferences = this.getStylesheetUserPreferences(request, stylesheetPreferencesKey);
if (stylesheetUserPreferences == null) {
return null;
}
value = stylesheetUserPreferences.getStylesheetParameter(name);
break;
}
default:
{
value = this.getDataValue(request, stylesheetPreferencesKey, scope, STYLESHEET_PARAMETERS_KEY, name);
break;
}
}
if (value == null) {
return null;
}
// 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);
return null;
}
return value;
}
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);
}
}
}
Aggregations