1. Project Clover database Tue Dec 20 2016 21:24:09 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

14
18
1
1
94
49
8
0.44
18
1
8

Classes

Class Line # Actions
CurrentEntityReferenceProvider 56 18 0% 8 1
0.96969797%
 

Contributing tests

This file is covered by 274 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.SpaceReference;
33   
34    import com.xpn.xwiki.XWikiContext;
35    import com.xpn.xwiki.doc.XWikiDocument;
36   
37    /**
38    * The behavior is the following:
39    * <ul>
40    * <li>The wiki value used is the current wiki if no wiki was specified in the passed reference (or if it was empty).
41    * Note that this is different from using the current document's wiki value.</li>
42    * <li>The space value used is the space from the current document reference if no space was specified in the passed
43    * reference (or if it was empty). If the current document reference is not defined then the default space value is used
44    * instead.</li>
45    * <li>The page value used is the page from the current document reference if no page was specified in the passed
46    * reference (or if it was empty). If the current document reference is not defined then the default page value is used
47    * instead.</li>
48    * </ul>
49    *
50    * @version $Id: 012b544283f6823dd739ad09fcc2a29a2da3050e $
51    * @since 7.2M1
52    */
53    @Component
54    @Named("current")
55    @Singleton
 
56    public class CurrentEntityReferenceProvider extends DefaultEntityReferenceProvider
57    {
58    @Inject
59    @Named("readonly")
60    private Provider<XWikiContext> xcontextProvider;
61   
 
62  15256552 toggle @Override
63    public EntityReference getDefaultReference(EntityType type)
64    {
65  15256594 EntityReference result = null;
66   
67  15256612 XWikiContext xcontext = this.xcontextProvider.get();
68  15258180 if (xcontext != null) {
69  15258410 if (type == EntityType.WIKI) {
70  6277305 result = xcontext.getWikiReference();
71  8981138 } else if (type == EntityType.SPACE) {
72  6095048 XWikiDocument currentDoc = xcontext.getDoc();
73  6095045 if (currentDoc != null) {
74  5207753 SpaceReference spaceReference = currentDoc.getDocumentReference().getLastSpaceReference();
75    // Keep only the spaces part
76  5207699 result = spaceReference.removeParent(spaceReference.getWikiReference());
77    }
78  2886090 } else if (type == EntityType.DOCUMENT) {
79  2886091 XWikiDocument currentDoc = xcontext.getDoc();
80  2886083 if (currentDoc != null) {
81  2443154 DocumentReference documentReference = currentDoc.getDocumentReference();
82    // Keep only the document part
83  2443141 result = documentReference.removeParent(documentReference.getLastSpaceReference());
84    }
85    }
86    }
87   
88  15256856 if (result == null) {
89  1359132 result = super.getDefaultReference(type);
90    }
91   
92  15256609 return result;
93    }
94    }