use of org.xwiki.rendering.macro.wikibridge.WikiMacroDescriptor in project xwiki-platform by xwiki.
the class DefaultWikiMacroManager method unregisterWikiMacro.
@Override
public void unregisterWikiMacro(DocumentReference documentReference) throws WikiMacroException {
WikiMacroData macroData = this.wikiMacroMap.get(documentReference);
if (macroData != null) {
WikiMacroDescriptor macroDescriptor = (WikiMacroDescriptor) macroData.getWikiMacro().getDescriptor();
// Verify that the user has the right to unregister this wiki macro for the chosen visibility
if (this.wikiMacroFactory.isAllowed(documentReference, macroDescriptor.getVisibility())) {
String currentUser = this.bridge.getCurrentUser();
EntityReference currentEntityReference = this.modelContext.getCurrentEntityReference();
try {
// Put the proper context information to let components manager use the proper keys to find
// components to unregister
this.bridge.setCurrentUser(this.serializer.serialize(macroData.getWikiMacro().getAuthorReference()));
this.modelContext.setCurrentEntityReference(documentReference);
findComponentManager(macroDescriptor.getVisibility()).unregisterComponent(Macro.class, macroData.getHint());
this.wikiMacroMap.remove(documentReference);
} catch (Exception e) {
throw new WikiMacroException(String.format("Failed to unregister macro [%s] in [%s] for " + "visibility [%s]", macroData.getHint(), documentReference, macroDescriptor.getVisibility()), e);
} finally {
this.bridge.setCurrentUser(currentUser);
this.modelContext.setCurrentEntityReference(currentEntityReference);
}
} else {
throw new WikiMacroException(String.format("Unable to unregister macro [%s] in [%s] for visibility " + "[%s] due to insufficient privileges", macroData.getWikiMacro().getDescriptor().getId().getId(), documentReference, macroDescriptor.getVisibility()));
}
} else {
throw new WikiMacroException(String.format("Macro in [%s] isn't registered", documentReference));
}
}
Aggregations