Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

LoggingCommand.java 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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.addons.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 isSilent Whetehr this command is silenced or not
  52. * @param args The user supplied arguments
  53. */
  54. public void execute(final CommandWindow origin, final Server server, final boolean isSilent, final String... args) {
  55. final Plugin gotPlugin = PluginManager.getPluginManager().getPlugin("com.dmdirc.addons.logging.LoggingPlugin");
  56. if (gotPlugin == null || !(gotPlugin instanceof LoggingPlugin)) {
  57. origin.addLine("commandError", "Logging Plugin is not loaded.");
  58. return;
  59. }
  60. final LoggingPlugin plugin = (LoggingPlugin) gotPlugin;
  61. if (args.length > 0) {
  62. if (args[0].equalsIgnoreCase("config")) {
  63. plugin.showConfig();
  64. } else if (args[0].equalsIgnoreCase("reload")) {
  65. if (PluginManager.getPluginManager().reloadPlugin("com.dmdirc.addons.logging.LoggingPlugin")) {
  66. origin.addLine("commandOutput", "Plugin reloaded.");
  67. } else {
  68. origin.addLine("commandOutput", "Plugin failed to reload.");
  69. }
  70. } else if (args[0].equalsIgnoreCase("help")) {
  71. origin.addLine("commandOutput", getName() + " reload - Reload the logging plugin.");
  72. origin.addLine("commandOutput", getName() + " help - Show this help.");
  73. origin.addLine("commandOutput", getName() + " config - Show the logging plugin configuration.");
  74. origin.addLine("commandOutput", getName() + " set <help|option> [value] - Set a configuration option.");
  75. } else if (args[0].equalsIgnoreCase("set")) {
  76. if (args.length < 2 || args[1].equalsIgnoreCase("help")) {
  77. final Properties config = Config.getConfig();
  78. origin.addLine("commandOutput", "Current Values:");
  79. final Enumeration values = config.propertyNames();
  80. while (values.hasMoreElements()) {
  81. final String property = (String) values.nextElement();
  82. if (property.toLowerCase().startsWith(plugin.getDomain().toLowerCase() + ".")) {
  83. origin.addLine("commandOutput", "[" + property.substring(property.indexOf(".") + 1) + "] => " + config.getProperty(property));
  84. }
  85. }
  86. origin.addLine("commandOutput", "");
  87. origin.addLine("commandOutput", "Use " + getName() + " set <option> [value] to change the value. (if [value] is not given, the current value will be displayed)");
  88. } else if (args.length > 1) {
  89. if (Config.hasOption(plugin.getDomain(), args[1].toLowerCase())) {
  90. String newValue = "";
  91. if (args.length > 2) { newValue = implodeArgs(2, args); }
  92. if (newValue.equals("")) {
  93. origin.addLine("commandOutput", "Current value of '" + args[1] + "' is '" + Config.getOption(plugin.getDomain(), args[1].toLowerCase()) + "'");
  94. } else {
  95. plugin.updateOption(null, args[1], newValue);
  96. origin.addLine("commandOutput", "Setting '" + args[1] + "' to '" + newValue + "'");
  97. }
  98. } else {
  99. origin.addLine("commandOutput", "'" + args[1] + "' is not a valid option");
  100. }
  101. }
  102. } else {
  103. origin.addLine("commandOutput", "Unknown command '" + args[0] + "'. Use " + getName() + " help for a list of commands.");
  104. }
  105. } else {
  106. origin.addLine("commandOutput", "Use " + getName() + " help for a list of commands.");
  107. }
  108. }
  109. /**
  110. * Returns this command's name.
  111. *
  112. * @return The name of this command
  113. */
  114. public String getName() { return "logging"; }
  115. /**
  116. * Returns whether or not this command should be shown in help messages.
  117. *
  118. * @return True iff the command should be shown, false otherwise
  119. */
  120. public boolean showInHelp() { return true; }
  121. /**
  122. * Indicates whether this command is polyadic or not.
  123. *
  124. * @return True iff this command is polyadic, false otherwise
  125. */
  126. public boolean isPolyadic() { return true; }
  127. /**
  128. * Returns the arity of this command.
  129. *
  130. * @return This command's arity
  131. */
  132. public int getArity() { return 0; }
  133. /**
  134. * Returns a string representing the help message for this command.
  135. *
  136. * @return the help message for this command
  137. */
  138. public String getHelp() { return this.getName() + " <config|set|help> [parameters]"; }
  139. /**
  140. * Get SVN Version information.
  141. *
  142. * @return SVN Version String
  143. */
  144. public static String getSvnInfo() { return "$Id: IRCParser.java 969 2007-04-30 18:38:20Z ShaneMcC $"; }
  145. }