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:de.xirp.plugin.ViewerBase.java
/** * If a property has changed the controls which are referenced by * this property are determined and the value of the property is * set to them. Controls which are already disposed are ignored. * /*from w w w .j a v a 2 s. c o m*/ * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) */ @Override public void propertyChange(PropertyChangeEvent event) { String propName = event.getPropertyName(); String setterName = SET_PREFIX + StringUtils.capitalize(propName); List<Control> controls = setter.get(setterName); List<Control> delete = new ArrayList<Control>(controls.size()); for (Control control : controls) { if (SWTUtil.swtAssert(control)) { Object value = event.getNewValue(); // if the method returned something // update the ui with it if (value != null) { setValue(control, value); } } else { // mark disposed controls for deletion delete.add(control); } } // Delete disposed controls for (Control control : delete) { setter.remove(setterName, control); } }
From source file:hudson.security.HudsonPrivateSecurityRealmTest.java
private void selfRegistration(String login) throws Exception { // user should not exist before assertNull(User.getById(login, false)); JenkinsRule.WebClient wc = j.createWebClient(); SignupPage signup = new SignupPage(wc.goTo("signup")); signup.enterUsername(login);// www .j a v a 2s. com signup.enterPassword(login); signup.enterFullName(StringUtils.capitalize(login)); signup.enterEmail(login + "@" + login + ".com"); HtmlPage p = signup.submit(j); assertEquals(200, p.getWebResponse().getStatusCode()); assertTrue(p.getDocumentElement().getElementsByAttribute("div", "class", "error").isEmpty()); assertNotNull(User.getById(login, false)); }
From source file:com.fortify.processrunner.RunProcessRunnerFromCLI.java
protected final void appendOptions(HelpPrinter hp, Context context, CLIOptionDefinitions cliOptionDefinitions) { for (String group : cliOptionDefinitions.getCLIOptionDefinitionGroups()) { boolean hasAppendedHeader = false; for (CLIOptionDefinition o : cliOptionDefinitions.getCLIOptionDefinitionsByGroup(group)) { if (!o.hideFromHelp()) { if (!hasAppendedHeader) { hp.appendEmptyLn();/*from w ww . ja v a2 s. c om*/ hp.append(0, StringUtils.capitalize(group) + " options:"); hasAppendedHeader = true; } hp.appendEmptyLn(); hp.append(2, "-" + o.getName() + (o.isFlag() ? " " : " <value> ") + (o.isRequiredAndNotIgnored(context) ? "(required)" : "(optional)")); hp.append(4, o.getDescription()); hp.keyValueGroupBuilder().append("Default value", o.getDefaultValueDescription()) .append("Current value", o.getCurrentValueDescription(context)) .append("Requires options", o.getDependsOnOptions()) .append("Alternative options", o.getIsAlternativeForOptions()) .append("Allowed values", o.getAllowedValues()) .append("Allowed sources", o.getAllowedSources()).append(o.getExtraInfo()).build(4); } } } }
From source file:com.haulmont.chile.core.loader.ChileAnnotationsLoader.java
protected boolean setterExists(Field field) { String name = "set" + StringUtils.capitalize(field.getName()); Method[] methods = field.getDeclaringClass().getDeclaredMethods(); for (Method method : methods) { if (method.getName().equals(name)) return true; }//from w w w .j a v a2 s . c om return false; }
From source file:com.ocs.dynamo.utils.ClassUtils.java
/** * @param obj// w ww .jav a 2s . c o m * @param fieldName * @param value */ public static void setFieldValue(Object obj, String fieldName, Object value) { 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) { setFieldValue(first, fieldName.substring(p + 1), value); } } else { MethodUtils.invokeMethod(obj, SET + StringUtils.capitalize(fieldName), new Object[] { value }); } } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { LOG.error(e.getMessage(), e); throw new OCSRuntimeException(e.getMessage(), e); } }
From source file:net.sf.firemox.clickable.target.card.VirtualCard.java
/** * Return HTML tooltip string of this card. * // w w w .j a v a 2s .c o m * @return HTML tooltip string of this card. */ public String getTooltipString() { final StringBuilder toolTip = new StringBuilder(400); // played activated ability if (card.getIdZone() == IdZones.STACK && card.isACopy()) { /* * -> this card is not the source of ability too. Only the information of * ability is displayed */ toolTip.append(CardFactory.ttHeaderAbility); toolTip.append( StackManager.getAbilityOf(card).toHtmlString(StackManager.getInstance().getAbilityContext())); toolTip.append(CardFactory.ttAbiltityEnd); toolTip.append(CardFactory.ttManacost); toolTip.append(StackManager.getHtmlManaCost(card)); toolTip.append("("); toolTip.append(StackManager.getTotalManaPaid(card)); toolTip.append(CardFactory.ttManapaid); toolTip.append(StackManager.getHtmlManaPaid(card)); } else { // html header and card name toolTip.append(CardFactory.ttHeader); final MZone container = card.getContainer(); if (!card.isVisibleForYou() && (container == null || !container.isVisibleForYou())) { toolTip.append("??"); } else { if (!card.isVisibleForYou()) { toolTip.append(LanguageManager.getString("unkown.card.name")); } else { toolTip.append(card.database.getLocalName()); } // get the tooltip filter final TooltipFilter privateFilter = refreshToolTipFilter(); // card types if (privateFilter.types && card.getIdCard() != 0) { int startIndex = CardFactory.exportedIdCardValues.length; int writtenTypes = 0; StringBuilder typeSet = null; while (startIndex-- > 0 && card.getIdCard() != 0) { if (MCard.hasIdCard(card.getIdCard(), CardFactory.exportedIdCardValues[startIndex])) { if (MCard.hasIdCard(writtenTypes, CardFactory.exportedIdCardValues[startIndex])) { // is a type sets if (typeSet == null) { typeSet = new StringBuilder(30); typeSet.append(" ("); } else { typeSet.append(", "); } typeSet.append(CardFactory.exportedIdCardNames[startIndex]); } else { if (writtenTypes == 0) { toolTip.append(CardFactory.ttTypes); } else { toolTip.append(", "); } toolTip.append(CardFactory.exportedIdCardNames[startIndex]); writtenTypes |= CardFactory.exportedIdCardValues[startIndex]; } } } if (typeSet != null) { toolTip.append(typeSet); toolTip.append(')'); } } // card colors if (privateFilter.colors) { int writtenColors = 0; for (int i = IdCardColors.CARD_COLOR_VALUES.length; i-- > 1;) { if (card.hasIdColor(IdCardColors.CARD_COLOR_VALUES[i])) { if (writtenColors == 0) { toolTip.append(CardFactory.ttColors); } else { toolTip.append(", "); } toolTip.append(StringUtils .capitalize(LanguageManager.getString(IdCardColors.CARD_COLOR_NAMES[i]))); writtenColors = 1; } } } if (privateFilter.properties) { // card properties final Iterator<Integer> it = card.cachedProperties.iterator(); if (it.hasNext()) { toolTip.append(CardFactory.ttProperties); while (it.hasNext()) { final Integer property = it.next(); boolean hasProperty = false; toolTip.append("<br> "); if (Configuration.getBoolean("card.property.tooltip.picture", true) && CardFactory.propertyPicturesHTML.get(property) != null) { // There is an associated picture to this property toolTip.append(CardFactory.propertyPicturesHTML.get(property)); hasProperty = true; } if (Configuration.getBoolean("card.property.tooltip.name", true)) { final String propertyName = CardFactory.exportedProperties.get(property); if (hasProperty) toolTip.append(" - "); hasProperty = true; if (propertyName == null) { // not name associated to this property toolTip.append("<font color='red'>(").append(property).append(")</font>"); } else { toolTip.append(propertyName); } } if (Configuration.getBoolean("card.property.tooltip.id", true)) { if (hasProperty) toolTip.append(" - "); toolTip.append(property); } } } } if (privateFilter.powerANDtoughness) { // power toolTip.append(CardFactory.ttPower); toolTip.append(card.getValue(IdTokens.POWER)); // toughness toolTip.append(CardFactory.ttToughness); toolTip.append(card.getValue(IdTokens.TOUGHNESS)); } if (card.isVisibleForYou()) { // states int value = card.getValue(IdCommonToken.STATE); if (value != 0) { int writtenStates = 0; toolTip.append(CardFactory.ttState); for (StatePicture statePicture : CardFactory.statePictures) { if (statePicture.hasState(value)) { if (writtenStates != 0) { toolTip.append(", "); } toolTip.append(LanguageManagerMDB.getString(statePicture.toString())); writtenStates = 1; } } } // damages value = card.getValue(IdCommonToken.DAMAGE); if (privateFilter.damage && value > 0) { toolTip.append(CardFactory.ttDamage); toolTip.append(value); } } // Display abilities if (card.getIdZone() == IdZones.STACK) { // played activated ability from this card toolTip.append(CardFactory.ttAbility); try { toolTip.append(StackManager.getAbilityOf(card) .toHtmlString(StackManager.getInstance().getAbilityContext())); } catch (Throwable e) { // The is not yet in the stack now. Log.info(e); return null; } toolTip.append(CardFactory.ttAbiltityEnd); toolTip.append(CardFactory.ttManacost); toolTip.append(StackManager.getHtmlManaCost(card)); toolTip.append("("); toolTip.append(StackManager.getTotalManaCost(card)); toolTip.append(CardFactory.ttManapaid); toolTip.append(StackManager.getHtmlManaPaid(card)); } else if (StackManager.actionManager.currentAction == WaitActivatedChoice.getInstance()) { // playable activated abilities of this card final List<Ability> list = WaitActivatedChoice.getInstance().abilitiesOf(card); final List<Ability> advList = WaitActivatedChoice.getInstance().advancedAbilitiesOf(card); if (list != null && !list.isEmpty()) { toolTip.append(CardFactory.ttAbility); for (Ability ability : list) { toolTip.append("<br> "); toolTip.append(ability.toHtmlString(null)); } toolTip.append(CardFactory.ttAbiltityEnd); } // playable advanced activated abilities of this card if (advList != null && !advList.isEmpty()) { toolTip.append(CardFactory.ttAdvancedAability); for (Ability ability : advList) { toolTip.append("<br> "); toolTip.append(ability.toHtmlString(null)); } toolTip.append(CardFactory.ttAdvancedAabilityEnd); } } // rule credits if (card.database.getRulesCredit() != null) { toolTip.append(CardFactory.ttRulesAuthor); toolTip.append(card.database.getRulesCredit()); } } } // append the "this is a copy if (card.hasDirtyDataBase()) { DatabaseCard orCard = card.getOriginalDatabase(); toolTip.append(TargetFactory.tooltipDirtyDataBase); toolTip.append(orCard.getLocalName()); } // append the "this is [not] a valid target" text if (StackManager.isTargetMode()) { if (((ChosenTarget) StackManager.actionManager.currentAction).isValidTarget(card)) { toolTip.append(TargetFactory.tooltipValidTarget); } else { toolTip.append(TargetFactory.tooltipInvalidTarget); } } final String id = TargetHelper.getInstance().getMyId(card); if (id != null) { if (id != TargetHelper.STR_CONTEXT1 // TODO I am in the context 1, draw a picture && id != TargetHelper.STR_CONTEXT2 // TODO I am in the context 2, draw a picture && id != TargetHelper.STR_SOURCE) { // TODO I am the source, draw a picture // I am already targeted toolTip.append("<br>"); toolTip.append(TargetHelper.getInstance().getTargetPictureAsUrl()); } } toolTip.append("</html>"); return toolTip.toString(); }
From source file:com.qcadoo.model.internal.classconverter.ModelXmlToClassConverterImpl.java
private void buildEquals(final CtClass ctClass, final List<String> fields) throws ModelXmlCompilingException { try {// www. jav a 2 s .c o m StringBuilder sb = new StringBuilder(); sb.append("if (obj == null) { return false; }"); sb.append("if (obj == this) { return true; }"); sb.append("if (!(obj instanceof " + ctClass.getName() + ")) { return false; }"); sb.append(ctClass.getName() + " other = (" + ctClass.getName() + ") obj;"); for (String field : fields) { sb.append("if (get" + StringUtils.capitalize(field) + "() == null) {"); sb.append(" if (other.get" + StringUtils.capitalize(field) + "() != null) { return false; }"); sb.append("} else if (!get" + StringUtils.capitalize(field) + "().equals(other.get" + StringUtils.capitalize(field) + "())) { return false; }"); } sb.append("return true;"); ctClass.addMethod( CtNewMethod.make("public boolean equals(Object obj) { " + sb.toString() + " }", ctClass)); } catch (CannotCompileException e) { throw new ModelXmlCompilingException(L_FAILED_TO_COMPILE_CLASS + ctClass.getName(), e); } }
From source file:mrcg.MRCGInstance.java
private void createListJSPs() throws Exception { for (JavaClass jclass : types.values()) { if (!(jclass.isEnum() || jclass.isMapping() || skipGui(jclass))) { String path = "beans." + jclass.getName() + ".list."; List<ListField> listFields = new ArrayList<ListField>(); List<Object> lfs = getList(path + "fields"); if (lfs != null && !lfs.isEmpty()) { for (Object o : lfs) { String s = StringUtils.trimToEmpty(o.toString()); ListField lf = new ListField(); if (s.contains(":")) { String[] ss = s.split(":"); lf.setName(ss[0]); lf.setLabel(ss[1]); } else { lf.setName(s);/*from ww w . j a va 2 s. c om*/ lf.setLabel( Utils.toSpacedCamelCase(StringUtils.capitaliseAllWords(s.replace('.', ' ')))); } listFields.add(lf); } } else { for (JavaField jf : jclass.getListFields()) { ListField lf = new ListField(); if (jf.isReferenceField()) { JavaClass ref = jf.getReferences(); lf.setLabel(jf.getNameAsLabel().replace(" Id", "")); String refField = "identifierLabel"; if (ref.getIdentifierField() != null) { refField = ref.getIdentifierField().getName(); } lf.setName(jf.getName().replace("Id", "") + "." + refField); } else { lf.setLabel(jf.getNameAsLabel()); lf.setName(jf.getName()); } listFields.add(lf); } } Map<String, Object> map = new HashMap<String, Object>(); map.put("basePackage", basePackage); map.put("classUpper", StringUtils.capitalize(jclass.getName())); map.put("classUpperSpaced", Utils.toSpacedCamelCase(StringUtils.capitalize(jclass.getName()))); map.put("classUpperSpacedPlural", Utils.toSpacedCamelCase(StringUtils.capitalize(Utils.pluralize(jclass.getName())))); map.put("classLower", jclass.getName().toLowerCase()); map.put("classLowerCamel", StringUtils.uncapitalize(jclass.getName())); map.put("fields", listFields); map.put("tagLibPrefix", tagLibPrefix); // map.put("mappings", convertToJspEditCode(jclass)); map.put("edit", getBoolean(path + "edit", true)); map.put("view", getBoolean(path + "view", true)); File file = new File(webPath + "admin/" + jclass.getName().toLowerCase() + "/list-generated.jsp"); velocity(file, getResourcePath("list-jsp.vel"), map, true); } } }
From source file:ddf.metrics.plugin.webconsole.MetricsWebConsolePlugin.java
/** * Convert string, if it is in camelCase, to individual words with each word starting with a * capital letter/*www. j a v a 2 s. com*/ */ String convertCamelCase(String input) { String[] parts = StringUtils.splitByCharacterTypeCamelCase(input); String convertedStr = StringUtils.join(parts, " "); convertedStr = StringUtils.capitalize(convertedStr); return convertedStr; }
From source file:com.bluexml.xforms.generator.tools.ModelTools.java
/** * Gets the association field./* ww w.j a va 2s .co m*/ * * @param association * the association * @param inverse * the inverse * @return the association field */ public static String getAssociationField(Association association, boolean inverse) { // String sourceS = getCompleteName(source).replace('.', '_'); // String targetS = getCompleteName(destination).replace('.', '_'); // ModelElement source = null; // ModelElement destination = null; String role = null; if (!inverse) { role = association.getSecondEnd().getName(); // source = association.getSource(); // destination = association.getDestination(); } else { role = association.getFirstEnd().getName(); // source = association.getDestination(); // destination = association.getSource(); } // String sourceS = ((Clazz) source).getName(); // String targetS = ((Clazz) destination).getName(); String field = null; if (role != null && !role.equals("")) { // field = sourceS + "_" + association.getName() + "_" + role + "_" // + targetS; field = association.getName() + StringUtils.capitalize(role); } else { // field = sourceS + "_" + association.getName() + "_" + targetS; field = association.getName(); } if (inverse) { field = "Inverse" + field; } return field; }