View Javadoc

1   /*
2    * Copyright [2005] [University Corporation for Advanced Internet Development, 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  
17  package edu.internet2.middleware.ant.input;
18  
19  import java.util.Iterator;
20  import java.util.Vector;
21  
22  import org.apache.tools.ant.ProjectComponent;
23  import org.apache.tools.ant.util.StringUtils;
24  
25  /**
26   * 
27   */
28  public class XInputOption extends ProjectComponent {
29  
30      private Boolean caseSensitive = null;
31  
32      private String value = "";
33  
34      private Vector validArgs = null;
35  
36      private String displayName = null;
37  
38      private boolean isDefault = false;
39  
40      public XInputOption() {
41  
42          super();
43      }
44  
45      public XInputOption(String value, String validargs, String displayName) {
46  
47          setValue(value);
48          setValidArgs(validargs);
49          addText(displayName);
50      }
51  
52      public void setCasesensitive(boolean b) {
53  
54          setCaseSensitive(new Boolean(b));
55      }
56  
57      public void setCaseSensitive(Boolean b) {
58  
59          this.caseSensitive = b;
60      }
61  
62      public Boolean getCaseSensitive() {
63  
64          return this.caseSensitive;
65      }
66  
67      public void setValue(String value) {
68  
69          this.value = value;
70      }
71  
72      public String getValue() {
73  
74          if (value == null || value.equals("")) {
75              return displayName();
76          }
77  
78          return this.value;
79      }
80  
81      public void setValidArgs(String validargs) {
82  
83          this.validArgs = StringUtils.split(validargs, ',');
84      }
85  
86      public Vector getValidArgs() {
87  
88          if (validArgs != null) {
89              return this.validArgs;
90          } else {
91              Vector v = new Vector();
92              v.add(getValue());
93              return v;
94          }
95      }
96  
97      public void addText(String text) {
98  
99          this.displayName = text;
100     }
101 
102     public String displayName() {
103 
104         return displayName;
105     }
106 
107     public void setIsDefault(boolean b) {
108 
109         this.isDefault = b;
110     }
111 
112     public boolean isDefault() {
113 
114         return this.isDefault;
115     }
116 
117     public boolean acceptsInput(String input) {
118 
119         if (input.equals("") && isDefault()) {
120             return true;
121         }
122 
123         Iterator i = getValidArgs().iterator();
124         while (i.hasNext()) {
125             String arg = (String) i.next();
126             if (getCaseSensitive().booleanValue()) {
127                 if (arg.equals(input)) {
128                     return true;
129                 }
130             } else {
131                 if (arg.equalsIgnoreCase(input)) {
132                     return true;
133                 }
134             }
135         }
136         return false;
137     }
138 }