Index: src/web/org/codehaus/groovy/grails/web/mapping/DefaultUrlMappingsHolder.java =================================================================== --- src/web/org/codehaus/groovy/grails/web/mapping/DefaultUrlMappingsHolder.java (revision 7443) +++ src/web/org/codehaus/groovy/grails/web/mapping/DefaultUrlMappingsHolder.java (working copy) @@ -22,6 +22,9 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; /** *
The default implementation of the UrlMappingsHolder interface that takes a list of mappings and @@ -109,7 +112,7 @@ */ public UrlCreator getReverseMapping(final String controller, final String action, Map params) { if(params == null) params = Collections.EMPTY_MAP; - + UrlMapping mapping = lookupMapping(controller, action, params); if(mapping == null || (mapping instanceof ResponseCodeUrlMapping)) { mapping = (UrlMapping)mappingsLookup.get(new UrlMappingKey(controller, action, Collections.EMPTY_SET)); @@ -159,7 +162,8 @@ */ public UrlMappingInfo match(String uri) { UrlMappingInfo info = null; - for (int i = 0; i < mappings.length; i++) { + uri = dashedToCamelCase(uri); + for (int i = 0; i < mappings.length; i++) { UrlMapping mapping = mappings[i]; if(LOG.isDebugEnabled()) @@ -177,6 +181,7 @@ public UrlMappingInfo[] matchAll(String uri) { List matchingUrls = new ArrayList(); + uri = dashedToCamelCase(uri); for (int i = 0; i < mappings.length; i++) { UrlMapping mapping = mappings[i]; if(LOG.isDebugEnabled()) @@ -223,6 +228,45 @@ return sw.toString(); } + /** + * A method used to transform a String that contains dashes to camelCase by + * using the following regular expression: {@code /-(\w)/}. + * + *
The regular expression is a dash, followed by parenthesis + * that form a group where we hold the word@apos;s first character.
+ * + * @param uri The original string to transform. + * + */ + public String dashedToCamelCase(String uri) { + String patternStr = "-(\\w)"; + + // Compile regular expression + Pattern pattern = Pattern.compile(patternStr); + Matcher matcher = pattern.matcher(uri); + + // Replace all occurrences of pattern + StringBuffer sb = new StringBuffer(); + boolean matchFound = false; + while ((matchFound = matcher.find() ) ) { + // Get the match result and remove the dash + String replaceStr = matcher.group().replaceAll("-", ""); + + // Convert to uppercase + replaceStr = replaceStr.toUpperCase(); + + // Insert replacement + matcher.appendReplacement(sb, replaceStr); + } + + matcher.appendTail(sb); + + // Get result + String result = sb.toString(); + + return result; + + } /** * A class used as a key to lookup a UrlMapping based on controller, action and parameter names */