1. /*
  2. * Copyright 2002-2004 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.web.servlet.mvc.multiaction;
  17. /**
  18. * Simple implementation of MethodNameResolver that maps URL to method
  19. * name. Although this is the default implementation used by the
  20. * MultiActionController class (because it requires no configuration),
  21. * it's bit naive for most applications. In particular, we don't usually
  22. * want to tie URL to implementation methods.
  23. *
  24. * <p>Maps the resource name after the last slash, ignoring an extension.
  25. * E.g. "/foo/bar/baz.html" to "baz", assuming a "/foo/bar/baz.html"
  26. * controller mapping to the respective MultiActionController.
  27. * Doesn't support wildcards.
  28. *
  29. * @author Rod Johnson
  30. * @author Juergen Hoeller
  31. */
  32. public class InternalPathMethodNameResolver extends AbstractUrlMethodNameResolver {
  33. protected String getHandlerMethodNameForUrlPath(String urlPath) {
  34. String name = urlPath;
  35. // look at resource name after last slash
  36. int slashIndex = name.lastIndexOf('/');
  37. if (slashIndex != -1) {
  38. name = name.substring(slashIndex+1);
  39. }
  40. // ignore extension
  41. int dotIndex = name.lastIndexOf('.');
  42. if (dotIndex != -1) {
  43. name = name.substring(0, dotIndex);
  44. }
  45. return name;
  46. }
  47. }