01: package org.andromda.metafacades.uml;
02:
03: import org.andromda.utils.StringUtilsHelper;
04: import org.apache.commons.lang.StringUtils;
05:
06: /**
07: * Provides the ability to <code>mask</code> names in a standard manner.
08: *
09: * @author Chad Brandon
10: */
11: public class NameMasker {
12: /**
13: * The <code>uppercase</code> mask.
14: */
15: public static final String UPPERCASE = "uppercase";
16:
17: /**
18: * The <code>underscore</code> mask.
19: */
20: public static final String UNDERSCORE = "underscore";
21:
22: /**
23: * The <code>upperunderscore</code> mask.
24: */
25: public static final String UPPERUNDERSCORE = "upperunderscore";
26:
27: /**
28: * The <code>lowercase</code> mask.
29: */
30: public static final String LOWERCASE = "lowercase";
31:
32: /**
33: * The <code>lowerunderscore</code> mask.
34: */
35: public static final String LOWERUNDERSCORE = "lowerunderscore";
36:
37: /**
38: * The <code>uppercamelcase</code> mask.
39: */
40: public static final String UPPERCAMELCASE = "uppercamelcase";
41:
42: /**
43: * The <code>lowercamelcase</code> mask.
44: */
45: public static final String LOWERCAMELCASE = "lowercamelcase";
46:
47: /**
48: * The <code>nospace</code> mask.
49: */
50: public static final String NOSPACE = "nospace";
51:
52: /**
53: * The <code>none</code> mask.
54: */
55: public static final String NONE = "none";
56:
57: /**
58: * Returns the name with the appropriate <code>mask</code> applied. The mask, must match one of the valid mask
59: * properties or will be ignored.
60: *
61: * @param name the name to be masked
62: * @param mask the mask to apply
63: * @return the masked name.
64: */
65: public static String mask(String name, String mask) {
66: mask = StringUtils.trimToEmpty(mask);
67: name = StringUtils.trimToEmpty(name);
68: if (!mask.equalsIgnoreCase(NONE)) {
69: if (mask.equalsIgnoreCase(UPPERCASE)) {
70: name = name.toUpperCase();
71: } else if (mask.equalsIgnoreCase(UNDERSCORE)) {
72: name = StringUtilsHelper.separate(name, "_");
73: } else if (mask.equalsIgnoreCase(UPPERUNDERSCORE)) {
74: name = StringUtilsHelper.separate(name, "_")
75: .toUpperCase();
76: } else if (mask.equalsIgnoreCase(LOWERCASE)) {
77: name = name.toLowerCase();
78: } else if (mask.equalsIgnoreCase(LOWERUNDERSCORE)) {
79: name = StringUtilsHelper.separate(name, "_")
80: .toLowerCase();
81: } else if (mask.equalsIgnoreCase(LOWERCAMELCASE)) {
82: name = StringUtilsHelper.lowerCamelCaseName(name);
83: } else if (mask.equalsIgnoreCase(UPPERCAMELCASE)) {
84: name = StringUtilsHelper.upperCamelCaseName(name);
85: } else if (mask.equalsIgnoreCase(NOSPACE)) {
86: name = StringUtils.deleteWhitespace(name);
87: }
88: }
89: return name;
90: }
91: }
|