use of com.xpn.xwiki.objects.PropertyInterface in project xwiki-platform by xwiki.
the class BaseClass method addTextAreaField.
/**
* @since 8.3
*/
public boolean addTextAreaField(String fieldName, String fieldPrettyName, int cols, int rows, String editor, String contenttype) {
boolean result = false;
TextAreaClass textAreaClass;
PropertyInterface field = get(fieldName);
if (field instanceof TextAreaClass) {
textAreaClass = (TextAreaClass) field;
} else {
// Remove the field if it already exist
if (field != null) {
removeField(fieldName);
}
// Create a new field
textAreaClass = new TextAreaClass();
textAreaClass.setName(fieldName);
textAreaClass.setObject(this);
put(fieldName, textAreaClass);
result = true;
}
if (!textAreaClass.getPrettyName().equals(fieldPrettyName)) {
textAreaClass.setPrettyName(fieldPrettyName);
result = true;
}
// comparing here. In addition when the editor is not, an empty string is returned from getEditor()...
if ((editor == null && !textAreaClass.getEditor().isEmpty()) || (editor != null && !textAreaClass.getEditor().equals(editor.toLowerCase()))) {
textAreaClass.setEditor(editor);
result = true;
}
// the content type is different (and vice versa).
if ((contenttype == null && !textAreaClass.getContentType().equalsIgnoreCase(ContentType.WIKI_TEXT.toString())) || (contenttype != null && !textAreaClass.getContentType().equalsIgnoreCase(contenttype))) {
textAreaClass.setContentType(contenttype);
result = true;
}
if (textAreaClass.getSize() != cols) {
textAreaClass.setSize(cols);
result = true;
}
if (textAreaClass.getRows() != rows) {
textAreaClass.setRows(rows);
result = true;
}
return result;
}
use of com.xpn.xwiki.objects.PropertyInterface in project xwiki-platform by xwiki.
the class XObjectEventGeneratorListener method onObjectPropertyModified.
/**
* Generate object property related events.
*
* @param doc the new version of the document
* @param diff the diff entry
* @param context the XWiki context
*/
private void onObjectPropertyModified(XWikiDocument doc, ObjectDiff diff, XWikiContext context) {
if (ObjectDiff.ACTION_PROPERTYREMOVED.equals(diff.getAction())) {
BaseObject object = doc.getOriginalDocument().getXObject(diff.getXClassReference(), diff.getNumber());
PropertyInterface property = object.getField(diff.getPropName());
this.observation.notify(new XObjectPropertyDeletedEvent(property.getReference()), doc, context);
} else {
BaseObject object = doc.getXObject(diff.getXClassReference(), diff.getNumber());
PropertyInterface property = object.getField(diff.getPropName());
if (ObjectDiff.ACTION_PROPERTYADDED.equals(diff.getAction())) {
this.observation.notify(new XObjectPropertyAddedEvent(property.getReference()), doc, context);
} else if (ObjectDiff.ACTION_PROPERTYCHANGED.equals(diff.getAction())) {
this.observation.notify(new XObjectPropertyUpdatedEvent(property.getReference()), doc, context);
}
}
}
use of com.xpn.xwiki.objects.PropertyInterface in project xwiki-platform by xwiki.
the class XClassPropertyEventGeneratorListener method onDocumentUpdatedEvent.
/**
* @param originalDoc the previous version of the document
* @param doc the new version of the document
* @param context the XWiki context
*/
private void onDocumentUpdatedEvent(XWikiDocument originalDoc, XWikiDocument doc, XWikiContext context) {
BaseClass baseClass = doc.getXClass();
BaseClass baseClassOriginal = originalDoc.getXClass();
for (List<ObjectDiff> objectChanges : doc.getClassDiff(originalDoc, doc, context)) {
for (ObjectDiff diff : objectChanges) {
PropertyInterface property = baseClass.getField(diff.getPropName());
PropertyInterface propertyOriginal = baseClassOriginal.getField(diff.getPropName());
if (ObjectDiff.ACTION_PROPERTYREMOVED.equals(diff.getAction())) {
this.observation.notify(new XClassPropertyDeletedEvent(propertyOriginal.getReference()), doc, context);
} else if (ObjectDiff.ACTION_PROPERTYADDED.equals(diff.getAction())) {
this.observation.notify(new XClassPropertyAddedEvent(property.getReference()), doc, context);
} else if (ObjectDiff.ACTION_PROPERTYCHANGED.equals(diff.getAction())) {
this.observation.notify(new XClassPropertyUpdatedEvent(property.getReference()), doc, context);
}
}
}
}
use of com.xpn.xwiki.objects.PropertyInterface in project xwiki-platform by xwiki.
the class AbstractClassPropertyValuesProvider method getPropertyDefinition.
@SuppressWarnings("unchecked")
protected T getPropertyDefinition(ClassPropertyReference propertyReference) throws XWikiRestException {
try {
XWikiContext xcontext = this.xcontextProvider.get();
PropertyInterface property = xcontext.getWiki().getDocument(propertyReference, xcontext).getXClass().get(propertyReference.getName());
if (property == null) {
throw new XWikiRestException(String.format("Property [%s] not found.", this.entityReferenceSerializer.serialize(propertyReference)));
} else if (getPropertyType().isInstance(property)) {
return (T) property;
} else {
throw new XWikiRestException(String.format("This [%s] is not a [%s] property.", this.entityReferenceSerializer.serialize(propertyReference), getPropertyType().getSimpleName()));
}
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
Aggregations