Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
ResourceMatcherImpl |
|
| 2.0;2 |
1 | // Copyright 2004, 2005 The Apache Software Foundation |
|
2 | // |
|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 | // you may not use this file except in compliance with the License. |
|
5 | // You may obtain a copy of the License at |
|
6 | // |
|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | // |
|
9 | // Unless required by applicable law or agreed to in writing, software |
|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12 | // See the License for the specific language governing permissions and |
|
13 | // limitations under the License. |
|
14 | package org.apache.tapestry.asset; |
|
15 | ||
16 | import java.util.List; |
|
17 | ||
18 | import org.apache.tapestry.event.ResetEventListener; |
|
19 | import org.apache.tapestry.util.RegexpMatcher; |
|
20 | ||
21 | ||
22 | /** |
|
23 | * Implementation of {@link ResourceMatcher}. |
|
24 | * |
|
25 | */ |
|
26 | public class ResourceMatcherImpl implements ResetEventListener, ResourceMatcher { |
|
27 | ||
28 | /** regexp matcher engine. */ |
|
29 | protected RegexpMatcher _matcher; |
|
30 | /** Resource match configuration regexp strings. */ |
|
31 | protected List _contributions; |
|
32 | ||
33 | /** no args constructor. */ |
|
34 | 3 | public ResourceMatcherImpl() { } |
35 | ||
36 | /** |
|
37 | * Invoked by hivemind by default to initialize |
|
38 | * service. |
|
39 | */ |
|
40 | public void initializeService() |
|
41 | { |
|
42 | 3 | _matcher = new RegexpMatcher(); |
43 | 3 | } |
44 | ||
45 | /** |
|
46 | * {@inheritDoc} |
|
47 | */ |
|
48 | public synchronized void resetEventDidOccur() |
|
49 | { |
|
50 | 0 | _matcher.clear(); |
51 | 0 | } |
52 | ||
53 | /** |
|
54 | * {@inheritDoc} |
|
55 | */ |
|
56 | public boolean containsResource(String path) |
|
57 | { |
|
58 | 18 | if (_contributions == null || _contributions.size() < 1 || path == null) |
59 | 0 | return false; |
60 | ||
61 | 82 | for (int i = 0; i < _contributions.size(); i++) { |
62 | 77 | String pattern = (String)_contributions.get(i); |
63 | ||
64 | 77 | if (_matcher.contains(pattern, path)) |
65 | 13 | return true; |
66 | } |
|
67 | ||
68 | 5 | return false; |
69 | } |
|
70 | ||
71 | /** |
|
72 | * The set of contributed regexp strings that will positively |
|
73 | * match incoming path strings for this matcher. |
|
74 | * @param contributions |
|
75 | */ |
|
76 | public void setContributions(List contributions) |
|
77 | { |
|
78 | 3 | this._contributions = contributions; |
79 | 3 | } |
80 | } |