01: /*
02: * Created on Apr 13, 2004
03: *
04: * To change the template for this generated file go to
05: * Window>Preferences>Java>Code Generation>Code and Comments
06: */
07: package org.xdev.base.xssl.util;
08:
09: import java.io.BufferedReader;
10: import java.io.InputStreamReader;
11: import java.util.HashMap;
12:
13: import org.xdev.base.util.Tools;
14: import org.xdev.base.xssl.XSSLReturn;
15:
16: /**
17: * @author AYegorov
18: *
19: * To change the template for this generated type comment go to
20: * Window>Preferences>Java>Code Generation>Code and Comments
21: */
22: public class ConsoleInput extends XSSLReturn {
23:
24: private Object returnValue = null;
25:
26: /**
27: * @param id
28: */
29: public ConsoleInput(String id) {
30: super (id);
31: }
32:
33: /**
34: * @param id
35: * @param properties
36: */
37: public ConsoleInput(String id, HashMap properties) {
38: super (id, properties);
39: }
40:
41: /* (non-Javadoc)
42: * @see org.xdev.base.core.object.Configuration#getValue()
43: */
44: public Object getObjectValue() {
45: return this .returnValue;
46: }
47:
48: /* (non-Javadoc)
49: * @see org.xdev.base.xssl.XSSLAction#set()
50: */
51: protected void set() throws Exception {
52:
53: String prompt = this .getProperty("prompt") + " ";
54:
55: System.out.print(prompt);
56:
57: String line = null;
58:
59: StringBuffer buffer = new StringBuffer();
60:
61: BufferedReader reader = new BufferedReader(
62: new InputStreamReader(System.in));
63:
64: String spacer = "";
65:
66: int size = prompt.length();
67:
68: for (int i = 0; i < size; i++) {
69: spacer += " ";
70: }
71:
72: boolean multiple = this .getBooleanProperty("multiple");
73:
74: while ((line = reader.readLine()) != null) {
75:
76: if (":quit".equalsIgnoreCase(line)) {
77: break;
78: }
79:
80: buffer.append(line);
81:
82: if (multiple) {
83: buffer.append("\n");
84: } else {
85: break;
86: }
87:
88: System.out.print(spacer);
89: }
90:
91: this.returnValue = buffer.toString();
92: }
93:
94: }
|