List of usage examples for org.apache.commons.lang WordUtils capitalize
public static String capitalize(String str, char[] delimiters)
Capitalizes all the delimiter separated words in a String.
From source file:org.gatherdata.alert.notify.mail.internal.MailtoUrl.java
public Map<String, String> getHeaderMap() { if (headerMap == null) { headerMap = new HashMap<String, String>(); String mailQuery = internalUrl.getQuery(); if (mailQuery != null) { StringTokenizer headerTokens = new StringTokenizer(mailQuery, "&"); while (headerTokens.hasMoreTokens()) { String header = headerTokens.nextToken(); String[] headerAndValue = header.split("="); headerMap.put(WordUtils.capitalize(headerAndValue[0].toLowerCase(), new char[] { '-' }), headerAndValue[1]); }//from w ww . j a v a 2s.c o m } } return headerMap; }
From source file:oscar.util.SqlUtils.java
/** * A simple and convenient method for retrieving object by criteria from the database. The ActiveRecord pattern is assumed whereby and object represents a row in the database. * <p>// w ww. jav a 2s . com * * @param qry * String * @param classType * Class * @return List */ public static List getBeanList(String qry, Class classType) { ArrayList rec = new ArrayList(); int colCount = 0; ResultSet rs = null; try { rs = DBHandler.GetSQL(qry); ResultSetMetaData rsmd = rs.getMetaData(); colCount = rsmd.getColumnCount(); while (rs.next()) { int recordCount = 0; // used to check if an objects methods have been determined Object obj = null; Method method[] = null; Hashtable methodNameMap = new Hashtable(colCount); obj = classType.newInstance(); Class cls = obj.getClass(); method = cls.getDeclaredMethods(); // iterate through each field in record and set data in the appropriate // object field. Each matching method name is to be placed in a list of method names // to be used in subsequent iterations. This will reduce the overhead in having to search those names needlessly for (int i = 0; i < colCount; i++) { String colName = rsmd.getColumnName(i + 1); Object value = getNewType(rs, i + 1); // if this is the first record, get list of method names in object // and perform method invocation if (recordCount == 0) { for (int j = 0; j < method.length; j++) { String methodName = method[j].getName(); char[] b = { '_' }; String columnCase = WordUtils.capitalize(colName, b); columnCase = org.apache.commons.lang.StringUtils.remove(columnCase, '_'); columnCase = org.apache.commons.lang.StringUtils.capitalize(columnCase); if (methodName.equalsIgnoreCase("set" + colName)) { method[j].invoke(obj, new Object[] { value }); methodNameMap.put(new Integer(j), methodName); } else if (methodName.equalsIgnoreCase("set" + columnCase)) { method[j].invoke(obj, new Object[] { value }); methodNameMap.put(new Integer(j), methodName); } } } // else method names have been determined so perform invocations based on list else { for (Enumeration keys = methodNameMap.keys(); keys.hasMoreElements();) { Integer key = (Integer) keys.nextElement(); MiscUtils.getLogger().debug( method[key.intValue()].getName() + " value " + value.getClass().getName()); method[key.intValue()].invoke(obj, new Object[] { value }); } } } rec.add(obj); recordCount++; } } catch (SQLException e) { MiscUtils.getLogger().error("Error", e); } catch (IllegalAccessException e) { MiscUtils.getLogger().error("Error", e); } catch (InvocationTargetException e) { MiscUtils.getLogger().error("Error", e); } catch (InstantiationException e) { MiscUtils.getLogger().error("Error", e); } finally { try { if (rs != null) { rs.close(); } } catch (SQLException ex) { MiscUtils.getLogger().error("Error", ex); } } return rec; }