1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.input.InputRequest;
23
24
25
26
27 public class XMultipleChoiceInputRequest extends InputRequest {
28
29 private Vector options = null;
30
31 public XMultipleChoiceInputRequest(String prompt, Vector options) {
32
33 super(prompt);
34 if (options == null) {
35 throw new IllegalArgumentException("choices must not be null");
36 }
37 this.options = options;
38 }
39
40 public Vector getOptions() {
41
42 return options;
43 }
44
45
46
47
48 public Vector getChoices() {
49
50 Vector choices = new Vector();
51
52 Iterator i = options.iterator();
53 while (i.hasNext()) {
54 XInputOption o = (XInputOption) i.next();
55 choices.add(o.displayName());
56 }
57
58 return choices;
59 }
60
61
62
63
64 public boolean isInputValid() {
65
66
67 Iterator i = options.iterator();
68 while (i.hasNext()) {
69 XInputOption o = (XInputOption) i.next();
70 if (o.acceptsInput(getInput())) {
71 setInput(o.getValue());
72 return true;
73 }
74 }
75
76
77 try {
78 Integer input = new Integer(getInput());
79 if (input.intValue() > 0 && input.intValue() <= options.size()) {
80 XInputOption o = (XInputOption) options.get(input.intValue() - 1);
81 setInput(o.getValue());
82 return true;
83 }
84 } catch (NumberFormatException nfe) {
85
86 }
87
88 return false;
89 }
90
91 }