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