Search in sources :

Example 1 with DocumentRevisionProvider

use of com.xpn.xwiki.doc.DocumentRevisionProvider in project xwiki-platform by xwiki.

the class DefaultDocumentRevisionProvider method getRevision.

@Override
public XWikiDocument getRevision(DocumentReference reference, String revision) throws XWikiException {
    // Parse the version
    String revisionPrefix = null;
    if (revision != null) {
        int revisionPrefixIndex = revision.indexOf(':');
        if (revisionPrefixIndex > 0) {
            revisionPrefix = revision.substring(0, revisionPrefixIndex);
        }
    }
    String shortRevision;
    if (revisionPrefix != null) {
        shortRevision = revision.substring(revisionPrefix.length() + 1);
    } else {
        shortRevision = revision;
    }
    // Find the provider
    DocumentRevisionProvider provider = this.databaseDocumentRevisionProvider;
    if (revisionPrefix != null) {
        ComponentManager componentManager = this.componentManagerProvider.get();
        if (componentManager.hasComponent(DocumentRevisionProvider.class, revisionPrefix)) {
            try {
                provider = componentManager.getInstance(DocumentRevisionProvider.class, revisionPrefix);
            } catch (ComponentLookupException e) {
                throw new XWikiException("Failed to get revision provider for revision [" + revision + "]", e);
            }
        }
    }
    // Load the document revision
    return provider.getRevision(reference, shortRevision);
}
Also used : ComponentManager(org.xwiki.component.manager.ComponentManager) DocumentRevisionProvider(com.xpn.xwiki.doc.DocumentRevisionProvider) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

XWikiException (com.xpn.xwiki.XWikiException)1 DocumentRevisionProvider (com.xpn.xwiki.doc.DocumentRevisionProvider)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 ComponentManager (org.xwiki.component.manager.ComponentManager)1