1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.internal.doc

File DefaultDocumentRevisionProvider.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart6.png
72% of files have more coverage

Code metrics

10
17
1
1
91
52
7
0.41
17
1
7

Classes

Class Line # Actions
DefaultDocumentRevisionProvider 47 17 0% 7 13
0.5357142753.6%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.internal.doc;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Provider;
25    import javax.inject.Singleton;
26   
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.component.manager.ComponentLookupException;
29    import org.xwiki.component.manager.ComponentManager;
30    import org.xwiki.model.reference.DocumentReference;
31   
32    import com.xpn.xwiki.XWikiException;
33    import com.xpn.xwiki.doc.DocumentRevisionProvider;
34    import com.xpn.xwiki.doc.XWikiDocument;
35   
36    /**
37    * The default implementation of {@link DocumentRevisionProvider}.
38    * <p>
39    * The main job of {@link DefaultDocumentRevisionProvider} is to call the right {@link DocumentRevisionProvider}
40    * depending on the revision prefix.
41    *
42    * @version $Id: 484c28047c19ed282ec40d9a0c2ff6b2739064b6 $
43    * @since 9.3rc1
44    */
45    @Component
46    @Singleton
 
47    public class DefaultDocumentRevisionProvider extends AbstractDocumentRevisionProvider
48    {
49    @Inject
50    @Named("context")
51    private Provider<ComponentManager> componentManagerProvider;
52   
53    @Inject
54    @Named("database")
55    private DocumentRevisionProvider databaseDocumentRevisionProvider;
56   
 
57  60 toggle @Override
58    public XWikiDocument getRevision(DocumentReference reference, String revision) throws XWikiException
59    {
60    // Parse the version
61  60 String revisionPrefix = null;
62  60 if (revision != null) {
63  60 int revisionPrefixIndex = revision.indexOf(':');
64  60 if (revisionPrefixIndex > 0) {
65  0 revisionPrefix = revision.substring(0, revisionPrefixIndex);
66    }
67    }
68  60 String shortRevision;
69  60 if (revisionPrefix != null) {
70  0 shortRevision = revision.substring(revisionPrefix.length() + 1);
71    } else {
72  60 shortRevision = revision;
73    }
74   
75    // Find the provider
76  60 DocumentRevisionProvider provider = this.databaseDocumentRevisionProvider;
77  60 if (revisionPrefix != null) {
78  0 ComponentManager componentManager = this.componentManagerProvider.get();
79  0 if (componentManager.hasComponent(DocumentRevisionProvider.class, revisionPrefix)) {
80  0 try {
81  0 provider = componentManager.getInstance(DocumentRevisionProvider.class, revisionPrefix);
82    } catch (ComponentLookupException e) {
83  0 throw new XWikiException("Failed to get revision provider for revision [" + revision + "]", e);
84    }
85    }
86    }
87   
88    // Load the document revision
89  60 return provider.getRevision(reference, shortRevision);
90    }
91    }