File Source: JoinChannelCommand.java
/*
P/P * Method: com.dmdirc.commandparser.commands.server.JoinChannelCommand__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.Channel;
26 import com.dmdirc.Server;
27 import com.dmdirc.actions.ActionManager;
28 import com.dmdirc.actions.CoreActionType;
29 import com.dmdirc.actions.interfaces.ActionType;
30 import com.dmdirc.commandparser.CommandArguments;
31 import com.dmdirc.commandparser.CommandManager;
32 import com.dmdirc.commandparser.commands.IntelligentCommand;
33 import com.dmdirc.commandparser.commands.ServerCommand;
34 import com.dmdirc.interfaces.ActionListener;
35 import com.dmdirc.ui.input.AdditionalTabTargets;
36 import com.dmdirc.ui.interfaces.InputWindow;
37 import com.dmdirc.ui.messages.Styliser;
38
39 import java.util.List;
40
41 /**
42 * Allows the user to join channels.
43 *
44 * @since 0.6.3m1
45 * @author chris
46 */
47 public final class JoinChannelCommand extends ServerCommand implements
48 ActionListener, IntelligentCommand {
49
50 /**
51 * Creates a new instance of the join channel command.
52 */
53 public JoinChannelCommand() {
/*
P/P * Method: void com.dmdirc.commandparser.commands.server.JoinChannelCommand()
*
* Preconditions:
* init'ed(com/dmdirc/commandparser/CommandManager.commandChar)
*
* Presumptions:
* init'ed(com.dmdirc.actions.CoreActionType.CHANNEL_ACTION)
* init'ed(com.dmdirc.actions.CoreActionType.CHANNEL_MESSAGE)
*/
54 super();
55
56 CommandManager.registerCommand(this);
57 ActionManager.addListener(this, CoreActionType.CHANNEL_MESSAGE,
58 CoreActionType.CHANNEL_ACTION);
59 }
60
61 /** {@inheritDoc} */
62 @Override
63 public void execute(final InputWindow origin, final Server server,
64 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(...)@78 != null
* com.dmdirc.Server:getQuery(...)@89 != null
* com.dmdirc.Server:getQuery(...)@92 != null
* com.dmdirc.Server:getQuery(...)@96 != null
* getArguments(...).length@78 >= 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(...)@88: {0}, {1}
* com.dmdirc.parser.irc.IRCParser:isValidChannelName(...)@78: {0}, {1}
* getArguments(...).length@65: {1..+Inf}, {0}
* getArguments(...).length@95: {0,1}, {2..+Inf}
*/
65 if (args.getArguments().length == 0) {
66 showUsage(origin, isSilent, "join", "join <channel [key]>[,channel [key]...]");
67 return;
68 }
69
70 for (String pair : args.getArgumentsAsString().split(",")) {
71 if (pair.trim().indexOf(' ') == -1) {
72 server.join(pair);
73 } else {
74
75 }
76 }
77
78 if (server.getParser().isValidChannelName(args.getArguments()[0])) {
79 sendLine(origin, isSilent, FORMAT_ERROR, "You can't open a query "
80 + "with a channel; maybe you meant " + Styliser.CODE_FIXED
81 + Styliser.CODE_BOLD + CommandManager.getCommandChar()
82 + (args.getArguments().length > 1 ? "msg" : "join")
83 + " " + args.getArgumentsAsString()
84 + Styliser.CODE_BOLD + Styliser.CODE_FIXED + "?");
85 return;
86 }
87
88 if (server.hasQuery(args.getArguments()[0])) {
89 server.getQuery(args.getArguments()[0]).activateFrame();
90 } else {
91 server.addQuery(args.getArguments()[0]);
92 server.getQuery(args.getArguments()[0]).show();
93 }
94
95 if (args.getArguments().length > 1) {
96 server.getQuery(args.getArguments()[0]).sendLine(args.getArgumentsAsString(1));
97 }
98 }
99
100
101 /** {@inheritDoc} */
102 @Override
103 public String getName() {
/*
P/P * Method: String getName()
*
* Postconditions:
* return_value == &"join"
*/
104 return "join";
105 }
106
107 /** {@inheritDoc} */
108 @Override
109 public boolean showInHelp() {
/*
P/P * Method: bool showInHelp()
*
* Postconditions:
* return_value == 1
*/
110 return true;
111 }
112
113 /** {@inheritDoc} */
114 @Override
115 public String getHelp() {
/*
P/P * Method: String getHelp()
*
* Postconditions:
* return_value == &"join <channel [key]>[,channel [key]...] - joins the specified channel(s)"
*/
116 return "join <channel [key]>[,channel [key]...] - joins the specified channel(s)";
117 }
118
119 /** {@inheritDoc} */
120 @Override
121 public void processEvent(final ActionType type, final StringBuffer format,
122 final Object... arguments) {
/*
P/P * Method: void processEvent(ActionType, StringBuffer, Object[])
*
* Preconditions:
* arguments != null
* arguments.length >= 3
* init'ed(arguments[0])
* init'ed(arguments[2])
*/
123 final Channel chan = (Channel) arguments[0];
124 final String message = (String) arguments[2];
125 }
126
127 /** {@inheritDoc} */
128 @Override
129 public AdditionalTabTargets getSuggestions(final int arg,
130 final List<String> previousArgs) {
/*
P/P * Method: AdditionalTabTargets getSuggestions(int, List)
* getSuggestions fails for all possible inputs
*/
131 throw new UnsupportedOperationException("Not supported yet.");
132 }
133
134 }
SofCheck Inspector Build Version : 2.17854
| JoinChannelCommand.java |
2009-Jun-25 01:54:24 |
| JoinChannelCommand.class |
2009-Sep-02 17:04:16 |