Search in sources :

Example 1 with EditException

use of org.xwiki.edit.EditException 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 2 with EditException

use of org.xwiki.edit.EditException in project xwiki-platform by xwiki.

the class TextAreaClass method displayEdit.

@Override
public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    String editorType = getEditorType(context);
    EditorManager editorManager = Utils.getComponent(EditorManager.class);
    Editor<SyntaxContent> editor = editorManager.getDefaultEditor(SyntaxContent.class, editorType);
    Map<String, Object> parameters = new HashMap<>();
    String fieldName = prefix + name;
    parameters.put("id", fieldName);
    parameters.put("name", fieldName);
    parameters.put("cols", getSize());
    parameters.put("rows", getRows());
    parameters.put("disabled", isDisabled());
    parameters.put("sourceDocumentReference", object.getDocumentReference());
    Syntax syntax = "puretext".equals(editorType) ? Syntax.PLAIN_1_0 : getObjectDocumentSyntax(object, context);
    SyntaxContent syntaxContent = new SyntaxContent(object.getStringValue(name), syntax);
    try {
        buffer.append(editor.render(syntaxContent, parameters));
    } catch (EditException e) {
        LOGGER.error("Failed to display the text area property.", e);
    }
}
Also used : HashMap(java.util.HashMap) Syntax(org.xwiki.rendering.syntax.Syntax) EditorManager(org.xwiki.edit.EditorManager) EditException(org.xwiki.edit.EditException) SyntaxContent(org.xwiki.rendering.syntax.SyntaxContent)

Aggregations

EditException (org.xwiki.edit.EditException)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 HashMap (java.util.HashMap)1 WikiComponentException (org.xwiki.component.wiki.WikiComponentException)1 EditorManager (org.xwiki.edit.EditorManager)1 Syntax (org.xwiki.rendering.syntax.Syntax)1 SyntaxContent (org.xwiki.rendering.syntax.SyntaxContent)1