Commits

mrdon  committed 0f82e75

Adding guessing of result type
WW-646

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@1840e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits 874e1b3

Comments (0)

Files changed (2)

File src/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProvider.java

                 ResultTypeConfig config = packageContext.getResultType(resultType);
 
                 if (config == null) {
-                    throw new ConfigurationException("There is no result type defined for type '" + resultType + "' mapped with name '" + resultName + "'", resultElement);
+                    throw new ConfigurationException("There is no result type defined for type '" + resultType
+                            + "' mapped with name '" + resultName + "'."
+                            + "  Did you mean '" + guessResultType(resultType) + "'?", resultElement);
                 }
 
                 String resultClass = config.getClazz();
         return results;
     }
 
+    protected String guessResultType(String type) {
+        StringBuilder sb = null;
+        if (type != null) {
+            sb = new StringBuilder();
+            boolean capNext = false;
+            for (int x=0; x<type.length(); x++) {
+                char c = type.charAt(x);
+                if (c == '-') {
+                    capNext = true;
+                    continue;
+                } else if (Character.isLowerCase(c) && capNext) {
+                    c = Character.toUpperCase(c);
+                    capNext = false;
+                }
+                sb.append(c);
+            }
+        }
+        return (sb != null ? sb.toString() : null);
+    }
+
     /**
      * Build a map of ResultConfig objects from below a given XML element.
      */

File src/test/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderTest.java

         assertNotNull(runtimeConfiguration.getActionConfig("/namespace4", "action4"));
         assertNotNull(runtimeConfiguration.getActionConfig("/namespace5", "action5"));
     }
+
+    public void testGuessResultType() {
+        XmlConfigurationProvider prov = new XmlConfigurationProvider();
+
+        assertEquals(null, prov.guessResultType(null));
+        assertEquals("foo", prov.guessResultType("foo"));
+        assertEquals("foo", prov.guessResultType("foo-"));
+        assertEquals("fooBar", prov.guessResultType("foo-bar"));
+        assertEquals("fooBarBaz", prov.guessResultType("foo-bar-baz"));
+    }
 }