Search in sources :

Example 11 with ListProperty

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));
}
Also used : ListProperty(com.xpn.xwiki.objects.ListProperty) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 12 with ListProperty

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) {
        }
    }
}
Also used : ListProperty(com.xpn.xwiki.objects.ListProperty) BaseStringProperty(com.xpn.xwiki.objects.BaseStringProperty) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) BaseProperty(com.xpn.xwiki.objects.BaseProperty) BaseCollection(com.xpn.xwiki.objects.BaseCollection) XWikiException(com.xpn.xwiki.XWikiException) InitializationException(org.xwiki.component.phase.InitializationException) MigrationRequiredException(com.xpn.xwiki.store.migration.MigrationRequiredException) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) QueryException(org.xwiki.query.QueryException) UnexpectedException(org.xwiki.store.UnexpectedException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) SQLException(java.sql.SQLException) XWikiException(com.xpn.xwiki.XWikiException) Session(org.hibernate.Session)

Aggregations

ListProperty (com.xpn.xwiki.objects.ListProperty)12 BaseProperty (com.xpn.xwiki.objects.BaseProperty)7 ArrayList (java.util.ArrayList)5 BaseObject (com.xpn.xwiki.objects.BaseObject)4 DBStringListProperty (com.xpn.xwiki.objects.DBStringListProperty)4 StringListProperty (com.xpn.xwiki.objects.StringListProperty)4 Test (org.junit.Test)3 StringProperty (com.xpn.xwiki.objects.StringProperty)2 XWikiException (com.xpn.xwiki.XWikiException)1 XMLAttributeValueFilter (com.xpn.xwiki.internal.xml.XMLAttributeValueFilter)1 BaseCollection (com.xpn.xwiki.objects.BaseCollection)1 BaseStringProperty (com.xpn.xwiki.objects.BaseStringProperty)1 MigrationRequiredException (com.xpn.xwiki.store.migration.MigrationRequiredException)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 org.apache.ecs.xhtml.select (org.apache.ecs.xhtml.select)1 Element (org.dom4j.Element)1 ObjectNotFoundException (org.hibernate.ObjectNotFoundException)1 Session (org.hibernate.Session)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1