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

File CurrentEntityReferenceProvider.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

18
23
1
1
102
56
10
0.43
23
1
10

Classes

Class Line # Actions
CurrentEntityReferenceProvider 57 23 0% 10 1
0.9761904597.6%
 

Contributing tests

This file is covered by 270 tests. .

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.model.reference;
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.model.EntityType;
29    import org.xwiki.model.internal.reference.DefaultEntityReferenceProvider;
30    import org.xwiki.model.reference.DocumentReference;
31    import org.xwiki.model.reference.EntityReference;
32    import org.xwiki.model.reference.PageReference;
33    import org.xwiki.model.reference.SpaceReference;
34   
35    import com.xpn.xwiki.XWikiContext;
36    import com.xpn.xwiki.doc.XWikiDocument;
37   
38    /**
39    * The behavior is the following:
40    * <ul>
41    * <li>The wiki value used is the current wiki if no wiki was specified in the passed reference (or if it was empty).
42    * Note that this is different from using the current document's wiki value.</li>
43    * <li>The space value used is the space from the current document reference if no space was specified in the passed
44    * reference (or if it was empty). If the current document reference is not defined then the default space value is used
45    * instead.</li>
46    * <li>The page value used is the page from the current document reference if no page was specified in the passed
47    * reference (or if it was empty). If the current document reference is not defined then the default page value is used
48    * instead.</li>
49    * </ul>
50    *
51    * @version $Id: 5ec064b2c354a29ab343735978fdcad843e1098f $
52    * @since 7.2M1
53    */
54    @Component
55    @Named("current")
56    @Singleton
 
57    public class CurrentEntityReferenceProvider extends DefaultEntityReferenceProvider
58    {
59    @Inject
60    @Named("readonly")
61    private Provider<XWikiContext> xcontextProvider;
62   
 
63  208778909 toggle @Override
64    public EntityReference getDefaultReference(EntityType type)
65    {
66  208786436 EntityReference result = null;
67   
68  208792336 XWikiContext xcontext = this.xcontextProvider.get();
69  208808777 if (xcontext != null) {
70  208819783 if (type == EntityType.WIKI) {
71  88703605 result = xcontext.getWikiReference();
72  120123393 } else if (type == EntityType.SPACE) {
73  80804551 XWikiDocument currentDoc = xcontext.getDoc();
74  80800051 if (currentDoc != null) {
75  78068509 SpaceReference spaceReference = currentDoc.getDocumentReference().getLastSpaceReference();
76    // Keep only the spaces part
77  78056051 result = spaceReference.removeParent(spaceReference.getWikiReference());
78    }
79  39318896 } else if (type == EntityType.DOCUMENT) {
80  39320006 XWikiDocument currentDoc = xcontext.getDoc();
81  39320693 if (currentDoc != null) {
82  37965460 DocumentReference documentReference = currentDoc.getDocumentReference();
83    // Keep only the document part
84  37962363 result = documentReference.removeParent(documentReference.getLastSpaceReference());
85    }
86  21 } else if (type == EntityType.PAGE) {
87  4 XWikiDocument currentDoc = xcontext.getDoc();
88  4 if (currentDoc != null) {
89  3 PageReference pageReference = currentDoc.getPageReference();
90    // Keep only the page part
91  3 result = pageReference.removeParent(pageReference.getWikiReference());
92    }
93    }
94    }
95   
96  208768184 if (result == null) {
97  4087512 result = super.getDefaultReference(type);
98    }
99   
100  208783822 return result;
101    }
102    }