Java Code Examples for org.springframework.util.StringUtils#capitalize()

The following examples show how to use org.springframework.util.StringUtils#capitalize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InitializrConfiguration.java    From initializr with Apache License 2.0 6 votes vote down vote up
/**
 * Generate a suitable application name based on the specified name. If no suitable
 * application name can be generated from the specified {@code name}, the
 * {@link Env#getFallbackApplicationName()} is used instead.
 * <p>
 * No suitable application name can be generated if the name is {@code null} or if it
 * contains an invalid character for a class identifier.
 * @param name the the source name
 * @return the generated application name
 * @see Env#getFallbackApplicationName()
 * @see Env#getInvalidApplicationNames()
 */
public String generateApplicationName(String name) {
	if (!StringUtils.hasText(name)) {
		return this.env.fallbackApplicationName;
	}
	String text = splitCamelCase(name.trim());
	// TODO: fix this
	String result = unsplitWords(text);
	if (!result.endsWith("Application")) {
		result = result + "Application";
	}
	String candidate = StringUtils.capitalize(result);
	if (hasInvalidChar(candidate) || this.env.invalidApplicationNames.contains(candidate)) {
		return this.env.fallbackApplicationName;
	}
	else {
		return candidate;
	}
}
 
Example 2
Source File: SwaggerAutoConfiguration.java    From jhipster with Apache License 2.0 5 votes vote down vote up
/**
 * Springfox configuration for the management endpoints (actuator) Swagger docs.
 *
 * @param appName               the application name
 * @param managementContextPath the path to access management endpoints
 * @return the Swagger Springfox configuration
 */
@Bean
@ConditionalOnClass(name = "org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties")
@ConditionalOnProperty("management.endpoints.web.base-path")
@ConditionalOnExpression("'${management.endpoints.web.base-path}'.length() > 0")
@ConditionalOnMissingBean(name = "swaggerSpringfoxManagementDocket")
public Docket swaggerSpringfoxManagementDocket(@Value("${spring.application.name:application}") String appName,
                                               @Value("${management.endpoints.web.base-path}") String managementContextPath) {

    ApiInfo apiInfo = new ApiInfo(
        StringUtils.capitalize(appName) + " " + MANAGEMENT_TITLE_SUFFIX,
        MANAGEMENT_DESCRIPTION,
        properties.getVersion(),
        "",
        ApiInfo.DEFAULT_CONTACT,
        "",
        "",
        new ArrayList<>()
    );

    return createDocket()
        .apiInfo(apiInfo)
        .useDefaultResponseMessages(properties.isUseDefaultResponseMessages())
        .groupName(MANAGEMENT_GROUP_NAME)
        .host(properties.getHost())
        .protocols(new HashSet<>(Arrays.asList(properties.getProtocols())))
        .forCodeGeneration(true)
        .directModelSubstitute(ByteBuffer.class, String.class)
        .genericModelSubstitutes(ResponseEntity.class)
        .ignoredParameterTypes(Pageable.class)
        .select()
        .paths(regex(managementContextPath + ".*"))
        .build();
}
 
Example 3
Source File: UnionTypeInterpreter.java    From springmvc-raml-plugin with Apache License 2.0 5 votes vote down vote up
private String getClassName(TypeDeclaration type) {
	UnionTypeDeclaration objectType = (UnionTypeDeclaration) type;
	String name = StringUtils.capitalize(objectType.name());

	// For mime types we need to take the type not the name
	try {
		MimeType.valueOf(name);
		name = objectType.type();
	} catch (Exception ex) {
		// not a valid mimetype do nothing
		logger.debug("mime: " + name);
	}
	return name;
}
 
Example 4
Source File: MethodRepositoryRenderParas.java    From WeBASE-Codegen-Monkey with Apache License 2.0 5 votes vote down vote up
@Override
public String getGeneratedFilePath(MethodMetaInfo method) {
    String packagePath = PackagePath.getPackagePath(PackageConstants.DB__METHOD_REPOSITORY_PACKAGE_POSTFIX,
            systemEnvironmentConfig.getGroup(), PackageConstants.SUB_PROJECT_PKG_DB);
    String className = method.getContractName() + StringUtils.capitalize(method.getName());
    String javaFilePath = packagePath + "/" + className + "MethodRepository.java";
    return javaFilePath;
}
 
