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.

DCCCommandParser.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 2006-2010 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.addons.dcc;
  23. import com.dmdirc.commandparser.CommandArguments;
  24. import com.dmdirc.commandparser.CommandManager;
  25. import com.dmdirc.commandparser.CommandType;
  26. import com.dmdirc.commandparser.commands.Command;
  27. import com.dmdirc.commandparser.commands.GlobalCommand;
  28. import com.dmdirc.commandparser.parsers.CommandParser;
  29. import com.dmdirc.ui.interfaces.InputWindow;
  30. /**
  31. * DCC CommandParser
  32. */
  33. public class DCCCommandParser extends CommandParser {
  34. /** The singleton instance of the DCC command parser. */
  35. private static DCCCommandParser me;
  36. /** A version number for this class. */
  37. private static final long serialVersionUID = 2009290901;
  38. /**
  39. * Creates a new instance of the GlobalCommandParser.
  40. */
  41. private DCCCommandParser() {
  42. super();
  43. }
  44. /**
  45. * Retrieves the singleton dcc command parser.
  46. *
  47. * @return The singleton DCCCommandParser
  48. */
  49. public static synchronized DCCCommandParser getDCCCommandParser() {
  50. if (me == null) {
  51. me = new DCCCommandParser();
  52. }
  53. return me;
  54. }
  55. /** Loads the relevant commands into the parser. */
  56. @Override
  57. protected void loadCommands() {
  58. CommandManager.loadCommands(this, CommandType.TYPE_GLOBAL);
  59. }
  60. /**
  61. * Executes the specified command with the given arguments.
  62. *
  63. * @param origin The window in which the command was typed
  64. * @param isSilent Whether the command is being silenced or not
  65. * @param command The command to be executed
  66. * @param args The arguments to the command
  67. */
  68. @Override
  69. protected void executeCommand(final InputWindow origin, final boolean isSilent, final Command command, final CommandArguments args) {
  70. ((GlobalCommand) command).execute(origin, isSilent, args);
  71. }
  72. /**
  73. * Called when the input was a line of text that was not a command.
  74. * This normally means it is sent to the server/channel/user as-is, with
  75. * no further processing.
  76. *
  77. * @param origin The window in which the command was typed
  78. * @param line The line input by the user
  79. */
  80. @Override
  81. protected void handleNonCommand(final InputWindow origin, final String line) {
  82. origin.getContainer().sendLine(line);
  83. }
  84. }