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