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