UriPatternMatcher.java revision 9e2d95b4393bd41b7eb882705d208124e2a4dd18
1/**
2 * Copyright (C) 2008 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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
17package com.google.inject.servlet;
18
19/**
20 * A general interface for matching a URI against a URI pattern. Guice-servlet provides regex and
21 * servlet-style pattern matching out of the box.
22 *
23 * @author dhanji@gmail.com (Dhanji R. Prasanna)
24 */
25interface UriPatternMatcher {
26  /**
27   * @param uri A "contextual" (i.e. relative) Request URI, *not* a complete one.
28   * @return Returns true if the uri matches the pattern.
29   */
30  boolean matches(String uri);
31
32  /**
33   * @param pattern The Path that this service pattern can match against.
34   * @return Returns a canonical servlet path from this pattern. For instance, if the pattern is
35   *         {@code /home/*} then the path extracted will be {@code /home}. Each pattern matcher
36   *         implementation must decide and publish what a canonical path represents.
37   *
38   *         NOTE(dhanji): This method returns null for the regex pattern matcher.
39   */
40  String extractPath(String pattern);
41
42  /** Returns the type of pattern this is. */
43  UriPatternType getPatternType();
44}
45