Search in sources :

Example 1 with MacroBlockMatcher

use of org.xwiki.rendering.block.match.MacroBlockMatcher in project xwiki-platform by xwiki.

the class XWikiDocument method getDefaultEditModeInternal.

private String getDefaultEditModeInternal(XWikiContext context) throws XWikiException {
    String editModeProperty = "defaultEditMode";
    DocumentReference editModeClass = getCurrentReferenceDocumentReferenceResolver().resolve(XWikiConstant.EDIT_MODE_CLASS);
    // check if the current document has any edit mode class object attached to it, and read the edit mode from it
    BaseObject editModeObject = this.getXObject(editModeClass);
    if (editModeObject != null) {
        String defaultEditMode = editModeObject.getStringValue(editModeProperty);
        if (StringUtils.isEmpty(defaultEditMode)) {
            return "edit";
        } else {
            return defaultEditMode;
        }
    }
    // otherwise look for included documents
    com.xpn.xwiki.XWiki xwiki = context.getWiki();
    if (is10Syntax()) {
        if (getContent().indexOf("includeForm(") != -1) {
            return "inline";
        }
    } else {
        // its own name since it's a deployment time concern.
        for (Block macroBlock : getXDOM().getBlocks(new MacroBlockMatcher("include"), Axes.CHILD)) {
            // Find the document reference to include by checking the macro's "reference" parameter.
            // For backward-compatibility we also check for a "document" parameter since this is the parameter name
            // that was used prior to XWiki 3.4M1 when the "reference" one was introduced and thus when the
            // "document" one was deprecated.
            String includedDocumentReference = macroBlock.getParameter("reference");
            if (includedDocumentReference == null) {
                includedDocumentReference = macroBlock.getParameter("document");
            }
            if (includedDocumentReference != null) {
                // Resolve the document name into a valid Reference
                DocumentReference documentReference = getCurrentMixedDocumentReferenceResolver().resolve(includedDocumentReference);
                XWikiDocument includedDocument = xwiki.getDocument(documentReference, context);
                if (!includedDocument.isNew()) {
                    // get the edit mode object, first the new class and then the deprecated class if new class
                    // is not found
                    editModeObject = includedDocument.getXObject(editModeClass);
                    if (editModeObject == null) {
                        editModeObject = includedDocument.getXObject(SHEETCLASS_REFERENCE);
                    }
                    if (editModeObject != null) {
                        // Use the user-defined default edit mode if set.
                        String defaultEditMode = editModeObject.getStringValue(editModeProperty);
                        if (StringUtils.isBlank(defaultEditMode)) {
                            // and inline only if the object is sheetclass
                            return "inline";
                        } else {
                            return defaultEditMode;
                        }
                    }
                }
            }
        }
    }
    return "edit";
}
Also used : XWiki(com.xpn.xwiki.XWiki) MacroBlockMatcher(org.xwiki.rendering.block.match.MacroBlockMatcher) LinkBlock(org.xwiki.rendering.block.LinkBlock) Block(org.xwiki.rendering.block.Block) MacroBlock(org.xwiki.rendering.block.MacroBlock) HeaderBlock(org.xwiki.rendering.block.HeaderBlock) SectionBlock(org.xwiki.rendering.block.SectionBlock) ToString(org.suigeneris.jrcs.util.ToString) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject)

Aggregations

XWiki (com.xpn.xwiki.XWiki)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 ToString (org.suigeneris.jrcs.util.ToString)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)1 Block (org.xwiki.rendering.block.Block)1 HeaderBlock (org.xwiki.rendering.block.HeaderBlock)1 LinkBlock (org.xwiki.rendering.block.LinkBlock)1 MacroBlock (org.xwiki.rendering.block.MacroBlock)1 SectionBlock (org.xwiki.rendering.block.SectionBlock)1 MacroBlockMatcher (org.xwiki.rendering.block.match.MacroBlockMatcher)1