1 package org.andromda.metafacades.uml;
2
3 import java.text.Normalizer;
4
5 import org.andromda.utils.StringUtilsHelper;
6 import org.apache.commons.lang.StringUtils;
7
8
9
10
11
12
13 public class NameMasker
14 {
15
16
17
18 public static final String UPPERCASE = "uppercase";
19
20
21
22
23 public static final String UNDERSCORE = "underscore";
24
25
26
27
28 public static final String UPPERUNDERSCORE = "upperunderscore";
29
30
31
32
33 public static final String LOWERCASE = "lowercase";
34
35
36
37
38 public static final String LOWERUNDERSCORE = "lowerunderscore";
39
40
41
42
43 public static final String UPPERCAMELCASE = "uppercamelcase";
44
45
46
47
48 public static final String LOWERCAMELCASE = "lowercamelcase";
49
50
51
52
53 public static final String NOSPACE = "nospace";
54
55
56
57
58 public static final String NOACCENT = "noaccent";
59
60
61
62
63 public static final String NONE = "none";
64
65
66
67
68
69
70
71
72
73 public static String mask(String name, String mask)
74 {
75 mask = StringUtils.trimToEmpty(mask);
76 name = StringUtils.trimToEmpty(name);
77 if (!mask.equalsIgnoreCase(NONE))
78 {
79 if (mask.equalsIgnoreCase(UPPERCASE))
80 {
81 name = name.toUpperCase();
82 }
83 else if (mask.equalsIgnoreCase(UNDERSCORE))
84 {
85 name = StringUtilsHelper.separate(name, "_");
86 }
87 else if (mask.equalsIgnoreCase(UPPERUNDERSCORE))
88 {
89 name = StringUtilsHelper.separate(name, "_").toUpperCase();
90 }
91 else if (mask.equalsIgnoreCase(LOWERCASE))
92 {
93 name = name.toLowerCase();
94 }
95 else if (mask.equalsIgnoreCase(LOWERUNDERSCORE))
96 {
97 name = StringUtilsHelper.separate(name, "_").toLowerCase();
98 }
99 else if (mask.equalsIgnoreCase(LOWERCAMELCASE))
100 {
101 name = StringUtilsHelper.lowerCamelCaseName(name);
102 }
103 else if (mask.equalsIgnoreCase(UPPERCAMELCASE))
104 {
105 name = StringUtilsHelper.upperCamelCaseName(name);
106 }
107 else if (mask.equalsIgnoreCase(NOSPACE))
108 {
109 name = StringUtils.deleteWhitespace(name);
110 }
111 else if (mask.equalsIgnoreCase(NOACCENT))
112 {
113 name = Normalizer.normalize(name, java.text.Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]","");
114 }
115 }
116 return name;
117 }
118 }