DATACMNS-221 - Added support for Unicode characters in PartTree.

Altered parsing regular expressions to support unicode characters.
This commit is contained in:
Aleksander Blomskøld
2012-09-03 06:39:37 +02:00
committed by Oliver Gierke
parent 4939fbf3bc
commit f0ffd0316c
4 changed files with 23 additions and 7 deletions

View File

@@ -340,7 +340,7 @@ public class PropertyPath implements Iterable<PropertyPath> {
exception = e;
}
Pattern pattern = Pattern.compile("[A-Z]+[a-z]*$");
Pattern pattern = Pattern.compile("\\p{Lu}+\\p{Ll}*$");
Matcher matcher = pattern.matcher(source);
if (matcher.find() && matcher.start() != 0) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2010 the original author or authors.
* Copyright 2008-2012 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.
@@ -35,7 +35,7 @@ import org.springframework.util.StringUtils;
*/
public class OrderBySource {
private static final String BLOCK_SPLIT = "(?<=Asc|Desc)(?=[A-Z])";
private static final String BLOCK_SPLIT = "(?<=Asc|Desc)(?=\\p{Lu})";
private static final Pattern DIRECTION_SPLIT = Pattern.compile("(.+)(Asc|Desc)$");
private final List<Order> orders;
@@ -107,4 +107,4 @@ public class OrderBySource {
public String toString() {
return "Order By " + StringUtils.collectionToDelimitedString(orders, ", ");
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2010 the original author or authors.
* Copyright 2008-2012 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.
@@ -37,8 +37,8 @@ import org.springframework.util.StringUtils;
*/
public class PartTree implements Iterable<OrPart> {
private static final Pattern PREFIX_TEMPLATE = Pattern.compile("^(find|read|get)(\\p{Upper}.*?)??By");
private static final String KEYWORD_TEMPLATE = "(%s)(?=[A-Z])";
private static final Pattern PREFIX_TEMPLATE = Pattern.compile("^(find|read|get)(\\p{Lu}.*?)??By");
private static final String KEYWORD_TEMPLATE = "(%s)(?=\\p{Lu})";
/**
* The subject, for example "findDistinctUserByNameOrderByAge" would have the subject "DistinctUser".

View File

@@ -307,6 +307,17 @@ public class PartTreeUnitTests {
"commonNameContaining", Organization.class) });
}
/**
* @see DATACMNS-221
*/
@Test
public void parsesSpecialCharactersCorrectly() {
PartTree tree = new PartTree("findByØreAndÅrOrderByÅrAsc", DomainObjectWithSpecialChars.class);
assertPart(tree, new Part[] { new Part("øre", DomainObjectWithSpecialChars.class),
new Part("år", DomainObjectWithSpecialChars.class) });
assertTrue(tree.getSort().getOrderFor("år").isAscending());
}
private static void assertType(Iterable<String> sources, Type type, String property) {
assertType(sources, type, property, 1, true);
}
@@ -380,4 +391,9 @@ public class PartTreeUnitTests {
String commonName;
String legalName;
}
class DomainObjectWithSpecialChars {
String øre;
String år;
}
}