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.sheet; |
21 |
|
|
22 |
|
import java.util.HashMap; |
23 |
|
import java.util.Map; |
24 |
|
import java.util.Set; |
25 |
|
|
26 |
|
import javax.inject.Inject; |
27 |
|
import javax.inject.Provider; |
28 |
|
import javax.inject.Singleton; |
29 |
|
|
30 |
|
import org.slf4j.Logger; |
31 |
|
import org.xwiki.bridge.DocumentModelBridge; |
32 |
|
import org.xwiki.component.annotation.Component; |
33 |
|
import org.xwiki.model.reference.DocumentReference; |
34 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
35 |
|
import org.xwiki.sheet.internal.ModelBridge; |
36 |
|
|
37 |
|
import com.xpn.xwiki.XWikiContext; |
38 |
|
import com.xpn.xwiki.XWikiException; |
39 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
@version |
45 |
|
@since |
46 |
|
|
47 |
|
@Component |
48 |
|
@Singleton |
|
|
| 87.5% |
Uncovered Elements: 4 (32) |
Complexity: 11 |
Complexity Density: 0.52 |
|
49 |
|
public class DefaultModelBridge implements ModelBridge |
50 |
|
{ |
51 |
|
|
52 |
|
@Inject |
53 |
|
private Logger logger; |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
@Inject |
59 |
|
private EntityReferenceSerializer<String> defaultEntityReferenceSerializer; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
@Inject |
65 |
|
private Provider<XWikiContext> xcontextProvider; |
66 |
|
|
|
|
| 50% |
Uncovered Elements: 2 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
67 |
25935 |
@Override... |
68 |
|
public String getDefaultEditMode(DocumentModelBridge document) |
69 |
|
{ |
70 |
25935 |
try { |
71 |
25933 |
return ((XWikiDocument) document).getDefaultEditMode(this.xcontextProvider.get()); |
72 |
|
} catch (XWikiException e) { |
73 |
0 |
this.logger.warn("Failed to get the default edit mode for [{}].", |
74 |
|
this.defaultEntityReferenceSerializer.serialize(document.getDocumentReference())); |
75 |
0 |
return null; |
76 |
|
} |
77 |
|
} |
78 |
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
79 |
25926 |
@Override... |
80 |
|
public DocumentModelBridge getDefaultTranslation(DocumentModelBridge document) |
81 |
|
{ |
82 |
|
|
83 |
25927 |
if (((XWikiDocument) document).getTranslation() != 0) { |
84 |
124 |
try { |
85 |
|
|
86 |
124 |
XWikiContext xcontext = this.xcontextProvider.get(); |
87 |
124 |
return xcontext.getWiki().getDocument(document.getDocumentReference(), xcontext); |
88 |
|
} catch (XWikiException e) { |
89 |
0 |
String stringReference = |
90 |
|
this.defaultEntityReferenceSerializer.serialize(document.getDocumentReference()); |
91 |
0 |
this.logger.warn("Failed to load the default translation of [{}].", stringReference, e); |
92 |
|
} |
93 |
|
} |
94 |
25803 |
return document; |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
97 |
25922 |
@Override... |
98 |
|
public String getCurrentAction() |
99 |
|
{ |
100 |
25923 |
return this.xcontextProvider.get().getAction(); |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
103 |
25930 |
@Override... |
104 |
|
public boolean isCurrentDocument(DocumentModelBridge document) |
105 |
|
{ |
106 |
25926 |
if (((XWikiDocument) document).getTranslation() == 0) { |
107 |
25804 |
return document == this.xcontextProvider.get().getDoc(); |
108 |
|
} else { |
109 |
124 |
return document == this.xcontextProvider.get().get("tdoc"); |
110 |
|
} |
111 |
|
} |
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
113 |
10871 |
@Override... |
114 |
|
public Map<String, Object> pushDocumentInContext(DocumentModelBridge document) |
115 |
|
{ |
116 |
10872 |
Map<String, Object> backupObjects = new HashMap<String, Object>(); |
117 |
|
|
118 |
|
|
119 |
10874 |
XWikiDocument.backupContext(backupObjects, this.xcontextProvider.get()); |
120 |
|
|
121 |
|
|
122 |
10875 |
((XWikiDocument) document).setAsContextDoc(this.xcontextProvider.get()); |
123 |
|
|
124 |
10874 |
return backupObjects; |
125 |
|
} |
126 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
127 |
25611 |
@Override... |
128 |
|
public Set<DocumentReference> getXObjectClassReferences(DocumentModelBridge document) |
129 |
|
{ |
130 |
25612 |
return ((XWikiDocument) document).getXObjects().keySet(); |
131 |
|
} |
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
133 |
2446 |
@Override... |
134 |
|
public DocumentModelBridge setSecurityDocument(DocumentModelBridge document) |
135 |
|
{ |
136 |
2446 |
return (DocumentModelBridge) this.xcontextProvider.get().put(XWikiDocument.CKEY_SDOC, document); |
137 |
|
} |
138 |
|
} |