Search in sources :

Example 1 with DBStringListProperty

use of com.xpn.xwiki.objects.DBStringListProperty in project xwiki-platform by xwiki.

the class TagPlugin method createTagProperty.

/**
 * Create and add the main tag property to the provided tag object. The new property corresponds to the definition
 * in the tag class, but in case of an error, the default type is a relational-stored list.
 *
 * @param tagObject the target tag object
 * @param context the current request context
 * @return the created property
 * @see #TAG_PROPERTY
 */
private BaseProperty createTagProperty(BaseObject tagObject, XWikiContext context) {
    BaseProperty tagProperty;
    try {
        BaseClass tagClass = context.getWiki().getClass(TAG_CLASS, context);
        PropertyClass tagPropertyDefinition = (PropertyClass) tagClass.getField(TAG_PROPERTY);
        tagProperty = tagPropertyDefinition.newProperty();
    } catch (XWikiException ex) {
        LOGGER.warn("Failed to properly create tag property for the tag object, creating a default one");
        tagProperty = new DBStringListProperty();
    }
    tagProperty.setName(TAG_PROPERTY);
    tagProperty.setObject(tagObject);
    tagObject.safeput(TAG_PROPERTY, tagProperty);
    return tagProperty;
}
Also used : BaseClass(com.xpn.xwiki.objects.classes.BaseClass) DBStringListProperty(com.xpn.xwiki.objects.DBStringListProperty) BaseProperty(com.xpn.xwiki.objects.BaseProperty) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

XWikiException (com.xpn.xwiki.XWikiException)1 BaseProperty (com.xpn.xwiki.objects.BaseProperty)1 DBStringListProperty (com.xpn.xwiki.objects.DBStringListProperty)1 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)1 PropertyClass (com.xpn.xwiki.objects.classes.PropertyClass)1