use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class DefaultWikiComponentBuilderEventListener method installOrUpdateComponentMethodXClass.
/**
* Verify that the {@link #METHOD_CLASS} exists and is up-to-date (act if not).
*
* @throws XWikiException on failure
*/
private void installOrUpdateComponentMethodXClass() throws XWikiException {
XWikiContext xcontext = getXWikiContext();
XWikiDocument doc = xcontext.getWiki().getDocument(METHOD_CLASS_REFRENCE, xcontext);
BaseClass bclass = doc.getXClass();
bclass.setDocumentReference(doc.getDocumentReference());
boolean needsUpdate = false;
needsUpdate |= this.initializeXClassDocumentMetadata(doc, "Wiki Component Method XWiki Class");
needsUpdate |= bclass.addTextField(METHOD_NAME_FIELD, "Method name", 30);
// This field contains wiki syntax (usually some scripting macr) but it's technical content that should be
// edited with a Text editor.
needsUpdate |= bclass.addTextAreaField(METHOD_CODE_FIELD, "Method body code", 40, 20, TextAreaClass.EditorType.TEXT, TextAreaClass.ContentType.WIKI_TEXT);
if (needsUpdate) {
this.update(doc);
}
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class XWikiDocument method addXObjectFromRequest.
/**
* Adds object from an new object creation form.
*
* @since 2.2.3
*/
public BaseObject addXObjectFromRequest(EntityReference classReference, String prefix, int num, XWikiContext context) throws XWikiException {
BaseObject object = newXObject(classReference, context);
BaseClass baseclass = object.getXClass(context);
String newPrefix = prefix + LOCAL_REFERENCE_SERIALIZER.serialize(resolveClassReference(classReference)) + "_" + num;
baseclass.fromMap(Util.getObject(context.getRequest(), newPrefix), object);
return object;
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class XWikiDocument method getFirstObject.
public BaseObject getFirstObject(String fieldname, XWikiContext context) {
Collection<List<BaseObject>> objectscoll = getXObjects().values();
if (objectscoll == null) {
return null;
}
for (List<BaseObject> objects : objectscoll) {
for (BaseObject obj : objects) {
if (obj != null) {
BaseClass bclass = obj.getXClass(context);
if (bclass != null) {
Set<String> set = bclass.getPropertyList();
if ((set != null) && set.contains(fieldname)) {
return obj;
}
}
Set<String> set = obj.getPropertyList();
if ((set != null) && set.contains(fieldname)) {
return obj;
}
}
}
}
return null;
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class XWikiDocument method getXClasses.
/**
* @since 2.2M1
*/
public List<BaseClass> getXClasses(XWikiContext context) {
List<BaseClass> list = new ArrayList<BaseClass>();
// getXObjects() is a TreeMap, with elements sorted by className reference
for (DocumentReference classReference : getXObjects().keySet()) {
BaseClass bclass = null;
List<BaseObject> objects = getXObjects(classReference);
for (BaseObject obj : objects) {
if (obj != null) {
bclass = obj.getXClass(context);
if (bclass != null) {
break;
}
}
}
if (bclass != null) {
list.add(bclass);
}
}
return list;
}
use of com.xpn.xwiki.objects.classes.BaseClass 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