1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
@version |
50 |
|
@since |
51 |
|
@deprecated@link |
52 |
|
|
53 |
|
@Component |
54 |
|
@Named("current") |
55 |
|
@Singleton |
56 |
|
@Deprecated |
|
|
| 0% |
Uncovered Elements: 42 (42) |
Complexity: 12 |
Complexity Density: 0.55 |
|
57 |
|
public class CurrentEntityReferenceValueProvider extends DefaultEntityReferenceValueProvider |
58 |
|
{ |
59 |
|
@Inject |
60 |
|
private ModelContext modelContext; |
61 |
|
|
62 |
|
@Inject |
63 |
|
private Execution execution; |
64 |
|
|
|
|
| 0% |
Uncovered Elements: 34 (34) |
Complexity: 10 |
Complexity Density: 0.56 |
|
65 |
0 |
@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 |
101 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
102 |
0 |
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 |
|
} |