File Source: Ignore.java
/*
P/P * Method: com.dmdirc.commandparser.commands.server.Ignore__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.config.Identity;
31 import com.dmdirc.ui.input.AdditionalTabTargets;
32 import com.dmdirc.ui.input.TabCompletionType;
33 import com.dmdirc.ui.interfaces.InputWindow;
34
35 import java.util.List;
36
37 /**
38 * Allows the user to add/view/delete ignores.
39 * @author chris
40 */
41 public final class Ignore extends ServerCommand implements IntelligentCommand {
42
43 /**
44 * Creates a new instance of Ignore.
45 */
46 public Ignore() {
/*
P/P * Method: void com.dmdirc.commandparser.commands.server.Ignore()
*
* Preconditions:
* init'ed(com/dmdirc/commandparser/CommandManager.commandChar)
*/
47 super();
48
49 CommandManager.registerCommand(this);
50 }
51
52 /**
53 * Executes this command.
54 * @param origin The frame in which this command was issued
55 * @param server The server object that this command is associated with
56 * @param isSilent Whether this command is silenced or not
57 * @param args The user supplied arguments
58 */
59 @Override
60 public void execute(final InputWindow origin, final Server server,
61 final boolean isSilent, final CommandArguments args) {
62
/*
P/P * Method: void execute(InputWindow, Server, bool, CommandArguments)
*
* Preconditions:
* args != null
* init'ed(args.words)
* server != null
* (soft) args.line != null
* (soft) init'ed(com.dmdirc.config.ConfigManager$1__static_init.new int[](ConfigManager$1__static_init#1)[...])
* (soft) init'ed(com/dmdirc/commandparser/CommandManager.commandChar)
*
* Presumptions:
* com.dmdirc.Server:getNetworkIdentity(...)@63 != null
* com.dmdirc.Server:getParser(...)@109 != null
* com.dmdirc.parser.irc.IRCParser:getIRCStringConverter(...)@109 != null
* getArguments(...).length@106 >= 1
* getArguments(...).length@65 >= 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)
* java.lang.StringBuilder:toString(...)._tainted == 0
* new ArrayList(getSources#1) num objects <= 1
* new ArrayList(getSources#1) num objects == 0
* new ConfigManager(setOption#2) num objects <= 1
* new ConfigManager(setOption#2) num objects == 0
* init'ed(new ConfigManager(setOption#2).channel)
* ...
*
* Test Vectors:
* getArguments(...).length@106: {0,1}, {2..+Inf}
* getArguments(...).length@65: {0}, {1..+Inf}
* getArguments(...).length@91: {0,1}, {2..+Inf}
* java.lang.String:equals(...)@106: {0}, {1}
* java.lang.String:equals(...)@65: {0}, {1}
* java.lang.String:equals(...)@91: {0}, {1}
* java.lang.String:isEmpty(...)@80: {1}, {0}
* java.util.Iterator:hasNext(...)@79: {0}, {1}
* java.util.List:isEmpty(...)@71: {0}, {1}
*/
63 final Identity identity = server.getNetworkIdentity();
64
65 if (args.getArguments().length == 0
66 || args.getArguments()[0].toLowerCase().equals("view")) {
67
68 if (identity.hasOptionString("network", "ignorelist")) {
69 final List<String> list = identity.getOptionList("network", "ignorelist");
70
71 if (list.isEmpty()) {
72 sendLine(origin, isSilent, FORMAT_ERROR,
73 "No ignore list entries for this network.");
74
75 } else {
76 sendLine(origin, isSilent, FORMAT_OUTPUT, "Ignore list:");
77
78 int i = 0;
79 for (String line : list) {
80 if (!line.isEmpty()) {
81 i++;
82 sendLine(origin, isSilent, FORMAT_OUTPUT, i + ". " + line);
83 }
84 }
85 }
86
87 } else {
88 sendLine(origin, isSilent, FORMAT_ERROR, "No ignore list entries for this network.");
89 }
90
91 } else if (args.getArguments()[0].toLowerCase().equals("add")
92 && args.getArguments().length > 1) {
93
94 final String host = args.getArgumentsAsString(1);
95 String list = host;
96
97 if (identity.hasOptionString("network", "ignorelist")) {
98 list = identity.getOption("network", "ignorelist");
99 list = list + "\n" + host;
100 }
101
102 identity.setOption("network", "ignorelist", list);
103
104 sendLine(origin, isSilent, FORMAT_OUTPUT, "Added " + host + " to the ignore list.");
105
106 } else if (args.getArguments()[0].toLowerCase().equals("remove")
107 && args.getArguments().length > 1) {
108
109 final String host = server.getParser().getIRCStringConverter()
110 .toLowerCase(args.getArgumentsAsString(1));
111
112 final StringBuffer newlist = new StringBuffer();
113 boolean found = false;
114
115 if (identity.hasOptionString("network", "ignorelist")) {
116 final String list = identity.getOption("network", "ignorelist");
117
118
119 for (String entry : list.split("\n")) {
120 if (server.getParser().getIRCStringConverter()
121 .toLowerCase(entry).equals(host)) {
122 found = true;
123 } else {
124 if (newlist.length() > 0) {
125 newlist.append('\n');
126 }
127 newlist.append(entry);
128 }
129 }
130 }
131
132 if (found) {
133 identity.setOption("network", "ignorelist", newlist.toString());
134 sendLine(origin, isSilent, FORMAT_OUTPUT, "Removed " + host
135 + " from the ignore list.");
136 } else {
137 sendLine(origin, isSilent, FORMAT_ERROR, "Host '" + host + "' not found.");
138 }
139
140 } else {
141 showUsage(origin, isSilent, "ignore", "<add|remove|view> [host]");
142 }
143
144 server.updateIgnoreList();
145
146 }
147
148 /** {@inheritDoc} */
149 @Override
150 public String getName() {
/*
P/P * Method: String getName()
*
* Postconditions:
* return_value == &"ignore"
*/
151 return "ignore";
152 }
153
154 /** {@inheritDoc} */
155 @Override
156 public boolean showInHelp() {
/*
P/P * Method: bool showInHelp()
*
* Postconditions:
* return_value == 1
*/
157 return true;
158 }
159
160 /** {@inheritDoc} */
161 @Override
162 public String getHelp() {
/*
P/P * Method: String getHelp()
*
* Postconditions:
* return_value == &"ignore <add|remove|view> [host] - manages the network's ignore list"
*/
163 return "ignore <add|remove|view> [host] - manages the network's ignore list";
164 }
165
166 /** {@inheritDoc} */
167 @Override
168 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)
* init'ed(com.dmdirc.ui.input.TabCompletionType.QUERY_NICK)
*
* Postconditions:
* return_value == &new AdditionalTabTargets(getSuggestions#1)
* new AdditionalTabTargets(getSuggestions#1) num objects == 1
*
* Test Vectors:
* arg: {-231..-1, 2..232-1}, {0}, {1}
*/
169 final AdditionalTabTargets targets = new AdditionalTabTargets();
170 targets.excludeAll();
171
172 if (arg == 0) {
173 targets.add("add");
174 targets.add("remove");
175 targets.add("view");
176 } else if (arg == 1) {
177 targets.include(TabCompletionType.CHANNEL_NICK);
178 targets.include(TabCompletionType.QUERY_NICK);
179 }
180
181 return targets;
182 }
183
184 }
SofCheck Inspector Build Version : 2.17854
| Ignore.java |
2009-Jun-25 01:54:24 |
| Ignore.class |
2009-Sep-02 17:04:16 |