aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/plugin
diff options
context:
space:
mode:
authorDanny van Heumen <danny@dannyvanheumen.nl>2014-11-18 21:59:39 +0100
committerDanny van Heumen <danny@dannyvanheumen.nl>2014-11-20 21:00:49 +0100
commit3eb7b3da0e95ed3c063656534428c74b4580764f (patch)
tree9ce8bc822713ba5e0b7b34d3c7d518b1bc65d6da /src/net/java/sip/communicator/plugin
parentd750dab7987c4ea9272475fa7be33db98b5a8daf (diff)
downloadjitsi-3eb7b3da0e95ed3c063656534428c74b4580764f.zip
jitsi-3eb7b3da0e95ed3c063656534428c74b4580764f.tar.gz
jitsi-3eb7b3da0e95ed3c063656534428c74b4580764f.tar.bz2
Moved IRC command implementations to separate plugin package: irccommands
Diffstat (limited to 'src/net/java/sip/communicator/plugin')
-rw-r--r--src/net/java/sip/communicator/plugin/irccommands/IrcCommandsActivator.java80
-rw-r--r--src/net/java/sip/communicator/plugin/irccommands/command/Join.java79
-rw-r--r--src/net/java/sip/communicator/plugin/irccommands/command/Me.java67
-rw-r--r--src/net/java/sip/communicator/plugin/irccommands/command/Mode.java69
-rw-r--r--src/net/java/sip/communicator/plugin/irccommands/command/Msg.java82
-rw-r--r--src/net/java/sip/communicator/plugin/irccommands/command/Nick.java69
-rw-r--r--src/net/java/sip/communicator/plugin/irccommands/command/package-info.java12
-rw-r--r--src/net/java/sip/communicator/plugin/irccommands/irccommands.manifest.mf10
-rw-r--r--src/net/java/sip/communicator/plugin/irccommands/package-info.java12
9 files changed, 480 insertions, 0 deletions
diff --git a/src/net/java/sip/communicator/plugin/irccommands/IrcCommandsActivator.java b/src/net/java/sip/communicator/plugin/irccommands/IrcCommandsActivator.java
new file mode 100644
index 0000000..6572446
--- /dev/null
+++ b/src/net/java/sip/communicator/plugin/irccommands/IrcCommandsActivator.java
@@ -0,0 +1,80 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.plugin.irccommands;
+
+import java.util.*;
+import java.util.Map.Entry;
+
+import net.java.sip.communicator.impl.protocol.irc.*;
+import net.java.sip.communicator.plugin.irccommands.command.*;
+import net.java.sip.communicator.plugin.irccommands.command.Mode;
+
+import org.osgi.framework.*;
+
+/**
+ * Activator of the IRC commands plugin.
+ *
+ * @author Danny van Heumen
+ */
+public class IrcCommandsActivator
+ implements BundleActivator
+{
+ /**
+ * Map of command-implementation mapping for IRC {@link Command}
+ * implementations.
+ *
+ * This map is used as reference when registering and unregistering the
+ * commands upon (resp.) starting and stopping the plugin bundle.
+ */
+ private static final Map<String, Class<? extends Command>> COMMANDS;
+
+ /**
+ * Building the commands registration reference.
+ */
+ static
+ {
+ HashMap<String, Class<? extends Command>> commands =
+ new HashMap<String, Class<? extends Command>>();
+ commands.put("me", Me.class);
+ commands.put("msg", Msg.class);
+ commands.put("mode", Mode.class);
+ commands.put("nick", Nick.class);
+ commands.put("join", Join.class);
+ COMMANDS = Collections.unmodifiableMap(commands);
+ }
+
+ /**
+ * Stopping the bundle.
+ *
+ * @param context the bundle context
+ */
+ @Override
+ public void stop(final BundleContext context)
+ {
+ final Set<Class<? extends Command>> implementations =
+ new HashSet<Class<? extends Command>>(COMMANDS.values());
+ for (Class<? extends Command> impl : implementations)
+ {
+ CommandFactory.unregisterCommand(impl, null);
+ }
+ }
+
+ /**
+ * Starting the bundle.
+ *
+ * @param context the bundle context
+ */
+ @Override
+ public void start(final BundleContext context)
+ {
+ for (Entry<String, Class<? extends Command>> entry : COMMANDS
+ .entrySet())
+ {
+ CommandFactory.registerCommand(entry.getKey(), entry.getValue());
+ }
+ }
+}
diff --git a/src/net/java/sip/communicator/plugin/irccommands/command/Join.java b/src/net/java/sip/communicator/plugin/irccommands/command/Join.java
new file mode 100644
index 0000000..20c9c72
--- /dev/null
+++ b/src/net/java/sip/communicator/plugin/irccommands/command/Join.java
@@ -0,0 +1,79 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.plugin.irccommands.command;
+
+import net.java.sip.communicator.impl.protocol.irc.*;
+
+/**
+ * Implementation of the /join command. Join a channel from the message input
+ * line.
+ *
+ * @author Danny van Heumen
+ */
+public class Join implements Command
+{
+ /**
+ * Index of end of command prefix.
+ */
+ private static final int END_OF_COMMAND_PREFIX = 6;
+
+ /**
+ * Instance of the IRC connection.
+ */
+ private final IrcConnection connection;
+
+ /**
+ * Initialization of the /join command. Join a channel.
+ *
+ * @param provider the provider instance
+ * @param connection the IRC connection instance
+ */
+ public Join(final ProtocolProviderServiceIrcImpl provider,
+ final IrcConnection connection)
+ {
+ if (connection == null)
+ {
+ throw new IllegalArgumentException("connection cannot be null");
+ }
+ this.connection = connection;
+ }
+
+ /**
+ * Execute join command.
+ *
+ * @param source the source channel/user from which the command was typed.
+ * @param line the command message line
+ */
+ @Override
+ public void execute(final String source, final String line)
+ {
+ if (line.length() < END_OF_COMMAND_PREFIX)
+ {
+ return;
+ }
+ final String part = line.substring(END_OF_COMMAND_PREFIX);
+ final String channel;
+ final String password;
+ int indexOfSep = part.indexOf(' ');
+ if (indexOfSep == -1)
+ {
+ channel = part;
+ password = "";
+ }
+ else
+ {
+ channel = part.substring(0, indexOfSep);
+ password = part.substring(indexOfSep + 1);
+ }
+ if (!channel.matches("[^,\\n\\r\\s\\a]+"))
+ {
+ throw new IllegalArgumentException(
+ "Invalid chat room name specified.");
+ }
+ this.connection.getClient().joinChannel(channel, password);
+ }
+}
diff --git a/src/net/java/sip/communicator/plugin/irccommands/command/Me.java b/src/net/java/sip/communicator/plugin/irccommands/command/Me.java
new file mode 100644
index 0000000..cbbb869
--- /dev/null
+++ b/src/net/java/sip/communicator/plugin/irccommands/command/Me.java
@@ -0,0 +1,67 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.plugin.irccommands.command;
+
+import net.java.sip.communicator.impl.protocol.irc.*;
+
+/**
+ * Implementation of the /me command. Send a message describing an act by local
+ * user.
+ *
+ * @author Danny van Heumen
+ */
+public class Me
+ implements Command
+{
+ /**
+ * Me command prefix index.
+ */
+ private static final int END_OF_ME_COMMAND_PREFIX = 4;
+
+ /**
+ * IRC connection instance.
+ */
+ private final IrcConnection connection;
+
+ /**
+ * Initialization of the /me command.
+ *
+ * @param provider the provider instance
+ * @param connection the connection instance
+ */
+ public Me(final ProtocolProviderServiceIrcImpl provider,
+ final IrcConnection connection)
+ {
+ if (connection == null)
+ {
+ throw new IllegalArgumentException("connection cannot be null");
+ }
+ this.connection = connection;
+ }
+
+ /**
+ * Execute the /me command: send ACT command.
+ *
+ * @param source source chat room or user from which the command originated.
+ * @param line the command message line
+ */
+ @Override
+ public void execute(final String source, final String line)
+ {
+ if (line.length() < END_OF_ME_COMMAND_PREFIX)
+ {
+ return;
+ }
+ final String message = line.substring(4);
+ if (message.isEmpty())
+ {
+ throw new IllegalArgumentException(
+ "Invalid /me command: message cannot be empty.");
+ }
+ this.connection.getClient().act(source, message);
+ }
+}
diff --git a/src/net/java/sip/communicator/plugin/irccommands/command/Mode.java b/src/net/java/sip/communicator/plugin/irccommands/command/Mode.java
new file mode 100644
index 0000000..f738ae6
--- /dev/null
+++ b/src/net/java/sip/communicator/plugin/irccommands/command/Mode.java
@@ -0,0 +1,69 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.plugin.irccommands.command;
+
+import net.java.sip.communicator.impl.protocol.irc.*;
+
+/**
+ * Implementation of the /mode command. Manually manage modes.
+ *
+ * @author Danny van Heumen
+ */
+public class Mode implements Command
+{
+ /**
+ * Constant for end index of command prefix.
+ */
+ private static final int END_OF_MODE_COMMAND_PREFIX = 6;
+
+ /**
+ * Instance of the IRC connection.
+ */
+ private IrcConnection connection;
+
+ /**
+ * Initialization of the /mode command.
+ *
+ * @param provider the provider instance
+ * @param connection the connection instance
+ */
+ public Mode(final ProtocolProviderServiceIrcImpl provider,
+ final IrcConnection connection)
+ {
+ if (connection == null)
+ {
+ throw new IllegalArgumentException("connection cannot be null");
+ }
+ this.connection = connection;
+ }
+
+ /**
+ * Execute the command: send the mode change message.
+ *
+ * @param line the command message line
+ * @param source the originating channel/user from which the message was
+ * sent.
+ */
+ @Override
+ public void execute(final String source, final String line)
+ {
+ if (line.length() <= END_OF_MODE_COMMAND_PREFIX)
+ {
+ // does not currently support requesting (and displaying) mode query
+ // results.
+ return;
+ }
+ final String rawModeString =
+ line.substring(END_OF_MODE_COMMAND_PREFIX);
+ if (rawModeString.trim().isEmpty())
+ {
+ throw new IllegalArgumentException(
+ "The mode command needs mode parameters to function.");
+ }
+ this.connection.getClient().changeMode(source + " " + rawModeString);
+ }
+}
diff --git a/src/net/java/sip/communicator/plugin/irccommands/command/Msg.java b/src/net/java/sip/communicator/plugin/irccommands/command/Msg.java
new file mode 100644
index 0000000..7e10659
--- /dev/null
+++ b/src/net/java/sip/communicator/plugin/irccommands/command/Msg.java
@@ -0,0 +1,82 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.plugin.irccommands.command;
+
+import net.java.sip.communicator.impl.protocol.irc.*;
+
+/**
+ * Implementation of the /msg command. Send a targeted private message.
+ *
+ * @author Danny van Heumen
+ */
+public class Msg implements Command
+{
+ /**
+ * Index of start of nick and message parameters.
+ */
+ private static final int END_OF_MSG_COMMAND_PREFIX = 5;
+
+ /**
+ * Instance of the IRC connection.
+ */
+ private IrcConnection connection;
+
+ /**
+ * Initialization of the /msg command.
+ *
+ * @param provider the provider instance
+ * @param connection the connection instance
+ */
+ public Msg(final ProtocolProviderServiceIrcImpl provider,
+ final IrcConnection connection)
+ {
+ if (connection == null)
+ {
+ throw new IllegalArgumentException("connection cannot be null");
+ }
+ this.connection = connection;
+ }
+
+ /**
+ * Execute the command: send the message to the specified target.
+ *
+ * @param line the command message line
+ * @param source the originating channel/user from which the message was
+ * sent.
+ */
+ @Override
+ public void execute(final String source, final String line)
+ {
+ if (line.length() < END_OF_MSG_COMMAND_PREFIX)
+ {
+ return;
+ }
+ final String part = line.substring(5);
+ int endOfNick = part.indexOf(' ');
+ if (endOfNick == -1)
+ {
+ throw new IllegalArgumentException("Invalid private message "
+ + "format: Expecting both nick and message. Message was "
+ + "not sent.");
+ }
+ final String target = part.substring(0, endOfNick);
+ if (target.length() == 0)
+ {
+ throw new IllegalArgumentException("Invalid private message "
+ + "format: Zero-length nick is not allowed. Message was not "
+ + "sent.");
+ }
+ final String message = part.substring(endOfNick + 1);
+ if (message.length() == 0)
+ {
+ throw new IllegalArgumentException("Invalid private message "
+ + "format: Zero-length message is not allowed. Message was not "
+ + "sent.");
+ }
+ this.connection.getClient().message(target, message);
+ }
+}
diff --git a/src/net/java/sip/communicator/plugin/irccommands/command/Nick.java b/src/net/java/sip/communicator/plugin/irccommands/command/Nick.java
new file mode 100644
index 0000000..39582cd
--- /dev/null
+++ b/src/net/java/sip/communicator/plugin/irccommands/command/Nick.java
@@ -0,0 +1,69 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.plugin.irccommands.command;
+
+import net.java.sip.communicator.impl.protocol.irc.*;
+
+/**
+ * Implementation of the /nick command. Change local user's nick name.
+ *
+ * @author Danny van Heumen
+ */
+public class Nick implements Command
+{
+ /**
+ * Instance of the IRC connection.
+ */
+ private IrcConnection connection;
+
+ /**
+ * Initialization of the command. Issue nick change.
+ *
+ * @param provider the provider instance
+ * @param connection the connection instance
+ */
+ public Nick(final ProtocolProviderServiceIrcImpl provider,
+ final IrcConnection connection)
+ {
+ if (connection == null)
+ {
+ throw new IllegalArgumentException("connection cannot be null");
+ }
+ this.connection = connection;
+ }
+
+ /**
+ * Execute the /nick command. Issue nick change to IRC server.
+ *
+ * @param source the source channel/user
+ * @param line the command message line
+ */
+ @Override
+ public void execute(final String source, final String line)
+ {
+ if (line.length() <= 5)
+ {
+ // no name parameter available, so nothing to do here
+ return;
+ }
+ final String part = line.substring(6);
+ final String newNick;
+ int indexOfSep = part.indexOf(' ');
+ if (indexOfSep == -1)
+ {
+ newNick = part;
+ }
+ else
+ {
+ newNick = part.substring(0, indexOfSep);
+ }
+ if (newNick.length() > 0)
+ {
+ this.connection.getIdentityManager().setNick(newNick);
+ }
+ }
+}
diff --git a/src/net/java/sip/communicator/plugin/irccommands/command/package-info.java b/src/net/java/sip/communicator/plugin/irccommands/command/package-info.java
new file mode 100644
index 0000000..5327958
--- /dev/null
+++ b/src/net/java/sip/communicator/plugin/irccommands/command/package-info.java
@@ -0,0 +1,12 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+/**
+ * Package containing implementations of IRC commands.
+ *
+ * @author Danny van Heumen
+ */
+package net.java.sip.communicator.plugin.irccommands.command;
diff --git a/src/net/java/sip/communicator/plugin/irccommands/irccommands.manifest.mf b/src/net/java/sip/communicator/plugin/irccommands/irccommands.manifest.mf
new file mode 100644
index 0000000..9ba9858
--- /dev/null
+++ b/src/net/java/sip/communicator/plugin/irccommands/irccommands.manifest.mf
@@ -0,0 +1,10 @@
+Bundle-Activator: net.java.sip.communicator.plugin.irccommands.IrcCommandsActivator
+Bundle-Name: IRC commands
+Bundle-Description: IRC commands package
+Bundle-Vendor: jitsi.org
+Bundle-Version: 0.0.1
+Bundle-SymbolicName: net.java.sip.communicator.plugin.irccommands
+Import-Package: org.osgi.framework,
+ net.java.sip.communicator.util,
+ net.java.sip.communicator.impl.protocol.irc,
+ com.ircclouds.irc.api
diff --git a/src/net/java/sip/communicator/plugin/irccommands/package-info.java b/src/net/java/sip/communicator/plugin/irccommands/package-info.java
new file mode 100644
index 0000000..70ba8e8
--- /dev/null
+++ b/src/net/java/sip/communicator/plugin/irccommands/package-info.java
@@ -0,0 +1,12 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+/**
+ * Plugin providing IRC commands for the IRC protocol.
+ *
+ * @author Danny van Heumen
+ */
+package net.java.sip.communicator.plugin.irccommands;