1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.model.internal.reference.converter; |
21 |
|
|
22 |
|
import java.lang.reflect.Type; |
23 |
|
|
24 |
|
import javax.inject.Inject; |
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Singleton; |
27 |
|
|
28 |
|
import org.apache.commons.lang3.EnumUtils; |
29 |
|
import org.xwiki.component.annotation.Component; |
30 |
|
import org.xwiki.component.namespace.Namespace; |
31 |
|
import org.xwiki.component.namespace.NamespaceUtils; |
32 |
|
import org.xwiki.model.EntityType; |
33 |
|
import org.xwiki.model.reference.EntityReference; |
34 |
|
import org.xwiki.model.reference.EntityReferenceResolver; |
35 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
36 |
|
import org.xwiki.properties.converter.AbstractConverter; |
37 |
|
|
38 |
|
|
39 |
|
@link |
40 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
@since |
44 |
|
|
45 |
|
@Component |
46 |
|
@Singleton |
|
|
| 91.7% |
Uncovered Elements: 2 (24) |
Complexity: 7 |
Complexity Density: 0.54 |
|
47 |
|
public class EntityReferenceConverter extends AbstractConverter<EntityReference> |
48 |
|
{ |
49 |
|
@Inject |
50 |
|
@Named("relative") |
51 |
|
private EntityReferenceResolver<String> stringResolver; |
52 |
|
|
53 |
|
@Inject |
54 |
|
private EntityReferenceSerializer<String> serialier; |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
56 |
75 |
@Override... |
57 |
|
protected EntityReference convertToType(Type type, Object value) |
58 |
|
{ |
59 |
75 |
if (value == null) { |
60 |
1 |
return null; |
61 |
|
} |
62 |
|
|
63 |
74 |
return convertToType(type, value.toString()); |
64 |
|
} |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
66 |
74 |
private EntityReference convertToType(Type type, String value)... |
67 |
|
{ |
68 |
74 |
Namespace namespace = NamespaceUtils.toNamespace(value); |
69 |
|
|
70 |
74 |
EntityType entityType = namespace.getType() != null |
71 |
|
? EnumUtils.getEnum(EntityType.class, namespace.getType().toUpperCase()) : null; |
72 |
74 |
String entityReference = namespace.getValue(); |
73 |
74 |
if (entityType == null) { |
74 |
68 |
entityType = EntityType.DOCUMENT; |
75 |
68 |
entityReference = value; |
76 |
|
} |
77 |
|
|
78 |
74 |
return this.stringResolver.resolve(entityReference, entityType); |
79 |
|
} |
80 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
81 |
1 |
@Override... |
82 |
|
protected String convertToString(EntityReference value) |
83 |
|
{ |
84 |
1 |
if (value == null) { |
85 |
0 |
return null; |
86 |
|
} |
87 |
|
|
88 |
1 |
return new Namespace(value.getType().getLowerCase(), this.serialier.serialize(value)).toString(); |
89 |
|
} |
90 |
|
} |