1 19 20 21 package org.apache.cayenne.gen; 22 23 import org.apache.cayenne.project.validator.MappingNamesHelper; 24 import org.apache.cayenne.util.NameConverter; 25 26 31 public class StringUtils { 32 33 private static StringUtils sharedInstance = null; 34 35 public static StringUtils getInstance() 36 { 37 if (null == sharedInstance) 38 { 39 sharedInstance = new StringUtils(); 40 } 41 42 return sharedInstance; 43 } 44 45 public StringUtils() 46 { 47 super(); 48 } 49 50 53 public String formatVariableName(String variableName) { 54 if (MappingNamesHelper.getInstance().isReservedJavaKeyword(variableName)) { 55 return "_" + variableName; 56 } else { 57 return variableName; 58 } 59 } 60 61 66 public String stripPackageName(String aString) 67 { 68 if (aString == null || aString.length() == 0) 69 return aString; 70 71 int lastDot = aString.lastIndexOf('.'); 72 73 if ((-1 == lastDot) || ((aString.length() - 1) == lastDot) ) return aString; 74 75 return aString.substring(lastDot + 1); 76 } 77 78 83 public String stripClass(String aString) 84 { 85 if (aString == null || aString.length() == 0) 86 return aString; 87 88 int lastDot = aString.lastIndexOf('.'); 89 90 if (-1 == lastDot) return ""; 91 92 return aString.substring(0, lastDot); 93 } 94 95 100 public String capitalized(String name) { 101 if (name == null || name.length() == 0) 102 return name; 103 104 char c = Character.toUpperCase(name.charAt(0)); 105 return (name.length() == 1) ? Character.toString(c) : c + name.substring(1); 106 } 107 108 113 public static String uncapitalized(String aString) 114 { 115 if (aString == null || aString.length() == 0) 116 return aString; 117 118 char c = Character.toLowerCase(aString.charAt(0)); 119 return (aString.length() == 1) ? Character.toString(c) : c + aString.substring(1); 120 } 121 122 127 public String capitalizedAsConstant(String name) { 128 if (name == null || name.length() == 0) 129 return name; 130 131 return NameConverter.javaToUnderscored(name); 132 } 133 } 134 | Popular Tags |