1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.url.internal.standard; |
21 |
|
|
22 |
|
import java.util.Map; |
23 |
|
|
24 |
|
import javax.inject.Inject; |
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Singleton; |
27 |
|
|
28 |
|
import org.xwiki.component.annotation.Component; |
29 |
|
import org.xwiki.component.descriptor.ComponentInstantiationStrategy; |
30 |
|
import org.xwiki.component.descriptor.DefaultComponentDependency; |
31 |
|
import org.xwiki.component.descriptor.DefaultComponentDescriptor; |
32 |
|
import org.xwiki.component.manager.ComponentManager; |
33 |
|
import org.xwiki.component.manager.ComponentRepositoryException; |
34 |
|
import org.xwiki.component.phase.Initializable; |
35 |
|
import org.xwiki.component.phase.InitializationException; |
36 |
|
import org.xwiki.component.util.DefaultParameterizedType; |
37 |
|
import org.xwiki.model.reference.EntityReference; |
38 |
|
import org.xwiki.model.reference.EntityReferenceResolver; |
39 |
|
import org.xwiki.resource.CreateResourceTypeException; |
40 |
|
import org.xwiki.resource.ResourceReferenceResolver; |
41 |
|
import org.xwiki.resource.ResourceType; |
42 |
|
import org.xwiki.resource.entity.EntityResourceReference; |
43 |
|
import org.xwiki.resource.internal.entity.EntityResourceActionLister; |
44 |
|
import org.xwiki.url.ExtendedURL; |
45 |
|
import org.xwiki.url.internal.AbstractExtendedURLResourceTypeResolver; |
46 |
|
import org.xwiki.url.internal.standard.entity.BinEntityResourceReferenceResolver; |
47 |
|
import org.xwiki.url.internal.standard.entity.WikiEntityResourceReferenceResolver; |
48 |
|
|
49 |
|
|
50 |
|
@link@link |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@version |
55 |
|
@since |
56 |
|
|
57 |
|
@Component |
58 |
|
@Named("standard") |
59 |
|
@Singleton |
|
|
| 97.1% |
Uncovered Elements: 1 (34) |
Complexity: 5 |
Complexity Density: 0.17 |
|
60 |
|
public class StandardExtendedURLResourceTypeResolver extends AbstractExtendedURLResourceTypeResolver implements |
61 |
|
Initializable |
62 |
|
{ |
63 |
|
private static final String HINT = "standard"; |
64 |
|
|
65 |
|
@Inject |
66 |
|
private ComponentManager rootComponentManager; |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
@Inject |
72 |
|
private StandardURLConfiguration configuration; |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
74 |
33 |
@Override... |
75 |
|
public void initialize() throws InitializationException |
76 |
|
{ |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
33 |
registerEntityResourceReferenceResolver(this.configuration.getWikiPathPrefix(), |
86 |
|
WikiEntityResourceReferenceResolver.class, "path"); |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
33 |
registerEntityResourceReferenceResolver(EntityResourceReference.TYPE.getId(), |
93 |
|
BinEntityResourceReferenceResolver.class, "domain"); |
94 |
|
} |
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
35230 |
@Override... |
97 |
|
public ResourceType resolve(ExtendedURL extendedURL, Map<String, Object> parameters) |
98 |
|
throws CreateResourceTypeException |
99 |
|
{ |
100 |
35230 |
return resolve(HINT, extendedURL, parameters); |
101 |
|
} |
102 |
|
|
|
|
| 96.2% |
Uncovered Elements: 1 (26) |
Complexity: 2 |
Complexity Density: 0.08 |
|
103 |
66 |
private void registerEntityResourceReferenceResolver(String registrationHint,... |
104 |
|
Class<? extends ResourceReferenceResolver<ExtendedURL>> registrationImplementation, |
105 |
|
String wikiExtractorHint) throws InitializationException |
106 |
|
{ |
107 |
66 |
DefaultComponentDescriptor<ResourceReferenceResolver<ExtendedURL>> resolverDescriptor = |
108 |
|
new DefaultComponentDescriptor<>(); |
109 |
66 |
resolverDescriptor.setImplementation(registrationImplementation); |
110 |
66 |
resolverDescriptor.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); |
111 |
66 |
String hint = computeHint(registrationHint); |
112 |
66 |
resolverDescriptor.setRoleHint(hint); |
113 |
66 |
resolverDescriptor.setRoleType( |
114 |
|
new DefaultParameterizedType(null, ResourceReferenceResolver.class, ExtendedURL.class)); |
115 |
|
|
116 |
|
|
117 |
|
|
118 |
66 |
DefaultComponentDependency<WikiReferenceExtractor> wikiReferenceExtractorDependency = |
119 |
|
new DefaultComponentDependency<>(); |
120 |
66 |
wikiReferenceExtractorDependency.setRoleType(WikiReferenceExtractor.class); |
121 |
66 |
wikiReferenceExtractorDependency.setRoleHint(wikiExtractorHint); |
122 |
66 |
wikiReferenceExtractorDependency.setName("wikiExtractor"); |
123 |
66 |
resolverDescriptor.addComponentDependency(wikiReferenceExtractorDependency); |
124 |
|
|
125 |
66 |
DefaultComponentDependency<EntityReferenceResolver<EntityReference>> entityReferenceResolverDependency = |
126 |
|
new DefaultComponentDependency<>(); |
127 |
66 |
entityReferenceResolverDependency.setRoleType(new DefaultParameterizedType(null, EntityReferenceResolver.class, |
128 |
|
EntityReference.class)); |
129 |
66 |
entityReferenceResolverDependency.setName("defaultReferenceEntityReferenceResolver"); |
130 |
66 |
resolverDescriptor.addComponentDependency(entityReferenceResolverDependency); |
131 |
|
|
132 |
66 |
DefaultComponentDependency<StandardURLConfiguration> standardURLConfigurationDependency = |
133 |
|
new DefaultComponentDependency<>(); |
134 |
66 |
standardURLConfigurationDependency.setRoleType(StandardURLConfiguration.class); |
135 |
66 |
standardURLConfigurationDependency.setName("configuration"); |
136 |
66 |
resolverDescriptor.addComponentDependency(standardURLConfigurationDependency); |
137 |
|
|
138 |
66 |
DefaultComponentDependency<EntityResourceActionLister> entityResourceActionListerDependency = |
139 |
|
new DefaultComponentDependency<>(); |
140 |
66 |
entityResourceActionListerDependency.setRoleType(EntityResourceActionLister.class); |
141 |
66 |
entityResourceActionListerDependency.setName("entityResourceActionLister"); |
142 |
66 |
resolverDescriptor.addComponentDependency(entityResourceActionListerDependency); |
143 |
|
|
144 |
66 |
try { |
145 |
66 |
this.rootComponentManager.registerComponent(resolverDescriptor); |
146 |
|
} catch (ComponentRepositoryException e) { |
147 |
0 |
throw new InitializationException(String.format( |
148 |
|
"Failed to dynamically register Resource Reference Resolver for hint [%s]", hint), e); |
149 |
|
} |
150 |
|
} |
151 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
152 |
66 |
private String computeHint(String type)... |
153 |
|
{ |
154 |
66 |
return String.format("%s/%s", HINT, type); |
155 |
|
} |
156 |
|
} |