1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document.web;
17
18 import java.util.Iterator;
19 import java.util.Map;
20 import java.util.Set;
21
22 import org.kuali.rice.krad.bo.PersistableBusinessObject;
23
24
25
26
27 public abstract class CodeDescriptionFormatterBase implements CodeDescriptionFormatter {
28
29 public static final String DEFAULT_DESCRIPTION = "(description unavailable)";
30
31
32
33
34
35 public static final int INIT_BUFFER_SIZE = 20;
36
37
38
39
40
41 public String getFormattedStringWithDescriptions(Set values, String startConjunction, String endConjunction) {
42 Map<String, PersistableBusinessObject> valueToBOMap = getValuesToBusinessObjectsMap(values);
43 StringBuffer buf = new StringBuffer();
44
45 Iterator valuesIter = values.iterator();
46
47 if (valuesIter.hasNext()) {
48 if (startConjunction != null && !"".equals(startConjunction)) {
49 buf.append(startConjunction).append(" ");
50 }
51 String currValue = (String) valuesIter.next();
52 buf.append(currValue).append(", ");
53
54 PersistableBusinessObject bo = valueToBOMap.get(currValue);
55 buf.append(bo == null ? getDefaultDescription() : getDescriptionOfBO(bo));
56 }
57 else {
58 buf.append("(none)");
59 }
60
61 while (valuesIter.hasNext()) {
62 buf.append("; ");
63
64 String currValue = (String) valuesIter.next();
65 if (!valuesIter.hasNext()) {
66
67 buf.append(endConjunction).append(" ");
68 }
69
70 buf.append(currValue).append(", ");
71
72 PersistableBusinessObject bo = valueToBOMap.get(currValue);
73 buf.append(bo == null ? getDefaultDescription() : getDescriptionOfBO(bo));
74 }
75 return buf.toString();
76 }
77
78
79
80
81
82
83
84
85
86 protected abstract Map<String, PersistableBusinessObject> getValuesToBusinessObjectsMap(Set values);
87
88
89
90
91
92
93
94 protected abstract String getDescriptionOfBO(PersistableBusinessObject bo);
95
96 protected String getDefaultDescription() {
97 return DEFAULT_DESCRIPTION;
98 }
99 }