1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.edit.internal; |
21 |
|
|
22 |
|
import java.lang.reflect.Type; |
23 |
|
|
24 |
|
import javax.inject.Inject; |
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Provider; |
27 |
|
import javax.inject.Singleton; |
28 |
|
|
29 |
|
import org.apache.commons.lang3.StringUtils; |
30 |
|
import org.xwiki.component.annotation.Component; |
31 |
|
import org.xwiki.component.manager.ComponentLookupException; |
32 |
|
import org.xwiki.component.manager.ComponentManager; |
33 |
|
import org.xwiki.component.util.DefaultParameterizedType; |
34 |
|
import org.xwiki.configuration.ConfigurationSource; |
35 |
|
import org.xwiki.edit.EditConfiguration; |
36 |
|
import org.xwiki.edit.EditorConfiguration; |
37 |
|
|
38 |
|
|
39 |
|
@link |
40 |
|
|
41 |
|
@version |
42 |
|
@since |
43 |
|
|
44 |
|
@Component |
45 |
|
@Singleton |
|
|
| 86.7% |
Uncovered Elements: 4 (30) |
Complexity: 9 |
Complexity Density: 0.5 |
|
46 |
|
public class DefaultEditConfiguration implements EditConfiguration |
47 |
|
{ |
48 |
|
@Inject |
49 |
|
@Named("context") |
50 |
|
private Provider<ComponentManager> componentManagerProvider; |
51 |
|
|
52 |
|
@Inject |
53 |
|
@Named("editorBindings/all") |
54 |
|
private ConfigurationSource allEditorBindingsSource; |
55 |
|
|
56 |
|
@Inject |
57 |
|
@Named("xwikiproperties") |
58 |
|
private ConfigurationSource xwikiPropertiesSource; |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
60 |
92 |
@Override... |
61 |
|
public String getDefaultEditor(Type dataType) |
62 |
|
{ |
63 |
92 |
return getDefaultEditor(dataType, null); |
64 |
|
} |
65 |
|
|
|
|
| 86.7% |
Uncovered Elements: 2 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
66 |
429 |
@Override... |
67 |
|
public String getDefaultEditor(Type dataType, String category) |
68 |
|
{ |
69 |
429 |
String dataTypeName = dataType.getTypeName(); |
70 |
429 |
if (!StringUtils.isEmpty(category)) { |
71 |
337 |
dataTypeName += "#" + category; |
72 |
|
} |
73 |
|
|
74 |
429 |
String defaultEditor = getDefaultEditor(dataTypeName); |
75 |
429 |
if (StringUtils.isEmpty(defaultEditor)) { |
76 |
|
|
77 |
|
|
78 |
429 |
EditorConfiguration<?> customConfig = getCustomConfiguration(dataType); |
79 |
429 |
if (customConfig != null) { |
80 |
429 |
defaultEditor = customConfig.getDefaultEditor(category); |
81 |
|
} |
82 |
|
} |
83 |
429 |
return defaultEditor; |
84 |
|
} |
85 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
86 |
429 |
private <D extends Type> EditorConfiguration<D> getCustomConfiguration(D dataType)... |
87 |
|
{ |
88 |
429 |
DefaultParameterizedType customConfigType = |
89 |
|
new DefaultParameterizedType(null, EditorConfiguration.class, dataType); |
90 |
429 |
try { |
91 |
429 |
return this.componentManagerProvider.get().getInstance(customConfigType); |
92 |
|
} catch (ComponentLookupException e) { |
93 |
0 |
return null; |
94 |
|
} |
95 |
|
} |
96 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
97 |
429 |
private String getDefaultEditor(String dataType)... |
98 |
|
{ |
99 |
429 |
String defaultEditor = this.allEditorBindingsSource.getProperty(dataType, String.class); |
100 |
429 |
if (StringUtils.isEmpty(defaultEditor)) { |
101 |
429 |
defaultEditor = this.xwikiPropertiesSource.getProperty("edit.defaultEditor." + dataType, String.class); |
102 |
|
} |
103 |
429 |
return defaultEditor; |
104 |
|
} |
105 |
|
} |