public void doTag()

in jelly-tags/interaction/src/main/java/org/apache/commons/jelly/tags/interaction/AskTag.java [139:202]


    public void doTag(XMLOutput output) {
        if (question != null) {
            if (defaultInput != null) {
                System.out.println(question + " [" + defaultInput + "]");
            } else {
                System.out.println(question);
            }
            // The prompt should be just before the user's input,
            // but it doesn't work ...
            //System.out.print(prompt + " ");
        }

        ConsoleReader consoleReader;
        String input = null;

        try {
            consoleReader = new ConsoleReader();
        } catch (IOException e) {
            logger.warn("couldnt create console reader", e);
            consoleReader = null;
        }

        try {
            if (consoleReader != null
                    && consoleReader.getTerminal().isSupported()) {

                // resue the static history, so our commands are remembered
                consoleReader.setHistory(consoleHistory);

                // hate the bell!
                consoleReader.setBellEnabled(false);

                // add old commands as tab completion history
                List oldCommandsAsList = useHistoryCompletor
                    ? new ArrayList(consoleHistory.getHistoryList()) : new ArrayList(0);
                // add predefined commands if given
                if (completor != null && !completor.isEmpty()) {
                    oldCommandsAsList.addAll(completor);
                }
                String[] oldCommands = new String[oldCommandsAsList.size()];
                oldCommandsAsList.toArray(oldCommands);
                consoleReader.addCompletor (new SimpleCompletor (oldCommands));

                // read the input!
                input = consoleReader.readLine();
                
                // trim the input for tab completion
                input = input.trim();

                if (defaultInput != null && input.trim().isEmpty()) {
                    input = defaultInput;
                }
            } else {
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(System.in));
                input = reader.readLine();
            }

        } catch (IOException ex) {
            logger.warn("error setting up the console reader", ex);
        }

        context.setVariable(answer, input);
    }