Moved over some of the security stuff from Photos.
[utils] / security / src / main / java / org / wamblee / security / authorization / RegexpPathCondition.java
1 /*
2  * Copyright 2005 the original author or authors.
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
17 package org.wamblee.security.authorization;
18
19 import org.wamblee.persistence.AbstractPersistent;
20
21 /**
22  * Condition to check whether a path  matches a given regula expression.
23  */
24 public class RegexpPathCondition extends AbstractPersistent implements PathCondition {
25     
26     /**
27      * String the path must start with. 
28      */
29     private String _pattern; 
30     
31     /**
32      * Constructs the condition. 
33      * @param aPattern String the path must start with. 
34      */
35     public RegexpPathCondition(String aPattern) { 
36         _pattern = aPattern; 
37     }
38     
39     /**
40      * For OR mapping. 
41      *
42      */
43     protected RegexpPathCondition() { 
44         _pattern = null; 
45     }
46
47     /* (non-Javadoc)
48      * @see org.wamblee.security.authorization.PathCondition#matches(java.lang.String)
49      */
50     public boolean matches(String aPath) {
51         return aPath.matches(_pattern);
52     }
53
54     /**
55      * @return Returns the _path.
56      */
57     protected String getPattern() {
58         return _pattern;
59     }
60
61     /**
62      * @param aPattern The _path to set.
63      */
64     protected void setPattern(String aPattern) {
65         _pattern = aPattern;
66     }
67     
68     /* (non-Javadoc)
69      * @see java.lang.Object#toString()
70      */
71     @Override
72     public String toString() {
73         return "RegexpCondition(pattern = '" + _pattern + "')";
74     }
75 }