1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.resources.mapping; |
35 |
|
|
36 |
|
import info.magnolia.cms.beans.config.URI2RepositoryMapping; |
37 |
|
import info.magnolia.context.MgnlContext; |
38 |
|
|
39 |
|
import javax.jcr.RepositoryException; |
40 |
|
import javax.jcr.Session; |
41 |
|
|
42 |
|
import org.apache.commons.lang3.StringUtils; |
43 |
|
import org.slf4j.Logger; |
44 |
|
import org.slf4j.LoggerFactory; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
@deprecated@link@link |
51 |
|
|
52 |
|
@Deprecated |
|
|
| 59.4% |
Uncovered Elements: 13 (32) |
Complexity: 11 |
Complexity Density: 0.58 |
|
53 |
|
public class URI2ResourcesRepositoryMapping extends URI2RepositoryMapping { |
54 |
|
|
55 |
|
private static Logger log = LoggerFactory.getLogger(URI2ResourcesRepositoryMapping.class); |
56 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
57 |
0 |
public URI2ResourcesRepositoryMapping() {... |
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
60 |
2 |
public URI2ResourcesRepositoryMapping(String uriPrefix, String repository, String handlePrefix) {... |
61 |
2 |
super(uriPrefix, repository, handlePrefix); |
62 |
|
} |
63 |
|
|
|
|
| 57.1% |
Uncovered Elements: 12 (28) |
Complexity: 9 |
Complexity Density: 0.5 |
|
64 |
2 |
@Override... |
65 |
|
public String getHandle(String uri) { |
66 |
2 |
String handle; |
67 |
2 |
handle = StringUtils.removeStart(uri, getURIPrefix()); |
68 |
2 |
if (StringUtils.isNotEmpty(getHandlePrefix())) { |
69 |
0 |
handle = StringUtils.removeStart(handle, "/"); |
70 |
0 |
handle = getHandlePrefix() + "/" + handle; |
71 |
|
} |
72 |
|
|
73 |
2 |
handle = cleanHandle(handle); |
74 |
|
|
75 |
2 |
try { |
76 |
2 |
final Session session = MgnlContext.getJCRSession(getRepository()); |
77 |
2 |
if (!session.itemExists(handle)) { |
78 |
1 |
String fileName = StringUtils.substringAfterLast(handle, "/"); |
79 |
1 |
String extension = StringUtils.substringAfterLast(fileName, "."); |
80 |
1 |
handle = StringUtils.removeEnd(handle, "." + extension); |
81 |
1 |
if (!session.itemExists(handle)) { |
82 |
0 |
String maybeHandle = (getHandlePrefix().endsWith("/") ? "/" : "") + StringUtils.removeStart(handle, getHandlePrefix()); |
83 |
|
|
84 |
0 |
if (session.itemExists(maybeHandle) || (maybeHandle.lastIndexOf("/") > 0 && session.itemExists(StringUtils.substringBeforeLast(maybeHandle, "/")))) { |
85 |
0 |
return maybeHandle; |
86 |
|
} |
87 |
|
} |
88 |
|
} |
89 |
|
} catch (RepositoryException e) { |
90 |
|
|
91 |
0 |
log.debug(e.getMessage(), e); |
92 |
|
} |
93 |
2 |
return handle; |
94 |
|
} |
95 |
|
} |