Search in sources :

Example 6 with StringProperty

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

the class ListClass method fromStringArray.

@Override
public BaseProperty fromStringArray(String[] strings) {
    if (!isMultiSelect()) {
        return fromString(strings[0]);
    }
    BaseProperty prop = newProperty();
    if (prop instanceof StringProperty) {
        return fromString(strings[0]);
    }
    List<String> list = new ArrayList<>();
    if (strings.length == 0) {
        return prop;
    }
    if ((strings.length == 1) && (getDisplayType().equals(DISPLAYTYPE_INPUT) || isMultiSelect())) {
        ((ListProperty) prop).setList(getListFromString(strings[0], getSeparators(), false));
        return prop;
    }
    // If Multiselect and multiple results
    for (String item : strings) {
        if (!item.trim().equals("")) {
            list.add(item);
        }
    }
    // setList will copy the list, so this call must be made last.
    ((ListProperty) prop).setList(list);
    return prop;
}
Also used : StringListProperty(com.xpn.xwiki.objects.StringListProperty) ListProperty(com.xpn.xwiki.objects.ListProperty) DBStringListProperty(com.xpn.xwiki.objects.DBStringListProperty) ArrayList(java.util.ArrayList) StringProperty(com.xpn.xwiki.objects.StringProperty) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 7 with StringProperty

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

the class ListClass method newPropertyfromXML.

@Override
public BaseProperty newPropertyfromXML(Element ppcel) {
    if (!isMultiSelect()) {
        return super.newPropertyfromXML(ppcel);
    }
    @SuppressWarnings("unchecked") List<Element> elist = ppcel.elements(ListXarObjectPropertySerializer.ELEMENT_VALUE);
    BaseProperty lprop = newProperty();
    if (lprop instanceof ListProperty) {
        List<String> llist = ((ListProperty) lprop).getList();
        for (int i = 0; i < elist.size(); i++) {
            Element el = elist.get(i);
            llist.add(el.getText());
        }
    } else {
        for (int i = 0; i < elist.size(); i++) {
            Element el = elist.get(i);
            ((StringProperty) lprop).setValue(el.getText());
        }
    }
    return lprop;
}
Also used : StringListProperty(com.xpn.xwiki.objects.StringListProperty) ListProperty(com.xpn.xwiki.objects.ListProperty) DBStringListProperty(com.xpn.xwiki.objects.DBStringListProperty) Element(org.dom4j.Element) StringProperty(com.xpn.xwiki.objects.StringProperty) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 8 with StringProperty

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

the class StringClass method newProperty.

@Override
public BaseProperty newProperty() {
    BaseProperty property = new StringProperty();
    property.setName(getName());
    return property;
}
Also used : StringProperty(com.xpn.xwiki.objects.StringProperty) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 9 with StringProperty

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

the class XWikiDocumentMockitoTest method testRemovingObjectWithWrongObjectVector.

/**
 * Normally the xobject vector has the Nth object on the Nth position, but in case an object gets misplaced, trying
 * to remove it should indeed remove that object, and no other.
 */
@Test
public void testRemovingObjectWithWrongObjectVector() {
    // Setup: Create a document and two xobjects
    BaseObject o1 = new BaseObject();
    BaseObject o2 = new BaseObject();
    o1.setXClassReference(CLASS_REFERENCE);
    o2.setXClassReference(CLASS_REFERENCE);
    // Test: put the second xobject on the third position
    // addObject creates the object vector and configures the objects
    // o1 is added at position 0
    // o2 is added at position 1
    XWikiDocument doc = new XWikiDocument(DOCUMENT_REFERENCE);
    doc.addXObject(o1);
    doc.addXObject(o2);
    // Modify the o2 object's position to ensure it can still be found and removed by the removeObject method.
    assertEquals(1, o2.getNumber());
    o2.setNumber(0);
    // Set a field on o1 so that when comparing it with o2 they are different. This is needed so that the remove
    // will pick the right object to remove (since we've voluntarily set a wrong number of o2 it would pick o1
    // if they were equals).
    o1.addField("somefield", new StringProperty());
    // Call the tested method, removing o2 from position 2 which is set to null
    boolean result = doc.removeXObject(o2);
    // Check the correct behavior:
    assertTrue(result);
    List<BaseObject> objects = doc.getXObjects(CLASS_REFERENCE);
    assertTrue(objects.contains(o1));
    assertFalse(objects.contains(o2));
    assertNull(objects.get(1));
    // Second test: swap the two objects, so that the first object is in the position the second should have
    // Start over, re-adding the two objects
    doc = new XWikiDocument(DOCUMENT_REFERENCE);
    doc.addXObject(o1);
    doc.addXObject(o2);
}
Also used : StringProperty(com.xpn.xwiki.objects.StringProperty) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 10 with StringProperty

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

the class PropertyConverterTest method singleToMultipleSelectOnDBList.

@Test
public void singleToMultipleSelectOnDBList() throws Exception {
    // The Database List property that was switched from single select to multiple select.
    DBListClass dbListClass = mock(DBListClass.class);
    when(dbListClass.isMultiSelect()).thenReturn(true);
    StringListProperty stringListProperty = mock(StringListProperty.class);
    when(dbListClass.newProperty()).thenReturn(stringListProperty);
    StringProperty stringProperty = mock(StringProperty.class);
    when(stringProperty.getValue()).thenReturn("one");
    assertEquals(stringListProperty, this.mocker.getComponentUnderTest().convertProperty(stringProperty, dbListClass));
    verify(stringListProperty).setValue(Arrays.asList("one"));
}
Also used : DBListClass(com.xpn.xwiki.objects.classes.DBListClass) StringProperty(com.xpn.xwiki.objects.StringProperty) StringListProperty(com.xpn.xwiki.objects.StringListProperty) Test(org.junit.Test)

Aggregations

StringProperty (com.xpn.xwiki.objects.StringProperty)14 BaseProperty (com.xpn.xwiki.objects.BaseProperty)7 Test (org.junit.Test)6 BaseObject (com.xpn.xwiki.objects.BaseObject)4 StringListProperty (com.xpn.xwiki.objects.StringListProperty)4 DBListClass (com.xpn.xwiki.objects.classes.DBListClass)3 DBStringListProperty (com.xpn.xwiki.objects.DBStringListProperty)2 ListProperty (com.xpn.xwiki.objects.ListProperty)2 StringClass (com.xpn.xwiki.objects.classes.StringClass)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Query (org.hibernate.Query)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 BaseCollection (com.xpn.xwiki.objects.BaseCollection)1 BaseStringProperty (com.xpn.xwiki.objects.BaseStringProperty)1 IntegerProperty (com.xpn.xwiki.objects.IntegerProperty)1 LargeStringProperty (com.xpn.xwiki.objects.LargeStringProperty)1