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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (c) 2006-2011 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.FrameContainer;
  24. import com.dmdirc.commandparser.CommandArguments;
  25. import com.dmdirc.commandparser.CommandInfo;
  26. import com.dmdirc.commandparser.CommandType;
  27. import com.dmdirc.commandparser.commands.Command;
  28. import com.dmdirc.commandparser.commands.IntelligentCommand;
  29. import com.dmdirc.commandparser.commands.context.CommandContext;
  30. import com.dmdirc.plugins.Plugin;
  31. import com.dmdirc.plugins.PluginInfo;
  32. import com.dmdirc.plugins.PluginManager;
  33. import com.dmdirc.ui.input.AdditionalTabTargets;
  34. /**
  35. * The dcop command retrieves information from a dcop application.
  36. *
  37. * @author Shane "Dataforce" Mc Cormack
  38. */
  39. public final class LoggingCommand extends Command implements IntelligentCommand,
  40. CommandInfo {
  41. /**
  42. * Creates a new instance of LoggingCommand.
  43. */
  44. public LoggingCommand() {
  45. super();
  46. }
  47. /** {@inheritDoc} */
  48. @Override
  49. public void execute(final FrameContainer<?> origin,
  50. final CommandArguments args, final CommandContext context) {
  51. final PluginInfo pluginInfo = PluginManager.getPluginManager().getPluginInfoByName("logging");
  52. if (pluginInfo == null) {
  53. sendLine(origin, args.isSilent(), FORMAT_ERROR, "Logging Plugin is not loaded.");
  54. return;
  55. }
  56. final Plugin gotPlugin = pluginInfo.getPlugin();
  57. if (!(gotPlugin instanceof LoggingPlugin)) {
  58. sendLine(origin, args.isSilent(), FORMAT_ERROR, "Logging Plugin is not loaded.");
  59. return;
  60. }
  61. final LoggingPlugin plugin = (LoggingPlugin) gotPlugin;
  62. if (args.getArguments().length > 0) {
  63. if (args.getArguments()[0].equalsIgnoreCase("reload")) {
  64. if (PluginManager.getPluginManager().reloadPlugin(pluginInfo.getFilename())) {
  65. sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Plugin reloaded.");
  66. } else {
  67. sendLine(origin, args.isSilent(), FORMAT_ERROR, "Plugin failed to reload.");
  68. }
  69. } else if (args.getArguments()[0].equalsIgnoreCase("history")) {
  70. if (!plugin.showHistory(origin)) {
  71. sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unable to open history for this window.");
  72. }
  73. } else if (args.getArguments()[0].equalsIgnoreCase("help")) {
  74. sendLine(origin, args.isSilent(), FORMAT_OUTPUT, getName() + " reload - Reload the logging plugin.");
  75. sendLine(origin, args.isSilent(), FORMAT_OUTPUT, getName() + " history - Open the history of this window, if available.");
  76. sendLine(origin, args.isSilent(), FORMAT_OUTPUT, getName() + " help - Show this help.");
  77. } else {
  78. sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unknown command '" + args.getArguments()[0] + "'. Use " + getName() + " help for a list of commands.");
  79. }
  80. } else {
  81. sendLine(origin, args.isSilent(), FORMAT_ERROR, "Use " + getName() + " help for a list of commands.");
  82. }
  83. }
  84. /** {@inheritDoc} */
  85. @Override
  86. public AdditionalTabTargets getSuggestions(final int arg,
  87. final IntelligentCommandContext context) {
  88. final AdditionalTabTargets res = new AdditionalTabTargets();
  89. if (arg == 0) {
  90. res.add("reload");
  91. res.add("history");
  92. res.add("help");
  93. res.excludeAll();
  94. }
  95. return res;
  96. }
  97. /** {@inheritDoc} */
  98. @Override
  99. public String getName() {
  100. return "logging";
  101. }
  102. /** {@inheritDoc} */
  103. @Override
  104. public boolean showInHelp() {
  105. return true;
  106. }
  107. /** {@inheritDoc} */
  108. @Override
  109. public CommandType getType() {
  110. return CommandType.TYPE_SERVER;
  111. }
  112. /** {@inheritDoc} */
  113. @Override
  114. public String getHelp() {
  115. return this.getName() + " <set|help> [parameters]";
  116. }
  117. }