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";
}
Aggregations