Subversion Repository Public Repository

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
127
package org.litesoft.core.util.externalization;

import java.util.*;

import org.litesoft.core.typeutils.*;
import org.litesoft.core.typeutils.Objects;

/**
 * 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 = Objects.assertNoEmptyToString( "templateIdCode", templateIdCode );
    }

    private synchronized E13nData addPair( boolean userData, String name, String value )
    {
        name = Strings.assertNotNullNotEmpty( "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, Strings.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, Strings.assertNotNullNotEmpty( "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();
    }
}

Commits for litesoft/trunk/Java/core/Anywhere/src/org/litesoft/core/util/externalization/E13nData.java

Diff revisions: vs.
Revision Author Commited Message
917 Diff Diff GeorgeS picture GeorgeS Sun 08 Dec, 2013 20:49:56 +0000

1.7 prep & VersionedStaticContentFilter upgrade to new “/ver” model!

822 Diff Diff GeorgeS picture GeorgeS Sun 19 Aug, 2012 01:03:51 +0000
821 Diff Diff GeorgeS picture GeorgeS Sun 19 Aug, 2012 00:08:41 +0000
802 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 04:04:47 +0000
726 Diff Diff GeorgeS picture GeorgeS Thu 14 Jun, 2012 13:33:38 +0000
725 GeorgeS picture GeorgeS Mon 11 Jun, 2012 00:50:44 +0000