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:net.sourceforge.fenixedu.presentationTier.Action.externalServices.DomainObjectJSONSerializer.java
public static JSONObject getDomainObject(DomainObject obj) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { final JSONObject jsonObject = new JSONObject(); final Class<? extends DomainObject> clazz = obj.getClass(); final String objClassName = clazz.getName(); jsonObject.put("externalId", obj.getExternalId()); jsonObject.put("className", objClassName); final DomainClass domainClass = getDomainClass(objClassName); if (domainClass == null) { return jsonObject; }//from w ww.j a v a 2 s.c o m for (Slot slot : getAllSlots(domainClass)) { final String slotName = slot.getName(); final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName)); final Object result = method.invoke(obj); jsonObject.put(slotName, result == null ? null : result.toString()); } for (Role roleSlot : getAllRoleSlots(domainClass)) { final String slotName = roleSlot.getName(); if (roleSlot.getMultiplicityUpper() == 1) { final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName)); final AbstractDomainObject singleRelationObj = (AbstractDomainObject) method.invoke(obj); final JSONArray oneRelation = new JSONArray(); if (singleRelationObj != null) { oneRelation.add(singleRelationObj.getExternalId()); } jsonObject.put(slotName, oneRelation); } else { final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName) + "Set"); final Set<? extends AbstractDomainObject> result = (Set<? extends AbstractDomainObject>) method .invoke(obj); jsonObject.put(slotName, serializeRelation(result)); } } return jsonObject; }
From source file:com.github.pfmiles.minvelocity.biztest.ApiCodeGenUtilTest.java
private static List<JavaSourceFile> genResultPojos(List<NsInfo> infos, Site site) { List<JavaSourceFile> ret = new ArrayList<JavaSourceFile>(); for (NsInfo ns : infos) { for (ApiInfo api : ns.getApiInfos()) { Map<String, Object> ctxPojo = getCtxMap(); ctxPojo.put("site", site); ctxPojo.put("api", api); ctxPojo.put("ns", ns); JavaSourceFile rstFile = new JavaSourceFile( StringUtils.capitalize(api.getMethodName()) + "Result.java", site.getBasePkgName() + ".result." + ns.getNsName(), TemplateUtil.render("sdkTemp/code/apiResult.vm", ctxPojo)); // JavaCodeFormattingUtil.tryFormat(rstFile); ret.add(rstFile);/*from www . j a v a 2s .c o m*/ // ?result?? for (DeepAttrInfo deepInfo : extractDeepInfos(api.getResultInfo())) { Map<String, Object> deepCtx = getCtxMap(); deepCtx.put("site", site); deepCtx.put("ns", ns); deepCtx.put("deepInfo", deepInfo); JavaSourceFile deepFile = new JavaSourceFile( StringUtils.capitalize(deepInfo.getAttClsName()) + ".java", site.getBasePkgName() + ".result." + ns.getNsName(), TemplateUtil.render("sdkTemp/code/deepResultBean.vm", deepCtx)); // JavaCodeFormattingUtil.tryFormat(deepFile); ret.add(deepFile); } } } return ret; }
From source file:ac.elements.parser.ExtendedFunctions.java
/** * The main method./*from w w w . j av a 2s . co m*/ * * @param args * the arguments */ public static void main(String[] args) { java.math.BigInteger myInt = new java.math.BigInteger("1223"); System.out.println(myInt); System.out.println(ExtendedFunctions.timePeriod(myInt)); myInt = new java.math.BigInteger("59000"); System.out.println(myInt); System.out.println(ExtendedFunctions.timePeriod(myInt)); myInt = new java.math.BigInteger("59900"); System.out.println(myInt); System.out.println(ExtendedFunctions.timePeriod(myInt)); myInt = new java.math.BigInteger("5990000"); System.out.println(myInt); System.out.println(ExtendedFunctions.timePeriod(myInt)); myInt = new java.math.BigInteger("599000000"); System.out.println(myInt); System.out.println(ExtendedFunctions.timePeriod(myInt)); myInt = new java.math.BigInteger("59900000000"); System.out.println(myInt); System.out.println(ExtendedFunctions.timePeriod(myInt)); String sql = "select * from domain where `this`='test' and this2=\"test\""; System.out.println(ExtendedFunctions.escapeSql(sql)); String unformattedXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><QueryMessage\n" + " xmlns=\"http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message\"\n" + " xmlns:query=\"http://www.SDMX.org/resources/SDMXML/schemas/v2_0/query\">\n" + " <Query>\n" + " <query:CategorySchemeWhere>\n" + " \t\t\t\t\t <query:AgencyID>ECB\n\n\n\n</query:AgencyID>\n" + " </query:CategorySchemeWhere>\n" + " </Query>\n\n\n\n\n" + "</QueryMessage>"; System.out.println(ExtendedFunctions.formatXml(unformattedXml)); String company = "international business MACHINES. iag is here."; System.out.println(ExtendedFunctions.capitalize(company)); String url = "\u1087\u1088\u1077\u1076\u1089"; System.out.println(url); System.out.println(ExtendedFunctions.escUniJs(url)); System.out.println(ExtendedFunctions.toUnicodeHTML(url)); ExtendedFunctions.trim(url); url = "http://news.google.com/news?hl=en&client=safari&rls=en-us&q=get%20part%20of%20paragraph%20words%20google%20algorithm&um=1&ie=UTF-8&sa=N&tab=wn"; System.out.println(ExtendedFunctions.chopUrl(url, 30)); url = "http://www.pcplus.co.uk/node/3061/"; System.out.println(ExtendedFunctions.chopUrl(url, 30)); url = "http://www.opent.net/forum/security-problem-with-ot-script-on-ssl-t159.html"; System.out.println(ExtendedFunctions.chopUrl(url, 30)); System.out.println(ExtendedFunctions.escapeJavaScript("escapeJavas'\"cript")); System.err.println(StringUtils.abbreviate("Take time off working", 0, 10)); System.err.println(StringUtils.capitalize("how is vandersar doing?")); String unescapedJava = "Are you \" for real?"; System.err.println(StringEscapeUtils.escapeJava(unescapedJava)); String unescapedJavaScript = "What's in a name?"; System.err.println(ExtendedFunctions.escapeJavaScript(unescapedJavaScript)); String unescapedSql = "Mc'Williams"; System.err.println(StringEscapeUtils.escapeSql(unescapedSql)); String unescapedXML = "<data>"; System.err.println(StringEscapeUtils.escapeXml(unescapedXML)); String unescapedHTML = "the data is <data>"; System.err.println(StringEscapeUtils.escapeHtml(unescapedHTML)); System.err.println(WordUtils.capitalize(unescapedHTML)); System.err.println(WordUtils.swapCase(unescapedHTML)); }
From source file:com.belle.infrastructure.util.ReflectionUtils.java
/** * Setter.//w w w. ja v a 2 s .co m * * @param propertyType Setter,valueClass. */ public static void invokeSetterMethod(Object target, String propertyName, Object value, Class<?> propertyType) { Class<?> type = propertyType != null ? propertyType : value.getClass(); String setterMethodName = "set" + StringUtils.capitalize(propertyName); invokeMethod(target, setterMethodName, new Class[] { type }, new Object[] { value }); }
From source file:cn.fastmc.core.utils.ReflectionUtils.java
/** * Getter.//from w w w . jav a2 s.c o m * * @param target * Object * @param propertyName * ?? * * @return Object */ public static <T> T invokeGetterMethod(Object target, String propertyName) { String getterMethodName = "get" + StringUtils.capitalize(propertyName); return (T) invokeMethod(target, getterMethodName, new Class[] {}, new Object[] {}); }
From source file:jp.primecloud.auto.nifty.soap.NiftyCloudJaxWsPortProxyFactoryBean.java
/** * {@inheritDoc}//from w w w. j a v a 2 s . c om */ @Override protected Object doInvoke(MethodInvocation invocation) throws Throwable { try { return super.doInvoke(invocation); } catch (Exception e) { // API?? String method = StringUtils.capitalize(invocation.getMethod().getName()); // String request = null; if (invocation.getArguments() != null || invocation.getArguments().length != 0) { request = jp.primecloud.auto.util.StringUtils.reflectToString(invocation.getArguments()[0]); } AutoException autoException; if (e instanceof JaxWsSoapFaultException) { JaxWsSoapFaultException ex = JaxWsSoapFaultException.class.cast(e); autoException = new AutoException("ENIFTY-000002", e, method, ex.getFaultCode(), ex.getFaultString(), request); } else { autoException = new AutoException("ENIFTY-000001", e, method, request); } throw autoException; } }
From source file:de.erdesignerng.generator.openxava.OpenXavaOptions.java
public String createTableName(String aName) { return StringUtils.capitalize(aName.toLowerCase()); }
From source file:com.neelo.glue.st.StringRenderer.java
public String toString(Object o, String format) { try {/*w ww . j a v a 2s .c om*/ String[] formats = format.split("[,]"); String formatted = o.toString(); for (String f : formats) { f = f.trim(); if (f.equals("uppercase")) formatted = formatted.toUpperCase(); else if (f.equals("lowercase")) formatted = formatted.toLowerCase(); else if (f.equals("capitalize")) formatted = StringUtils.capitalize(formatted); else if (f.startsWith("abbreviate")) { String[] parts = f.split("[:]"); if (parts.length == 2) { formatted = StringUtils.abbreviate(formatted, Integer.parseInt(parts[1].trim())); } } else if (f.equals("encode")) formatted = URLEncoder.encode(o.toString(), "UTF-8"); else if (f.equals("csv")) { formatted = formatted.replace("\"", "\"\""); formatted = "\"" + formatted + "\""; } } return formatted; } catch (Exception e) { return toString(o); } }
From source file:com.agimatec.annotations.jam.JAMDtoGenerator.java
/** * replacement for the freemarker build-in ?capitalize: * this creates a capatialized string according to java property standards. * Freemarker instead lowers all characters expect the first one. * * @param string/*from w w w.j a v a 2 s.c om*/ * @return */ public String capitalize(String string) { return StringUtils.capitalize(string); }
From source file:com.ocs.dynamo.utils.ClassUtils.java
/** * Checks if the specified property can be set for the specified object. This method supports * nested properties// w w w . j a v a 2 s. com * * @param obj * the object * @param fieldName * the name of the field * @return */ public static boolean canSetProperty(Object obj, String fieldName) { try { int p = fieldName.indexOf("."); if (p >= 0) { String firstProperty = fieldName.substring(0, p); Object first = MethodUtils.invokeMethod(obj, GET + StringUtils.capitalize(firstProperty), new Object[] {}); if (first != null) { return canSetProperty(first, fieldName.substring(p + 1)); } return false; } else { return hasMethod(obj, SET + StringUtils.capitalize(fieldName)); } } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new OCSRuntimeException(e.getMessage(), e); } }