ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/proposal/sandbox/input/src/main/org/apache/tools/ant/input DefaultInputHandler.java
Date Fri, 08 Mar 2002 08:32:28 GMT
bodewig     02/03/08 00:32:28

  Modified:    proposal/sandbox/input/src/main/org/apache/tools/ant/input
                        DefaultInputHandler.java
  Log:
  Make DefaultInputHandler subclass friendly.
  
  Revision  Changes    Path
  1.3       +36 -13    jakarta-ant/proposal/sandbox/input/src/main/org/apache/tools/ant/input/DefaultInputHandler.java
  
  Index: DefaultInputHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/input/src/main/org/apache/tools/ant/input/DefaultInputHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultInputHandler.java	26 Feb 2002 10:29:29 -0000	1.2
  +++ DefaultInputHandler.java	8 Mar 2002 08:32:28 -0000	1.3
  @@ -56,6 +56,7 @@
   
   import java.io.BufferedReader;
   import java.io.IOException;
  +import java.io.InputStream;
   import java.io.InputStreamReader;
   import java.util.Enumeration;
   
  @@ -65,7 +66,7 @@
    * Prompts on System.out, reads input from System.in
    *
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   public class DefaultInputHandler implements InputHandler {
       
  @@ -76,6 +77,31 @@
       }
   
       public void handleInput(InputRequest request) throws BuildException {
  +        String prompt = getPrompt(request);
  +        BufferedReader in = 
  +            new BufferedReader(new InputStreamReader(getInputStream()));
  +        do {
  +            System.out.println(prompt);
  +            try {
  +                String input = in.readLine();
  +                request.setInput(input);
  +            } catch (IOException e) {
  +                throw new BuildException("Failed to read input from Console.",
  +                                         e);
  +            }
  +        } while (!request.isInputValid());
  +    }
  +
  +    /**
  +     * Constructs user prompt from a request.
  +     *
  +     * <p>This implemenation adds (choice1,choice2,choice3,...) to the
  +     * prompt for <code>MultipleChoiceInputRequest</code>s.</p>
  +     *
  +     * @param request the request to construct the prompt for.
  +     *                Must not be <code>null</code>.
  +     */
  +    protected String getPrompt(InputRequest request) {
           String prompt = request.getPrompt();
           if (request instanceof MultipleChoiceInputRequest) {
               StringBuffer sb = new StringBuffer(prompt);
  @@ -94,17 +120,14 @@
               sb.append(")");
               prompt = sb.toString();
           }
  -            
  -        do {
  -            System.out.println(prompt);
  -            try {
  -                BufferedReader in = 
  -                    new BufferedReader(new InputStreamReader(System.in));
  -                String input = in.readLine();
  -                request.setInput(input);
  -            } catch (IOException e) {
  -                throw  new BuildException("Failed to read input from Console.", e);
  -            }
  -        } while (!request.isInputValid());
  +        return prompt;
  +    }
  +
  +    /**
  +     * Returns the input stream from which the user input should be read.
  +     */
  +    protected InputStream getInputStream() {
  +        return System.in;
       }
  +
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message