use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.
the class DefaultRatingsConfiguration method getConfigurationParameter.
/**
* Retrieves configuration parameter from the current space's WebPreferences and fallback to XWiki.RatingsConfig if
* it does not exist.
*
* @param documentReference the document being rated or for which the existing ratings are fetched
* @param parameterName the parameter for which to retrieve the value
* @param defaultValue the default value for the parameter
* @return the value of the given parameter name from the current configuration context
*/
public String getConfigurationParameter(DocumentReference documentReference, String parameterName, String defaultValue) {
XWikiDocument configurationDocument = getConfigurationDocument(documentReference);
if (configurationDocument != null && !configurationDocument.isNew() && configurationDocument.getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE) != null) {
try {
BaseProperty prop = (BaseProperty) configurationDocument.getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE).get(parameterName);
String propValue = (prop == null) ? defaultValue : prop.getValue().toString();
return (propValue.equals("") ? defaultValue : propValue);
} catch (XWikiException e) {
logger.error("Failed to retrieve the property for the configurationDocument [{}].", configurationDocument, e);
return null;
}
}
return defaultValue;
}
use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.
the class ConfiguredRatingsManagerProvider method get.
/**
* Retrieve an instance of the desired RatingsManager (default/separate). - default: save the rating information in
* the same page - separate: save the rating information in a specified space
*
* @param documentRef the document to which the ratings are associated to
* @return the ratings manager selected by looking at the current configuration settings
*/
@Override
public RatingsManager get(DocumentReference documentRef) {
String defaultHint = "default";
String ratingsHint = getXWiki().Param(RatingsManager.RATINGS_CONFIG_PARAM_PREFIX + RatingsManager.RATINGS_CONFIG_FIELDNAME_MANAGER_HINT, defaultHint);
try {
XWikiDocument configurationDocument = ratingsConfiguration.getConfigurationDocument(documentRef);
if (!configurationDocument.isNew() && configurationDocument.getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE) != null) {
BaseProperty prop = (BaseProperty) configurationDocument.getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE).get(RatingsManager.RATINGS_CONFIG_CLASS_FIELDNAME_MANAGER_HINT);
String hint = (prop == null) ? null : (String) prop.getValue();
ratingsHint = (hint == null) ? ratingsHint : hint;
}
} catch (Exception e) {
logger.error("Cannot read ratings config", e);
}
try {
return componentManager.getInstance(RatingsManager.class, ratingsHint);
} catch (ComponentLookupException e) {
// TODO Auto-generated catch block
logger.error("Error loading ratings manager component for hint " + ratingsHint, e);
try {
return componentManager.getInstance(RatingsManager.class, defaultHint);
} catch (ComponentLookupException e1) {
return null;
}
}
}
use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.
the class AbstractDocumentConfigurationSource method getBaseProperty.
protected Object getBaseProperty(String propertyName, boolean text) throws XWikiException {
BaseObject baseObject = getBaseObject();
if (baseObject != null) {
BaseProperty property = (BaseProperty) baseObject.getField(propertyName);
Object value = property != null ? (text ? property.toText() : property.getValue()) : null;
// When this is implemented modify the code below.
if (isEmpty(value)) {
value = null;
}
return value;
}
return null;
}
use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.
the class XWikiDocument method getTagsList.
public List<String> getTagsList(XWikiContext context) {
List<String> tagList = null;
BaseProperty prop = getTagProperty(context);
if (prop != null) {
tagList = (List<String>) prop.getValue();
}
return tagList;
}
use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.
the class PropertyComparator method getDeprecatedObjectProperties.
/**
* Retrieves deprecated properties of the given object compared to the class. A deprecated property is a property
* which exists in the Object but doesn't exist anymore in the Class. This is used for synchronization of existing
* or imported Objects with respect to the modifications of their associated Class.
*
* @param object the instance of this class where to look for undefined properties
* @return a list containing the properties of the object which don't exist in the class
* @see #getDeprecatedObjectPropertyNames(Object)
* @since 2.4M2
*/
public List<Property> getDeprecatedObjectProperties(Object object) {
List<BaseProperty> deprecatedObjectProperties = getBaseClass().getDeprecatedObjectProperties(object.getBaseObject());
List<Property> result = new ArrayList<Property>(deprecatedObjectProperties.size());
for (BaseProperty property : deprecatedObjectProperties) {
result.add(new Property(property, getXWikiContext()));
}
return result;
}
Aggregations