File Source: LoggingCommand.java

         /* 
    P/P   *  Method: com.dmdirc.addons.logging.LoggingCommand__static_init
          */
     1  /*
     2   * Copyright (c) 2006-2009 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  
    23  package com.dmdirc.addons.logging;
    24  
    25  import com.dmdirc.Server;
    26  import com.dmdirc.commandparser.CommandArguments;
    27  import com.dmdirc.commandparser.CommandManager;
    28  import com.dmdirc.commandparser.commands.IntelligentCommand;
    29  import com.dmdirc.commandparser.commands.ServerCommand;
    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  import com.dmdirc.ui.interfaces.InputWindow;
    35  import java.util.List;
    36  
    37  /**
    38   * The dcop command retrieves information from a dcop application.
    39   *
    40   * @author Shane "Dataforce" Mc Cormack
    41   */
    42  public final class LoggingCommand extends ServerCommand implements IntelligentCommand {
    43  
    44  	/**
    45  	 * Creates a new instance of LoggingCommand.
    46  	 */
    47  	public LoggingCommand() {
        		 /* 
    P/P 		  *  Method: void com.dmdirc.addons.logging.LoggingCommand()
        		  */
    48  		super();
    49  		CommandManager.registerCommand(this);
    50  	}
    51  		
    52      /** {@inheritDoc} */
    53      @Override
    54  	public void execute(final InputWindow origin, final Server server,
    55              final boolean isSilent, final CommandArguments args) {
        		 /* 
    P/P 		  *  Method: void execute(InputWindow, Server, bool, CommandArguments)
        		  * 
        		  *  Preconditions:
        		  *    (soft) args != null
        		  *    (soft) origin != null
        		  * 
        		  *  Presumptions:
        		  *    com.dmdirc.commandparser.CommandArguments:getArguments(...).length@71 >= 1
        		  *    com.dmdirc.commandparser.CommandArguments:getArguments(...).length@77 >= 1
        		  *    com.dmdirc.commandparser.CommandArguments:getArguments(...).length@81 >= 1
        		  *    com.dmdirc.commandparser.CommandArguments:getArguments(...).length@86 >= 1
        		  *    com.dmdirc.commandparser.CommandArguments:getArguments(...)@70 != null
        		  *    ...
        		  * 
        		  *  Test Vectors:
        		  *    com.dmdirc.commandparser.CommandArguments:getArguments(...).length@70: {0}, {1..+Inf}
        		  *    com.dmdirc.plugins.PluginManager:getPluginInfoByName(...)@56: Inverse{null}, Addr_Set{null}
        		  *    com.dmdirc.plugins.PluginManager:reloadPlugin(...)@72: {0}, {1}
        		  *    java.lang.String:equalsIgnoreCase(...)@71: {0}, {1}
        		  *    java.lang.String:equalsIgnoreCase(...)@77: {0}, {1}
        		  *    java.lang.String:equalsIgnoreCase(...)@81: {0}, {1}
        		  */
    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  		
    63  		if (!(gotPlugin instanceof LoggingPlugin)) {
    64  			sendLine(origin, isSilent, FORMAT_ERROR, "Logging Plugin is not loaded.");
    65  			return;
    66  		}
    67  		
    68  		final LoggingPlugin plugin = (LoggingPlugin) gotPlugin;
    69  		
    70  		if (args.getArguments().length > 0) {
    71  			if (args.getArguments()[0].equalsIgnoreCase("reload")) {
    72  				if (PluginManager.getPluginManager().reloadPlugin(pluginInfo.getFilename())) {
    73  					sendLine(origin, isSilent, FORMAT_OUTPUT, "Plugin reloaded.");
    74  				} else {
    75  					sendLine(origin, isSilent, FORMAT_ERROR, "Plugin failed to reload.");
    76  				}
    77  			} else if (args.getArguments()[0].equalsIgnoreCase("history")) {
    78  				if (!plugin.showHistory(origin)) {
    79  					sendLine(origin, isSilent, FORMAT_ERROR, "Unable to open history for this window.");
    80      		}
    81  			} else if (args.getArguments()[0].equalsIgnoreCase("help")) {
    82  				sendLine(origin, isSilent, FORMAT_OUTPUT, getName() + " reload           - Reload the logging plugin.");
    83  				sendLine(origin, isSilent, FORMAT_OUTPUT, getName() + " history          - Open the history of this window, if available.");
    84  				sendLine(origin, isSilent, FORMAT_OUTPUT, getName() + " help             - Show this help.");
    85  			} else {
    86  				sendLine(origin, isSilent, FORMAT_ERROR, "Unknown command '" + args.getArguments()[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  	/**
    94  	 * Returns a list of suggestions for the specified argument, given the list
    95  	 * of previous arguments.
    96  	 *
    97  	 * @param arg The argument that is being completed
    98  	 * @param previousArgs The contents of the previous arguments, if any
    99  	 * @return A list of suggestions for the argument
   100  	 */
   101      @Override
   102  	public AdditionalTabTargets getSuggestions(final int arg, final List<String> previousArgs) {
        			 /* 
    P/P 			  *  Method: AdditionalTabTargets getSuggestions(int, List)
        			  * 
        			  *  Postconditions:
        			  *    return_value == &amp;new AdditionalTabTargets(getSuggestions#1)
        			  *    new AdditionalTabTargets(getSuggestions#1) num objects == 1
        			  * 
        			  *  Test Vectors:
        			  *    arg: {-231..-1, 1..232-1}, {0}
        			  */
   103  			final AdditionalTabTargets res = new AdditionalTabTargets();
   104  			if (arg == 0) {
   105  				res.add("reload");
   106  				res.add("history");
   107  				res.add("help");
   108  				res.excludeAll();
   109  			}
   110  			return res;
   111  	}
   112  
   113  	/**
   114  	 * Returns this command's name.
   115  	 *
   116  	 * @return The name of this command
   117  	 */
   118      @Override
        	 /* 
    P/P 	  *  Method: String getName()
        	  * 
        	  *  Postconditions:
        	  *    return_value == &amp;"logging"
        	  */
   119  	public String getName() { return "logging"; }
   120  	
   121  	/**
   122  	 * Returns whether or not this command should be shown in help messages.
   123  	 *
   124  	 * @return True iff the command should be shown, false otherwise
   125  	 */
   126      @Override
        	 /* 
    P/P 	  *  Method: bool showInHelp()
        	  * 
        	  *  Postconditions:
        	  *    return_value == 1
        	  */
   127  	public boolean showInHelp() { return true; }
   128  	
   129  	/**
   130  	 * Returns a string representing the help message for this command.
   131  	 *
   132  	 * @return the help message for this command
   133  	 */
   134      @Override
        	 /* 
    P/P 	  *  Method: String getHelp()
        	  * 
        	  *  Postconditions:
        	  *    java.lang.StringBuilder:toString(...)._tainted == 0
        	  *    return_value == &amp;java.lang.StringBuilder:toString(...)
        	  */
   135  	public String getHelp() { return this.getName() + " <set|help> [parameters]"; }
   136  	
   137  }
   138  








SofCheck Inspector Build Version : 2.17854
LoggingCommand.java 2009-Jun-25 01:54:24
LoggingCommand.class 2009-Sep-02 17:04:15