Паттерн: Шаблонный метод (Template Method)
Фрагмент: RequestProcessor.processPath() [java]
  1. protected String processPath(HttpServletRequest request,
  2. HttpServletResponse response)
  3. throws IOException {
  4. String path;
  5.  
  6. // For prefix matching, match on the path info (if any)
  7. path = (String) request.getAttribute(INCLUDE_PATH_INFO);
  8.  
  9. if (path == null) {
  10. path = request.getPathInfo();
  11. }
  12.  
  13. if ((path != null) && (path.length() > 0)) {
  14. return (path);
  15. }
  16.  
  17. // For extension matching, strip the module prefix and extension
  18. path = (String) request.getAttribute(INCLUDE_SERVLET_PATH);
  19.  
  20. if (path == null) {
  21. path = request.getServletPath();
  22. }
  23.  
  24. String prefix = moduleConfig.getPrefix();
  25.  
  26. if (!path.startsWith(prefix)) {
  27. String msg = getInternal().getMessage("processPath");
  28.  
  29. log.error(msg + " " + request.getRequestURI());
  30. response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
  31.  
  32. return null;
  33. }
  34.  
  35. path = path.substring(prefix.length());
  36.  
  37. int slash = path.lastIndexOf("/");
  38. int period = path.lastIndexOf(".");
  39.  
  40. if ((period >= 0) && (period > slash)) {
  41. path = path.substring(0, period);
  42. }
  43.  
  44. return (path);
  45. }