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  
21  import org.apache.tools.ant.input.DefaultInputHandler;
22  import org.apache.tools.ant.input.InputRequest;
23  
24  /**
25   * Extended version of <code>org.apache.tools.ant.input.DefaultInputHandler</code>.
26   */
27  public class XInputHandler extends DefaultInputHandler {
28  
29      public XInputHandler() {
30  
31          super();
32  
33      }
34  
35      protected String getPrompt(InputRequest request) {
36  
37          String prompt = request.getPrompt();
38          if (request instanceof XMultipleChoiceInputRequest) {
39              StringBuffer sb = new StringBuffer("\n" + prompt);
40              sb.append(" [");
41              Iterator i = ((XMultipleChoiceInputRequest) request).getOptions().iterator();
42              boolean first = true;
43              while (i.hasNext()) {
44                  if (!first) {
45                      sb.append(",");
46                  }
47                  XInputOption o = (XInputOption) i.next();
48                  sb.append(o.isDefault() ? o.displayName().toUpperCase() : o.displayName());
49                  first = false;
50              }
51              sb.append("]");
52              prompt = sb.toString();
53          }
54          return prompt;
55      }
56  
57  }