Search in sources :

Example 46 with BaseProperty

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

the class ObjectSolrReferenceResolver method getReferences.

@Override
public List<EntityReference> getReferences(EntityReference objectReference) throws SolrIndexerException {
    List<EntityReference> result = new ArrayList<>();
    // Object itself
    result.add(objectReference);
    // Object properties
    DocumentReference documentReference = new DocumentReference(objectReference.getParent());
    XWikiDocument document;
    try {
        document = getDocument(documentReference);
    } catch (Exception e) {
        throw new SolrIndexerException("Failed to get document for object [" + objectReference + "]", e);
    }
    BaseObject object = document.getXObject(objectReference);
    if (object != null) {
        for (Object field : object.getFieldList()) {
            BaseProperty<ObjectPropertyReference> objectProperty = (BaseProperty<ObjectPropertyReference>) field;
            ObjectPropertyReference objectPropertyReference = objectProperty.getReference();
            try {
                Iterables.addAll(result, this.objectPropertyResolverProvider.get().getReferences(objectPropertyReference));
            } catch (Exception e) {
                this.logger.error("Failed to resolve references for object property [" + objectPropertyReference + "]", e);
            }
        }
    }
    return result;
}
Also used : SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ObjectPropertyReference(org.xwiki.model.reference.ObjectPropertyReference) EntityReference(org.xwiki.model.reference.EntityReference) ArrayList(java.util.ArrayList) BaseObject(com.xpn.xwiki.objects.BaseObject) BaseProperty(com.xpn.xwiki.objects.BaseProperty) DocumentReference(org.xwiki.model.reference.DocumentReference) SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 47 with BaseProperty

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

the class DBListClass method displayView.

@Override
public void displayView(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    List<String> selectlist;
    String separator = getSeparator();
    BaseProperty prop = (BaseProperty) object.safeget(name);
    Map<String, ListItem> map = getMap(context);
    // Skip unset values.
    if (prop == null) {
        return;
    }
    if (prop instanceof ListProperty) {
        selectlist = ((ListProperty) prop).getList();
        List<String> newlist = new ArrayList<>();
        for (String entry : selectlist) {
            newlist.add(getDisplayValue(entry, name, map, context));
        }
        buffer.append(StringUtils.join(newlist, separator));
    } else {
        buffer.append(getDisplayValue(prop.getValue(), name, map, context));
    }
}
Also used : ListProperty(com.xpn.xwiki.objects.ListProperty) ArrayList(java.util.ArrayList) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 48 with BaseProperty

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

the class DBTreeListClass method displayTreeSelectEdit.

protected void displayTreeSelectEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    select select = new select(prefix + name, 1);
    select.setAttributeFilter(new XMLAttributeValueFilter());
    select.setMultiple(isMultiSelect());
    select.setSize(getSize());
    select.setName(prefix + name);
    select.setID(prefix + name);
    select.setDisabled(isDisabled());
    Map<String, ListItem> map = getMap(context);
    Map<String, List<ListItem>> treemap = getTreeMap(context);
    List<String> selectlist;
    BaseProperty prop = (BaseProperty) object.safeget(name);
    if (prop == null) {
        selectlist = new ArrayList<String>();
    } else if (prop instanceof ListProperty) {
        selectlist = ((ListProperty) prop).getList();
    } else {
        selectlist = new ArrayList<String>();
        selectlist.add(String.valueOf(prop.getValue()));
    }
    // Add options from Set
    addToSelect(select, selectlist, map, treemap, "", "", context);
    buffer.append(select.toString());
}
Also used : ListProperty(com.xpn.xwiki.objects.ListProperty) org.apache.ecs.xhtml.select(org.apache.ecs.xhtml.select) XMLAttributeValueFilter(com.xpn.xwiki.internal.xml.XMLAttributeValueFilter) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 49 with BaseProperty

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

the class DBTreeListClass method displayView.

@Override
public void displayView(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    List<String> selectlist;
    BaseProperty prop = (BaseProperty) object.safeget(name);
    if (prop == null) {
        selectlist = new ArrayList<String>();
    } else if (prop instanceof ListProperty) {
        selectlist = ((ListProperty) prop).getList();
    } else {
        selectlist = new ArrayList<String>();
        selectlist.add(String.valueOf(prop.getValue()));
    }
    String result = displayFlatView(selectlist, context);
    if (result.equals("")) {
        super.displayView(buffer, name, prefix, object, context);
    } else {
        buffer.append(result);
    }
}
Also used : ListProperty(com.xpn.xwiki.objects.ListProperty) ArrayList(java.util.ArrayList) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 50 with BaseProperty

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

the class DBTreeListClass method displayEdit.

@Override
public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    BaseProperty prop = (BaseProperty) object.safeget(name);
    List<String> selectlist = toList(prop);
    if (isPicker()) {
        String result = displayTree(name, prefix, selectlist, "edit", context);
        if (result.equals("")) {
            displayTreeSelectEdit(buffer, name, prefix, object, context);
        } else {
            displayHidden(buffer, name, prefix, object, context);
            buffer.append(result);
        }
    } else {
        displayTreeSelectEdit(buffer, name, prefix, object, context);
    }
}
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