List of usage examples for org.apache.commons.lang StringUtils capitalize
public static String capitalize(String str)
Capitalizes a String changing the first letter to title case as per Character#toTitleCase(char) .
From source file:edu.ku.brc.af.ui.weblink.WebLinkEditorDlg.java
/** * //from ww w . j ava 2s . c o m */ protected void parseForFields() { if (isParsingError) { //baseUrlTF.setForeground(txtFGColor); baseUrlTF.setBackground(txtBGColor); isParsingError = false; enableUI(); } boolean wasIncomplete = isParsingIncomplete; fields.clear(); args.clear(); model.fire(); String baseStr = baseUrlTF.getText(); Pattern pattern = Pattern.compile("<.*?>"); Matcher matcher = pattern.matcher(baseStr); while (matcher.find()) { String token = matcher.group(0); if (token.length() > 2) { token = token.substring(1, token.length() - 1); if (StringUtils.contains(token, ">") || StringUtils.contains(token, "<")) { setURLToError(); return; } if (tableInfo == null || fieldInfoHash.get(token) != null) { if (tableInfo != null && token.equals("this")) { setURLToError(); return; } fields.put(token, token); String titleStr = titleHash.get(token); if (StringUtils.isEmpty(titleStr) && fieldInfoHash == null) { titleStr = StringUtils.capitalize(token); } model.addItem(token, titleStr, !token.equals("this")); } else { String titleStr = StringUtils.capitalize(token); model.addItem(token, titleStr, !token.equals("this")); } } } if (wasIncomplete != isParsingIncomplete) { enableUI(); } adjustAvailableJList(); format = baseStr; }
From source file:jos.parser.Parser.java
private void processProperty(String line, boolean appearance) { boolean ro = false; String getter = null;/* ww w . ja v a2s .c om*/ line = cleanDeclaration(line); if (line.length() == 0) { return; } int p = line.indexOf(')'); String sub = line.substring(0, p + 1); if (sub.indexOf("readonly") != -1) { ro = true; } int j = sub.indexOf("getter="); if (j != -1) { int k = StringUtils.indexOfAny(sub.substring(j + 1), ",)") + j + 1; // TODO check translation log("j=%d k=%d str=%s", j, k, sub); getter = sub.substring(j + 7, j + 7 + k - (j + 7)); } final StringBuilder type = new StringBuilder(); int i = p + 1; for (; i < line.length(); i++) { char c = line.charAt(i); if (!Character.isWhitespace(c)) { break; } } for (; i < line.length(); i++) { char c = line.charAt(i); if (Character.isWhitespace(c)) { break; } type.append(c); } for (; i < line.length(); i++) { char c = line.charAt(i); if (Character.isWhitespace(c) || c == '*') { continue; } else { break; } } final StringBuilder selector = new StringBuilder(); for (; i < line.length(); i++) { char c = line.charAt(i); if (Character.isWhitespace(c) || c == ';') { break; } selector.append(c); } if (extraAnnotation != null) { gencs.println("\t/**"); gencs.printf("\t * @%s", extraAnnotation); gencs.println(); gencs.println("\t */"); } if (appearance) { gencs.printf("\t@Appearance"); gencs.println(); } //gencs.printf("\t@Export(\"%s\")", selector); //gencs.println(); final String retval = remapType(type.toString()); // gencs.printf("\tpublic %s %s;", retval, selector); // gencs.println(); // gencs.println(); if (getter != null) { gencs.printf("\t@Bind(\"" + getter + "\")"); gencs.println(); } gencs.printf("\t@Export(\"%s\")", selector.toString()); gencs.println(); gencs.printf("\tpublic %s get%s() {", retval, StringUtils.capitalize(selector.toString())); gencs.println(); gencs.printf("\t\tthrow new RuntimeException();"); gencs.println(); gencs.printf("\t}"); gencs.println(); gencs.println(); if (!ro) { gencs.printf("\t@Export(\"set%s:\")", StringUtils.capitalize(selector.toString())); gencs.println(); gencs.printf("\tpublic void set%s(%s value) {", StringUtils.capitalize(selector.toString()), retval); gencs.println(); gencs.printf("\t\tthrow new RuntimeException();"); gencs.println(); gencs.printf("\t}"); gencs.println(); gencs.println(); } }
From source file:edu.upenn.mkse212.pennbook.server.UserServiceImpl.java
private String likeClauses(String term) { final String TEMPLATE = "%s LIKE '%s%%'"; String[] subterms = term.split(" "); ArrayList<String> variants = new ArrayList<String>(); for (int i = 0; i < subterms.length && i < 4; i++) { String[] clauses = new String[4]; //lowercase and capitalized (but not all uppercase) forms for first name and last name clauses[0] = String.format(TEMPLATE, LAST_NAME_ATTR, StringUtils.capitalize(subterms[i])); clauses[1] = String.format(TEMPLATE, LAST_NAME_ATTR, StringUtils.lowerCase(subterms[i])); clauses[2] = String.format(TEMPLATE, FIRST_NAME_ATTR, StringUtils.capitalize(subterms[i])); clauses[3] = String.format(TEMPLATE, FIRST_NAME_ATTR, StringUtils.lowerCase(subterms[i])); variants.add("(" + StringUtils.join(clauses, " OR ") + ")"); }/* w w w . j a v a 2 s . co m*/ return StringUtils.join(variants, " AND "); }
From source file:com.ocs.dynamo.utils.ClassUtils.java
/** * Retrieves the getter method for a certain property * /* w w w . j ava2s . co m*/ * @param clazz * the class * @param fieldName * the name of the property * @return */ public static Method getGetterMethod(Class<?> clazz, String fieldName) { Method method = null; if (clazz != null) { try { // first, try to find a "get" method method = clazz.getDeclaredMethod(GET + StringUtils.capitalize(fieldName), new Class[] {}); } catch (NoSuchMethodException | SecurityException ex) { try { // next, try to find an "is" method method = clazz.getDeclaredMethod(IS + StringUtils.capitalize(fieldName), new Class[] {}); } catch (NoSuchMethodException | SecurityException ex2) { // if that fails, try the superclass if (clazz.getSuperclass() != null) { return getGetterMethod(clazz.getSuperclass(), fieldName); } } } } return method; }
From source file:com.qcadoo.model.internal.classconverter.ModelXmlToClassConverterImpl.java
private void buildToString(final CtClass ctClass, final List<String> fields) throws ModelXmlCompilingException { try {//from ww w . j av a 2 s. co m StringBuilder sb = new StringBuilder(); sb.append("return new java.lang.StringBuilder().append(\"" + ctClass.getName() + "[\")."); boolean first = true; for (String field : fields) { if (first) { first = false; } else { sb.append("append(\",\")."); } sb.append("append(\"" + field + "=\").append(get" + StringUtils.capitalize(field) + "())."); } sb.append("append(\"]\").toString();"); ctClass.addMethod(CtNewMethod.make("public String toString() { " + sb.toString() + " }", ctClass)); } catch (CannotCompileException e) { throw new ModelXmlCompilingException(L_FAILED_TO_COMPILE_CLASS + ctClass.getName(), e); } }
From source file:com.microsoft.office.plugin.AbstractUtility.java
public String capitalize(final String str) { return StringUtils.capitalize(str); }
From source file:com.redhat.red.offliner.PomArtifactListReaderTest.java
private void check(final String subject, final List<String> heap, final String needle, final boolean present) { if (present) { String msg = StringUtils.capitalize(subject) + " " + needle + " was not found in the result"; assertTrue(msg, heap.contains(needle)); } else {//from ww w . j ava2 s. co m assertFalse("Additional " + subject + " " + needle + " was found in the result", heap.contains(needle)); } }
From source file:edu.ku.brc.dbsupport.DatabaseDriverInfo.java
/** * Reads the Form Registry. The forms are loaded when needed and onlu one ViewSet can be the "core" ViewSet which is where most of the forms * reside. This could also be thought of as the "default" set of forms. * @return the list of info objects/*from w w w . j ava 2s. c o m*/ */ protected static Vector<DatabaseDriverInfo> loadDatabaseDriverInfo() { Vector<DatabaseDriverInfo> dbDrivers = new Vector<DatabaseDriverInfo>(); try { Element root = XMLHelper .readFileToDOM4J(new FileInputStream(XMLHelper.getConfigDirPath("dbdrivers.xml"))); //$NON-NLS-1$ if (root != null) { Hashtable<String, String> hash = new Hashtable<String, String>(); for (Iterator<?> i = root.elementIterator("db"); i.hasNext();) //$NON-NLS-1$ { Element dbElement = (Element) i.next(); String name = getAttr(dbElement, "name", null); //$NON-NLS-1$ if (hash.get(name) == null) { hash.put(name, name); String driver = getAttr(dbElement, "driver", null); //$NON-NLS-1$ String dialect = getAttr(dbElement, "dialect", null); //$NON-NLS-1$ String port = getAttr(dbElement, "port", null); //$NON-NLS-1$ boolean isEmbedded = getAttr(dbElement, "embedded", false); //$NON-NLS-1$ if (UIRegistry.isEmbedded() || UIRegistry.isMobile()) // Application is Embedded { if (!isEmbedded) { continue; } } else if (isEmbedded) { continue; } // these can go away once we validate the XML if (StringUtils.isEmpty(driver)) { throw new RuntimeException("Driver cannot be null!"); //$NON-NLS-1$ } if (StringUtils.isEmpty(driver)) { throw new RuntimeException("Dialect cannot be null!"); //$NON-NLS-1$ } DatabaseDriverInfo drv = new DatabaseDriverInfo(name, driver, dialect, isEmbedded, port); // Load up the Connection Types for (Iterator<?> connIter = dbElement.elementIterator("connection"); connIter.hasNext();) //$NON-NLS-1$ { Element connElement = (Element) connIter.next(); String typeStr = getAttr(connElement, "type", null); //$NON-NLS-1$ String connFormat = connElement.getTextTrim(); ConnectionType type = ConnectionType.valueOf(StringUtils.capitalize(typeStr)); drv.addFormat(type, connFormat); } /*if (drv.getConnectionStr(DatabaseDriverInfo.ConnectionType.Open, " ", " ", " ", " ", " ") == null) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ { log.error("Meg might've screwed up generating connection strings, contact her if you get this error"); //$NON-NLS-1$ throw new RuntimeException("Dialect ["+name+"] has no 'Open' connection type!"); //$NON-NLS-1$ //$NON-NLS-2$ }*/ dbDrivers.add(drv); } else { log.error("Database Driver Name[" + name + "] is in use."); //$NON-NLS-1$ //$NON-NLS-2$ } } } else { String msg = "The root element for the document was null!"; //$NON-NLS-1$ log.error(msg); throw new ConfigurationException(msg); } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DatabaseDriverInfo.class, ex); ex.printStackTrace(); log.error(ex); } Collections.sort(dbDrivers); return dbDrivers; }
From source file:edu.ku.brc.specify.utilapps.DataModelClassGenerator.java
public void process() { String template = ""; try {/*from w w w. j av a2 s . c om*/ File templateFile = new File("src/edu/ku/brc/specify/utilapps/DataModelGenTemplate.txt"); template = FileUtils.readFileToString(templateFile); } catch (IOException ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DataModelClassGenerator.class, ex); ex.printStackTrace(); return; } String className = dataClass.getSimpleName(); String noCapClassName = className.substring(0, 1).toLowerCase() + className.substring(1); String idName = className.substring(0, 1).toLowerCase() + className.substring(1) + "Id"; SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy"); template = StringUtils.replace(template, "<!-- TableName -->", className.toLowerCase()); template = StringUtils.replace(template, "<!-- ClassName -->", className); template = StringUtils.replace(template, "<!-- Id -->", idName); template = StringUtils.replace(template, "<!-- IdNum -->", tableIdTxt.getText()); template = StringUtils.replace(template, "<!-- Dev -->", devTxt.getText()); template = StringUtils.replace(template, "<!-- Date -->", sdf.format(Calendar.getInstance().getTime())); Hashtable<String, Boolean> duplicateClassNames = new Hashtable<String, Boolean>(); for (Field field : dataClass.getDeclaredFields()) { UIRow row = fieldRowhash.get(field); String fieldsType = (row != null && row.getSizetxt() != null) ? row.getSizetxt().getText() : field.getType().getSimpleName(); Boolean bool = duplicateClassNames.get(fieldsType); if (bool == null) { duplicateClassNames.put(fieldsType, false); } else if (!bool) { duplicateClassNames.put(fieldsType, true); } } StringBuilder declarationsSB = new StringBuilder(); StringBuilder initersSB = new StringBuilder(); StringBuilder methodsSB = new StringBuilder(); StringBuilder osDeclarationsSB = new StringBuilder(); StringBuilder osInitersSB = new StringBuilder(); StringBuilder osMethodsSB = new StringBuilder(); // Initializer int maxWidth = 0; for (Field field : dataClass.getDeclaredFields()) { String typeStr; UIRow row = fieldRowhash.get(field); if (row != null && row.isSet()) { typeStr = field.getType().getSimpleName() + "<" + row.getSizetxt().getText() + ">"; } else { typeStr = field.getType().getSimpleName(); } maxWidth = Math.max(maxWidth, typeStr.length()); } int initerMaxWidth = 0; for (Field field : dataClass.getDeclaredFields()) { initerMaxWidth = Math.max(initerMaxWidth, field.getName().length()); } String prevType = ""; for (Field field : dataClass.getDeclaredFields()) { String fieldName = field.getName(); UIRow row = fieldRowhash.get(field); boolean isSet = row != null && row.isSet(); boolean isThereMoreThanOne = false; String othersideClassType = ""; String othersideFieldName = ""; String othersideMethodName = ""; String otherSideID = ""; boolean isFieldObj = false; String fieldsType; if (row != null) { fieldsType = isSet ? row.getSizetxt().getText() : field.getType().getSimpleName(); } else { fieldsType = field.getType().getSimpleName(); } //System.out.println("isField["+fieldsType+"]["+isFieldObj + "] " + fieldName); //String checkClass = ""; if (!isSet) { // Check to see if the field is a basic Java type we should ignore // or a Data Object we need to hook up isFieldObj = baseClassHash.get(fieldsType) != null;// Check to see if it is a basic type if (!isFieldObj) { othersideClassType = "Set<" + className + ">"; isThereMoreThanOne = duplicateClassNames.get(fieldsType) != null && duplicateClassNames.get(fieldsType); if (isThereMoreThanOne) { // OK since it isn't a basic field than it is a Set of this class String fName = fieldName.substring(0, fieldName.length() - 1); othersideFieldName = fName + className + "s"; othersideMethodName = StringUtils.capitalize(fName) + className + "s"; otherSideID = fName + className + "ID"; } else { othersideFieldName = noCapClassName + "s"; othersideMethodName = className + "s"; otherSideID = className + "ID"; } } } else { // Since this side is a Set than the otherside will be just this class othersideClassType = className; isThereMoreThanOne = duplicateClassNames.get(fieldsType) != null && duplicateClassNames.get(fieldsType); if (isThereMoreThanOne) { String fName = fieldName.substring(0, fieldName.length() - 1); othersideFieldName = fName + className; othersideMethodName = StringUtils.capitalize(fName) + className; otherSideID = fName + className + "ID"; } else { othersideFieldName = noCapClassName; othersideMethodName = className; otherSideID = className + "ID"; } } boolean isNewOSClassType = !fieldsType.equals(prevType); if (isNewOSClassType) { prevType = fieldsType; } boolean doOtherSide = isSet || !isFieldObj; //------------------------------------- // Declarations //------------------------------------- String typeStr; if (row != null && row.isSet()) { typeStr = field.getType().getSimpleName() + "<" + row.getSizetxt().getText() + ">"; } else { typeStr = field.getType().getSimpleName(); } declarationsSB.append(" protected "); declarationsSB.append(typeStr); for (int i = 0; i < (maxWidth - typeStr.length() + 1); i++) { declarationsSB.append(' '); } declarationsSB.append(field.getName()); declarationsSB.append(";\n"); if (doOtherSide) { if (isNewOSClassType) { osDeclarationsSB.append("\n\n // Copy this Code into Class " + fieldsType + "\n\n"); } // use the same width (just because) osDeclarationsSB.append(" protected "); osDeclarationsSB.append(othersideClassType); for (int i = 0; i < (maxWidth - typeStr.length() + 1); i++) { osDeclarationsSB.append(' '); } osDeclarationsSB.append(othersideFieldName); osDeclarationsSB.append(";\n"); } //------------------------------------- // Initers //------------------------------------- if (row != null && row.isSet()) { typeStr = "new HashSet<" + row.getSizetxt().getText() + ">()"; } else { typeStr = "null"; } initersSB.append(" "); initersSB.append(field.getName()); for (int i = 0; i < (initerMaxWidth - field.getName().length() + 1); i++) { initersSB.append(' '); } initersSB.append(" = "); initersSB.append(typeStr); initersSB.append(";\n"); if (doOtherSide && !isFieldObj) { if (isNewOSClassType) { osInitersSB.append("\n\n // Copy this Code into Class " + fieldsType + "\n\n"); } osInitersSB.append(" "); osInitersSB.append(othersideFieldName); for (int i = 0; i < (initerMaxWidth - field.getName().length() + 1); i++) { osInitersSB.append(' '); } osInitersSB.append(" = "); if (othersideClassType.startsWith("Set")) { osInitersSB.append( "new HashSet<" + (row != null ? row.getSizetxt().getText() : className) + ">()"); } else { osInitersSB.append("null"); } osInitersSB.append(";\n"); } // Do Methods if (isSet) { typeStr = field.getType().getSimpleName() + "<" + row.getSizetxt().getText() + ">"; isSet = true; } else { typeStr = field.getType().getSimpleName(); } methodsSB.append(" /**\n"); methodsSB.append(" *\n"); methodsSB.append(" */\n"); String size = ""; if (row != null) { if (row.isCBXString()) { size = row.getSizetxt().getText(); } else if (row.getType() != DataType.Set) { methodsSB.append(" @Lob\n"); } } else if (field.getType() == Date.class || field.getType() == Calendar.class) { methodsSB.append(" @Temporal(TemporalType.DATE)\n"); } if (isSet) { String singularFieldName = field.getName().substring(0, fieldName.length() - 1); methodsSB.append(" @OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = \"" + singularFieldName + "\")\n"); } else if (baseClassHash.get(field.getType()) != null) { methodsSB.append(" @Column(name = \"" + StringUtils.capitalize(fieldName) + "\", unique = false, nullable = true, insertable = true, updatable = true" + (StringUtils.isNotEmpty(size) ? (", length = " + size + "") : "") + ")\n"); } else { methodsSB.append(" @ManyToOne(cascade = {}, fetch = FetchType.LAZY)\n"); methodsSB.append( " @Cascade( { CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.LOCK })\n"); methodsSB.append(" @JoinColumn(name = \"" + className + "ID\", unique = false, nullable = true, insertable = true, updatable = true)\n"); } methodsSB.append(" public " + typeStr + " get" + StringUtils.capitalize(fieldName) + "()\n {\n"); methodsSB.append(" return this." + fieldName + ";\n"); methodsSB.append(" }\n\n"); methodsSB.append(" public void set" + StringUtils.capitalize(fieldName) + "(final " + typeStr + " " + fieldName + ")\n {\n"); methodsSB.append(" this." + fieldName + " = " + fieldName + ";\n"); methodsSB.append(" }\n\n"); if (fieldsType.startsWith("Agent")) { int x = 0; x++; } if (doOtherSide && !isFieldObj) { if (isNewOSClassType) { osMethodsSB.append("\n\n // Copy this Code into Class " + fieldsType + "\n\n"); } osMethodsSB.append(" /**\n"); osMethodsSB.append(" *\n"); osMethodsSB.append(" */\n"); if (isSet) { osMethodsSB.append(" @OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = \"" + fieldName + "\")\n"); } else { osMethodsSB.append(" @ManyToOne(cascade = {}, fetch = FetchType.LAZY)\n"); osMethodsSB.append( " @Cascade( { CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.LOCK })\n"); osMethodsSB.append(" @JoinColumn(name = \"" + otherSideID + "\", unique = false, nullable = true, insertable = true, updatable = true)\n"); } osMethodsSB .append(" public " + othersideClassType + " get" + othersideMethodName + "()\n {\n"); osMethodsSB.append(" return this." + othersideFieldName + ";\n"); osMethodsSB.append(" }\n\n"); osMethodsSB.append(" public void set" + othersideMethodName + "(final " + othersideClassType + " " + othersideFieldName + ")\n {\n"); osMethodsSB.append(" this." + othersideFieldName + " = " + othersideFieldName + ";\n"); osMethodsSB.append(" }\n\n"); } } template = StringUtils.replace(template, "<!-- Fields -->", declarationsSB.toString()); template = StringUtils.replace(template, "<!-- Initers -->", initersSB.toString()); template = StringUtils.replace(template, "<!-- Methods -->", methodsSB.toString()); StringBuilder sb = new StringBuilder(); sb.append("/* ---------------------------------------------\n"); sb.append(osDeclarationsSB); sb.append(osInitersSB); sb.append(osMethodsSB); sb.append("\n*/"); logArea.setText(template + sb.toString()); try { File outFile = new File(className + ".java"); FileUtils.writeStringToFile(outFile, template + sb.toString()); } catch (IOException ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DataModelClassGenerator.class, ex); ex.printStackTrace(); } }
From source file:adalid.core.jee.AbstractJavaWebModule.java
private String pageName(Entity entity, EntityReference reference, DisplayMode mode, DisplayFormat format) { String name = entity.getName() + mode.ordinal() + format.ordinal(); if (reference != null) { name += BY + StringUtils.capitalize(reference.getName()); }/*from w ww . j av a2 s . c o m*/ logger.debug("page=" + name); return name; }