1 56 57 package org.objectstyle.cayenne.gen; 58 59 import org.objectstyle.cayenne.project.validator.MappingNamesHelper; 60 import org.objectstyle.cayenne.util.NameConverter; 61 62 67 public class StringUtils { 68 69 private static StringUtils sharedInstance = null; 70 71 public static StringUtils getInstance() 72 { 73 if (null == sharedInstance) 74 { 75 sharedInstance = new StringUtils(); 76 } 77 78 return sharedInstance; 79 } 80 81 public StringUtils() 82 { 83 super(); 84 } 85 86 89 public String formatVariableName(String variableName) { 90 if (MappingNamesHelper.getInstance().isReservedJavaKeyword(variableName)) { 91 return "_" + variableName; 92 } else { 93 return variableName; 94 } 95 } 96 97 102 public String stripPackageName(String aString) 103 { 104 if (aString == null || aString.length() == 0) 105 return aString; 106 107 int lastDot = aString.lastIndexOf('.'); 108 109 if ((-1 == lastDot) || ((aString.length() - 1) == lastDot) ) return aString; 110 111 return aString.substring(lastDot + 1); 112 } 113 114 119 public String stripClass(String aString) 120 { 121 if (aString == null || aString.length() == 0) 122 return aString; 123 124 int lastDot = aString.lastIndexOf('.'); 125 126 if (-1 == lastDot) return ""; 127 128 return aString.substring(0, lastDot); 129 } 130 131 136 public String capitalized(String name) { 137 if (name == null || name.length() == 0) 138 return name; 139 140 char c = Character.toUpperCase(name.charAt(0)); 141 return (name.length() == 1) ? Character.toString(c) : c + name.substring(1); 142 } 143 144 149 public static String uncapitalized(String aString) 150 { 151 if (aString == null || aString.length() == 0) 152 return aString; 153 154 char c = Character.toLowerCase(aString.charAt(0)); 155 return (aString.length() == 1) ? Character.toString(c) : c + aString.substring(1); 156 } 157 158 163 public String capitalizedAsConstant(String name) { 164 if (name == null || name.length() == 0) 165 return name; 166 167 return NameConverter.javaToUnderscored(name); 168 } 169 } | Popular Tags |