Search in sources :

Example 16 with BaseProperty

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

the class DefaultDocumentAccessBridge method getProperty.

@Override
public Object getProperty(String documentReference, String propertyName) {
    Object value = null;
    try {
        XWikiContext xcontext = getContext();
        if (xcontext != null && xcontext.getWiki() != null) {
            XWikiDocument doc = xcontext.getWiki().getDocument(documentReference, xcontext);
            BaseObject object = doc.getFirstObject(propertyName, xcontext);
            if (object != null) {
                BaseProperty property = (BaseProperty) object.get(propertyName);
                if (property != null) {
                    value = property.getValue();
                }
            }
        }
    } catch (Exception e) {
        this.logger.error("Failed to get property", e);
    }
    return value;
}
Also used : XWikiContext(com.xpn.xwiki.XWikiContext) BaseObject(com.xpn.xwiki.objects.BaseObject) BaseProperty(com.xpn.xwiki.objects.BaseProperty) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 17 with BaseProperty

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

the class AbstractSolrMetadataExtractor method setObjectContent.

/**
 * Adds the properties of a given object to a Solr document.
 *
 * @param solrDocument the document where to add the properties
 * @param object the object whose properties to add
 * @param locale the locale of the indexed document; in case of translations, this will obviously be different than
 *            the original document's locale
 */
protected void setObjectContent(SolrInputDocument solrDocument, BaseObject object, Locale locale) {
    if (object == null) {
        // Yes, the platform can return null objects.
        return;
    }
    BaseClass xClass = object.getXClass(this.xcontextProvider.get());
    for (Object field : object.getFieldList()) {
        @SuppressWarnings("unchecked") BaseProperty<EntityReference> property = (BaseProperty<EntityReference>) field;
        // Avoid indexing empty properties.
        if (property.getValue() != null) {
            PropertyClass propertyClass = (PropertyClass) xClass.get(property.getName());
            setPropertyValue(solrDocument, property, propertyClass, locale);
        }
    }
}
Also used : BaseClass(com.xpn.xwiki.objects.classes.BaseClass) EntityReference(org.xwiki.model.reference.EntityReference) BaseObject(com.xpn.xwiki.objects.BaseObject) BaseProperty(com.xpn.xwiki.objects.BaseProperty) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass)

Example 18 with BaseProperty

use of com.xpn.xwiki.objects.BaseProperty 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)

Example 19 with BaseProperty

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

the class TagPlugin method setDocumentTags.

/**
 * Set tags of the given document.
 *
 * @param document document to put the tags to.
 * @param tags list of tags.
 * @param context XWiki context.
 */
private void setDocumentTags(XWikiDocument document, List<String> tags, XWikiContext context) {
    BaseProperty prop = (BaseProperty) document.getObject(TAG_CLASS, true, context).safeget(TAG_PROPERTY);
    // Properties aren't added to an object unless a value is specified either from the Web or from an XML.
    if (prop == null) {
        prop = createTagProperty(document.getObject(TAG_CLASS, true, context), context);
    }
    prop.setValue(tags);
}
Also used : BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 20 with BaseProperty

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

the class BaseObjectEventGenerator method write.

@Override
public void write(BaseObject xobject, Object filter, BaseObjectFilter objectFilter, DocumentInstanceInputProperties properties) throws FilterException {
    XWikiContext xcontext = this.xcontextProvider.get();
    // > WikiObject
    FilterEventParameters objectParameters = new FilterEventParameters();
    objectParameters.put(WikiObjectFilter.PARAMETER_NAME, xobject.getName());
    objectParameters.put(WikiObjectFilter.PARAMETER_CLASS_REFERENCE, xobject.getClassName());
    objectParameters.put(WikiObjectFilter.PARAMETER_GUID, xobject.getGuid());
    objectParameters.put(WikiObjectFilter.PARAMETER_NUMBER, xobject.getNumber());
    objectFilter.beginWikiObject(xobject.getReference() != null ? xobject.getReference().getName() : null, objectParameters);
    // Object class
    BaseClass xclass = xobject.getXClass(xcontext);
    ((BaseClassEventGenerator) this.classEventGenerator).write(xclass, filter, objectFilter, properties);
    // Properties
    // Iterate over values/properties sorted by field name so that the values are
    // exported to XML in a consistent order.
    Iterator<BaseProperty<?>> it = xobject.getSortedIterator();
    while (it.hasNext()) {
        BaseProperty<?> xproperty = it.next();
        String pname = xproperty.getName();
        if (pname != null && !pname.trim().equals("")) {
            ((BasePropertyEventGenerator) this.propertyEventGenerator).write(xproperty, filter, (Map<String, Object>) properties);
        }
    }
    // < WikiObject
    objectFilter.endWikiObject(xobject.getReference().getName(), objectParameters);
}
Also used : FilterEventParameters(org.xwiki.filter.FilterEventParameters) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) XWikiContext(com.xpn.xwiki.XWikiContext) BaseObject(com.xpn.xwiki.objects.BaseObject) 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