Search in sources :

Example 26 with PropertyClass

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

the class DefaultClassPropertyValuesProviderTest method configure.

@Before
public void configure() throws Exception {
    this.xcontextProvider = this.mocker.getInstance(XWikiContext.TYPE_PROVIDER);
    XWikiContext xcontext = mock(XWikiContext.class);
    XWiki xwiki = mock(XWiki.class);
    XWikiDocument classDocument = mock(XWikiDocument.class);
    BaseClass xclass = mock(BaseClass.class);
    PropertyClass propertyClass = mock(PropertyClass.class);
    when(this.xcontextProvider.get()).thenReturn(xcontext);
    when(xcontext.getWiki()).thenReturn(xwiki);
    when(xwiki.getDocument((EntityReference) this.classReference, xcontext)).thenReturn(classDocument);
    when(classDocument.getXClass()).thenReturn(xclass);
    when(xclass.get("category")).thenReturn(propertyClass);
    when(propertyClass.getClassType()).thenReturn("DBList");
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass) Before(org.junit.Before)

Example 27 with PropertyClass

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

the class CurrentUserPropertyResourceImpl method computeNewValue.

private java.lang.Object computeNewValue(BaseObject object, String propertyName, XWikiContext xcontext) {
    java.lang.Object newValue = null;
    PropertyClass propertyClass = (PropertyClass) object.getXClass(xcontext).get(propertyName);
    if (propertyClass.getClassType().equals("Boolean")) {
        // Note: if not defined, then set it to true
        if (object.getIntValue(propertyName) == 1) {
            newValue = 0;
        } else {
            newValue = 1;
        }
    } else if (propertyClass.getClassType().equals("StaticList")) {
        newValue = computeNewStaticListValue((StaticListClass) propertyClass, object, propertyName, xcontext);
    }
    return newValue;
}
Also used : PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass)

Example 28 with PropertyClass

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

the class XWikiDocument method displayForm.

/**
 * @since 2.2M1
 */
public String displayForm(DocumentReference classReference, String header, String format, boolean linebreak, XWikiContext context) {
    List<BaseObject> objects = getXObjects(classReference);
    if (format.endsWith("\\n")) {
        linebreak = true;
    }
    BaseObject firstobject = null;
    Iterator<BaseObject> foit = objects.iterator();
    while ((firstobject == null) && foit.hasNext()) {
        firstobject = foit.next();
    }
    if (firstobject == null) {
        return "";
    }
    BaseClass bclass = firstobject.getXClass(context);
    if (bclass.getPropertyList().size() == 0) {
        return "";
    }
    StringBuilder result = new StringBuilder();
    VelocityContext vcontext = new VelocityContext();
    for (String propertyName : bclass.getPropertyList()) {
        PropertyClass pclass = (PropertyClass) bclass.getField(propertyName);
        vcontext.put(pclass.getName(), pclass.getPrettyName());
    }
    result.append(evaluate(header, context.getDoc().getPrefixedFullName(), vcontext, context));
    if (linebreak) {
        result.append("\n");
    }
    // display each line
    for (int i = 0; i < objects.size(); i++) {
        vcontext.put("id", Integer.valueOf(i + 1));
        BaseObject object = objects.get(i);
        if (object != null) {
            for (String name : bclass.getPropertyList()) {
                vcontext.put(name, display(name, object, context));
            }
            result.append(evaluate(format, context.getDoc().getPrefixedFullName(), vcontext, context));
            if (linebreak) {
                result.append("\n");
            }
        }
    }
    return result.toString();
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) ToString(org.suigeneris.jrcs.util.ToString) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass) BaseObject(com.xpn.xwiki.objects.BaseObject)

Aggregations

PropertyClass (com.xpn.xwiki.objects.classes.PropertyClass)28 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)16 XWikiException (com.xpn.xwiki.XWikiException)8 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)7 BaseObject (com.xpn.xwiki.objects.BaseObject)5 BaseProperty (com.xpn.xwiki.objects.BaseProperty)5 ToString (org.suigeneris.jrcs.util.ToString)5 XWiki (com.xpn.xwiki.XWiki)4 ArrayList (java.util.ArrayList)4 QueryException (org.xwiki.query.QueryException)4 XWikiContext (com.xpn.xwiki.XWikiContext)3 IOException (java.io.IOException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 DifferentiationFailedException (org.suigeneris.jrcs.diff.DifferentiationFailedException)3 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)3 ExecutionContextException (org.xwiki.context.ExecutionContextException)3 MissingParserException (org.xwiki.rendering.parser.MissingParserException)3 ParseException (org.xwiki.rendering.parser.ParseException)3 TransformationException (org.xwiki.rendering.transformation.TransformationException)3 HashMap (java.util.HashMap)2