소스 검색

Added ValidatingCommand and made /me implement it

Initial work for issue 907

git-svn-id: http://svn.dmdirc.com/trunk@3487 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith 16 년 전
부모
커밋
a896f35e8b
2개의 변경된 파일65개의 추가작업 그리고 1개의 파일을 삭제
  1. 46
    0
      src/com/dmdirc/commandparser/commands/ValidatingCommand.java
  2. 19
    1
      src/com/dmdirc/commandparser/commands/chat/Me.java

+ 46
- 0
src/com/dmdirc/commandparser/commands/ValidatingCommand.java 파일 보기

@@ -0,0 +1,46 @@
1
+/*
2
+ * Copyright (c) 2006-2008 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
+package com.dmdirc.commandparser.commands;
23
+
24
+import com.dmdirc.config.prefs.validator.ValidationResponse;
25
+import com.dmdirc.ui.interfaces.InputWindow;
26
+
27
+import java.util.List;
28
+
29
+/**
30
+ * Validating commands are capable of validating their arguments to determine
31
+ * whether the input would be valid or not.
32
+ * 
33
+ * @author chris
34
+ */
35
+public interface ValidatingCommand {
36
+    
37
+    /**
38
+     * Validates the specified arguments.
39
+     * 
40
+     * @param origin The window the command is being executed in
41
+     * @param arguments The arguments that the user has entered (so far)
42
+     * @return A validation response indicating the validity of the arguments
43
+     */
44
+    ValidationResponse validateArguments(InputWindow origin, List<String> arguments);
45
+
46
+}

+ 19
- 1
src/com/dmdirc/commandparser/commands/chat/Me.java 파일 보기

@@ -26,13 +26,17 @@ import com.dmdirc.MessageTarget;
26 26
 import com.dmdirc.Server;
27 27
 import com.dmdirc.commandparser.commands.ChatCommand;
28 28
 import com.dmdirc.commandparser.CommandManager;
29
+import com.dmdirc.commandparser.commands.ValidatingCommand;
30
+import com.dmdirc.config.prefs.validator.ValidationResponse;
29 31
 import com.dmdirc.ui.interfaces.InputWindow;
30 32
 
33
+import java.util.List;
34
+
31 35
 /**
32 36
  * The me command sends a CTCP action to the current channel.
33 37
  * @author chris
34 38
  */
35
-public final class Me extends ChatCommand {
39
+public final class Me extends ChatCommand implements ValidatingCommand {
36 40
     
37 41
     /** Creates a new instance of Me. */
38 42
     public Me() {
@@ -69,5 +73,19 @@ public final class Me extends ChatCommand {
69 73
     public String getHelp() {
70 74
         return "me <action> - sends the specified action";
71 75
     }
76
+
77
+    /** {@inheritDoc} */
78
+    @Override
79
+    public ValidationResponse validateArguments(final InputWindow origin, 
80
+            final List<String> arguments) {
81
+        final int length = implodeArgs(arguments.toArray(new String[0])).length();
82
+        
83
+        if (origin.getContainer().getServer().getParser().getMaxLength("PRIVMSG",
84
+                origin.getContainer().toString()) <= length) {
85
+            return new ValidationResponse("Too long");
86
+        } else {
87
+            return new ValidationResponse();
88
+        }
89
+    }
72 90
     
73 91
 }

Loading…
취소
저장