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;
}
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);
}
}
}
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;
}
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);
}
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);
}
Aggregations