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.6KB

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