Search in sources :

Example 86 with BaseClass

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);
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) XWikiContext(com.xpn.xwiki.XWikiContext)

Example 87 with BaseClass

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;
}
Also used : BaseClass(com.xpn.xwiki.objects.classes.BaseClass) ToString(org.suigeneris.jrcs.util.ToString) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 88 with BaseClass

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;
}
Also used : BaseClass(com.xpn.xwiki.objects.classes.BaseClass) XWikiAttachmentList(com.xpn.xwiki.internal.doc.XWikiAttachmentList) ArrayList(java.util.ArrayList) List(java.util.List) ToString(org.suigeneris.jrcs.util.ToString) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 89 with BaseClass

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;
}
Also used : BaseClass(com.xpn.xwiki.objects.classes.BaseClass) ArrayList(java.util.ArrayList) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 90 with BaseClass

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

BaseClass (com.xpn.xwiki.objects.classes.BaseClass)100 DocumentReference (org.xwiki.model.reference.DocumentReference)42 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)41 BaseObject (com.xpn.xwiki.objects.BaseObject)40 XWikiException (com.xpn.xwiki.XWikiException)26 XWikiContext (com.xpn.xwiki.XWikiContext)24 ArrayList (java.util.ArrayList)18 PropertyClass (com.xpn.xwiki.objects.classes.PropertyClass)16 XWiki (com.xpn.xwiki.XWiki)15 Test (org.junit.Test)15 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)15 EntityReference (org.xwiki.model.reference.EntityReference)10 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)9 BaseProperty (com.xpn.xwiki.objects.BaseProperty)9 List (java.util.List)9 ToString (org.suigeneris.jrcs.util.ToString)9 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)7 Before (org.junit.Before)6 TextAreaClass (com.xpn.xwiki.objects.classes.TextAreaClass)5 MigrationRequiredException (com.xpn.xwiki.store.migration.MigrationRequiredException)5