Search in sources :

Example 11 with XWikiContext

use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.

the class EditorWikiComponent method render.

@Override
protected String render() throws EditException {
    try {
        XWikiContext xcontext = this.xcontextProvider.get();
        XWikiDocument editorDocument = xcontext.getWiki().getDocument(this.getDocumentReference(), xcontext);
        BaseObject editorObject = editorDocument.getXObject(EDITOR_CLASS_REFERENCE);
        String editorCode = editorObject.getStringValue("code");
        // Make sure the editor code is executed with the rights of the editor document author.
        XWikiDocument sdoc = editorDocument;
        // the data that has been put on the script context).
        return xcontext.getDoc().getRenderedContent(editorCode, editorDocument.getSyntax().toIdString(), false, sdoc, xcontext);
    } catch (Exception e) {
        throw new EditException("Failed to render the editor code.", e);
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException) EditException(org.xwiki.edit.EditException) WikiComponentException(org.xwiki.component.wiki.WikiComponentException) EditException(org.xwiki.edit.EditException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 12 with XWikiContext

use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.

the class EditorWikiComponent method initialize.

/**
 * Initializes the editor component based on the definition provided by the specified document.
 *
 * @param editorReference the reference to the wiki page that defines the editor (i.e. that has a
 *            {@code XWiki.EditorClass} object)
 * @throws WikiComponentException if the editor component fails to be initialized
 */
public void initialize(DocumentReference editorReference) throws WikiComponentException {
    if (this.editorReference != null) {
        throw new WikiComponentException("This editor component is already initialized.");
    }
    this.editorReference = editorReference;
    try {
        XWikiContext xcontext = this.xcontextProvider.get();
        initialize(xcontext.getWiki().getDocument(editorReference, xcontext));
    } catch (XWikiException e) {
        throw new WikiComponentException("Failed to load the editor document.", e);
    }
}
Also used : WikiComponentException(org.xwiki.component.wiki.WikiComponentException) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException)

Example 13 with XWikiContext

use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.

the class DocumentTreeNode method getParent.

@Override
protected EntityReference getParent(DocumentReference documentReference) throws Exception {
    XWikiContext xcontext = this.xcontextProvider.get();
    XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext);
    DocumentReference parentReference = document.getParentReference();
    // The parent document must be on the same space.
    if (parentReference != null && parentReference.getParent().equals(documentReference.getParent())) {
        return parentReference;
    }
    return documentReference.getParent();
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 14 with XWikiContext

use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.

the class ObjectTreeNode method getChildCount.

private int getChildCount(ObjectReference objectReference) throws Exception {
    XWikiContext xcontext = this.xcontextProvider.get();
    XWikiDocument document = xcontext.getWiki().getDocument(objectReference.getParent(), xcontext);
    BaseObject object = document.getXObject(objectReference);
    return object == null ? 0 : object.getPropertyList().size();
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 15 with XWikiContext

use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.

the class ObjectsOfTypeTreeNode method getXObjectReferences.

private List<ObjectReference> getXObjectReferences(DocumentReference documentReference, DocumentReference classReference) throws Exception {
    XWikiContext xcontext = this.xcontextProvider.get();
    XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext);
    List<ObjectReference> objectReferences = new ArrayList<ObjectReference>();
    List<BaseObject> objects = document.getXObjects(classReference);
    if (objects != null) {
        for (BaseObject object : objects) {
            // Yes, the list of objects can contain null values..
            if (object != null) {
                objectReferences.add(object.getReference());
            }
        }
    }
    return objectReferences;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ObjectReference(org.xwiki.model.reference.ObjectReference) ArrayList(java.util.ArrayList) XWikiContext(com.xpn.xwiki.XWikiContext) BaseObject(com.xpn.xwiki.objects.BaseObject)

Aggregations

XWikiContext (com.xpn.xwiki.XWikiContext)564 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)203 XWikiException (com.xpn.xwiki.XWikiException)195 DocumentReference (org.xwiki.model.reference.DocumentReference)150 XWiki (com.xpn.xwiki.XWiki)106 BaseObject (com.xpn.xwiki.objects.BaseObject)104 Test (org.junit.Test)64 ArrayList (java.util.ArrayList)55 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)43 ExecutionContext (org.xwiki.context.ExecutionContext)43 Session (org.hibernate.Session)37 InitializationException (org.xwiki.component.phase.InitializationException)36 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)34 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)33 WikiReference (org.xwiki.model.reference.WikiReference)31 Before (org.junit.Before)29 EntityReference (org.xwiki.model.reference.EntityReference)28 QueryException (org.xwiki.query.QueryException)28 Execution (org.xwiki.context.Execution)27 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)24