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; |
21 |
|
|
22 |
|
import java.lang.reflect.ParameterizedType; |
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.manager.ComponentLookupException; |
30 |
|
import org.xwiki.component.manager.ComponentManager; |
31 |
|
import org.xwiki.component.util.DefaultParameterizedType; |
32 |
|
import org.xwiki.resource.ResourceReference; |
33 |
|
import org.xwiki.resource.ResourceReferenceSerializer; |
34 |
|
import org.xwiki.resource.SerializeResourceReferenceException; |
35 |
|
import org.xwiki.resource.UnsupportedResourceReferenceException; |
36 |
|
import org.xwiki.url.ExtendedURL; |
37 |
|
import org.xwiki.url.URLContextManager; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
@link |
42 |
|
|
43 |
|
@version |
44 |
|
@since |
45 |
|
|
46 |
|
@Component |
47 |
|
@Singleton |
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.33 |
|
48 |
|
public class DefaultResourceReferenceSerializer implements ResourceReferenceSerializer<ResourceReference, ExtendedURL> |
49 |
|
{ |
50 |
|
@Inject |
51 |
|
private URLContextManager urlContextManager; |
52 |
|
|
53 |
|
|
54 |
|
@link |
55 |
|
|
56 |
|
@Inject |
57 |
|
@Named("context") |
58 |
|
private ComponentManager componentManager; |
59 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
60 |
25715 |
@Override... |
61 |
|
public ExtendedURL serialize(ResourceReference resource) |
62 |
|
throws SerializeResourceReferenceException, UnsupportedResourceReferenceException |
63 |
|
{ |
64 |
25715 |
ResourceReferenceSerializer<ResourceReference, ExtendedURL> serializer; |
65 |
25715 |
ParameterizedType type = new DefaultParameterizedType(null, ResourceReferenceSerializer.class, |
66 |
|
ResourceReference.class, ExtendedURL.class); |
67 |
25713 |
try { |
68 |
25713 |
serializer = this.componentManager.getInstance(type, this.urlContextManager.getURLFormatId()); |
69 |
|
} catch (ComponentLookupException e) { |
70 |
0 |
throw new UnsupportedResourceReferenceException( |
71 |
|
String.format("Invalid URL format id [%s]. Cannot serialize Resource Reference [%s].", |
72 |
|
this.urlContextManager.getURLFormatId(), resource), e); |
73 |
|
} |
74 |
|
|
75 |
25715 |
return serializer.serialize(resource); |
76 |
|
} |
77 |
|
} |