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.

LoggingCommand.java 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (c) 2006-2008 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.logging;
  23. import com.dmdirc.Server;
  24. import com.dmdirc.commandparser.CommandManager;
  25. import com.dmdirc.commandparser.commands.IntelligentCommand;
  26. import com.dmdirc.commandparser.commands.ServerCommand;
  27. import com.dmdirc.plugins.Plugin;
  28. import com.dmdirc.plugins.PluginInfo;
  29. import com.dmdirc.plugins.PluginManager;
  30. import com.dmdirc.ui.input.AdditionalTabTargets;
  31. import com.dmdirc.ui.interfaces.InputWindow;
  32. import java.util.List;
  33. /**
  34. * The dcop command retrieves information from a dcop application.
  35. *
  36. * @author Shane "Dataforce" Mc Cormack
  37. * @version $Id: LoggingCommand.java 969 2007-04-30 18:38:20Z ShaneMcC $
  38. */
  39. public final class LoggingCommand extends ServerCommand implements IntelligentCommand {
  40. /**
  41. * Creates a new instance of LoggingCommand.
  42. */
  43. public LoggingCommand() {
  44. super();
  45. CommandManager.registerCommand(this);
  46. }
  47. /**
  48. * Executes this command.
  49. *
  50. * @param origin The frame in which this command was issued
  51. * @param server The server object that this command is associated with
  52. * @param isSilent Whether this command is silenced or not
  53. * @param args The user supplied arguments
  54. */
  55. public void execute(final InputWindow origin, final Server server, final boolean isSilent, final String... args) {
  56. final PluginInfo pluginInfo = PluginManager.getPluginManager().getPluginInfoByName("logging");
  57. if (pluginInfo == null) {
  58. sendLine(origin, isSilent, FORMAT_ERROR, "Logging Plugin is not loaded.");
  59. return;
  60. }
  61. final Plugin gotPlugin = pluginInfo.getPlugin();
  62. if (gotPlugin == null || !(gotPlugin instanceof LoggingPlugin)) {
  63. sendLine(origin, isSilent, FORMAT_ERROR, "Logging Plugin is not loaded.");
  64. return;
  65. }
  66. final LoggingPlugin plugin = (LoggingPlugin) gotPlugin;
  67. if (args.length > 0) {
  68. if (args[0].equalsIgnoreCase("config")) {
  69. plugin.showConfig();
  70. } else if (args[0].equalsIgnoreCase("reload")) {
  71. if (PluginManager.getPluginManager().reloadPlugin(pluginInfo.getFilename())) {
  72. sendLine(origin, isSilent, FORMAT_OUTPUT, "Plugin reloaded.");
  73. } else {
  74. sendLine(origin, isSilent, FORMAT_ERROR, "Plugin failed to reload.");
  75. }
  76. } else if (args[0].equalsIgnoreCase("history")) {
  77. if (!plugin.showHistory(origin)) {
  78. sendLine(origin, isSilent, FORMAT_ERROR, "Unable to open history for this window.");
  79. }
  80. } else if (args[0].equalsIgnoreCase("help")) {
  81. sendLine(origin, isSilent, FORMAT_OUTPUT, getName() + " reload - Reload the logging plugin.");
  82. sendLine(origin, isSilent, FORMAT_OUTPUT, getName() + " history - Open the history of this window, if available.");
  83. sendLine(origin, isSilent, FORMAT_OUTPUT, getName() + " help - Show this help.");
  84. sendLine(origin, isSilent, FORMAT_OUTPUT, getName() + " config - Show the logging plugin configuration.");
  85. } else {
  86. sendLine(origin, isSilent, FORMAT_ERROR, "Unknown command '" + args[0] + "'. Use " + getName() + " help for a list of commands.");
  87. }
  88. } else {
  89. sendLine(origin, isSilent, FORMAT_ERROR, "Use " + getName() + " help for a list of commands.");
  90. }
  91. }
  92. /**
  93. * Returns a list of suggestions for the specified argument, given the list
  94. * of previous arguments.
  95. *
  96. * @param arg The argument that is being completed
  97. * @param previousArgs The contents of the previous arguments, if any
  98. * @return A list of suggestions for the argument
  99. */
  100. public AdditionalTabTargets getSuggestions(final int arg, final List<String> previousArgs) {
  101. final AdditionalTabTargets res = new AdditionalTabTargets();
  102. if (arg == 0) {
  103. res.add("config");
  104. res.add("reload");
  105. res.add("history");
  106. res.add("help");
  107. res.setIncludeNormal(false);
  108. }
  109. return res;
  110. }
  111. /**
  112. * Returns this command's name.
  113. *
  114. * @return The name of this command
  115. */
  116. public String getName() { return "logging"; }
  117. /**
  118. * Returns whether or not this command should be shown in help messages.
  119. *
  120. * @return True iff the command should be shown, false otherwise
  121. */
  122. public boolean showInHelp() { return true; }
  123. /**
  124. * Returns a string representing the help message for this command.
  125. *
  126. * @return the help message for this command
  127. */
  128. public String getHelp() { return this.getName() + " <config|set|help> [parameters]"; }
  129. /**
  130. * Get SVN Version information.
  131. *
  132. * @return SVN Version String
  133. */
  134. public static String getSvnInfo() { return "$Id: IRCParser.java 969 2007-04-30 18:38:20Z ShaneMcC $"; }
  135. }