| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
package org.apache.camel.component.irc; |
| 19 |
|
|
| 20 |
|
import org.apache.camel.Processor; |
| 21 |
|
import org.apache.camel.impl.DefaultConsumer; |
| 22 |
|
import org.apache.commons.logging.Log; |
| 23 |
|
import org.apache.commons.logging.LogFactory; |
| 24 |
|
import org.schwering.irc.lib.IRCConnection; |
| 25 |
|
import org.schwering.irc.lib.IRCEventAdapter; |
| 26 |
|
import org.schwering.irc.lib.IRCModeParser; |
| 27 |
|
import org.schwering.irc.lib.IRCUser; |
| 28 |
|
|
| 29 |
0 |
public class IrcConsumer extends DefaultConsumer<IrcExchange> { |
| 30 |
0 |
private static final transient Log log = LogFactory.getLog(IrcConsumer.class); |
| 31 |
|
final private IrcEndpoint endpoint; |
| 32 |
|
final private IRCConnection connection; |
| 33 |
|
final IrcConfiguration configuration; |
| 34 |
0 |
private FilteredIRCEventAdapter listener = null; |
| 35 |
|
|
| 36 |
|
public IrcConsumer(IrcEndpoint endpoint, Processor processor, IRCConnection connection) { |
| 37 |
0 |
super(endpoint, processor); |
| 38 |
0 |
this.endpoint = endpoint; |
| 39 |
0 |
this.connection = connection; |
| 40 |
0 |
configuration = endpoint.getConfiguration(); |
| 41 |
0 |
} |
| 42 |
|
|
| 43 |
|
@Override |
| 44 |
|
protected void doStop() throws Exception { |
| 45 |
0 |
String target = endpoint.getConfiguration().getTarget(); |
| 46 |
0 |
connection.doPart(target); |
| 47 |
0 |
connection.removeIRCEventListener(listener); |
| 48 |
|
|
| 49 |
0 |
super.doStop(); |
| 50 |
0 |
} |
| 51 |
|
|
| 52 |
|
@Override |
| 53 |
|
protected void doStart() throws Exception { |
| 54 |
0 |
super.doStart(); |
| 55 |
|
|
| 56 |
0 |
String target = endpoint.getConfiguration().getTarget(); |
| 57 |
0 |
connection.addIRCEventListener(new FilteredIRCEventAdapter(target)); |
| 58 |
|
|
| 59 |
0 |
log.debug("joining: " + target); |
| 60 |
0 |
connection.doJoin(target); |
| 61 |
0 |
} |
| 62 |
|
|
| 63 |
|
public IRCConnection getConnection() { |
| 64 |
0 |
return connection; |
| 65 |
|
} |
| 66 |
|
|
| 67 |
|
class FilteredIRCEventAdapter extends IRCEventAdapter { |
| 68 |
|
final String target; |
| 69 |
|
|
| 70 |
0 |
public FilteredIRCEventAdapter(String target) { |
| 71 |
0 |
this.target = target; |
| 72 |
0 |
} |
| 73 |
|
|
| 74 |
|
@Override |
| 75 |
|
public void onNick(IRCUser user, String newNick) { |
| 76 |
0 |
if (configuration.isOnNick()) { |
| 77 |
0 |
IrcExchange exchange = endpoint.createOnNickExchange(user, newNick); |
| 78 |
|
try { |
| 79 |
0 |
getProcessor().process(exchange); |
| 80 |
|
} |
| 81 |
0 |
catch (Exception e) { |
| 82 |
|
|
| 83 |
0 |
e.printStackTrace(); |
| 84 |
0 |
} |
| 85 |
|
} |
| 86 |
0 |
} |
| 87 |
|
|
| 88 |
|
@Override |
| 89 |
|
public void onQuit(IRCUser user, String msg) { |
| 90 |
0 |
if (configuration.isOnQuit()) { |
| 91 |
0 |
IrcExchange exchange = endpoint.createOnQuitExchange(user, msg); |
| 92 |
|
try { |
| 93 |
0 |
getProcessor().process(exchange); |
| 94 |
|
} |
| 95 |
0 |
catch (Exception e) { |
| 96 |
|
|
| 97 |
0 |
e.printStackTrace(); |
| 98 |
0 |
} |
| 99 |
|
} |
| 100 |
0 |
} |
| 101 |
|
|
| 102 |
|
@Override |
| 103 |
|
public void onJoin(String channel, IRCUser user) { |
| 104 |
0 |
if (configuration.isOnJoin()) { |
| 105 |
0 |
if (channel.equals(configuration.getTarget())) { |
| 106 |
0 |
IrcExchange exchange = endpoint.createOnJoinExchange(channel, user); |
| 107 |
|
try { |
| 108 |
0 |
getProcessor().process(exchange); |
| 109 |
|
} |
| 110 |
0 |
catch (Exception e) { |
| 111 |
|
|
| 112 |
0 |
e.printStackTrace(); |
| 113 |
0 |
} |
| 114 |
|
} |
| 115 |
|
} |
| 116 |
0 |
} |
| 117 |
|
|
| 118 |
|
@Override |
| 119 |
|
public void onKick(String channel, IRCUser user, String passiveNick, String msg) { |
| 120 |
0 |
if (configuration.isOnKick()) { |
| 121 |
0 |
if (channel.equals(configuration.getTarget())) { |
| 122 |
0 |
IrcExchange exchange = endpoint.createOnKickExchange(channel, user, passiveNick, msg); |
| 123 |
|
try { |
| 124 |
0 |
getProcessor().process(exchange); |
| 125 |
|
} |
| 126 |
0 |
catch (Exception e) { |
| 127 |
|
|
| 128 |
0 |
e.printStackTrace(); |
| 129 |
0 |
} |
| 130 |
|
} |
| 131 |
|
} |
| 132 |
0 |
} |
| 133 |
|
|
| 134 |
|
@Override |
| 135 |
|
public void onMode(String channel, IRCUser user, IRCModeParser modeParser) { |
| 136 |
0 |
if (configuration.isOnMode()) { |
| 137 |
0 |
if (channel.equals(configuration.getTarget())) { |
| 138 |
0 |
IrcExchange exchange = endpoint.createOnModeExchange(channel, user, modeParser); |
| 139 |
|
try { |
| 140 |
0 |
getProcessor().process(exchange); |
| 141 |
|
} |
| 142 |
0 |
catch (Exception e) { |
| 143 |
|
|
| 144 |
0 |
e.printStackTrace(); |
| 145 |
0 |
} |
| 146 |
|
} |
| 147 |
|
} |
| 148 |
0 |
} |
| 149 |
|
|
| 150 |
|
@Override |
| 151 |
|
public void onPart(String channel, IRCUser user, String msg) { |
| 152 |
0 |
if (configuration.isOnPart()) { |
| 153 |
0 |
if (channel.equals(configuration.getTarget())) { |
| 154 |
0 |
IrcExchange exchange = endpoint.createOnPartExchange(channel, user, msg); |
| 155 |
|
try { |
| 156 |
0 |
getProcessor().process(exchange); |
| 157 |
|
} |
| 158 |
0 |
catch (Exception e) { |
| 159 |
|
|
| 160 |
0 |
e.printStackTrace(); |
| 161 |
0 |
} |
| 162 |
|
} |
| 163 |
|
} |
| 164 |
0 |
} |
| 165 |
|
|
| 166 |
|
@Override |
| 167 |
|
public void onTopic(String channel, IRCUser user, String topic) { |
| 168 |
0 |
if (configuration.isOnTopic()) { |
| 169 |
0 |
if (channel.equals(configuration.getTarget())) { |
| 170 |
0 |
IrcExchange exchange = endpoint.createOnTopicExchange(channel, user, topic); |
| 171 |
|
try { |
| 172 |
0 |
getProcessor().process(exchange); |
| 173 |
|
} |
| 174 |
0 |
catch (Exception e) { |
| 175 |
|
|
| 176 |
0 |
e.printStackTrace(); |
| 177 |
0 |
} |
| 178 |
|
} |
| 179 |
|
} |
| 180 |
0 |
} |
| 181 |
|
|
| 182 |
|
@Override |
| 183 |
|
public void onPrivmsg(String target, IRCUser user, String msg) { |
| 184 |
0 |
if (configuration.isOnPrivmsg()) { |
| 185 |
0 |
if (target.equals(configuration.getTarget())) { |
| 186 |
0 |
IrcExchange exchange = endpoint.createOnPrivmsgExchange(target, user, msg); |
| 187 |
|
try { |
| 188 |
0 |
getProcessor().process(exchange); |
| 189 |
|
} |
| 190 |
0 |
catch (Exception e) { |
| 191 |
|
|
| 192 |
0 |
e.printStackTrace(); |
| 193 |
0 |
} |
| 194 |
|
} |
| 195 |
|
} |
| 196 |
0 |
} |
| 197 |
|
} |
| 198 |
|
} |