Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
f7cd9865
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f7cd9865
编写于
10月 10, 2010
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
polishing
上级
ebe8052d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
24 deletion
+23
-24
org.springframework.core/src/main/java/org/springframework/util/AntPathMatcher.java
...rc/main/java/org/springframework/util/AntPathMatcher.java
+15
-16
org.springframework.core/src/main/java/org/springframework/util/PathMatcher.java
...e/src/main/java/org/springframework/util/PathMatcher.java
+8
-8
未找到文件。
org.springframework.core/src/main/java/org/springframework/util/AntPathMatcher.java
浏览文件 @
f7cd9865
/*
* Copyright 2002-20
09
the original author or authors.
* Copyright 2002-20
10
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -19,8 +19,8 @@ package org.springframework.util;
import
java.util.Comparator
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
java.util.regex.Pattern
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* PathMatcher implementation for Ant-style path patterns. Examples are provided below.
...
...
@@ -53,11 +53,13 @@ public class AntPathMatcher implements PathMatcher {
private
String
pathSeparator
=
DEFAULT_PATH_SEPARATOR
;
/** Set the path separator to use for pattern parsing. Default is "/", as in Ant. */
public
void
setPathSeparator
(
String
pathSeparator
)
{
this
.
pathSeparator
=
(
pathSeparator
!=
null
?
pathSeparator
:
DEFAULT_PATH_SEPARATOR
);
}
public
boolean
isPattern
(
String
path
)
{
return
(
path
.
indexOf
(
'*'
)
!=
-
1
||
path
.
indexOf
(
'?'
)
!=
-
1
);
}
...
...
@@ -70,19 +72,18 @@ public class AntPathMatcher implements PathMatcher {
return
doMatch
(
pattern
,
path
,
false
,
null
);
}
/**
* Actually match the given <code>path</code> against the given <code>pattern</code>.
*
* @param pattern the pattern to match against
* @param path the path String to test
* @param fullMatch whether a full pattern match is required (else a pattern match
as far as the given base path goes
* is sufficient)
* @param fullMatch whether a full pattern match is required (else a pattern match
*
as far as the given base path goes
is sufficient)
* @return <code>true</code> if the supplied <code>path</code> matched, <code>false</code> if it didn't
*/
protected
boolean
doMatch
(
String
pattern
,
String
path
,
boolean
fullMatch
,
protected
boolean
doMatch
(
String
pattern
,
String
path
,
boolean
fullMatch
,
Map
<
String
,
String
>
uriTemplateVariables
)
{
if
(
path
.
startsWith
(
this
.
pathSeparator
)
!=
pattern
.
startsWith
(
this
.
pathSeparator
))
{
return
false
;
}
...
...
@@ -210,7 +211,6 @@ public class AntPathMatcher implements PathMatcher {
/**
* Tests whether or not a string matches against a pattern. The pattern may contain two special characters:<br> '*'
* means zero or more characters<br> '?' means one and only one character
*
* @param pattern pattern to match against. Must not be <code>null</code>.
* @param str string which must be matched against the pattern. Must not be <code>null</code>.
* @return <code>true</code> if the string matches against the pattern, or <code>false</code> otherwise.
...
...
@@ -271,9 +271,11 @@ public class AntPathMatcher implements PathMatcher {
}
/**
* Combines two patterns into a new pattern that is returned. <p>This implementation simply concatenates the two
* patterns, unless the first pattern contains a file extension match (such as {@code *.html}. In that case, the second
* pattern should be included in the first, or an {@code IllegalArgumentException} is thrown. <p>For example: <table>
* Combines two patterns into a new pattern that is returned.
* <p>This implementation simply concatenates the two patterns, unless the first pattern
* contains a file extension match (such as {@code *.html}. In that case, the second pattern
* should be included in the first, or an {@code IllegalArgumentException} is thrown.
* <p>For example: <table>
* <tr><th>Pattern 1</th><th>Pattern 2</th><th>Result</th></tr> <tr><td>/hotels</td><td>{@code
* null}</td><td>/hotels</td></tr> <tr><td>{@code null}</td><td>/hotels</td><td>/hotels</td></tr>
* <tr><td>/hotels</td><td>/bookings</td><td>/hotels/bookings</td></tr> <tr><td>/hotels</td><td>bookings</td><td>/hotels/bookings</td></tr>
...
...
@@ -282,7 +284,6 @@ public class AntPathMatcher implements PathMatcher {
* <tr><td>/hotels/**</td><td>{hotel}</td><td>/hotels/**/{hotel}</td></tr>
* <tr><td>/*.html</td><td>/hotels.html</td><td>/hotels.html</td></tr> <tr><td>/*.html</td><td>/hotels</td><td>/hotels.html</td></tr>
* <tr><td>/*.html</td><td>/*.txt</td><td>IllegalArgumentException</td></tr> </table>
*
* @param pattern1 the first pattern
* @param pattern2 the second pattern
* @return the combination of the two patterns
...
...
@@ -354,16 +355,13 @@ public class AntPathMatcher implements PathMatcher {
/**
* Given a full path, returns a {@link Comparator} suitable for sorting patterns in order of explicitness.
*
* <p>The returned <code>Comparator</code> will {@linkplain java.util.Collections#sort(java.util.List,
* java.util.Comparator) sort} a list so that more specific patterns (without uri templates or wild cards) come before
* generic patterns. So given a list with the following patterns: <ol> <li><code>/hotels/new</code></li>
* <li><code>/hotels/{hotel}</code></li> <li><code>/hotels/*</code></li> </ol> the returned comparator will sort this
* list so that the order will be as indicated.
*
* <p>The full path given as parameter is used to test for exact matches. So when the given path is {@code /hotels/2},
* the pattern {@code /hotels/2} will be sorted before {@code /hotels/1}.
*
* @param path the full path to use for comparison
* @return a comparator capable of sorting patterns in order of explicitness
*/
...
...
@@ -371,6 +369,7 @@ public class AntPathMatcher implements PathMatcher {
return
new
AntPatternComparator
(
path
);
}
private
static
class
AntPatternComparator
implements
Comparator
<
String
>
{
private
final
String
path
;
...
...
org.springframework.core/src/main/java/org/springframework/util/PathMatcher.java
浏览文件 @
f7cd9865
/*
* Copyright 2002-20
09
the original author or authors.
* Copyright 2002-20
10
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -96,7 +96,6 @@ public interface PathMatcher {
* variables are expressed through curly brackets ('{' and '}').
* <p>For example: For pattern "/hotels/{hotel}" and path "/hotels/1", this method will
* return a map containing "hotel"->"1".
*
* @param pattern the path pattern, possibly containing URI templates
* @param path the full path to extract template variables from
* @return a map, containing variable names as keys; variables values as values
...
...
@@ -104,11 +103,12 @@ public interface PathMatcher {
Map
<
String
,
String
>
extractUriTemplateVariables
(
String
pattern
,
String
path
);
/**
* Given a full path, returns a {@link Comparator} suitable for sorting patterns in order of explicitness for that path.
* <p>The full algorithm used depends on the underlying implementation, but generally, the returned
* <code>Comparator</code> will {@linkplain java.util.Collections#sort(java.util.List, java.util.Comparator) sort} a
* list so that more specific patterns (for that come before generic patterns.
*
* Given a full path, returns a {@link Comparator} suitable for sorting patterns
* in order of explicitness for that path.
* <p>The full algorithm used depends on the underlying implementation, but generally,
* the returned <code>Comparator</code> will
* {@linkplain java.util.Collections#sort(java.util.List, java.util.Comparator) sort}
* a list so that more specific patterns come before generic patterns.
* @param path the full path to use for comparison
* @return a comparator capable of sorting patterns in order of explicitness
*/
...
...
@@ -117,11 +117,11 @@ public interface PathMatcher {
/**
* Combines two patterns into a new pattern that is returned.
* <p>The full algorithm used for combining the two pattern depends on the underlying implementation.
*
* @param pattern1 the first pattern
* @param pattern2 the second pattern
* @return the combination of the two patterns
* @throws IllegalArgumentException when the two patterns cannot be combined
*/
String
combine
(
String
pattern1
,
String
pattern2
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录