You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

QueryCommandParser.java 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.commandparser;
  23. import com.dmdirc.Query;
  24. import com.dmdirc.Server;
  25. import com.dmdirc.ui.interfaces.InputWindow;
  26. /**
  27. * A command parser that is tailored for use in a query environment. Handles
  28. * both query and server commands.
  29. * @author chris
  30. */
  31. public final class QueryCommandParser extends CommandParser {
  32. /**
  33. * The server instance that this parser is attached to.
  34. */
  35. private final Server server;
  36. /**
  37. * The query instance that this parser is attached to.
  38. */
  39. private final Query query;
  40. /**
  41. * Creates a new instance of QueryCommandParser.
  42. * @param newServer The server instance that this parser is attached to
  43. * @param newQuery The query instance that this parser is attached to
  44. */
  45. public QueryCommandParser(final Server newServer, final Query newQuery) {
  46. super();
  47. server = newServer;
  48. query = newQuery;
  49. }
  50. /** Loads the relevant commands into the parser. */
  51. protected void loadCommands() {
  52. CommandManager.loadGlobalCommands(this);
  53. CommandManager.loadServerCommands(this);
  54. CommandManager.loadQueryCommands(this);
  55. }
  56. /** {@inheritDoc} */
  57. protected void executeCommand(final InputWindow origin,
  58. final boolean isSilent, final Command command, final String... args) {
  59. if (command instanceof QueryCommand) {
  60. ((QueryCommand) command).execute(origin, server, query, isSilent, args);
  61. } else if (command instanceof ServerCommand) {
  62. ((ServerCommand) command).execute(origin, server, isSilent, args);
  63. } else {
  64. ((GlobalCommand) command).execute(origin, isSilent, args);
  65. }
  66. }
  67. /**
  68. * Called when the input was a line of text that was not a command. This normally
  69. * means it is sent to the server/channel/user as-is, with no further processing.
  70. * @param origin The window in which the command was typed
  71. * @param line The line input by the user
  72. */
  73. protected void handleNonCommand(final InputWindow origin, final String line) {
  74. query.sendLine(line);
  75. }
  76. }