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 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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.plugins.plugins.logging;
  23. import java.util.Enumeration;
  24. import java.util.Properties;
  25. import com.dmdirc.Config;
  26. import com.dmdirc.Server;
  27. import com.dmdirc.commandparser.CommandManager;
  28. import com.dmdirc.commandparser.CommandWindow;
  29. import com.dmdirc.commandparser.ServerCommand;
  30. import com.dmdirc.plugins.Plugin;
  31. import com.dmdirc.plugins.PluginManager;
  32. /**
  33. * The dcop command retrieves information from a dcop application.
  34. *
  35. * @author Shane "Dataforce" Mc Cormack
  36. * @version $Id: LoggingCommand.java 969 2007-04-30 18:38:20Z ShaneMcC $
  37. */
  38. public final class LoggingCommand extends ServerCommand {
  39. /**
  40. * Creates a new instance of DcopCommand.
  41. */
  42. public LoggingCommand() {
  43. super();
  44. CommandManager.registerCommand(this);
  45. }
  46. /**
  47. * Executes this command.
  48. *
  49. * @param origin The frame in which this command was issued
  50. * @param server The server object that this command is associated with
  51. * @param args The user supplied arguments
  52. */
  53. public void execute(final CommandWindow origin, final Server server, final String... args) {
  54. final Plugin gotPlugin = PluginManager.getPluginManager().getPlugin("com.dmdirc.plugins.plugins.logging.LoggingPlugin");
  55. if (gotPlugin == null || !(gotPlugin instanceof LoggingPlugin)) {
  56. origin.addLine("commandError", "Logging Plugin is not loaded.");
  57. return;
  58. }
  59. final LoggingPlugin plugin = (LoggingPlugin) gotPlugin;
  60. if (args.length > 0) {
  61. if (args[0].equalsIgnoreCase("config")) {
  62. plugin.showConfig();
  63. } else if (args[0].equalsIgnoreCase("reload")) {
  64. if (PluginManager.getPluginManager().reloadPlugin("com.dmdirc.plugins.plugins.logging.LoggingPlugin")) {
  65. origin.addLine("commandOutput", "Plugin reloaded.");
  66. } else {
  67. origin.addLine("commandOutput", "Plugin failed to reload.");
  68. }
  69. } else if (args[0].equalsIgnoreCase("help")) {
  70. origin.addLine("commandOutput", getName() + " reload - Reload the logging plugin.");
  71. origin.addLine("commandOutput", getName() + " help - Show this help.");
  72. origin.addLine("commandOutput", getName() + " config - Show the logging plugin configuration.");
  73. origin.addLine("commandOutput", getName() + " set <help|option> [value] - Set a configuration option.");
  74. } else if (args[0].equalsIgnoreCase("set")) {
  75. if (args.length < 2 || args[1].equalsIgnoreCase("help")) {
  76. final Properties config = Config.getConfig();
  77. origin.addLine("commandOutput", "Current Values:");
  78. final Enumeration values = config.propertyNames();
  79. while (values.hasMoreElements()) {
  80. final String property = (String) values.nextElement();
  81. if (property.toLowerCase().startsWith(plugin.getDomain().toLowerCase() + ".")) {
  82. origin.addLine("commandOutput", "[" + property.substring(property.indexOf(".") + 1) + "] => " + config.getProperty(property));
  83. }
  84. }
  85. origin.addLine("commandOutput", "");
  86. origin.addLine("commandOutput", "Use " + getName() + " set <option> [value] to change the value. (if [value] is not given, the current value will be displayed)");
  87. } else if (args.length > 1) {
  88. if (Config.hasOption(plugin.getDomain(), args[1].toLowerCase())) {
  89. String newValue = "";
  90. if (args.length > 2) { newValue = implodeArgs(2, args); }
  91. if (newValue.equals("")) {
  92. origin.addLine("commandOutput", "Current value of '" + args[1] + "' is '" + Config.getOption(plugin.getDomain(), args[1].toLowerCase()) + "'");
  93. } else {
  94. plugin.updateOption(null, args[1], newValue);
  95. origin.addLine("commandOutput", "Setting '" + args[1] + "' to '" + newValue + "'");
  96. }
  97. } else {
  98. origin.addLine("commandOutput", "'" + args[1] + "' is not a valid option");
  99. }
  100. }
  101. } else {
  102. origin.addLine("commandOutput", "Unknown command '" + args[0] + "'. Use " + getName() + " help for a list of commands.");
  103. }
  104. } else {
  105. origin.addLine("commandOutput", "Use " + getName() + " help for a list of commands.");
  106. }
  107. }
  108. /**
  109. * Returns this command's name.
  110. *
  111. * @return The name of this command
  112. */
  113. public String getName() { return "logging"; }
  114. /**
  115. * Returns whether or not this command should be shown in help messages.
  116. *
  117. * @return True iff the command should be shown, false otherwise
  118. */
  119. public boolean showInHelp() { return true; }
  120. /**
  121. * Indicates whether this command is polyadic or not.
  122. *
  123. * @return True iff this command is polyadic, false otherwise
  124. */
  125. public boolean isPolyadic() { return true; }
  126. /**
  127. * Returns the arity of this command.
  128. *
  129. * @return This command's arity
  130. */
  131. public int getArity() { return 0; }
  132. /**
  133. * Returns a string representing the help message for this command.
  134. *
  135. * @return the help message for this command
  136. */
  137. public String getHelp() { return this.getName() + " <config|set|help> [parameters]"; }
  138. /**
  139. * Get SVN Version information.
  140. *
  141. * @return SVN Version String
  142. */
  143. public static String getSvnInfo() { return "$Id: IRCParser.java 969 2007-04-30 18:38:20Z ShaneMcC $"; }
  144. }