1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.util;
17
18 import com.google.common.collect.Maps;
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
21 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
22 import org.kuali.rice.krad.datadictionary.uif.UifDictionaryBeanBase;
23 import org.kuali.rice.krad.uif.UifConstants;
24 import org.kuali.rice.krad.util.KRADUtils;
25
26 import java.io.Serializable;
27 import java.util.HashMap;
28 import java.util.Map;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 @BeanTag(name = "url-bean", parent = "Uif-Url")
47 public class UrlInfo extends UifDictionaryBeanBase implements Serializable {
48
49 private static final long serialVersionUID = 3195177614468120958L;
50
51 private String href;
52 private String originalHref;
53 private String baseUrl;
54 private String controllerMapping;
55 private String viewType;
56 private String viewId;
57 private String pageId;
58 private String formKey;
59 private String methodToCall;
60 private Map<String, String> requestParameters;
61
62
63
64
65 public UrlInfo() {}
66
67
68
69
70
71
72 public UrlInfo(String href) {
73 this.href = href;
74 this.originalHref = href;
75 }
76
77
78
79
80
81
82
83
84
85 public UrlInfo(String baseUrl, String controllerMapping, String viewId, String methodToCall) {
86 this.baseUrl = baseUrl;
87 this.controllerMapping = controllerMapping;
88 this.viewId = viewId;
89 this.methodToCall = methodToCall;
90 }
91
92
93
94
95
96
97 protected String generateUrl() {
98 String generatedUrl = "";
99
100 if (StringUtils.isBlank(baseUrl)) {
101 return generatedUrl;
102 }
103
104 generatedUrl = baseUrl;
105
106 if (StringUtils.isNotBlank(controllerMapping) && !controllerMapping.startsWith("/")) {
107 generatedUrl = generatedUrl + "/" + controllerMapping;
108 } else if (StringUtils.isNotBlank(controllerMapping)) {
109 generatedUrl = generatedUrl + controllerMapping;
110 }
111
112 Map<String, String> allRequestParameters = new HashMap<String, String>();
113
114 if (StringUtils.isNotBlank(methodToCall)) {
115 allRequestParameters.put(UifConstants.CONTROLLER_METHOD_DISPATCH_PARAMETER_NAME, methodToCall);
116 }
117
118 if (StringUtils.isNotBlank(viewId)) {
119 allRequestParameters.put(UifConstants.UrlParams.VIEW_ID, viewId);
120 }
121
122 if (StringUtils.isNotBlank(pageId)) {
123 allRequestParameters.put(UifConstants.UrlParams.PAGE_ID, pageId);
124 }
125
126 if (StringUtils.isNotBlank(formKey)) {
127 allRequestParameters.put(UifConstants.UrlParams.FORM_KEY, formKey);
128 }
129
130 if (requestParameters != null) {
131 allRequestParameters.putAll(requestParameters);
132 }
133
134
135 generatedUrl = generatedUrl + KRADUtils.getRequestStringFromMap(allRequestParameters);
136
137 return generatedUrl;
138 }
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156 @BeanTagAttribute(name = "href")
157 public String getHref() {
158 if (StringUtils.isBlank(this.href)) {
159 this.href = generateUrl();
160 }
161
162 return href;
163 }
164
165
166
167
168
169
170
171 public void setHref(String href) {
172 this.href = href;
173 this.originalHref = href;
174 }
175
176
177
178
179
180
181
182 @BeanTagAttribute(name = "baseUrl")
183 public String getBaseUrl() {
184 return baseUrl;
185 }
186
187
188
189
190
191
192 public void setBaseUrl(String baseUrl) {
193 this.baseUrl = baseUrl;
194 }
195
196
197
198
199
200
201 @BeanTagAttribute(name = "controllerMapping")
202 public String getControllerMapping() {
203 return controllerMapping;
204 }
205
206
207
208
209
210
211 public void setControllerMapping(String controllerMapping) {
212 this.controllerMapping = controllerMapping;
213 }
214
215
216
217
218
219
220 @BeanTagAttribute(name = "viewType")
221 public String getViewType() {
222 return viewType;
223 }
224
225
226
227
228
229
230 public void setViewType(String viewType) {
231 this.viewType = viewType;
232 }
233
234
235
236
237
238
239 @BeanTagAttribute(name = "viewId")
240 public String getViewId() {
241 return viewId;
242 }
243
244
245
246
247
248
249 public void setViewId(String viewId) {
250 this.viewId = viewId;
251 }
252
253
254
255
256
257
258 @BeanTagAttribute(name = "pageId")
259 public String getPageId() {
260 return pageId;
261 }
262
263
264
265
266
267
268 public void setPageId(String pageId) {
269 this.pageId = pageId;
270 }
271
272
273
274
275
276
277 @BeanTagAttribute(name = "formKey")
278 public String getFormKey() {
279 return formKey;
280 }
281
282
283
284
285
286
287 public void setFormKey(String formKey) {
288 this.formKey = formKey;
289 }
290
291
292
293
294
295
296 @BeanTagAttribute(name = "methodToCall")
297 public String getMethodToCall() {
298 return methodToCall;
299 }
300
301
302
303
304
305
306 public void setMethodToCall(String methodToCall) {
307 this.methodToCall = methodToCall;
308 }
309
310
311
312
313
314
315 @BeanTagAttribute(name = "requestParameters", type = BeanTagAttribute.AttributeType.MAPVALUE)
316 public Map<String, String> getRequestParameters() {
317 return requestParameters;
318 }
319
320
321
322
323
324
325 public void setRequestParameters(Map<String, String> requestParameters) {
326 this.requestParameters = requestParameters;
327 }
328
329
330
331
332
333
334
335 public String getOriginalHref() {
336 return originalHref;
337 }
338
339
340
341
342
343
344 @Override
345 public String toString() {
346 return this.getHref();
347 }
348
349
350
351
352
353
354 public void setOriginalHref(String originalHref) {
355 this.originalHref = originalHref;
356 }
357
358 @Override
359 protected <T> void copyProperties(T dictionaryBaseBean) {
360 super.copyProperties(dictionaryBaseBean);
361
362 UrlInfo urlInfoCopy = (UrlInfo) dictionaryBaseBean;
363
364 urlInfoCopy.setHref(this.href);
365 urlInfoCopy.setOriginalHref(this.originalHref);
366 urlInfoCopy.setBaseUrl(this.baseUrl);
367 urlInfoCopy.setControllerMapping(this.controllerMapping);
368 urlInfoCopy.setViewType(this.viewType);
369 urlInfoCopy.setViewId(this.viewId);
370 urlInfoCopy.setPageId(this.pageId);
371 urlInfoCopy.setFormKey(this.formKey);
372 urlInfoCopy.setMethodToCall(this.methodToCall);
373
374 if (this.requestParameters != null) {
375 Map<String, String> requestParametersCopy = Maps.newHashMapWithExpectedSize(this.requestParameters.size());
376 for (Map.Entry requestParameter : requestParameters.entrySet()) {
377 requestParametersCopy.put(requestParameter.getKey().toString(), requestParameter.getValue().toString());
378 }
379
380 urlInfoCopy.setRequestParameters(requestParametersCopy);
381 }
382 }
383 }