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.beans.config.URI2RepositoryManager;
37 import info.magnolia.cms.i18n.I18nContentSupportFactory;
38 import info.magnolia.context.MgnlContext;
39
40 import org.apache.commons.lang.StringUtils;
41
42
43
44
45
46
47
48
49 public class AbsolutePathTransformer implements LinkTransformer {
50
51 boolean addContextPath = true;
52
53 boolean useURI2RepositoryMapping = true;
54
55 boolean useI18N = true;
56
57
58
59
60
61
62
63 public AbsolutePathTransformer(boolean addContextPath, boolean useURI2RepositoryMapping, boolean useI18N) {
64 this.addContextPath = addContextPath;
65 this.useURI2RepositoryMapping = useURI2RepositoryMapping;
66 this.useI18N = useI18N;
67 }
68
69
70
71
72 @Override
73 public String transform(Link uuidLink) {
74 String linkStr;
75 if(useURI2RepositoryMapping){
76 linkStr = getURI2RepositoryManager().getURI(uuidLink);
77 }
78 else{
79 linkStr = getURI2RepositoryManager().getDefaultMapping().getURI(uuidLink);
80 }
81 linkStr += getURISuffix(uuidLink);
82 if(useI18N){
83 linkStr = I18nContentSupportFactory.getI18nSupport().toI18NURI(linkStr);
84 }
85 linkStr = prefixLink(linkStr);
86 return linkStr;
87 }
88
89 protected URI2RepositoryManager getURI2RepositoryManager() {
90 return URI2RepositoryManager.getInstance();
91 }
92
93 protected String prefixLink(String linkStr) {
94 if(addContextPath){
95 return MgnlContext.getContextPath() + linkStr;
96 }
97 return linkStr;
98 }
99
100
101
102
103 public String getURISuffix(Link uuidLink) {
104 String anchor = uuidLink.getAnchor();
105 String parameters = uuidLink.getParameters();
106
107 return "" + (StringUtils.isNotEmpty(anchor)? "#" + anchor : "") +
108 (StringUtils.isNotEmpty(parameters)? "?" + parameters : "");
109
110 }
111
112 public boolean isAddContextPath() {
113 return this.addContextPath;
114 }
115
116
117 public void setAddContextPath(boolean addContextPath) {
118 this.addContextPath = addContextPath;
119 }
120
121
122 public boolean isUseI18N() {
123 return this.useI18N;
124 }
125
126
127 public void setUseI18N(boolean useI18N) {
128 this.useI18N = useI18N;
129 }
130
131
132 public boolean isUseURI2RepositoryMapping() {
133 return this.useURI2RepositoryMapping;
134 }
135
136
137 public void setUseURI2RepositoryMapping(boolean useURI2RepositoryMapping) {
138 this.useURI2RepositoryMapping = useURI2RepositoryMapping;
139 }
140
141 }
142