Search in sources :

Example 11 with DocumentDisplayerParameters

use of org.xwiki.display.internal.DocumentDisplayerParameters in project xwiki-platform by xwiki.

the class XWikiDocument method display.

/**
 * Parse, execute and render the document.
 *
 * @param targetSyntax the syntax to use to render the document
 * @param executionContextIsolated see {@link DocumentDisplayerParameters#isExecutionContextIsolated()}
 * @param transformationContextIsolated see {@link DocumentDisplayerParameters#isTransformationContextIsolated()}
 * @param transformationContextRestricted see
 *            {@link DocumentDisplayerParameters#isTransformationContextRestricted()}
 * @param translate get translated content of the document
 * @return the result of the document execution rendered in the passed syntax
 * @throws XWikiException when failing to display the document
 */
private String display(Syntax targetSyntax, boolean executionContextIsolated, boolean transformationContextIsolated, boolean transformationContextRestricted, boolean translate) throws XWikiException {
    // Note: We are currently duplicating code from getRendered signature because some calling
    // code is expecting that the rendering will happen in the calling document's context and not in this
    // document's context. For example this is true for the Admin page, see
    // https://jira.xwiki.org/browse/XWIKI-4274 for more details.
    getProgress().startStep(this, "document.progress.render", "Render document [{}] in syntax [{}]", getDocumentReference(), targetSyntax);
    try {
        getProgress().pushLevelProgress(3, getDocumentReference());
        getProgress().startStep(getDocumentReference(), "document.progress.render.translatedcontent", "Get translated content");
        XWikiContext xcontext = getXWikiContext();
        XWikiDocument tdoc = translate ? getTranslatedDocument(xcontext) : this;
        String translatedContent = tdoc.getContent();
        getProgress().startStep(getDocumentReference(), "document.progress.render.cache", "Try to get content from the cache");
        String renderedContent = getRenderingCache().getRenderedContent(tdoc.getDocumentReferenceWithLocale(), translatedContent, xcontext);
        if (renderedContent == null) {
            getProgress().startStep(getDocumentReference(), "document.progress.render.execute", "Execute content");
            // Configure display
            DocumentDisplayerParameters parameters = new DocumentDisplayerParameters();
            parameters.setExecutionContextIsolated(executionContextIsolated);
            parameters.setTransformationContextIsolated(transformationContextIsolated);
            parameters.setTransformationContextRestricted(transformationContextRestricted);
            // Render the translated content (matching the current language) using this document's syntax.
            parameters.setContentTranslated(tdoc != this);
            parameters.setTargetSyntax(targetSyntax);
            // Execute display
            XDOM contentXDOM = getDocumentDisplayer().display(this, parameters);
            // Render the result
            renderedContent = renderXDOM(contentXDOM, targetSyntax);
            getRenderingCache().setRenderedContent(getDocumentReference(), translatedContent, renderedContent, xcontext);
        }
        return renderedContent;
    } finally {
        getProgress().popLevelProgress(getDocumentReference());
        getProgress().endStep(this);
    }
}
Also used : DocumentDisplayerParameters(org.xwiki.display.internal.DocumentDisplayerParameters) XDOM(org.xwiki.rendering.block.XDOM) XWikiContext(com.xpn.xwiki.XWikiContext) ToString(org.suigeneris.jrcs.util.ToString)

Aggregations

DocumentDisplayerParameters (org.xwiki.display.internal.DocumentDisplayerParameters)11 XDOM (org.xwiki.rendering.block.XDOM)7 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)5 XWikiException (com.xpn.xwiki.XWikiException)3 HashMap (java.util.HashMap)3 DocumentDisplayer (org.xwiki.display.internal.DocumentDisplayer)3 MacroExecutionException (org.xwiki.rendering.macro.MacroExecutionException)3 XWikiContext (com.xpn.xwiki.XWikiContext)2 Test (org.junit.Test)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 Block (org.xwiki.rendering.block.Block)2 MacroBlock (org.xwiki.rendering.block.MacroBlock)2 MetaDataBlock (org.xwiki.rendering.block.MetaDataBlock)2 Syntax (org.xwiki.rendering.syntax.Syntax)2 SheetManager (org.xwiki.sheet.SheetManager)2 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 DifferentiationFailedException (org.suigeneris.jrcs.diff.DifferentiationFailedException)1 ToString (org.suigeneris.jrcs.util.ToString)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1