Search in sources :

Example 6 with PropertyInterface

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

Example 7 with PropertyInterface

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

Example 8 with PropertyInterface

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);
            }
        }
    }
}
Also used : ObjectDiff(com.xpn.xwiki.objects.ObjectDiff) PropertyInterface(com.xpn.xwiki.objects.PropertyInterface) BaseClass(com.xpn.xwiki.objects.classes.BaseClass)

Example 9 with PropertyInterface

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);
    }
}
Also used : PropertyInterface(com.xpn.xwiki.objects.PropertyInterface) XWikiRestException(org.xwiki.rest.XWikiRestException) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

PropertyInterface (com.xpn.xwiki.objects.PropertyInterface)9 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)4 XWikiException (com.xpn.xwiki.XWikiException)3 BaseObject (com.xpn.xwiki.objects.BaseObject)3 XWikiContext (com.xpn.xwiki.XWikiContext)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 ObjectDiff (com.xpn.xwiki.objects.ObjectDiff)2 XWikiRestException (org.xwiki.rest.XWikiRestException)2 MergeResult (com.xpn.xwiki.doc.merge.MergeResult)1 XWikiAttachmentList (com.xpn.xwiki.internal.doc.XWikiAttachmentList)1 ParseGroovyFromString (com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString)1 PasswordClass (com.xpn.xwiki.objects.classes.PasswordClass)1 PropertyClass (com.xpn.xwiki.objects.classes.PropertyClass)1 XWikiRequest (com.xpn.xwiki.web.XWikiRequest)1 IncludeServletAsString (com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1