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.link;
35
36 import info.magnolia.cms.core.Content;
37
38 import javax.jcr.Node;
39 import javax.jcr.RepositoryException;
40
41
42
43
44 public class RelativePathTransformer extends AbsolutePathTransformer {
45
46 protected String absolutSourcePath;
47
48 public void setAbsolutSourcePath(Node sourceNode) {
49 try {
50 Link link = new Link(sourceNode);
51 link.setRepository(sourceNode.getSession().getWorkspace().getName());
52 link.setExtension("html");
53 absolutSourcePath = super.transform(link);
54 } catch (RepositoryException e) {
55 throw new RuntimeException(e);
56 }
57 }
58
59 public void setAbsolutSourcePath(String absolutSourcePath) {
60 this.absolutSourcePath = absolutSourcePath;
61 }
62
63 public RelativePathTransformer() {
64 }
65
66 public RelativePathTransformer(Content sourcePage, boolean useURI2RepositoryMapping, boolean useI18N) {
67 this(sourcePage.getJCRNode(), useURI2RepositoryMapping, useI18N);
68 }
69
70 public RelativePathTransformer(Node sourcePage, boolean useURI2RepositoryMapping, boolean useI18N) {
71 super(false, useURI2RepositoryMapping, useI18N);
72 try {
73 Link link = new Link(sourcePage);
74 link.setRepository(sourcePage.getSession().getWorkspace().getName());
75 link.setExtension("html");
76 absolutSourcePath = super.transform(link);
77 } catch (RepositoryException e) {
78 throw new RuntimeException(e);
79 }
80 }
81
82 public RelativePathTransformer(String absoluteSourcePath, boolean useURI2RepositoryMapping, boolean useI18N) {
83 super(false, useURI2RepositoryMapping, useI18N);
84 this.absolutSourcePath = absoluteSourcePath;
85 }
86
87 @Override
88 public String transform(Link target) {
89 String link = super.transform(target);
90 return LinkUtil.makePathRelative(absolutSourcePath, link);
91 }
92 }