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