Index: src/plugins/broadcast/readme.html
===================================================================
--- src/plugins/broadcast/readme.html (revision 10222)
+++ src/plugins/broadcast/readme.html (working copy)
@@ -76,6 +76,8 @@
to broadcast messages to all connected users at once. When this property isn't set,
anyone is allowed to broadcast messages to all users. Users should be specified by their
bare JID (e.g. john@myserver.com)
+
plugin.broadcast.messagePrefix -- string prepended to all broadcast messages.
+ If no value is set, the default is to leave the message unaltered.
Using the Plugin
Index: src/plugins/broadcast/src/java/org/jivesoftware/openfire/plugin/BroadcastPlugin.java
===================================================================
--- src/plugins/broadcast/src/java/org/jivesoftware/openfire/plugin/BroadcastPlugin.java (revision 10222)
+++ src/plugins/broadcast/src/java/org/jivesoftware/openfire/plugin/BroadcastPlugin.java (working copy)
@@ -44,6 +44,7 @@
public class BroadcastPlugin implements Plugin, Component, PropertyEventListener {
private String serviceName;
+ private String messagePrefix;
private SessionManager sessionManager;
private GroupManager groupManager;
private List allowedUsers;
@@ -62,6 +63,7 @@
groupMembersAllowed = JiveGlobals.getBooleanProperty(
"plugin.broadcast.groupMembersAllowed", true);
allowedUsers = stringToList(JiveGlobals.getProperty("plugin.broadcast.allowedUsers", ""));
+ messagePrefix = JiveGlobals.getProperty("plugin.broadcast.messagePrefix", null);
}
// Plugin Interface
@@ -173,6 +175,10 @@
private void processMessage(Message message, boolean targetAll, Group group,
boolean canProceed) {
+ // Prepend each message with the global prefix.
+ if (messagePrefix != null && message.getBody() != null) {
+ prependMessage(message.getElement());
+ }
// Check to see if trying to broadcast to all connected users.
if (targetAll) {
if (!canProceed) {
@@ -574,4 +580,23 @@
}
return values;
}
-}
\ No newline at end of file
+
+ /**
+ * Iteratively prepend all message bodys within a given Element with
+ * value from messagePrefix property.
+ *
+ * @param element a Message element.
+ */
+ private void prependMessage(Element element) {
+ Iterator it = element.elementIterator();
+ while (it.hasNext()) {
+ Element el = (Element)it.next();
+ if (el.getName().equals("body")) {
+ el.setText(messagePrefix + el.getText());
+ }
+ else {
+ prependMessage(el);
+ }
+ }
+ }
+}