Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/GWT_Sandbox/FormEngine/src/org/litesoft/core/util/externalization/E13nData.java

Diff revisions: vs.
  @@ -1,111 +1,111 @@
1 - package org.litesoft.core.util.externalization;
2 -
3 - import com.temp.shared.utils.*;
4 -
5 - import java.util.*;
6 -
7 - /**
8 - * Externalization Data to be used with an Externally Sourced String keyed
9 - * template system that supports substitutions within any specific template by
10 - * "named" values.
11 - */
12 - public class E13nData {
13 -
14 - /**
15 - * Substitution Value w/ a flag indicating if it is User Data, or another
16 - * Template Id Code to be used as a Sub-Template.
17 - */
18 - public static class SubstitutionValue {
19 - private final boolean userData;
20 - private final String value;
21 -
22 - public SubstitutionValue( boolean userData, String value ) {
23 - this.userData = userData;
24 - this.value = value;
25 - }
26 -
27 - /**
28 - * Flag indicating if the "value" is User Data, or another Template Id
29 - * Code to be used as a Sub-Template.
30 - */
31 - public boolean isUserData() {
32 - return userData;
33 - }
34 -
35 - /**
36 - * User Data, or another Template Id Code to be used as a Sub-Template.
37 - */
38 - public String getValue() {
39 - return value;
40 - }
41 -
42 - @Override
43 - public String toString() {
44 - return userData ? value : "{" + value + "}";
45 - }
46 - }
47 -
48 - private final String templateIdCode;
49 - private Map<String, SubstitutionValue> templateSubstitutionNamedValues;
50 -
51 - /**
52 - * Convert the templateIdCode (parameter) into an acceptable string form for
53 - * the templateIdCode.
54 - *
55 - * @param templateIdCode Template Identifying Code
56 - */
57 - public E13nData( Object templateIdCode ) {
58 - this.templateIdCode = Assert.noEmptyToString( "templateIdCode", templateIdCode );
59 - }
60 -
61 - private synchronized E13nData addPair( boolean userData, String name, String value ) {
62 - name = Assert.noEmpty( "name", name );
63 - if ( templateSubstitutionNamedValues == null ) {
64 - templateSubstitutionNamedValues = new HashMap<String, SubstitutionValue>();
65 - }
66 - templateSubstitutionNamedValues.put( name, new SubstitutionValue( userData, value ) );
67 - return this;
68 - }
69 -
70 - /**
71 - * Add a User Substitution Named Value.
72 - *
73 - * @param name Not allowed to be empty
74 - * @param userData null converted to ""
75 - */
76 - public E13nData addSubstitutionNamedUserData( String name, String userData ) {
77 - return addPair( true, name, StringUtils.deNull( userData ) );
78 - }
79 -
80 - /**
81 - * Add a User Substitution Named Value.
82 - *
83 - * @param name Not allowed to be empty
84 - * @param subTemplateIdCode Not allowed to be empty
85 - */
86 - public E13nData addSubstitutionNamedSubTemplateIdCode( String name, String subTemplateIdCode ) {
87 - return addPair( false, name, Assert.noEmpty( "subTemplateIdCode", subTemplateIdCode ) );
88 - }
89 -
90 - /**
91 - * @return Not Empty TemplateIdCode
92 - */
93 - public String getTemplateIdCode() {
94 - return templateIdCode;
95 - }
96 -
97 - /**
98 - * @return Not null map of Template Substitution Named Values
99 - */
100 - public synchronized Map<String, SubstitutionValue> getTemplateSubstitutionNamedValues() {
101 - if ( templateSubstitutionNamedValues == null ) {
102 - return Collections.emptyMap();
103 - }
104 - return new HashMap<String, SubstitutionValue>( templateSubstitutionNamedValues ); // defensive copy for Thread Safety
105 - }
106 -
107 - @Override
108 - public String toString() {
109 - return getTemplateIdCode() + getTemplateSubstitutionNamedValues();
110 - }
111 - }
1 + package org.litesoft.core.util.externalization;
2 +
3 + import com.temp.shared.utils.*;
4 +
5 + import java.util.*;
6 +
7 + /**
8 + * Externalization Data to be used with an Externally Sourced String keyed
9 + * template system that supports substitutions within any specific template by
10 + * "named" values.
11 + */
12 + public class E13nData {
13 +
14 + /**
15 + * Substitution Value w/ a flag indicating if it is User Data, or another
16 + * Template Id Code to be used as a Sub-Template.
17 + */
18 + public static class SubstitutionValue {
19 + private final boolean userData;
20 + private final String value;
21 +
22 + public SubstitutionValue( boolean userData, String value ) {
23 + this.userData = userData;
24 + this.value = value;
25 + }
26 +
27 + /**
28 + * Flag indicating if the "value" is User Data, or another Template Id
29 + * Code to be used as a Sub-Template.
30 + */
31 + public boolean isUserData() {
32 + return userData;
33 + }
34 +
35 + /**
36 + * User Data, or another Template Id Code to be used as a Sub-Template.
37 + */
38 + public String getValue() {
39 + return value;
40 + }
41 +
42 + @Override
43 + public String toString() {
44 + return userData ? value : "{" + value + "}";
45 + }
46 + }
47 +
48 + private final String templateIdCode;
49 + private Map<String, SubstitutionValue> templateSubstitutionNamedValues;
50 +
51 + /**
52 + * Convert the templateIdCode (parameter) into an acceptable string form for
53 + * the templateIdCode.
54 + *
55 + * @param templateIdCode Template Identifying Code
56 + */
57 + public E13nData( Object templateIdCode ) {
58 + this.templateIdCode = Assert.noEmptyToString( "templateIdCode", templateIdCode );
59 + }
60 +
61 + private synchronized E13nData addPair( boolean userData, String name, String value ) {
62 + name = Assert.noEmpty( "name", name );
63 + if ( templateSubstitutionNamedValues == null ) {
64 + templateSubstitutionNamedValues = new HashMap<String, SubstitutionValue>();
65 + }
66 + templateSubstitutionNamedValues.put( name, new SubstitutionValue( userData, value ) );
67 + return this;
68 + }
69 +
70 + /**
71 + * Add a User Substitution Named Value.
72 + *
73 + * @param name Not allowed to be empty
74 + * @param userData null converted to ""
75 + */
76 + public E13nData addSubstitutionNamedUserData( String name, String userData ) {
77 + return addPair( true, name, StringUtils.deNull( userData ) );
78 + }
79 +
80 + /**
81 + * Add a User Substitution Named Value.
82 + *
83 + * @param name Not allowed to be empty
84 + * @param subTemplateIdCode Not allowed to be empty
85 + */
86 + public E13nData addSubstitutionNamedSubTemplateIdCode( String name, String subTemplateIdCode ) {
87 + return addPair( false, name, Assert.noEmpty( "subTemplateIdCode", subTemplateIdCode ) );
88 + }
89 +
90 + /**
91 + * @return Not Empty TemplateIdCode
92 + */
93 + public String getTemplateIdCode() {
94 + return templateIdCode;
95 + }
96 +
97 + /**
98 + * @return Not null map of Template Substitution Named Values
99 + */
100 + public synchronized Map<String, SubstitutionValue> getTemplateSubstitutionNamedValues() {
101 + if ( templateSubstitutionNamedValues == null ) {
102 + return Collections.emptyMap();
103 + }
104 + return new HashMap<String, SubstitutionValue>( templateSubstitutionNamedValues ); // defensive copy for Thread Safety
105 + }
106 +
107 + @Override
108 + public String toString() {
109 + return getTemplateIdCode() + getTemplateSubstitutionNamedValues();
110 + }
111 + }