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
51
52 @Deprecated
53 public class URI2ResourcesRepositoryMapping extends URI2RepositoryMapping {
54
55 private static Logger log = LoggerFactory.getLogger(URI2ResourcesRepositoryMapping.class);
56
57 public URI2ResourcesRepositoryMapping() {
58 }
59
60 public URI2ResourcesRepositoryMapping(String uriPrefix, String repository, String handlePrefix) {
61 super(uriPrefix, repository, handlePrefix);
62 }
63
64 @Override
65 public String getHandle(String uri) {
66 String handle;
67 handle = StringUtils.removeStart(uri, getURIPrefix());
68 if (StringUtils.isNotEmpty(getHandlePrefix())) {
69 handle = StringUtils.removeStart(handle, "/");
70 handle = getHandlePrefix() + "/" + handle;
71 }
72
73 handle = cleanHandle(handle);
74
75 try {
76 final Session session = MgnlContext.getJCRSession(getRepository());
77 if (!session.itemExists(handle)) {
78 String fileName = StringUtils.substringAfterLast(handle, "/");
79 String extension = StringUtils.substringAfterLast(fileName, ".");
80 handle = StringUtils.removeEnd(handle, "." + extension);
81 if (!session.itemExists(handle)) {
82 String maybeHandle = (getHandlePrefix().endsWith("/") ? "/" : "") + StringUtils.removeStart(handle, getHandlePrefix());
83
84 if (session.itemExists(maybeHandle) || (maybeHandle.lastIndexOf("/") > 0 && session.itemExists(StringUtils.substringBeforeLast(maybeHandle, "/")))) {
85 return maybeHandle;
86 }
87 }
88 }
89 } catch (RepositoryException e) {
90
91 log.debug(e.getMessage(), e);
92 }
93 return handle;
94 }
95 }