Search in sources :

Example 6 with BaseProperty

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

the class ModelFactory method toRestObject.

public Object toRestObject(URI baseUri, Document doc, BaseObject xwikiObject, boolean useVersion, Boolean withPrettyNames) {
    Object object = this.objectFactory.createObject();
    fillObjectSummary(object, doc, xwikiObject, withPrettyNames);
    XWikiContext xwikiContext = this.xcontextProvider.get();
    BaseClass xwikiClass = xwikiObject.getXClass(xwikiContext);
    for (java.lang.Object propertyClassObject : xwikiClass.getProperties()) {
        com.xpn.xwiki.objects.classes.PropertyClass propertyClass = (com.xpn.xwiki.objects.classes.PropertyClass) propertyClassObject;
        Property property = this.objectFactory.createProperty();
        for (java.lang.Object o : propertyClass.getProperties()) {
            BaseProperty baseProperty = (BaseProperty) o;
            Attribute attribute = this.objectFactory.createAttribute();
            attribute.setName(baseProperty.getName());
            /* Check for null values in order to prevent NPEs */
            if (baseProperty.getValue() != null) {
                attribute.setValue(baseProperty.getValue().toString());
            } else {
                attribute.setValue("");
            }
            property.getAttributes().add(attribute);
        }
        if (propertyClass instanceof ListClass) {
            ListClass listClass = (ListClass) propertyClass;
            List allowedValueList = listClass.getList(xwikiContext);
            if (!allowedValueList.isEmpty()) {
                Formatter f = new Formatter();
                for (int i = 0; i < allowedValueList.size(); i++) {
                    if (i != allowedValueList.size() - 1) {
                        f.format("%s,", allowedValueList.get(i).toString());
                    } else {
                        f.format("%s", allowedValueList.get(i).toString());
                    }
                }
                Attribute attribute = this.objectFactory.createAttribute();
                attribute.setName(Constants.ALLOWED_VALUES_ATTRIBUTE_NAME);
                attribute.setValue(f.toString());
                property.getAttributes().add(attribute);
            }
        }
        property.setName(propertyClass.getName());
        property.setType(propertyClass.getClassType());
        try {
            property.setValue(serializePropertyValue(xwikiObject.get(propertyClass.getName())));
        } catch (XWikiException e) {
        // Should never happen
        }
        String propertyUri;
        if (useVersion) {
            propertyUri = Utils.createURI(baseUri, ObjectPropertyAtPageVersionResource.class, doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName(), doc.getVersion(), xwikiObject.getClassName(), xwikiObject.getNumber(), propertyClass.getName()).toString();
        } else {
            propertyUri = Utils.createURI(baseUri, ObjectPropertyResource.class, doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName(), xwikiObject.getClassName(), xwikiObject.getNumber(), propertyClass.getName()).toString();
        }
        Link propertyLink = this.objectFactory.createLink();
        propertyLink.setHref(propertyUri);
        propertyLink.setRel(Relations.SELF);
        property.getLinks().add(propertyLink);
        object.getProperties().add(property);
    }
    Link objectLink = getObjectLink(this.objectFactory, baseUri, doc, xwikiObject, useVersion, Relations.SELF);
    object.getLinks().add(objectLink);
    return object;
}
Also used : Attribute(org.xwiki.rest.model.jaxb.Attribute) Formatter(java.util.Formatter) XWikiContext(com.xpn.xwiki.XWikiContext) PropertyClass(com.xpn.xwiki.api.PropertyClass) ListClass(com.xpn.xwiki.objects.classes.ListClass) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) BaseObject(com.xpn.xwiki.objects.BaseObject) Object(org.xwiki.rest.model.jaxb.Object) List(java.util.List) ArrayList(java.util.ArrayList) BaseProperty(com.xpn.xwiki.objects.BaseProperty) Property(org.xwiki.rest.model.jaxb.Property) BaseProperty(com.xpn.xwiki.objects.BaseProperty) XWikiException(com.xpn.xwiki.XWikiException) Link(org.xwiki.rest.model.jaxb.Link)

Example 7 with BaseProperty

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

the class Collection method getProperties.

public Element[] getProperties() {
    @SuppressWarnings("unchecked") java.util.Collection<BaseProperty> coll = getCollection().getFieldList();
    if (coll == null) {
        return null;
    }
    Property[] properties = new Property[coll.size()];
    int i = 0;
    for (BaseProperty prop : coll) {
        properties[i++] = new Property(prop, getXWikiContext());
    }
    return properties;
}
Also used : BaseProperty(com.xpn.xwiki.objects.BaseProperty) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 8 with BaseProperty

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

the class PropertyComparator method getDeprecatedObjectPropertyNames.

/**
 * Get the names of deprecated properties of the given object compared to the class. A deprecated property is a
 * property which exists in the Object but doesn't exist anymore in the Class. This is used for synchronization of
 * existing or imported Objects with respect to the modifications of their associated Class.
 *
 * @param object the instance of this class where to look for undefined properties
 * @return a list of deprecated property names
 * @see #getDeprecatedObjectProperties(Object)
 * @since 2.4M2
 */
public List<String> getDeprecatedObjectPropertyNames(Object object) {
    List<BaseProperty> properties = this.getBaseClass().getDeprecatedObjectProperties(object.getBaseObject());
    List<String> result = new ArrayList<String>(properties.size());
    for (BaseProperty property : properties) {
        if (property != null) {
            result.add(property.getName());
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 9 with BaseProperty

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

the class XWikiStats method fromXML.

/**
 * Initialize statistics object from XML schema.
 *
 * @param oel the XML root node containing statistics datas.
 * @throws XWikiException error when parsing XML schema.
 */
public void fromXML(Element oel) throws XWikiException {
    Element cel = oel.element("class");
    BaseClass bclass = new BaseClass();
    if (cel != null) {
        bclass.fromXML(cel);
        setClassName(bclass.getName());
    }
    setName(oel.element(XMLNODE_NAME).getText());
    List<?> list = oel.elements(XMLNODE_PROPERTY);
    for (int i = 0; i < list.size(); i++) {
        Element pcel = (Element) ((Element) list.get(i)).elements().get(0);
        String name = pcel.getName();
        PropertyClass pclass = (PropertyClass) bclass.get(name);
        if (pclass != null) {
            BaseProperty property = pclass.newPropertyfromXML(pcel);
            property.setName(name);
            property.setObject(this);
            safeput(name, property);
        }
    }
}
Also used : Element(org.dom4j.Element) DOMElement(org.dom4j.dom.DOMElement) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) BaseProperty(com.xpn.xwiki.objects.BaseProperty) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass)

Example 10 with BaseProperty

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

the class PageTagsResourceImpl method getTagsFromDocument.

private List<String> getTagsFromDocument(String documentId) throws XWikiException {
    XWikiDocument document = Utils.getXWiki(componentManager).getDocument(documentId, Utils.getXWikiContext(componentManager));
    BaseObject object = document.getObject("XWiki.TagClass");
    if (object != null) {
        BaseProperty prop = (BaseProperty) object.safeget("tags");
        if (prop != null) {
            return (List<String>) prop.getValue();
        }
    }
    return new ArrayList<String>();
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BaseProperty(com.xpn.xwiki.objects.BaseProperty) BaseObject(com.xpn.xwiki.objects.BaseObject)

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