Search in sources :

Example 11 with BaseProperty

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

the class XWikiDocument method renameProperties.

/**
 * @since 2.2M2
 */
public void renameProperties(DocumentReference classReference, Map<String, String> fieldsToRename) {
    List<BaseObject> objects = this.xObjects.get(classReference);
    if (objects == null) {
        return;
    }
    boolean isDirty = false;
    for (BaseObject bobject : objects) {
        if (bobject == null) {
            continue;
        }
        for (Map.Entry<String, String> entry : fieldsToRename.entrySet()) {
            String origname = entry.getKey();
            String newname = entry.getValue();
            BaseProperty origprop = (BaseProperty) bobject.safeget(origname);
            if (origprop != null) {
                BaseProperty prop = origprop.clone();
                bobject.removeField(origname);
                prop.setName(newname);
                bobject.addField(newname, prop);
                isDirty = true;
            }
        }
    }
    // If at least one property was renamed, mark the document dirty.
    if (isDirty) {
        setMetaDataDirty(true);
    }
}
Also used : ToString(org.suigeneris.jrcs.util.ToString) BaseProperty(com.xpn.xwiki.objects.BaseProperty) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 12 with BaseProperty

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

the class DefaultDocumentAccessBridge method getProperty.

@Override
public Object getProperty(ObjectReference objectReference, String propertyName) {
    Object value = null;
    try {
        XWikiContext xcontext = getContext();
        if (xcontext != null && xcontext.getWiki() != null) {
            DocumentReference documentReference = (DocumentReference) objectReference.extractReference(EntityType.DOCUMENT);
            XWikiDocument doc = xcontext.getWiki().getDocument(documentReference, xcontext);
            BaseObject object = doc.getXObject(objectReference);
            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) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 13 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 className, int objectNumber, 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.getObject(className, objectNumber);
            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 14 with BaseProperty

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

the class DefaultDocumentAccessBridge method getProperty.

@Override
public Object getProperty(DocumentReference documentReference, DocumentReference classReference, 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.getXObject(classReference);
            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 15 with BaseProperty

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

the class Property method getValue.

/**
 * @return the actual value of the property, as a String, Number or List.
 */
public java.lang.Object getValue() {
    BaseProperty baseProperty = getBaseProperty();
    com.xpn.xwiki.objects.classes.PropertyClass propertyClass = baseProperty.getPropertyClass(getXWikiContext());
    // API level, so that java code using core classes will still have access, regardless or rights.
    if (propertyClass != null && "Password".equals(propertyClass.getClassType())) {
        if (!getXWikiContext().getWiki().getRightService().hasProgrammingRights(getXWikiContext())) {
            return null;
        }
    }
    return getBaseProperty().getValue();
}
Also used : 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