1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.wysiwyg.server.wiki; |
21 |
|
|
22 |
|
import java.util.HashMap; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
import javax.inject.Named; |
27 |
|
import javax.inject.Singleton; |
28 |
|
|
29 |
|
import org.apache.commons.lang3.StringUtils; |
30 |
|
import org.xwiki.component.annotation.Component; |
31 |
|
import org.xwiki.gwt.wysiwyg.client.wiki.WikiPageReference; |
32 |
|
import org.xwiki.model.EntityType; |
33 |
|
import org.xwiki.model.reference.AttachmentReference; |
34 |
|
import org.xwiki.model.reference.DocumentReference; |
35 |
|
import org.xwiki.model.reference.EntityReference; |
36 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
37 |
|
import org.xwiki.model.reference.SpaceReference; |
38 |
|
import org.xwiki.model.reference.SpaceReferenceResolver; |
39 |
|
import org.xwiki.model.reference.WikiReference; |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
@version |
45 |
|
|
46 |
|
@Component(roles = EntityReferenceConverter.class) |
47 |
|
@Singleton |
|
|
| 91.3% |
Uncovered Elements: 6 (69) |
Complexity: 16 |
Complexity Density: 0.35 |
|
48 |
|
public class EntityReferenceConverter |
49 |
|
{ |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
private static final Map<EntityType, String> REFERENCE_COMPONENT_NAME; |
54 |
|
|
55 |
|
@Inject |
56 |
|
private SpaceReferenceResolver<String> spaceResolver; |
57 |
|
|
58 |
|
@Inject |
59 |
|
@Named("local") |
60 |
|
private EntityReferenceSerializer<String> localEntityReferenceSerializer; |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
62 |
1 |
static {... |
63 |
1 |
REFERENCE_COMPONENT_NAME = new HashMap<EntityType, String>(); |
64 |
1 |
REFERENCE_COMPONENT_NAME.put(EntityType.WIKI, WikiPageReference.WIKI_NAME); |
65 |
1 |
REFERENCE_COMPONENT_NAME.put(EntityType.SPACE, WikiPageReference.SPACE_NAME); |
66 |
1 |
REFERENCE_COMPONENT_NAME.put(EntityType.DOCUMENT, WikiPageReference.PAGE_NAME); |
67 |
1 |
REFERENCE_COMPONENT_NAME.put(EntityType.ATTACHMENT, |
68 |
|
org.xwiki.gwt.wysiwyg.client.wiki.AttachmentReference.FILE_NAME); |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
@param |
75 |
|
@return |
76 |
|
|
|
|
| 84.6% |
Uncovered Elements: 4 (26) |
Complexity: 6 |
Complexity Density: 0.38 |
|
77 |
2 |
public EntityReference convert(org.xwiki.gwt.wysiwyg.client.wiki.EntityReference clientEntityReference)... |
78 |
|
{ |
79 |
2 |
if (clientEntityReference == null) { |
80 |
1 |
return null; |
81 |
|
} |
82 |
1 |
EntityReference serverEntityReference = null; |
83 |
1 |
String wikiName = clientEntityReference.getComponent(REFERENCE_COMPONENT_NAME.get(EntityType.WIKI)); |
84 |
1 |
if (!StringUtils.isEmpty(wikiName)) { |
85 |
1 |
serverEntityReference = new EntityReference(wikiName, EntityType.WIKI); |
86 |
|
} |
87 |
1 |
String localSpaceReference = clientEntityReference.getComponent(REFERENCE_COMPONENT_NAME.get(EntityType.SPACE)); |
88 |
1 |
if (!StringUtils.isEmpty(localSpaceReference)) { |
89 |
1 |
serverEntityReference = this.spaceResolver.resolve(localSpaceReference, serverEntityReference); |
90 |
|
} |
91 |
1 |
String pageName = clientEntityReference.getComponent(REFERENCE_COMPONENT_NAME.get(EntityType.DOCUMENT)); |
92 |
1 |
if (!StringUtils.isEmpty(pageName)) { |
93 |
1 |
serverEntityReference = new EntityReference(pageName, EntityType.DOCUMENT, serverEntityReference); |
94 |
|
} |
95 |
1 |
String fileName = clientEntityReference.getComponent(REFERENCE_COMPONENT_NAME.get(EntityType.ATTACHMENT)); |
96 |
1 |
if (!StringUtils.isEmpty(fileName)) { |
97 |
1 |
serverEntityReference = new EntityReference(fileName, EntityType.ATTACHMENT, serverEntityReference); |
98 |
|
} |
99 |
1 |
return serverEntityReference; |
100 |
|
} |
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
@param |
106 |
|
@return |
107 |
|
|
|
|
| 91.3% |
Uncovered Elements: 2 (23) |
Complexity: 5 |
Complexity Density: 0.29 |
|
108 |
2 |
public org.xwiki.gwt.wysiwyg.client.wiki.EntityReference convert(EntityReference serverEntityReference)... |
109 |
|
{ |
110 |
2 |
org.xwiki.gwt.wysiwyg.client.wiki.EntityReference clientEntityReference = |
111 |
|
new org.xwiki.gwt.wysiwyg.client.wiki.EntityReference(); |
112 |
2 |
try { |
113 |
2 |
clientEntityReference.setType(org.xwiki.gwt.wysiwyg.client.wiki.EntityReference.EntityType |
114 |
|
.valueOf(serverEntityReference.getType().toString())); |
115 |
|
} catch (Exception e) { |
116 |
1 |
return null; |
117 |
|
} |
118 |
|
|
119 |
1 |
EntityReference child = serverEntityReference; |
120 |
|
|
121 |
|
|
122 |
1 |
EntityReference spaceReference = serverEntityReference.extractReference(EntityType.SPACE); |
123 |
1 |
if (spaceReference != null) { |
124 |
1 |
String localSpaceReference = this.localEntityReferenceSerializer.serialize(spaceReference); |
125 |
1 |
EntityReference wikiReference = serverEntityReference.extractReference(EntityType.WIKI); |
126 |
1 |
EntityReference newSpaceReference = new SpaceReference(localSpaceReference, wikiReference); |
127 |
1 |
child = serverEntityReference.replaceParent(spaceReference, newSpaceReference); |
128 |
|
} |
129 |
|
|
130 |
5 |
while (child != null) { |
131 |
4 |
String componentName = REFERENCE_COMPONENT_NAME.get(child.getType()); |
132 |
4 |
if (componentName != null) { |
133 |
4 |
clientEntityReference.setComponent(componentName, child.getName()); |
134 |
|
} |
135 |
4 |
child = child.getParent(); |
136 |
|
} |
137 |
1 |
return clientEntityReference; |
138 |
|
} |
139 |
|
|
140 |
|
|
141 |
|
@param |
142 |
|
@return |
143 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
144 |
1 |
public WikiPageReference convert(DocumentReference documentReference)... |
145 |
|
{ |
146 |
1 |
String wikiName = documentReference.getWikiReference().getName(); |
147 |
1 |
String spaceName = this.localEntityReferenceSerializer.serialize(documentReference.getLastSpaceReference()); |
148 |
1 |
String pageName = documentReference.getName(); |
149 |
1 |
return new WikiPageReference(wikiName, spaceName, pageName); |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
|
@param |
154 |
|
@return |
155 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
156 |
1 |
public DocumentReference convert(WikiPageReference reference)... |
157 |
|
{ |
158 |
1 |
SpaceReference spaceReference = |
159 |
|
this.spaceResolver.resolve(reference.getSpaceName(), new WikiReference(reference.getWikiName())); |
160 |
1 |
return new DocumentReference(reference.getPageName(), spaceReference); |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
|
@param |
165 |
|
@return |
166 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
167 |
1 |
public org.xwiki.gwt.wysiwyg.client.wiki.AttachmentReference convert(AttachmentReference attachmentReference)... |
168 |
|
{ |
169 |
1 |
return new org.xwiki.gwt.wysiwyg.client.wiki.AttachmentReference(attachmentReference.getName(), |
170 |
|
convert(attachmentReference.getDocumentReference())); |
171 |
|
} |
172 |
|
|
173 |
|
|
174 |
|
@param |
175 |
|
@return |
176 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
177 |
1 |
public AttachmentReference convert(org.xwiki.gwt.wysiwyg.client.wiki.AttachmentReference clientAttachmentReference)... |
178 |
|
{ |
179 |
1 |
return new AttachmentReference(clientAttachmentReference.getFileName(), |
180 |
|
convert(clientAttachmentReference.getWikiPageReference())); |
181 |
|
} |
182 |
|
} |