Example 5
Source File: ReflectivePropertyAccessor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Return the method suffix for a given property name. The default implementation
 * uses JavaBean conventions.
 */
protected String getPropertyMethodSuffix(String propertyName) {
	if (propertyName.length() > 1 && Character.isUpperCase(propertyName.charAt(1))) {
		return propertyName;
	}
	return StringUtils.capitalize(propertyName);
}
 
Example 6
Source File: RedissonMultiLockDefinitionParser.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
protected String getBeanClassName(Element element) {
    String elementName
            = Conventions.attributeNameToPropertyName(
                    element.getLocalName());
    return RedissonNamespaceParserSupport.IMPL_CLASS_PATH_PREFIX
            + StringUtils.capitalize(elementName);
}
 
Example 7
Source File: MethodCrawlerImplParas.java    From WeBASE-Codegen-Monkey with Apache License 2.0 5 votes vote down vote up
@Override
public String getGeneratedFilePath(MethodMetaInfo method) {
    String packagePath = PackagePath.getPackagePath(PackageConstants.CRAWLER_METHOD_IMPL_PACKAGE_POSTFIX,
            systemEnvironmentConfig.getGroup(), PackageConstants.SUB_PROJECT_PKG_PARSER);
    String className = method.getContractName() + StringUtils.capitalize(method.getName());
    String javaFilePath = packagePath + "/" + className + "MethodCrawlerImpl.java";
    return javaFilePath;
}
 
Example 8
Source File: ReflectivePropertyAccessor.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Return the method suffix for a given property name. The default implementation
 * uses JavaBean conventions.
 */
protected String getPropertyMethodSuffix(String propertyName) {
	if (propertyName.length() > 1 && Character.isUpperCase(propertyName.charAt(1))) {
		return propertyName;
	}
	return StringUtils.capitalize(propertyName);
}
 
Example 9
Source File: EntityExistException.java    From eladmin with Apache License 2.0 4 votes vote down vote up
private static String generateMessage(String entity, String field, String val) {
    return StringUtils.capitalize(entity)
            + " with " + field + " "+ val + " existed";
}
 
Example 10
Source File: StatusResultMatchersTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private Method getMethodForHttpStatus(HttpStatus status) throws NoSuchMethodException {
	String name = status.name().toLowerCase().replace("_", "-");
	name = "is" + StringUtils.capitalize(Conventions.attributeNameToPropertyName(name));
	return StatusResultMatchers.class.getMethod(name);
}
 
Example 11
Source File: CustomAnnotationBeanNameGenerator.java    From wicket-spring-boot with Apache License 2.0 4 votes vote down vote up
@Override
public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
	return "wicketextension"+StringUtils.capitalize(super.generateBeanName(definition, registry));
}
 
Example 12
Source File: EntityNotFoundException.java    From sk-admin with Apache License 2.0 4 votes vote down vote up
private static String generateMessage(String entity, String field, String val) {
    return StringUtils.capitalize(entity)
            + " with " + field + " "+ val + " does not exist";
}
 
Example 13
Source File: StatusResultMatchersTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private Method getMethodForHttpStatus(HttpStatus status) throws NoSuchMethodException {
	String name = status.name().toLowerCase().replace("_", "-");
	name = "is" + StringUtils.capitalize(Conventions.attributeNameToPropertyName(name));
	return StatusResultMatchers.class.getMethod(name);
}
 
Example 14
Source File: EntityExistException.java    From albedo with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static String generateMessage(String entity, String field, String val) {
	return StringUtils.capitalize(entity)
		+ " with " + field + " " + val + " existed";
}
 
Example 15
Source File: StatusResultMatchersTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private Method getMethodForHttpStatus(HttpStatus status) throws NoSuchMethodException {
	String name = status.name().toLowerCase().replace("_", "-");
	name = "is" + StringUtils.capitalize(Conventions.attributeNameToPropertyName(name));
	return StatusResultMatchers.class.getMethod(name);
}
 
