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