1 | |
package org.seasar.cubby.routing.impl; |
2 | |
|
3 | |
import java.util.Collections; |
4 | |
import java.util.List; |
5 | |
import java.util.regex.Matcher; |
6 | |
import java.util.regex.Pattern; |
7 | |
|
8 | |
import javax.servlet.http.HttpServletRequest; |
9 | |
import javax.servlet.http.HttpServletResponse; |
10 | |
|
11 | |
import org.seasar.cubby.routing.InternalForwardInfo; |
12 | |
import org.seasar.cubby.routing.PathResolver; |
13 | |
import org.seasar.cubby.routing.Router; |
14 | |
import org.seasar.cubby.util.CubbyUtils; |
15 | |
import org.seasar.framework.log.Logger; |
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | 0 | public class RouterImpl implements Router { |
24 | |
|
25 | |
|
26 | 0 | private static final Logger logger = Logger.getLogger(RouterImpl.class); |
27 | |
|
28 | |
|
29 | 0 | private static final List<Pattern> EMPTY_IGNORE_PATH_PATTERNS = Collections |
30 | |
.emptyList(); |
31 | |
|
32 | |
|
33 | |
private PathResolver pathResolver; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
public void setPathResolver(final PathResolver pathResolver) { |
42 | 0 | this.pathResolver = pathResolver; |
43 | 0 | } |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
public InternalForwardInfo routing(final HttpServletRequest request, |
49 | |
final HttpServletResponse response) { |
50 | 0 | return routing(request, response, EMPTY_IGNORE_PATH_PATTERNS); |
51 | |
} |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
public InternalForwardInfo routing(final HttpServletRequest request, |
57 | |
final HttpServletResponse response, List<Pattern> ignorePathPatterns) { |
58 | 0 | final String path = CubbyUtils.getPath(request); |
59 | 0 | if (logger.isDebugEnabled()) { |
60 | 0 | logger.log("DCUB0006", new Object[] { path }); |
61 | |
} |
62 | |
|
63 | 0 | if (isIgnorePath(path, ignorePathPatterns)) { |
64 | 0 | return null; |
65 | |
} |
66 | |
|
67 | 0 | final InternalForwardInfo internalForwardInfo = pathResolver |
68 | |
.getInternalForwardInfo(path, request.getMethod()); |
69 | 0 | return internalForwardInfo; |
70 | |
} |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
private boolean isIgnorePath(final String path, |
83 | |
List<Pattern> ignorePathPatterns) { |
84 | 0 | for (final Pattern pattern : ignorePathPatterns) { |
85 | 0 | final Matcher matcher = pattern.matcher(path); |
86 | 0 | if (matcher.matches()) { |
87 | 0 | return true; |
88 | |
} |
89 | 0 | } |
90 | 0 | return false; |
91 | |
} |
92 | |
|
93 | |
} |