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;
}
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;
}
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;
}
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);
}
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"));
}
Aggregations