Search in sources :

Example 81 with BaseProperty

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;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BaseProperty(com.xpn.xwiki.objects.BaseProperty) XWikiException(com.xpn.xwiki.XWikiException)

Example 82 with BaseProperty

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;
        }
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) BaseProperty(com.xpn.xwiki.objects.BaseProperty) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 83 with BaseProperty

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;
}
Also used : BaseObject(com.xpn.xwiki.objects.BaseObject) BaseProperty(com.xpn.xwiki.objects.BaseProperty) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 84 with BaseProperty

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;
}
Also used : ToString(org.suigeneris.jrcs.util.ToString) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 85 with BaseProperty

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;
}
Also used : ArrayList(java.util.ArrayList) BaseProperty(com.xpn.xwiki.objects.BaseProperty) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Aggregations

BaseProperty (com.xpn.xwiki.objects.BaseProperty)87 BaseObject (com.xpn.xwiki.objects.BaseObject)26 ArrayList (java.util.ArrayList)16 XWikiException (com.xpn.xwiki.XWikiException)14 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)12 XMLAttributeValueFilter (com.xpn.xwiki.internal.xml.XMLAttributeValueFilter)12 org.apache.ecs.xhtml.input (org.apache.ecs.xhtml.input)11 XWikiContext (com.xpn.xwiki.XWikiContext)10 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)9 DocumentReference (org.xwiki.model.reference.DocumentReference)9 StringProperty (com.xpn.xwiki.objects.StringProperty)8 ListProperty (com.xpn.xwiki.objects.ListProperty)7 XWiki (com.xpn.xwiki.XWiki)5 BaseCollection (com.xpn.xwiki.objects.BaseCollection)5 LargeStringProperty (com.xpn.xwiki.objects.LargeStringProperty)5 List (java.util.List)5 Test (org.junit.Test)5 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)5 DBStringListProperty (com.xpn.xwiki.objects.DBStringListProperty)4 PropertyClass (com.xpn.xwiki.objects.classes.PropertyClass)4