01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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:
17: package org.springframework.util;
18:
19: /**
20: * Strategy interface for <code>String</code>-based path matching.
21: *
22: * <p>Used by {@link org.springframework.core.io.support.PathMatchingResourcePatternResolver},
23: * {@link org.springframework.web.servlet.handler.AbstractUrlHandlerMapping},
24: * {@link org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver},
25: * and {@link org.springframework.web.servlet.mvc.WebContentInterceptor}.
26: *
27: * <p>The default implementation is {@link AntPathMatcher}, supporting the
28: * Ant-style pattern syntax.
29: *
30: * @author Juergen Hoeller
31: * @since 1.2
32: * @see AntPathMatcher
33: */
34: public interface PathMatcher {
35:
36: /**
37: * Does the given <code>string</code> represent a pattern that can be matched
38: * by an implementation of this interface?
39: * <p>If the return value is <code>false</code>, then the {@link #match}
40: * method does not have to be used because direct equality comparisons
41: * on the static path Strings will lead to the same result.
42: * @param text the <code>string</code> to check
43: * @return <code>true</code> if the given <code>string</code> represents a pattern
44: */
45: boolean isPattern(String text);
46:
47: /**
48: * Match the given <code>text</code> against the given <code>pattern</code>,
49: * according to this PathMatcher's matching strategy.
50: * @param pattern the pattern to match against
51: * @param text the string to test
52: * @return <code>true</code> if the supplied <code>text</code> matched,
53: * <code>false</code> if it didn't
54: */
55: boolean match(String pattern, String text);
56:
57: /**
58: * Given a pattern and a full path, determine the pattern-mapped part.
59: * <p>This method is supposed to find out which part of the path is matched
60: * dynamically through an actual pattern, that is, it strips off a statically
61: * defined leading path from the given full path, returning only the actually
62: * pattern-matched part of the path.
63: * <p>For example: For "myroot/*.html" as pattern and "myroot/myfile.html"
64: * as full path, this method should return "myfile.html". The detailed
65: * determination rules are specified to this PathMatcher's matching strategy.
66: * <p>A simple implementation may return the given full path as-is in case
67: * of an actual pattern, and the empty String in case of the pattern not
68: * containing any dynamic parts (i.e. the <code>pattern</code> parameter being
69: * a static path that wouldn't qualify as an actual {@link #isPattern pattern}).
70: * A sophisticated implementation will differentiate between the static parts
71: * and the dynamic parts of the given path pattern.
72: * @param pattern the path pattern
73: * @param path the full path to introspect
74: * @return the pattern-mapped part of the given <code>path</code>
75: * (never <code>null</code>)
76: */
77: String extractPathWithinPattern(String pattern, String path);
78:
79: }
|