Subversion Repository Public Repository

litesoft

Diff Revisions 594 vs 595 for /trunk/GWT_Sandbox/FormEngine/src/com/temp/shared/E13nData.java

Diff revisions: vs.
  @@ -9,8 +9,41 @@
9 9 * substitutions within any specific template by "named" values.
10 10 */
11 11 public class E13nData {
12 +
13 + /**
14 + * Substitution Value w/ a flag indicating if it is User Data, or another Template Id Code to be used as a Sub-Template.
15 + */
16 + public static class SubstitutionValue {
17 + private final boolean userData;
18 + private final String value;
19 +
20 + public SubstitutionValue(boolean userData, String value) {
21 + this.userData = userData;
22 + this.value = value;
23 + }
24 +
25 + /**
26 + * Flag indicating if the "vale" is User Data, or another Template Id Code to be used as a Sub-Template.
27 + */
28 + public boolean isUserData() {
29 + return userData;
30 + }
31 +
32 + /**
33 + * User Data, or another Template Id Code to be used as a Sub-Template.
34 + */
35 + public String getValue() {
36 + return value;
37 + }
38 +
39 + @Override
40 + public String toString() {
41 + return userData ? value : "{" + value + "}";
42 + }
43 + }
44 +
12 45 private final String templateIdCode;
13 - private Map<String, String> templateSubstitutionNamedValues;
46 + private Map<String, SubstitutionValue> templateSubstitutionNamedValues;
14 47
15 48 /**
16 49 * @param templateIdCode Template Identifying Code
  @@ -19,54 +52,33 @@
19 52 this.templateIdCode = Validate.noEmpty("templateIdCode", templateIdCode);
20 53 }
21 54
22 - /**
23 - * @param templateIdCode Template Identifying Code
24 - * @param templateSubstitutionNamedValues
25 - * Template Substitution Named Values (must be specified as "pairs")
26 - */
27 - public E13nData(String templateIdCode, String... templateSubstitutionNamedValues) {
28 - this(templateIdCode);
29 - addSubstitutionNamedValues(templateSubstitutionNamedValues);
30 - }
31 -
32 - private synchronized void addPair(int whichName, String name, String value) {
33 - name = StringUtils.noEmpty(name);
34 - if (name == null) {
35 - String what = "name";
36 - if (whichName != -1) {
37 - what += "(templateSubstitutionNamedValues[" + whichName + "])";
38 - }
39 - Validate.noEmpty(what, name);
40 - }
55 + private synchronized E13nData addPair(boolean userData, String name, String value) {
56 + name = Validate.noEmpty("name", name);
41 57 if (templateSubstitutionNamedValues == null) {
42 - templateSubstitutionNamedValues = new HashMap<String, String>();
58 + templateSubstitutionNamedValues = new HashMap<String, SubstitutionValue>();
43 59 }
44 - templateSubstitutionNamedValues.put(name, StringUtils.deNull(value));
60 + templateSubstitutionNamedValues.put(name, new SubstitutionValue(userData, value));
61 + return this;
45 62 }
46 63
47 64 /**
48 - * Add a Substitution Named Value.
65 + * Add a User Substitution Named Value.
49 66 *
50 - * @param name Not allowed to be empty
51 - * @param value null converted to ""
67 + * @param name Not allowed to be empty
68 + * @param userData null converted to ""
52 69 */
53 - public void addSubstitutionNamedValue(String name, String value) {
54 - addPair(-1, name, value);
70 + public E13nData addSubstitutionNamedUserData(String name, String userData) {
71 + return addPair(true, name, StringUtils.deNull(userData));
55 72 }
56 73
57 74 /**
58 - * @param templateSubstitutionNamedValues
59 - * Template Substitution Named Values (must be specified as "pairs")
75 + * Add a User Substitution Named Value.
76 + *
77 + * @param name Not allowed to be empty
78 + * @param subTemplateIdCode Not allowed to be empty
60 79 */
61 - public synchronized void addSubstitutionNamedValues(String... templateSubstitutionNamedValues) {
62 - if (templateSubstitutionNamedValues != null) {
63 - if ((templateSubstitutionNamedValues.length & 1) == 1) {
64 - throw new IllegalArgumentException("Provided templateSubstitutionNamedValues not made up of Name Value 'Pairs'");
65 - }
66 - for (int i = 0; i < templateSubstitutionNamedValues.length; i += 2) {
67 - addPair(i, templateSubstitutionNamedValues[i], templateSubstitutionNamedValues[i + 1]);
68 - }
69 - }
80 + public E13nData addSubstitutionNamedSubTemplateIdCode(String name, String subTemplateIdCode) {
81 + return addPair(false, name, Validate.noEmpty("subTemplateIdCode", subTemplateIdCode));
70 82 }
71 83
72 84 /**
  @@ -79,11 +91,11 @@
79 91 /**
80 92 * @return Not null map of Template Substitution Named Values
81 93 */
82 - public synchronized Map<String, String> getTemplateSubstitutionNamedValues() {
94 + public synchronized Map<String, SubstitutionValue> getTemplateSubstitutionNamedValues() {
83 95 if (templateSubstitutionNamedValues == null) {
84 96 return Collections.emptyMap();
85 97 }
86 - return new HashMap<String, String>(templateSubstitutionNamedValues); // defensive copy for Thread Safety
98 + return new HashMap<String, SubstitutionValue>(templateSubstitutionNamedValues); // defensive copy for Thread Safety
87 99 }
88 100
89 101 @Override