01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.tools.ant.types.resources.selectors;
19:
20: import org.apache.tools.ant.types.Resource;
21: import org.apache.tools.ant.types.selectors.SelectorUtils;
22:
23: /**
24: * Name ResourceSelector.
25: * @since Ant 1.7
26: */
27: public class Name implements ResourceSelector {
28: private String pattern;
29: private boolean cs = true;
30:
31: /**
32: * Set the pattern to compare names against.
33: * @param n the pattern String to set.
34: */
35: public void setName(String n) {
36: pattern = n;
37: }
38:
39: /**
40: * Get the pattern used by this Name ResourceSelector.
41: * @return the String selection pattern.
42: */
43: public String getName() {
44: return pattern;
45: }
46:
47: /**
48: * Set whether the name comparisons are case-sensitive.
49: * @param b boolean case-sensitivity flag.
50: */
51: public void setCaseSensitive(boolean b) {
52: cs = b;
53: }
54:
55: /**
56: * Learn whether this Name ResourceSelector is case-sensitive.
57: * @return boolean case-sensitivity flag.
58: */
59: public boolean isCaseSensitive() {
60: return cs;
61: }
62:
63: /**
64: * Return true if this Resource is selected.
65: * @param r the Resource to check.
66: * @return whether the Resource was selected.
67: */
68: public boolean isSelected(Resource r) {
69: String n = r.getName();
70: if (SelectorUtils.match(pattern, n, cs)) {
71: return true;
72: }
73: String s = r.toString();
74: return s.equals(n) ? false : SelectorUtils
75: .match(pattern, s, cs);
76: }
77:
78: }
|