1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/main/java/org/vaadin/console/DefaultConsoleHandler.java Sun May 15 17:46:06 2011 +0400
1.3 @@ -0,0 +1,48 @@
1.4 +package org.vaadin.console;
1.5 +
1.6 +import java.util.HashSet;
1.7 +import java.util.Set;
1.8 +
1.9 +import org.vaadin.console.Console.Command;
1.10 +import org.vaadin.console.Console.Handler;
1.11 +
1.12 +/**
1.13 + * Default handler for console.
1.14 + *
1.15 + */
1.16 +public class DefaultConsoleHandler implements Handler {
1.17 +
1.18 + private static final long serialVersionUID = 1L;
1.19 +
1.20 + public void handleException(final Console console, final Exception e,
1.21 + final Command cmd, final String[] argv) {
1.22 + e.printStackTrace();
1.23 + console.println(e.getClass().getSimpleName() + ": " + e.getMessage());
1.24 + }
1.25 +
1.26 + public Set<String> getSuggestions(final Console console, final String input) {
1.27 +
1.28 + final String prefix = console.parseCommandPrefix(input);
1.29 + if (prefix != null) {
1.30 + final Set<String> matches = new HashSet<String>();
1.31 + final Set<String> cmds = console.getCommands();
1.32 + for (final String cmd : cmds) {
1.33 + if (cmd.startsWith(prefix)) {
1.34 + matches.add(cmd);
1.35 + }
1.36 + }
1.37 + return matches;
1.38 + }
1.39 + return null;
1.40 + }
1.41 +
1.42 + public void inputReceived(final Console console, final String lastInput) {
1.43 + console.parseAndExecuteCommand(lastInput);
1.44 + console.prompt();
1.45 + }
1.46 +
1.47 + public void commandNotFound(final Console console, final String[] argv) {
1.48 + console.print("ERROR: " + argv[0] + ": command not found.");
1.49 + }
1.50 +
1.51 +}