Browse Source

Add IRCDataInEvent that presents an IRCReader.ReadLine object rather than just the line of data.

This gives us access to MessageTags (#19) and pre-tokenised lines in DataIn rather than everything neededing to tokenise themselves.

There are probably a few other events we want to expose messagetags on that we still don't.
pull/115/head
Shane Mc Cormack 8 years ago
parent
commit
822bf59490

+ 1
- 1
common/src/com/dmdirc/parser/events/DataInEvent.java View File

@@ -29,7 +29,7 @@ import java.time.LocalDateTime;
29 29
 import static com.google.common.base.Preconditions.checkNotNull;
30 30
 
31 31
 /**
32
- * Interface Used on every incoming line BEFORE parsing.
32
+ * Called on every incoming line BEFORE parsing.
33 33
  */
34 34
 public class DataInEvent extends ParserEvent {
35 35
 

+ 5
- 4
irc/src/com/dmdirc/parser/irc/IRCParser.java View File

@@ -47,6 +47,7 @@ import com.dmdirc.parser.interfaces.Encoder;
47 47
 import com.dmdirc.parser.interfaces.EncodingParser;
48 48
 import com.dmdirc.parser.interfaces.SecureParser;
49 49
 import com.dmdirc.parser.irc.IRCReader.ReadLine;
50
+import com.dmdirc.parser.irc.events.IRCDataInEvent;
50 51
 import com.dmdirc.parser.irc.events.IRCDataOutEvent;
51 52
 import com.dmdirc.parser.irc.outputqueue.OutputQueue;
52 53
 
@@ -535,10 +536,10 @@ public class IRCParser extends BaseSocketAwareParser implements SecureParser, En
535 536
     /**
536 537
      * Callback to all objects implementing the DataIn Callback.
537 538
      *
538
-     * @param data Incoming Line.
539
+     * @param line Incoming Line.
539 540
      */
540
-    protected void callDataIn(final String data) {
541
-        getCallbackManager().publish(new DataInEvent(this, LocalDateTime.now(), data));
541
+    protected void callDataIn(final ReadLine line) {
542
+        getCallbackManager().publish(new IRCDataInEvent(this, LocalDateTime.now(), line));
542 543
     }
543 544
 
544 545
     /**
@@ -1085,7 +1086,7 @@ public class IRCParser extends BaseSocketAwareParser implements SecureParser, En
1085 1086
      */
1086 1087
     @SuppressWarnings("fallthrough")
1087 1088
     protected void processLine(final ReadLine line) {
1088
-        callDataIn(line.getLine());
1089
+        callDataIn(line);
1089 1090
         final String[] token = line.getTokens();
1090 1091
         LocalDateTime lineTS = LocalDateTime.now();
1091 1092
 

+ 79
- 0
irc/src/com/dmdirc/parser/irc/events/IRCDataInEvent.java View File

@@ -0,0 +1,79 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
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.parser.irc.events;
24
+
25
+import com.dmdirc.parser.events.DataInEvent;
26
+import com.dmdirc.parser.interfaces.Parser;
27
+import com.dmdirc.parser.irc.IRCParser;
28
+import com.dmdirc.parser.irc.IRCReader.ReadLine;
29
+
30
+import java.time.LocalDateTime;
31
+
32
+import static com.google.common.base.Preconditions.checkNotNull;
33
+
34
+/**
35
+ * Called on every incoming line BEFORE parsing.
36
+ *
37
+ * This extends the standard DataInEvent to provide access to IRC-Specific bits.
38
+ */
39
+public class IRCDataInEvent extends DataInEvent {
40
+
41
+    private final ReadLine line;
42
+    private final String[] tokenisedData;
43
+    private final String action;
44
+
45
+    public IRCDataInEvent(final IRCParser parser, final LocalDateTime date, final ReadLine line) {
46
+        super(parser, date, checkNotNull(line).getLine());
47
+        this.line = line;
48
+        tokenisedData = line.getTokens();
49
+
50
+        // Action is slightly more complicated than for DataOut
51
+        if (tokenisedData.length > 1) {
52
+            if (tokenisedData[0].length() > 0 && tokenisedData[0].charAt(0) == ':') {
53
+                if (tokenisedData[1].equalsIgnoreCase("NOTICE") && !parser.got001) {
54
+                    action = "NOTICE AUTH";
55
+                } else {
56
+                    action = tokenisedData[1].toUpperCase();
57
+                }
58
+            } else if (tokenisedData[0].equalsIgnoreCase("NOTICE")) {
59
+                action = "NOTICE AUTH";
60
+            } else {
61
+                action = tokenisedData[0].toUpperCase();
62
+            }
63
+        } else {
64
+            action = "";
65
+        }
66
+    }
67
+
68
+    public String[] getTokenisedData() {
69
+        return tokenisedData;
70
+    }
71
+
72
+    public ReadLine getLine() {
73
+        return line;
74
+    }
75
+
76
+    public String getAction() {
77
+        return action;
78
+    }
79
+}

Loading…
Cancel
Save