01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.deployment.cli;
17:
18: import java.io.IOException;
19: import java.io.InputStream;
20: import java.io.Writer;
21: import java.io.OutputStream;
22: import java.io.PrintWriter;
23: import java.io.OutputStreamWriter;
24:
25: import jline.ConsoleReader;
26:
27: /**
28: * Prompts a user for input; optionally masking.
29: *
30: * <p>
31: * Uses the <a href="http://jline.sf.net">JLine</a> library to provide a rich user experence.
32: *
33: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
34: */
35: public class InputPrompt {
36: private ConsoleReader reader;
37:
38: public InputPrompt(final InputStream in, final Writer out)
39: throws IOException {
40: this .reader = new ConsoleReader(in, out);
41: }
42:
43: public InputPrompt(final InputStream in, final OutputStream out)
44: throws IOException {
45: this (in, new PrintWriter(new OutputStreamWriter(out), true));
46: }
47:
48: /**
49: * Displays the prompt, grabs the input.
50: */
51: public String getInput(final String prompt, final Character mask)
52: throws IOException {
53: if (mask == null) {
54: return reader.readLine(prompt);
55: } else {
56: return reader.readLine(prompt, mask);
57: }
58: }
59:
60: public String getInput(final String prompt, final char mask)
61: throws IOException {
62: return getInput(prompt, new Character(mask));
63: }
64:
65: public String getInput(final String prompt) throws IOException {
66: return getInput(prompt, null);
67: }
68:
69: /**
70: * Displays the prompt, grabs the input masking with '*'.
71: */
72: public String getPassword(final String prompt) throws IOException {
73: return getInput(prompt, '*');
74: }
75: }
|