1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.internal.model.reference

File CurrentEntityReferenceValueProvider.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

18
22
2
1
112
61
12
0.55
11
2
6

Classes

Class Line # Actions
CurrentEntityReferenceValueProvider 57 22 0% 12 42
0.00%
 

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.model.reference;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Singleton;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.context.Execution;
28    import org.xwiki.model.EntityType;
29    import org.xwiki.model.ModelContext;
30    import org.xwiki.model.internal.reference.DefaultEntityReferenceValueProvider;
31    import org.xwiki.model.reference.EntityReference;
32   
33    import com.xpn.xwiki.XWikiContext;
34    import com.xpn.xwiki.doc.XWikiDocument;
35   
36    /**
37    * The behavior is the following:
38    * <ul>
39    * <li>The wiki value used is the current wiki if no wiki was specified in the passed reference (or if it was empty).
40    * Note that this is different from using the current document's wiki value.</li>
41    * <li>The space value used is the space from the current document reference if no space was specified in the passed
42    * reference (or if it was empty). If the current document reference is not defined then the default space value is used
43    * instead.</li>
44    * <li>The page value used is the page from the current document reference if no page was specified in the passed
45    * reference (or if it was empty). If the current document reference is not defined then the default page value is used
46    * instead.</li>
47    * </ul>
48    *
49    * @version $Id: 18f32504b83e9f67549b37dbdde5ec3f5c6f9867 $
50    * @since 2.3M1
51    * @deprecated since 7.2M1, use {@link CurrentEntityReferenceProvider} instead
52    */
53    @Component
54    @Named("current")
55    @Singleton
56    @Deprecated
 
57    public class CurrentEntityReferenceValueProvider extends DefaultEntityReferenceValueProvider
58    {
59    @Inject
60    private ModelContext modelContext;
61   
62    @Inject
63    private Execution execution;
64   
 
65  0 toggle @Override
66    public String getDefaultValue(EntityType type)
67    {
68  0 String result = null;
69   
70  0 if (type == EntityType.WIKI) {
71  0 EntityReference wikiReference = this.modelContext.getCurrentEntityReference();
72  0 if (wikiReference != null) {
73  0 wikiReference = wikiReference.extractReference(EntityType.WIKI);
74    }
75  0 if (wikiReference != null) {
76  0 result = wikiReference.getName();
77    }
78  0 } else if (type == EntityType.SPACE || type == EntityType.DOCUMENT) {
79  0 XWikiContext xcontext = getContext();
80  0 if (xcontext != null) {
81  0 XWikiDocument currentDoc = xcontext.getDoc();
82  0 if (currentDoc != null) {
83  0 if (type == EntityType.SPACE) {
84  0 result = currentDoc.getDocumentReference().getLastSpaceReference().getName();
85    } else {
86  0 result = currentDoc.getDocumentReference().getName();
87    }
88    }
89    }
90    }
91   
92  0 if (result == null) {
93  0 result = super.getDefaultValue(type);
94    }
95   
96  0 return result;
97    }
98   
99    /**
100    * @return the XWiki Context used to bridge with the old API
101    */
 
102  0 toggle private XWikiContext getContext()
103    {
104  0 XWikiContext xcontext = null;
105   
106  0 if (this.execution.getContext() != null) {
107  0 xcontext = (XWikiContext) this.execution.getContext().getProperty("xwikicontext");
108    }
109   
110  0 return xcontext;
111    }
112    }