1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.rice.kns.lookup;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.config.property.ConfigContext;
20  import org.kuali.rice.core.web.format.DateFormatter;
21  import org.kuali.rice.kns.document.authorization.BusinessObjectRestrictions;
22  import org.kuali.rice.kns.document.authorization.FieldRestriction;
23  import org.kuali.rice.kns.service.BusinessObjectAuthorizationService;
24  import org.kuali.rice.kns.service.KNSServiceLocator;
25  import org.kuali.rice.kns.util.KNSConstants;
26  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
27  import org.kuali.rice.krad.util.KRADConstants;
28  import org.kuali.rice.krad.util.ObjectUtils;
29  
30  import java.io.Serializable;
31  import java.sql.Date;
32  import java.util.HashMap;
33  import java.util.Iterator;
34  import java.util.List;
35  import java.util.Map;
36  
37  
38  
39  
40  
41  
42  
43  
44  @Deprecated
45  public abstract class HtmlData implements Serializable {
46  
47  	protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(HtmlData.class);
48  
49  	public static final String ANCHOR_HTML_DATA_TYPE = AnchorHtmlData.class.getName();
50  	public static final String INPUT_HTML_DATA_TYPE = InputHtmlData.class.getName();
51  	
52  	protected String name = "";
53  	protected String title = "";
54  	protected String methodToCall = "";
55  	protected String displayText = "";
56  	protected String prependDisplayText = "";
57  	protected String appendDisplayText = "";
58  	protected List<HtmlData> childUrlDataList;
59  	protected String maxLength;
60  	
61  	
62  
63  
64  
65  
66  
67  
68  	public abstract String constructCompleteHtmlTag();
69  
70  	
71  
72  
73  	public String getAppendDisplayText() {
74  		return this.appendDisplayText;
75  	}
76  
77  	
78  
79  
80  	public void setAppendDisplayText(String appendDisplayText) {
81  		this.appendDisplayText = appendDisplayText;
82  	}
83  
84  	
85  
86  
87  	public List<HtmlData> getChildUrlDataList() {
88  		return this.childUrlDataList;
89  	}
90  
91  	
92  
93  
94  	public void setChildUrlDataList(List<HtmlData> childUrlDataList) {
95  		this.childUrlDataList = childUrlDataList;
96  	}
97  
98  	
99  
100 
101 	public String getPrependDisplayText() {
102 		return this.prependDisplayText;
103 	}
104 
105 	
106 
107 
108 	public void setPrependDisplayText(String prependDisplayText) {
109 		this.prependDisplayText = prependDisplayText;
110 	}
111 
112 	
113 
114 
115 	public String getTitle() {
116 		return this.title;
117 	}
118 
119 	
120 
121 
122 	public void setTitle(String title) {
123 		this.title = title;
124 	}
125 
126 	
127 
128 
129 	public String getName() {
130 		return this.name;
131 	}
132 
133 	
134 
135 
136 	public void setName(String name) {
137 		this.name = name;
138 	}
139 
140 	
141 
142 
143 	public String getDisplayText() {
144 		return this.displayText;
145 	}
146 
147 	
148 
149 
150 	public void setDisplayText(String displayText) {
151 		this.displayText = displayText;
152 	}
153 
154 	
155 
156 
157 	public String getMethodToCall() {
158 		return this.methodToCall;
159 	}
160 
161 	
162 
163 
164 	public void setMethodToCall(String methodToCall) {
165 		this.methodToCall = methodToCall;
166 	}
167 
168 	public String getTitle(String prependText, Class bo, List keys) {
169 		return KRADConstants.EMPTY_STRING;
170 	}
171 
172 	
173 
174 
175 
176 
177 
178 
179 
180 
181 	public static String getTitleText(String prependText, Object dataObject, List<String> keys, BusinessObjectRestrictions businessObjectRestrictions) {
182 		if (dataObject == null)
183 			return KRADConstants.EMPTY_STRING;
184 
185 		Map<String, String> keyValueMap = new HashMap<String, String>();
186 		Iterator keysIt = keys.iterator();
187 		while (keysIt.hasNext()) {
188 			String fieldNm = (String) keysIt.next();
189 			Object fieldVal = ObjectUtils.getPropertyValue(dataObject, fieldNm);
190 
191 			FieldRestriction fieldRestriction = null;
192 			if (businessObjectRestrictions != null) {
193 				fieldRestriction = businessObjectRestrictions.getFieldRestriction(fieldNm);
194 			}
195 
196             if (KNSServiceLocator.getDataDictionaryService().getAttributeDefinition(dataObject.getClass().getName(), fieldNm) == null) {
197                 fieldVal = KRADConstants.EMPTY_STRING;
198             } else if (fieldRestriction != null && (fieldRestriction.isMasked() || fieldRestriction.isPartiallyMasked())) {
199 				fieldVal = fieldRestriction.getMaskFormatter().maskValue(fieldVal);
200 			} else if (fieldVal == null) {
201 				fieldVal = KRADConstants.EMPTY_STRING;
202 			} else if (fieldVal instanceof Date) {
203 				
204 				DateFormatter dateFormatter = new DateFormatter();
205 				fieldVal = dateFormatter.format(fieldVal);
206 			}
207 			keyValueMap.put(fieldNm, fieldVal.toString());
208 		}
209 		return getTitleText(prependText, dataObject.getClass(), keyValueMap);
210 	}
211 	
212 	private static BusinessObjectAuthorizationService businessObjectAuthorizationService;
213 	private static BusinessObjectAuthorizationService getBusinessObjectAuthorizationService() {
214 		if (businessObjectAuthorizationService == null) {
215 			businessObjectAuthorizationService = KNSServiceLocator.getBusinessObjectAuthorizationService();
216 		}
217 		return businessObjectAuthorizationService;
218 	}
219 
220 	public static String getTitleText(String prependText, Class<?> dataObjectClass, Map<String, String> keyValueMap) {
221 		StringBuffer titleText = new StringBuffer(prependText);
222 		for (String key : keyValueMap.keySet()) {
223 			String fieldVal = keyValueMap.get(key).toString();
224 
225             if (StringUtils.isNotBlank(fieldVal)) {
226                 titleText.append(KRADServiceLocatorWeb.getDataDictionaryService()
227                         .getAttributeLabel(dataObjectClass, key)
228                         + "=" + fieldVal.toString() + " ");
229             }
230 		}
231 		return titleText.toString();
232 	}
233 
234 	
235 
236 
237 
238 
239 
240 
241 	public static class AnchorHtmlData extends HtmlData {
242 		public static final String TARGET_BLANK = "_blank";
243 		protected String href = "";
244 		protected String target = "";
245 		protected String style = "";
246 		protected String styleClass ="";
247 		protected String onclick ="";
248 
249 		
250 
251 
252 		public AnchorHtmlData() {
253 		}
254 
255 		public AnchorHtmlData(String href, String title) {
256 			this.href = href;
257 			this.title = title;
258 		}
259 
260 		public AnchorHtmlData(String href, String methodToCall,
261 				String displayText) {
262 			this.href = href;
263 			this.methodToCall = methodToCall;
264 			this.displayText = displayText;
265 		}
266 
267 		
268 
269 
270 		public void setHref(String href) {
271 			this.href = href;
272 		}
273 
274 		
275 
276 
277 
278 
279 
280 		public String constructCompleteHtmlTag() {
281 			String completeHtmlTag;
282 			if (StringUtils.isEmpty(getHref()))
283 				completeHtmlTag = getDisplayText();
284 			else
285 				completeHtmlTag = getPrependDisplayText()
286 						+ "<a title=\""
287 						+ title
288 						+ "\""
289 						+ " href=\""
290 						+ getHref()
291 						+ "\""
292 						+ getStyle()
293 						+ " "
294 						+ getStyleClass()
295 						+ " "
296 						+ (StringUtils.isEmpty(getOnclick()) ? "" : " onClick=\""
297 							+ getOnclick() + "\" ")
298 						+ (StringUtils.isEmpty(getTarget()) ? "" : " target=\""
299 								+ getTarget() + "\" ") + ">" + getDisplayText()
300 						+ "</a>" + getAppendDisplayText();
301 			return completeHtmlTag;
302 		}
303 
304 		
305 
306 
307 		public String getTarget() {
308 			return this.target;
309 		}
310 
311 		
312 
313 
314 
315 		public void setTarget(String target) {
316 			this.target = target;
317 		}
318 
319 		
320 
321 
322         public String getStyle() {
323         	return this.style;
324         }
325 
326 		
327 
328 
329         public void setStyle(String style) {
330         	this.style = style;
331         }
332 
333 		
334 
335 
336         public String getStyleClass() {
337         	return this.styleClass;
338         }
339 
340 		
341 
342 
343         public void setStyleClass(String styleClass) {
344         	this.styleClass = styleClass;
345         }
346         
347 		
348 
349 
350 		public String getOnclick() {
351 			return this.onclick;
352 		}
353 
354 		
355 
356 
357 		public void setOnclick(String onclick) {
358 			this.onclick = onclick;
359 		}        
360 
361 		
362 
363 
364 		public String getHref() {
365 			return this.href;
366 		}
367 
368 		
369 
370 
371 		public String getMethodToCall() {
372 			return this.methodToCall;
373 		}
374 
375 	}
376 
377 	
378 
379 
380 
381 
382 
383 
384 	public static class InputHtmlData extends HtmlData {
385 		public static final String CHECKBOX_INPUT_TYPE = "checkbox";
386 		public static final String CHECKBOX_CHECKED_VALUE = "checked";
387 
388 		protected String inputType = "";
389 		protected String src = "";
390 		protected String styleClass = "";
391 		protected String border = "0";
392 		protected String checked = "";
393 		protected String value = "";
394 
395 		public InputHtmlData(String name, String inputType) {
396 			this.name = name;
397 			this.inputType = inputType;
398 		}
399 
400 		public InputHtmlData(String name, String inputType, String src) {
401 			this.name = name;
402 			this.inputType = inputType;
403 			this.src = src;
404 		}
405 
406 		
407 
408 
409 
410 
411 
412 		public String constructCompleteHtmlTag() {
413 			return getPrependDisplayText()
414 					+ "<input title=\""
415 					+ title
416 					+ "\""
417 					+ " name=\""
418 					+ getName()
419 					+ "\""
420 					+ (StringUtils.isEmpty(src) ? ""
421 							: " src=\"" + src + "\" ")
422 					+ " type=\""
423 					+ getInputType()
424 					+ "\""
425 					+ (StringUtils.isEmpty(value) ? ""
426 							: " value=\"" + value + "\" ")
427 					+ (StringUtils.isEmpty(checked) ? ""
428 							: " checked=\"" + checked + "\" ")
429 					+ (StringUtils.isEmpty(getStyleClass()) ? ""
430 							: " styleClass=\"" + getStyleClass() + "\" ")
431 					+ " border=\"" + getBorder() + "\"" + " value=\""
432 					+ getDisplayText() + "\"" + "/>" + getAppendDisplayText();
433 		}
434 
435 		
436 
437 
438 		public String getInputType() {
439 			return this.inputType;
440 		}
441 
442 		
443 
444 
445 		public String getSrc() {
446 			return this.src;
447 		}
448 
449 		
450 
451 
452 		public String getBorder() {
453 			return this.border;
454 		}
455 
456 		
457 
458 
459 
460 		public void setBorder(String border) {
461 			this.border = border;
462 		}
463 
464 		
465 
466 
467 		public String getStyleClass() {
468 			return this.styleClass;
469 		}
470 
471 		
472 
473 
474 
475 		public void setStyleClass(String styleClass) {
476 			this.styleClass = styleClass;
477 		}
478 
479 		
480 
481 
482 		public void setChecked(String checked) {
483 			this.checked = checked;
484 		}
485 
486 		
487 
488 
489 		public void setValue(String value) {
490 			this.value = value;
491 		}
492 
493 	}
494 
495 	public static class MultipleAnchorHtmlData extends AnchorHtmlData {
496 		protected List<AnchorHtmlData> anchorHtmlData;
497 		protected static final String ANCHORS_SEPARATOR = ", ";
498 		
499 		
500 
501 
502 		public MultipleAnchorHtmlData(List<AnchorHtmlData> anchorHtmlData) {
503 			this.anchorHtmlData = anchorHtmlData;
504 		}
505 		
506 		
507 
508 
509 
510 
511 
512 		public String constructCompleteHtmlTag() {
513 			StringBuffer completeHtmlTag = new StringBuffer();
514 			for(AnchorHtmlData anchor: anchorHtmlData){
515 				completeHtmlTag.append(anchor.constructCompleteHtmlTag()+",");
516 			}
517 	        if(completeHtmlTag.toString().endsWith(ANCHORS_SEPARATOR))
518 	        	completeHtmlTag.delete(completeHtmlTag.length()-ANCHORS_SEPARATOR.length(), completeHtmlTag.length());
519 			return completeHtmlTag.toString();
520 		}
521 
522 		
523 
524 
525 		public List<AnchorHtmlData> getAnchorHtmlData() {
526 			return this.anchorHtmlData;
527 		}
528 
529 	}
530 
531 	
532 
533 
534 	public int getMaxLength() {
535 		try{
536 			return Integer.parseInt(this.maxLength);
537 		} catch(Exception ex){
538 			return -1;
539 		}
540 	}
541 
542 	
543 
544 
545 	public void setMaxLength(String maxLength) {
546 		this.maxLength = maxLength;
547 	}
548 
549 }