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.blossom.view;
35
36 import java.util.Locale;
37
38 import org.springframework.beans.factory.BeanInitializationException;
39 import org.springframework.beans.factory.InitializingBean;
40 import org.springframework.core.Ordered;
41 import org.springframework.web.servlet.View;
42 import org.springframework.web.servlet.ViewResolver;
43
44 import info.magnolia.repository.RepositoryConstants;
45
46
47
48
49
50
51
52
53
54 public class UuidRedirectViewResolver implements ViewResolver, Ordered, InitializingBean {
55
56 private String[] workspaces = new String[]{RepositoryConstants.WEBSITE, "dms"};
57 private String[] prefixes;
58 private boolean http10Compatible = true;
59 private int order = Integer.MAX_VALUE;
60
61 @Override
62 public int getOrder() {
63 return order;
64 }
65
66 public void setOrder(int order) {
67 this.order = order;
68 }
69
70 public String[] getWorkspaces() {
71 return workspaces;
72 }
73
74 public void setWorkspaces(String[] workspaces) {
75 this.workspaces = workspaces;
76 }
77
78 public void setWorkspace(String workspace) {
79 this.workspaces = new String[]{workspace};
80 }
81
82 @Deprecated
83 public String[] getRepositories() {
84 return workspaces;
85 }
86
87 @Deprecated
88 public void setRepositories(String[] repositories) {
89 this.workspaces = repositories;
90 }
91
92 @Deprecated
93 public void setRepository(String repository) {
94 this.workspaces = new String[]{repository};
95 }
96
97 public String[] getPrefixes() {
98 return prefixes;
99 }
100
101 public void setPrefixes(String[] prefixes) {
102 this.prefixes = prefixes;
103 }
104
105 public void setPrefix(String prefix) {
106 this.prefixes = new String[]{prefix};
107 }
108
109 public boolean isHttp10Compatible() {
110 return http10Compatible;
111 }
112
113 public void setHttp10Compatible(boolean http10Compatible) {
114 this.http10Compatible = http10Compatible;
115 }
116
117 @Override
118 public View resolveViewName(String viewName, Locale locale) throws Exception {
119 for (int i = 0; i < prefixes.length; i++) {
120 String prefix = prefixes[i];
121 if (viewName.startsWith(prefix)) {
122 UuidRedirectView view = new UuidRedirectView(workspaces[i], viewName.substring(prefix.length()));
123 view.setHttp10Compatible(http10Compatible);
124 return view;
125 }
126 }
127 return null;
128 }
129
130 @Override
131 public void afterPropertiesSet() throws Exception {
132 if (prefixes == null) {
133 prefixes = new String[workspaces.length];
134 for (int i = 0; i < workspaces.length; i++) {
135 prefixes[i] = workspaces[i] + ":";
136 }
137 }
138 if (prefixes.length != workspaces.length) {
139 throw new BeanInitializationException("The number of prefixes configured must match the number of workspaces.");
140 }
141 }
142 }