URLPatternpublic class URLPattern extends Object implements Comparable
Fields Summary |
---|
private static String | DEFAULT_PATTERN | private int | patternType | private final String | pattern | public static final int | PT_DEFAULT | public static final int | PT_EXTENSION | public static final int | PT_PREFIX | public static final int | PT_EXACT |
Constructors Summary |
---|
public URLPattern()
this.pattern = DEFAULT_PATTERN;
this.patternType = PT_DEFAULT;
| public URLPattern(String p)
if (p == null) {
this.pattern = DEFAULT_PATTERN;
this.patternType = PT_DEFAULT;
}
else this.pattern = p;
|
Methods Summary |
---|
public int | compareTo(java.lang.Object o)
if (!(o instanceof URLPattern))
throw new ClassCastException("argument must be URLPattern");
URLPattern p = (URLPattern) o;
if (p == null) p = new URLPattern(null);
int refPatternType = this.patternType();
/* The comparison yields increasing sort order
* by pattern type. That is, prefix patterns sort before exact
* patterns. Also shorter length patterns precede longer
* length patterns. This is important for the URLPatternList
* canonicalization done by URLPatternSpec.setURLPatternArray
*/
int result = refPatternType - p.patternType();
if (result == 0) {
if (refPatternType == PT_PREFIX || refPatternType == PT_EXACT) {
result = this.getPatternDepth() - p.getPatternDepth();
if (result == 0) result = this.pattern.compareTo(p.pattern);
}
else result = this.pattern.compareTo(p.pattern);
}
return (result > 0 ? 1 : (result < 0 ? -1 : 0));
| public boolean | equals(java.lang.Object obj)
if (! (obj instanceof URLPattern)) return false;
return this.pattern.equals(((URLPattern) obj).pattern);
| public int | getPatternDepth()
int i = 0;
int depth = 1;
while (i >= 0) {
i = this.pattern.indexOf("/",i);
if (i >= 0 ) {
if (i == 0 && depth != 1)
throw new IllegalArgumentException("// in pattern");
i += 1;
}
}
return depth;
| public boolean | implies(javax.security.jacc.URLPattern p)Does this pattern imply (that is, match) the argument pattern?
This method follows the same rules (in the same order) as those used
for mapping requests to servlets.
Two URL patterns match if they are related as follows:
- their pattern values are String equivalent, or
- this pattern is the path-prefix pattern "/*", or
- this pattern is a path-prefix pattern (that is, it starts with
"/" and ends with "/*") and the argument pattern starts with the
substring of this pattern, minus its last 2 characters, and the
next character of the argument pattern, if there is one, is "/", or
- this pattern is an extension pattern (that is, it starts with
"*.") and the argument pattern ends with this pattern, or
- the reference pattern is the special default pattern, "/",
which matches all argument patterns.
// Normalize the argument
if (p == null) p = new URLPattern(null);
String path = p.pattern;
String pattern = this.pattern;
// Check for exact match
if (pattern.equals(path))
return (true);
// Check for path prefix matching
if (pattern.startsWith("/") && pattern.endsWith("/*")) {
pattern = pattern.substring(0, pattern.length() - 2);
int length = pattern.length();
if (length == 0) return (true); // "/*" is the same as the DEFAULT_PATTERN
return (path.startsWith(pattern) &&
(path.length() == length ||
path.substring(length).startsWith("/")));
}
// Check for suffix matching
if (pattern.startsWith("*.")) {
int slash = path.lastIndexOf('/");
int period = path.lastIndexOf('.");
if ((slash >= 0) && (period > slash) &&
path.endsWith(pattern.substring(1))) {
return (true);
}
return (false);
}
// Check for universal mapping
if (pattern.equals(DEFAULT_PATTERN))
return (true);
return (false);
| public int | patternType()
if (this.patternType < 0) {
if (this.pattern.startsWith("*."))
this.patternType = PT_EXTENSION;
else if (this.pattern.startsWith("/") &&
this.pattern.endsWith("/*")) this.patternType = PT_PREFIX;
else if (this.pattern.equals(DEFAULT_PATTERN))
this.patternType = PT_DEFAULT;
else this.patternType = PT_EXACT;
}
return this.patternType;
| public java.lang.String | toString()
return this.pattern;
|
|