File Source: OpenQuery.java

         /* 
    P/P   *  Method: com.dmdirc.commandparser.commands.server.OpenQuery__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.server;
    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.commandparser.commands.WrappableCommand;
    31  import com.dmdirc.ui.input.AdditionalTabTargets;
    32  import com.dmdirc.ui.input.TabCompletionType;
    33  import com.dmdirc.ui.interfaces.InputWindow;
    34  import com.dmdirc.ui.messages.Styliser;
    35  
    36  import java.util.List;
    37  
    38  /**
    39   * Allows the user to open a query dialog with another user.
    40   * @author chris
    41   */
    42  public final class OpenQuery extends ServerCommand implements
    43          IntelligentCommand, WrappableCommand {
    44      
    45      /**
    46       * Creates a new instance of Query.
    47       */
    48      public OpenQuery() {
                 /* 
    P/P           *  Method: void com.dmdirc.commandparser.commands.server.OpenQuery()
                  * 
                  *  Preconditions:
                  *    init'ed(com/dmdirc/commandparser/CommandManager.commandChar)
                  */
    49          super();
    50          
    51          CommandManager.registerCommand(this);
    52      }
    53      
    54      /** {@inheritDoc} */
    55      @Override
    56      public void execute(final InputWindow origin, final Server server,
    57              final boolean isSilent, final CommandArguments args) {
                 /* 
    P/P           *  Method: void execute(InputWindow, Server, bool, CommandArguments)
                  * 
                  *  Preconditions:
                  *    args != null
                  *    init'ed(args.words)
                  *    (soft) args.line != null
                  *    (soft) init'ed(com/dmdirc/commandparser/CommandManager.commandChar)
                  *    (soft) server != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.Server:getParser(...)@63 != null
                  *    com.dmdirc.Server:getQuery(...)@74 != null
                  *    com.dmdirc.Server:getQuery(...)@77 != null
                  *    com.dmdirc.Server:getQuery(...)@81 != null
                  *    getArguments(...).length@63 >= 1
                  *    ...
                  * 
                  *  Postconditions:
                  *    args.words != null
                  *    init'ed(java.lang.String:split(...)._tainted)
                  *    java.lang.String:split(...)._tainted == 0
                  *    init'ed(java.lang.String:split(...).length)
                  * 
                  *  Test Vectors:
                  *    com.dmdirc.Server:hasQuery(...)@73: {0}, {1}
                  *    com.dmdirc.parser.irc.IRCParser:isValidChannelName(...)@63: {0}, {1}
                  *    getArguments(...).length@58: {1..+Inf}, {0}
                  *    getArguments(...).length@80: {0,1}, {2..+Inf}
                  */
    58          if (args.getArguments().length == 0) {
    59              showUsage(origin, isSilent, "query", "<target> <message>");
    60              return;
    61          }
    62              
    63          if (server.getParser().isValidChannelName(args.getArguments()[0])) {
    64              sendLine(origin, isSilent, FORMAT_ERROR, "You can't open a query "
    65                      + "with a channel; maybe you meant " + Styliser.CODE_FIXED
    66                      + Styliser.CODE_BOLD + CommandManager.getCommandChar()
    67                      + (args.getArguments().length > 1 ? "msg" : "join") + " "
    68                      + args.getArgumentsAsString()
    69                      + Styliser.CODE_BOLD + Styliser.CODE_FIXED + "?");
    70              return;
    71          }
    72  
    73          if (server.hasQuery(args.getArguments()[0])) {
    74              server.getQuery(args.getArguments()[0]).activateFrame();
    75          } else {
    76              server.addQuery(args.getArguments()[0]);
    77              server.getQuery(args.getArguments()[0]).show();
    78          }
    79  
    80          if (args.getArguments().length > 1) {
    81              server.getQuery(args.getArguments()[0]).sendLine(args.getArgumentsAsString(1));
    82          }
    83      }
    84      
    85      
    86      /** {@inheritDoc} */
    87      @Override
    88      public String getName() {
                 /* 
    P/P           *  Method: String getName()
                  * 
                  *  Postconditions:
                  *    return_value == &amp;"query"
                  */
    89          return "query";
    90      }
    91      
    92      /** {@inheritDoc} */
    93      @Override
    94      public boolean showInHelp() {
                 /* 
    P/P           *  Method: bool showInHelp()
                  * 
                  *  Postconditions:
                  *    return_value == 1
                  */
    95          return true;
    96      }
    97      
    98      /** {@inheritDoc} */
    99      @Override
   100      public String getHelp() {
                 /* 
    P/P           *  Method: String getHelp()
                  * 
                  *  Postconditions:
                  *    return_value == &amp;"query <user> [message] - opens a query with the specified user"
                  */
   101          return "query <user> [message] - opens a query with the specified user";
   102      }
   103      
   104      /** {@inheritDoc} */
   105      @Override
   106      public AdditionalTabTargets getSuggestions(final int arg, final List<String> previousArgs) {
                 /* 
    P/P           *  Method: AdditionalTabTargets getSuggestions(int, List)
                  * 
                  *  Presumptions:
                  *    init'ed(com.dmdirc.ui.input.TabCompletionType.CHANNEL_NICK)
                  * 
                  *  Postconditions:
                  *    return_value == &amp;new AdditionalTabTargets(getSuggestions#1)
                  *    new AdditionalTabTargets(getSuggestions#1) num objects == 1
                  * 
                  *  Test Vectors:
                  *    arg: {-231..-1, 1..232-1}, {0}
                  */
   107          final AdditionalTabTargets targets = new AdditionalTabTargets();
   108          
   109          if (arg == 0) {
   110              targets.excludeAll();
   111              targets.include(TabCompletionType.CHANNEL_NICK);
   112          }
   113          
   114          return targets;
   115      }
   116      
   117      /** {@inheritDoc} */
   118      @Override
   119      public int getLineCount(final InputWindow origin, final CommandArguments arguments) {
                 /* 
    P/P           *  Method: int getLineCount(InputWindow, CommandArguments)
                  * 
                  *  Preconditions:
                  *    arguments != null
                  *    init'ed(arguments.words)
                  *    (soft) arguments.line != null
                  *    (soft) origin != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.WritableFrameContainer:getServer(...)@122 != null
                  *    com.dmdirc.ui.interfaces.InputWindow:getContainer(...)@122 != null
                  *    getArguments(...).length@121 >= 1
                  *    java.util.Arrays:copyOfRange(...)@99 != null
                  * 
                  *  Postconditions:
                  *    arguments.words != null
                  *    init'ed(java.lang.String:split(...)._tainted)
                  *    java.lang.String:split(...)._tainted == 0
                  *    init'ed(java.lang.String:split(...).length)
                  *    init'ed(return_value)
                  * 
                  *  Test Vectors:
                  *    getArguments(...).length@120: {0,1}, {2..+Inf}
                  */
   120          if (arguments.getArguments().length >= 2) {
   121              final String target = arguments.getArguments()[0];
   122              return origin.getContainer().getServer().getNumLines("PRIVMSG "
   123                      + target + " :" + arguments.getArgumentsAsString(1));
   124          } else {
   125              return 1;
   126          }
   127      }
   128      
   129  }








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