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
21 import org.apache.tools.ant.input.DefaultInputHandler;
22 import org.apache.tools.ant.input.InputRequest;
23
24 /**
25 * Input handler to display of a multiple choice menu
26 *
27 */
28 public class XMenuInputHandler extends DefaultInputHandler {
29
30 /**
31 *
32 */
33 public XMenuInputHandler() {
34
35 super();
36 }
37
38 protected String getPrompt(InputRequest request) {
39
40 String prompt = request.getPrompt();
41 if (request instanceof XMultipleChoiceInputRequest) {
42 StringBuffer sb = new StringBuffer("\n" + prompt);
43 sb.append("\n\n");
44 Iterator i = ((XMultipleChoiceInputRequest) request).getOptions().iterator();
45 boolean first = true;
46 int count = 0;
47 while (i.hasNext()) {
48 if (!first) {
49 sb.append("\n");
50 }
51 count++;
52 XInputOption o = (XInputOption) i.next();
53 sb.append(" " + count + ") " + o.displayName());
54 if (o.isDefault()) {
55 sb.append(" (default)");
56 }
57 first = false;
58 }
59 prompt = sb.toString();
60 }
61 return prompt;
62 }
63
64 }