#47, #60 - Added RelProvider implementation pluralizing using the Evo Inflector algorithm.

See http://www.csse.monash.edu.au/~damian/papers/HTML/Plurals.html for details of the algorithm.
This commit is contained in:
Oliver Gierke
2013-04-15 23:18:29 +02:00
parent 254339c3b2
commit 6acf17e730
5 changed files with 102 additions and 1 deletions

View File

@@ -41,6 +41,7 @@ import org.springframework.hateoas.core.AnnotationRelProvider;
import org.springframework.hateoas.core.DefaultLinkDiscoverer;
import org.springframework.hateoas.core.DefaultRelProvider;
import org.springframework.hateoas.core.DelegatingRelProvider;
import org.springframework.hateoas.core.EvoInflectorRelProvider;
import org.springframework.hateoas.hal.HalLinkDiscoverer;
import org.springframework.hateoas.hal.Jackson1HalModule;
import org.springframework.hateoas.hal.Jackson2HalModule;
@@ -71,6 +72,7 @@ class HypermediaSupportBeanDefinitionRegistrar implements ImportBeanDefinitionRe
private static final boolean JACKSON2_PRESENT = ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper",
null);
private static final boolean JSONPATH_PRESENT = ClassUtils.isPresent("com.jayway.jsonpath.JsonPath", null);
private static final boolean EVO_PRESENT = ClassUtils.isPresent("org.atteo.evo.inflector.English", null);
private final ImportBeanDefinitionRegistrar linkBuilderBeanDefinitionRegistrar = new LinkBuilderBeanDefinitionRegistrar();
@@ -114,7 +116,8 @@ class HypermediaSupportBeanDefinitionRegistrar implements ImportBeanDefinitionRe
*/
private static void registerRelProviderPluginRegistryAndDelegate(BeanDefinitionRegistry registry) {
RootBeanDefinition defaultRelProviderBeanDefinition = new RootBeanDefinition(DefaultRelProvider.class);
Class<?> defaultRelProviderType = EVO_PRESENT ? EvoInflectorRelProvider.class : DefaultRelProvider.class;
RootBeanDefinition defaultRelProviderBeanDefinition = new RootBeanDefinition(defaultRelProviderType);
registry.registerBeanDefinition("defaultRelProvider", defaultRelProviderBeanDefinition);
RootBeanDefinition annotationRelProviderBeanDefinition = new RootBeanDefinition(AnnotationRelProvider.class);

View File

@@ -0,0 +1,38 @@
/*
* Copyright 2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.hateoas.core;
import org.atteo.evo.inflector.English;
import org.springframework.hateoas.RelProvider;
/**
* {@link RelProvider} implementation using the Evo Inflector implementation of an algorithmic approach to English
* plurals.
*
* @see http://www.csse.monash.edu.au/~damian/papers/HTML/Plurals.html
* @author Oliver Gierke
*/
public class EvoInflectorRelProvider extends DefaultRelProvider {
/*
* (non-Javadoc)
* @see org.springframework.hateoas.core.DefaultRelProvider#getCollectionResourceRelFor(java.lang.Class)
*/
@Override
public String getCollectionResourceRelFor(Class<?> type) {
return English.plural(getSingleResourceRelFor(type));
}
}