use of com.xpn.xwiki.objects.ListProperty in project xwiki-platform by xwiki.
the class StaticListClassTest method testDisplayView.
/**
* Tests that the list values are joined using the specified separator without being XML-encoded.
*
* @see "XWIKI-9680: Apostrophes in static list value are encoded on .display()"
*/
@Test
public void testDisplayView() {
ListProperty listProperty = new ListProperty();
listProperty.setValue(VALUES_WITH_HTML_SPECIAL_CHARS);
String propertyName = "foo";
BaseObject object = new BaseObject();
object.addField(propertyName, listProperty);
StaticListClass staticListClass = new StaticListClass();
staticListClass.setSeparator(" * ");
staticListClass.setValues(VALUES_WITH_HTML_SPECIAL_CHARS.get(0) + '|' + VALUES_WITH_HTML_SPECIAL_CHARS.get(1) + '=' + StringUtils.reverse(VALUES_WITH_HTML_SPECIAL_CHARS.get(1)) + '|' + VALUES_WITH_HTML_SPECIAL_CHARS.get(2));
assertEquals("a<b>c * 3'2\"1 * x{y&z", staticListClass.displayView(propertyName, "", object, null));
}
use of com.xpn.xwiki.objects.ListProperty in project xwiki-platform by xwiki.
the class XWikiHibernateStore method loadXWikiProperty.
private void loadXWikiProperty(PropertyInterface property, XWikiContext context, boolean bTransaction) throws XWikiException {
try {
if (bTransaction) {
checkHibernate(context);
bTransaction = beginTransaction(false, context);
}
Session session = getSession(context);
try {
session.load(property, (Serializable) property);
// safe to assume that a retrieved NULL value should actually be an empty string.
if (property instanceof BaseStringProperty) {
BaseStringProperty stringProperty = (BaseStringProperty) property;
if (stringProperty.getValue() == null) {
stringProperty.setValue("");
}
}
((BaseProperty) property).setValueDirty(false);
} catch (ObjectNotFoundException e) {
// Let's accept that there is no data in property tables but log it
this.logger.error("No data for property [{}] of object id [{}]", property.getName(), property.getId());
}
// Without this test ViewEditTest.testUpdateAdvanceObjectProp fails
if (property instanceof ListProperty) {
((ListProperty) property).getList();
}
if (bTransaction) {
endTransaction(context, false, false);
}
} catch (Exception e) {
BaseCollection obj = property.getObject();
Object[] args = { (obj != null) ? obj.getName() : "unknown", property.getName() };
throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_OBJECT, "Exception while loading property {1} of object {0}", e, args);
} finally {
try {
if (bTransaction) {
endTransaction(context, false, false);
}
} catch (Exception e) {
}
}
}
Aggregations