View Javadoc
1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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  package org.kuali.common.aws.s3;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.common.aws.s3.monitor.BaseCase;
20  
21  public class ExternalOnlyBaseCase implements BaseCase {
22  
23  	String delimiter;
24  	String token;
25  
26  	public boolean isBaseCase(String prefix) {
27  		boolean test1 = endsWithVersionNumber(prefix, delimiter);
28  		boolean test2 = endsWithToken(prefix, delimiter, token);
29  		boolean test3 = !prefix.startsWith("external/");
30  		return test1 || test2 || test3;
31  	}
32  
33  	public boolean endsWithVersionNumber(String prefix, String delimiter) {
34  		String[] tokens = prefix.split(delimiter);
35  		String lastToken = tokens[tokens.length - 1];
36  		String firstChar = lastToken.substring(0, 1);
37  		return StringUtils.isNumeric(firstChar);
38  	}
39  
40  	public boolean endsWithToken(String prefix, String delimiter, String token) {
41  		return prefix.endsWith(delimiter + token + delimiter);
42  	}
43  
44  	public String getDelimiter() {
45  		return delimiter;
46  	}
47  
48  	public void setDelimiter(String delimiter) {
49  		this.delimiter = delimiter;
50  	}
51  
52  	public String getToken() {
53  		return token;
54  	}
55  
56  	public void setToken(String token) {
57  		this.token = token;
58  	}
59  
60  }