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