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