List of usage examples for org.springframework.util StringUtils capitalize
public static String capitalize(String str)
From source file:net.nan21.dnet.core.presenter.converter.ReflookupResolver.java
/** * Get the setter for the entity field with the given name. * // w w w .j a v a 2 s .c o m * @param fieldName * @return * @throws Exception */ private Method _getEntitySetter(String fieldName) throws Exception { return this.entityClass.getMethod("set" + StringUtils.capitalize(fieldName), this._getEntityField(fieldName).getType()); }
From source file:com.agileapes.couteau.context.spring.event.impl.GenericTranslationScheme.java
@Override public void fillIn(Event originalEvent, ApplicationEvent translated) throws EventTranslationException { if (!(translated instanceof GenericApplicationEvent)) { return;//from ww w .j av a 2 s. c o m } GenericApplicationEvent applicationEvent = (GenericApplicationEvent) translated; final Enumeration<?> propertyNames = applicationEvent.getPropertyNames(); while (propertyNames.hasMoreElements()) { final String property = (String) propertyNames.nextElement(); final Object value = applicationEvent.getProperty(property); final Method method = ReflectionUtils.findMethod(originalEvent.getClass(), "set" + StringUtils.capitalize(property)); if (method == null || !Modifier.isPublic(method.getModifiers()) || method.getParameterTypes().length != 1 || !method.getReturnType().equals(void.class) || !method.getParameterTypes()[0].isInstance(value)) { continue; } try { method.invoke(originalEvent, value); } catch (Exception e) { throw new EventTranslationException("Failed to call setter on original event", e); } } }
From source file:io.spring.initializr.metadata.InitializrConfiguration.java
private static String splitCamelCase(String text) { return String.join("", Arrays.stream(text.split("(?<!(^|[A-Z]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])")) .map((it) -> StringUtils.capitalize(it.toLowerCase())).toArray(String[]::new)); }
From source file:org.syncope.console.pages.panels.PolicyBeanPanel.java
public PolicyBeanPanel(final String id, final AbstractPolicySpec policy) { super(id);// ww w . java2 s.c o m FieldWrapper fieldWrapper = null; final List<FieldWrapper> items = new ArrayList<FieldWrapper>(); for (Field field : policy.getClass().getDeclaredFields()) { if (!"serialVersionUID".equals(field.getName())) { fieldWrapper = new FieldWrapper(); fieldWrapper.setName(field.getName()); fieldWrapper.setType(field.getType()); final SchemaList schemaList = field.getAnnotation(SchemaList.class); fieldWrapper.setSchemaList(schemaList); items.add(fieldWrapper); } } final ListView<FieldWrapper> policies = new ListView<FieldWrapper>("policies", items) { private static final long serialVersionUID = 9101744072914090143L; @Override protected void populateItem(ListItem<FieldWrapper> item) { final FieldWrapper field = item.getModelObject(); item.add(new Label("label", new ResourceModel(field.getName()))); final AbstractFieldPanel component; Method classMethod; try { if (field.getType().equals(ConflictResolutionAction.class)) { classMethod = policy.getClass().getMethod("get" + StringUtils.capitalize(field.getName()), new Class[] {}); component = new AjaxDropDownChoicePanel("field", field.getName(), new PropertyModel(policy, field.getName()), false); ((AjaxDropDownChoicePanel) component) .setChoices(Arrays.asList(ConflictResolutionAction.values())); item.add(component); item.add(getActivationControl(component, (Enum) classMethod.invoke(policy, new Object[] {}) != null, ConflictResolutionAction.IGNORE, ConflictResolutionAction.IGNORE)); } else if (field.getType().equals(boolean.class) || field.getType().equals(Boolean.class)) { item.add(new AjaxCheckBoxPanel("check", field.getName(), new PropertyModel(policy, field.getName()), false)); item.add(new Label("field", new Model(null))); } else if (field.getType().equals(List.class) || field.getType().equals(Set.class)) { classMethod = policy.getClass().getMethod("get" + StringUtils.capitalize(field.getName()), new Class[] {}); if (field.getSchemaList() != null) { final List values = schemas.getObject(); if (field.getSchemaList().extended()) { values.add("id"); values.add("username"); } component = new AjaxPalettePanel("field", new PropertyModel(policy, field.getName()), new ListModel<String>(values)); item.add(component); item.add(getActivationControl(component, !((List) classMethod.invoke(policy, new Object[] {})).isEmpty(), new ArrayList<String>(), new ArrayList<String>())); } else { final FieldPanel panel = new AjaxTextFieldPanel("panel", field.getName(), new Model(null), true); panel.setRequired(true); component = new MultiValueSelectorPanel<String>("field", new PropertyModel(policy, field.getName()), String.class, panel); item.add(component); final List<String> reinitializedValue = new ArrayList<String>(); reinitializedValue.add(""); item.add(getActivationControl(component, !((List<String>) classMethod.invoke(policy, new Object[] {})).isEmpty(), (Serializable) new ArrayList<String>(), (Serializable) reinitializedValue)); } } else if (field.getType().equals(int.class) || field.getType().equals(Integer.class)) { classMethod = policy.getClass().getMethod("get" + StringUtils.capitalize(field.getName()), new Class[] {}); component = new AjaxTextFieldPanel("field", field.getName(), new PropertyModel(policy, field.getName()), false); item.add(component); item.add(getActivationControl(component, (Integer) classMethod.invoke(policy, new Object[] {}) > 0, 0, 0)); } else { item.add(new AjaxCheckBoxPanel("check", field.getName(), new Model(), false)); item.add(new Label("field", new Model(null))); } } catch (Exception e) { LOG.error("Error retrieving policy fields", e); } } }; add(policies); }
From source file:com.phoenixnap.oss.ramlapisync.data.ApiMappingMetadata.java
private void parseRequest() { requestParameters = new LinkedHashSet<>(); for (Entry<String, QueryParameter> param : action.getQueryParameters().entrySet()) { requestParameters.add(new ApiParameterMetadata(param.getKey(), param.getValue())); }/*from w ww. j a v a 2s. co m*/ if (ActionType.POST.equals(actionType) && action.getBody() != null && action.getBody().containsKey(MediaType.APPLICATION_FORM_URLENCODED_VALUE)) { MimeType requestBody = action.getBody().get(MediaType.APPLICATION_FORM_URLENCODED_VALUE); for (Entry<String, List<FormParameter>> params : requestBody.getFormParameters().entrySet()) { for (FormParameter param : params.getValue()) { requestParameters.add(new ApiParameterMetadata(params.getKey(), param)); } } } if (ResourceParser.doesActionTypeSupportRequestBody(actionType) && action.getBody() != null && !action.getBody().isEmpty()) { for (Entry<String, MimeType> body : action.getBody().entrySet()) { if (body.getKey().toLowerCase().contains("json")) { // Continue here! String schema = body.getValue().getSchema(); if (StringUtils.hasText(schema)) { ApiBodyMetadata requestBody = SchemaHelper.mapSchemaToPojo(parent.getDocument(), schema, parent.getBasePackage() + ".model", StringUtils.capitalize(getName()) + "Request"); if (requestBody != null) { setRequestBody(requestBody); } } } } } }
From source file:com.consol.citrus.admin.converter.AbstractObjectConverter.java
/** * Construct default Java bean property getter for field name. * @param fieldName/*from ww w. ja v a2 s . c om*/ * @return */ private String getMethodName(String fieldName) { return "get" + StringUtils.capitalize(fieldName); }
From source file:com.ethercamp.harmony.service.PeersService.java
private String getPeerDetails(NodeStatistics nodeStatistics, String country, long maxBlockNumber) { final String countryRow = "Country: " + country; if (nodeStatistics == null || nodeStatistics.getClientId() == null) { return countryRow; }//from w ww .j av a 2s . c o m final String delimiter = "\n"; final String blockNumber = "Block number: #" + NumberFormat.getNumberInstance(Locale.US).format(maxBlockNumber); final String clientId = StringUtils.trimWhitespace(nodeStatistics.getClientId()); final String details = "Details: " + clientId; final String supports = "Supported protocols: " + nodeStatistics.capabilities.stream() .filter(c -> c != null).map(c -> StringUtils.capitalize(c.getName()) + ": " + c.getVersion()) .collect(joining(", ")); final String[] array = clientId.split("/"); if (array.length >= 4) { final String type = "Type: " + array[0]; final String os = "OS: " + StringUtils.capitalize(array[2]); final String version = "Version: " + array[3]; return String.join(delimiter, type, os, version, countryRow, "", details, supports, blockNumber); } else { return String.join(delimiter, countryRow, details, supports, blockNumber); } }
From source file:org.jasig.portlet.contacts.adapters.impl.ldap.ConfigurableContactAttributesMapper.java
/** * Sets the object's property from the LDAP attribute value or default property value. * @param obj object to set property on/*from w ww .j av a 2 s . com*/ * @param propertyName property name to set * @param propertyNameToLDAPNameMap Map of object property names to ldap attribute names * @param attrs LDAP attributes * @return Populated object, or null if the LDAP attributes do not contain values that create a * reasonably useful object of the requested type */ private <T> void setProperty(T obj, String propertyName, Map<String, ?> propertyNameToLDAPNameMap, Attributes attrs) { String method = "set" + StringUtils.capitalize(propertyName); String ldapAttributeName = (String) propertyNameToLDAPNameMap.get(propertyName); try { if (StringUtils.hasLength(ldapAttributeName)) { if (ldapAttributeName.startsWith(defaultPrefix)) { obj.getClass().getMethod(method, String.class).invoke(obj, ldapAttributeName.substring(defaultPrefix.length())); } else { Attribute attr = attrs.get(ldapAttributeName); obj.getClass().getMethod(method, String.class).invoke(obj, getValue(attr)); if (attr != null && attr.size() > 1) { logger.warn("Found multiple values for LDAP attribute " + ldapAttributeName + attrs.get("cn") != null ? ", cn=" + config.get("cn") : ""); } } } } catch (Exception ex) { logger.error("Exception setting property for " + obj.getClass().getCanonicalName() + "." + method + ", LDAP attribute " + ldapAttributeName, ex); } }
From source file:com.nixmash.springdata.mvc.controller.UserController.java
@RequestMapping(value = "/signup", method = RequestMethod.GET) public String signupForm(@ModelAttribute SocialUserDTO socialUserDTO, WebRequest request, Model model) { if (request.getUserPrincipal() != null) return "redirect:/"; else {/*from ww w . j ava2 s. co m*/ Connection<?> connection = providerSignInUtils.getConnectionFromSession(request); request.setAttribute("connectionSubheader", webUI.parameterizedMessage(MESSAGE_KEY_SOCIAL_SIGNUP, StringUtils.capitalize(connection.getKey().getProviderId())), RequestAttributes.SCOPE_REQUEST); socialUserDTO = createSocialUserDTO(request, connection); ConnectionData connectionData = connection.createData(); SignInUtils.setUserConnection(request, connectionData); model.addAttribute(MODEL_ATTRIBUTE_SOCIALUSER, socialUserDTO); return SIGNUP_VIEW; } }
From source file:es.logongas.ix3.dao.impl.ExceptionTranslator.java
private ClassAndLabel getMethodLabel(Class clazz, String methodName) { String suffixMethodName = StringUtils.capitalize(methodName); Method method = ReflectionUtils.findMethod(clazz, "get" + suffixMethodName); if (method == null) { method = ReflectionUtils.findMethod(clazz, "is" + suffixMethodName); if (method == null) { return null; }//from w ww . j av a2 s.c om } Label label = method.getAnnotation(Label.class); if (label != null) { return new ClassAndLabel(method.getReturnType(), label.value()); } else { return new ClassAndLabel(method.getReturnType(), null); } }