File Source: Echo.java

         /* 
    P/P   *  Method: com.dmdirc.commandparser.commands.global.Echo__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.commandparser.commands.global;
    24  
    25  import com.dmdirc.Main;
    26  import com.dmdirc.commandparser.CommandArguments;
    27  import com.dmdirc.commandparser.CommandManager;
    28  import com.dmdirc.commandparser.commands.GlobalCommand;
    29  import com.dmdirc.commandparser.commands.IntelligentCommand;
    30  import com.dmdirc.ui.WindowManager;
    31  import com.dmdirc.ui.input.AdditionalTabTargets;
    32  import com.dmdirc.ui.interfaces.InputWindow;
    33  import com.dmdirc.ui.interfaces.Window;
    34  
    35  import java.util.List;
    36  
    37  /**
    38   * The echo commands simply echos text to the current window.
    39   * 
    40   * @author chris
    41   */
    42  public final class Echo extends GlobalCommand implements IntelligentCommand {
    43  
    44      /**
    45       * Creates a new instance of Echo.
    46       */
    47      public Echo() {
                 /* 
    P/P           *  Method: void com.dmdirc.commandparser.commands.global.Echo()
                  * 
                  *  Preconditions:
                  *    init'ed(com/dmdirc/commandparser/CommandManager.commandChar)
                  */
    48          super();
    49  
    50          CommandManager.registerCommand(this);
    51      }
    52  
    53      /** {@inheritDoc} */
    54      @Override
    55      public void execute(final InputWindow origin, final boolean isSilent,
    56              final CommandArguments args) {
                 /* 
    P/P           *  Method: void execute(InputWindow, bool, CommandArguments)
                  * 
                  *  Preconditions:
                  *    args != null
                  *    init'ed(args.words)
                  *    (soft) args.line != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.Main:getUI(...)@59 != null
                  *    getArguments(...).length@57 >= 1
                  *    getArguments(...).length@63 >= 1
                  *    getArguments(...).length@69 >= 2
                  *    getArguments(...).length@74 >= 2
                  *    ...
                  * 
                  *  Postconditions:
                  *    init'ed(args.words)
                  *    init'ed(java.lang.String:split(...)._tainted)
                  *    java.lang.String:split(...)._tainted == 0
                  *    init'ed(java.lang.String:split(...).length)
                  * 
                  *  Test Vectors:
                  *    getArguments(...).length@57: {0}, {1..+Inf}
                  *    getArguments(...).length@63: {0,1}, {2..+Inf}
                  *    java.lang.String:equalsIgnoreCase(...)@57: {0}, {1}
                  *    java.lang.String:equalsIgnoreCase(...)@63: {0}, {1}
                  */
    57          if (args.getArguments().length > 0
    58                  && args.getArguments()[0].equalsIgnoreCase("--active")) {
    59              final Window frame = Main.getUI().getActiveWindow();
    60              if (frame instanceof InputWindow) {
    61                  ((InputWindow) frame).addLine(FORMAT_OUTPUT, args.getArgumentsAsString(1));
    62              }
    63          } else if (args.getArguments().length > 1
    64                  && args.getArguments()[0].equalsIgnoreCase("--target")) {
    65              Window frame = null;
    66              Window target = origin;
    67  
    68              while (frame == null && target != null) {
    69                  frame = WindowManager.findCustomWindow(target, args.getArguments()[1]);
    70                  target = WindowManager.getParent(target);
    71              }
    72  
    73              if (frame == null) {
    74                  frame = WindowManager.findCustomWindow(args.getArguments()[1]);
    75              }
    76  
    77              if (frame == null) {
    78                  sendLine(origin, isSilent, FORMAT_ERROR,
    79                          "Unable to find target window");
    80              } else {
    81                  frame.addLine(FORMAT_OUTPUT, args.getArgumentsAsString(2));
    82              }
    83  
    84          } else {
    85              sendLine(origin, isSilent, FORMAT_OUTPUT, args.getArgumentsAsString());
    86          }
    87      }
    88  
    89      /** {@inheritDoc} */
    90      @Override
    91      public String getName() {
                 /* 
    P/P           *  Method: String getName()
                  * 
                  *  Postconditions:
                  *    return_value == &"echo"
                  */
    92          return "echo";
    93      }
    94  
    95      /** {@inheritDoc} */
    96      @Override
    97      public boolean showInHelp() {
                 /* 
    P/P           *  Method: bool showInHelp()
                  * 
                  *  Postconditions:
                  *    return_value == 1
                  */
    98          return true;
    99      }
   100  
   101      /** {@inheritDoc} */
   102      @Override
   103      public String getHelp() {
                 /* 
    P/P           *  Method: String getHelp()
                  * 
                  *  Postconditions:
                  *    return_value == &amp;"echo [--active|--target <window>] <line> - echos the specified line to the window"
                  */
   104          return "echo [--active|--target <window>] <line> "
   105                  + "- echos the specified line to the window";
   106      }
   107  
   108      /** {@inheritDoc} */
   109      @Override
   110      public AdditionalTabTargets getSuggestions(final int arg, final List<String> previousArgs) {
                 /* 
    P/P           *  Method: AdditionalTabTargets getSuggestions(int, List)
                  * 
                  *  Preconditions:
                  *    (soft) previousArgs != null
                  * 
                  *  Presumptions:
                  *    java.util.List:get(...)@116 != null
                  * 
                  *  Postconditions:
                  *    return_value == &amp;new AdditionalTabTargets(getSuggestions#1)
                  *    new AdditionalTabTargets(getSuggestions#1) num objects == 1
                  * 
                  *  Test Vectors:
                  *    arg: {-231..-1, 2..232-1}, {0}, {1}
                  *    java.lang.String:equals(...)@116: {0}, {1}
                  */
   111          final AdditionalTabTargets targets = new AdditionalTabTargets();
   112          
   113          if (arg == 0) {
   114              targets.add("--active");
   115              targets.add("--target");
   116          } else if (arg == 1 && previousArgs.get(0).equals("--target")) {
   117              targets.excludeAll();
   118              // TODO: Include window names
   119          }
   120          
   121          return targets;
   122      }
   123  
   124  }








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