Example 16
Source File: EntityNotFoundException.java    From spring-glee-o-meter with GNU General Public License v3.0 4 votes vote down vote up
private static String generateMessage(String entity, Map<String, String> searchParams) {
    return StringUtils.capitalize(entity) +
            " was not found for parameters " +
            searchParams;
}
 
Example 17
Source File: NamingHelper.java    From springmvc-raml-plugin with Apache License 2.0 4 votes vote down vote up
private static String getActionNameFromObjects(ApiActionMetadata apiActionMetadata) {

		String uri = apiActionMetadata.getResource().getUri();
		String name = convertActionTypeToIntent(apiActionMetadata.getActionType(), doesUriEndsWithParam(uri));

		if (apiActionMetadata.getActionType().equals(RamlActionType.GET)) {
			Map<String, ApiBodyMetadata> responseBody = apiActionMetadata.getResponseBody();
			if (responseBody.size() > 0) {
				ApiBodyMetadata apiBodyMetadata = responseBody.values().iterator().next();
				String responseObjectName = cleanNameForJava(StringUtils.capitalize(apiBodyMetadata.getName()));
				if (apiBodyMetadata.isArray()) {
					responseObjectName = StringUtils.capitalize(NamingHelper.pluralize(responseObjectName));
				}
				name += responseObjectName;
			} else {
				name += "Object";
			}

			name = appendActionNameWithSingleParameter(apiActionMetadata, name);

		} else if (apiActionMetadata.getActionType().equals(RamlActionType.DELETE)) {

			// for DELETE method we'll still use resource name
			String url = cleanLeadingAndTrailingNewLineAndChars(apiActionMetadata.getResource().getUri());
			String[] splitUrl = SLASH.split(url);
			String resourceNameToUse = null;
			if (splitUrl.length > 1 && StringUtils.countOccurrencesOf(splitUrl[splitUrl.length - 1], "{") > 0) {
				resourceNameToUse = splitUrl[splitUrl.length - 2];
			} else {
				resourceNameToUse = splitUrl[splitUrl.length - 1];
			}

			name = name + StringUtils.capitalize(cleanNameForJava(singularize(resourceNameToUse)));
			name = appendActionNameWithSingleParameter(apiActionMetadata, name);

		} else {
			ApiBodyMetadata requestBody = apiActionMetadata.getRequestBody();
			String creationObject;
			if (requestBody != null) {
				creationObject = requestBody.getName();
			} else {
				creationObject = apiActionMetadata.getParent().getResourceUri();
				creationObject = creationObject.substring(creationObject.lastIndexOf('/') + 1);
			}
			return name + cleanNameForJava(StringUtils.capitalize(creationObject));
		}

		return name;
	}
 
Example 18
Source File: JmxUtils.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Return the JMX attribute name to use for the given JavaBeans property.
 * <p>When using strict casing, a JavaBean property with a getter method
 * such as {@code getFoo()} translates to an attribute called
 * {@code Foo}. With strict casing disabled, {@code getFoo()}
 * would translate to just {@code foo}.
 * @param property the JavaBeans property descriptor
 * @param useStrictCasing whether to use strict casing
 * @return the JMX attribute name to use
 */
public static String getAttributeName(PropertyDescriptor property, boolean useStrictCasing) {
	if (useStrictCasing) {
		return StringUtils.capitalize(property.getName());
	}
	else {
		return property.getName();
	}
}
 
Example 19
Source File: UtilsFunctionPackage.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * 首字母大写
 *
 * @param input
 *            输入文本
 * @return 首字母大写
 */
public String capitalize(String input) {
	return StringUtils.capitalize(input);
}
 
Example 20
Source File: NamingHelper.java    From springmvc-raml-plugin with Apache License 2.0 2 votes vote down vote up
/**
 * Convert a name into a java className.
 *
 * eg. MonitorServiceImpl becomes Monitor
 *
 * @param clazz
 *            The name
 * @return The name for this using Java class convention
 */
public static String convertToClassName(String clazz) {
	return StringUtils.capitalize(cleanNameForJava(clazz, false));
}