|
From: <de...@us...> - 2003-10-09 14:04:15
|
Update of /cvsroot/babeldoc/modules/jabber/src/com/babeldoc/jabber/pipeline/stage
In directory sc8-pr-cvs1:/tmp/cvs-serv13397/jabber/src/com/babeldoc/jabber/pipeline/stage
Added Files:
XmppWriterPipelineStage.java
Log Message:
Importing jabber module. Also creating new root directory for modules
--- NEW FILE: XmppWriterPipelineStage.java ---
/*
* Created on 2003.10.3
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.babeldoc.jabber.pipeline.stage;
import java.util.ArrayList;
import java.util.Collection;
import com.babeldoc.core.option.ConfigOption;
import com.babeldoc.core.option.IConfigOptionType;
import com.babeldoc.core.pipeline.PipelineException;
import com.babeldoc.core.pipeline.PipelineStageInfo;
import com.babeldoc.core.pipeline.PipelineStageResult;
import com.babeldoc.core.pipeline.stage.GenericWriterPipelineStage;
import org.apache.commons.lang.StringUtils;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.packet.Message;;
/**
* @author dejan
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class XmppWriterPipelineStage extends GenericWriterPipelineStage {
public static final String HOST = "host";
public static final String PORT = "port";
public static final String USERNAME = "username";
public static final String PASSWORD = "password";
public static final String RECIPIENTS = "recipients";
public static final String CHATROOM = "chatroom";
public static final String NICKNAME = "nickname";
public static final String SSL = "ssl";
public XmppWriterPipelineStage() {
super(new PipelineStageInfo() {
public String getName() {
return "XmppWriter";
}
public String getDescription() {
return "Pipeline stage that use XMPP (Jabber) protocol for sending messages";
}
public Collection getTypeSpecificOptions() {
ArrayList options = new ArrayList();
options.add(new ConfigOption(HOST, IConfigOptionType.STRING,
"jabber.org", false, "Jabber server name"));
options.add(new ConfigOption(PORT, IConfigOptionType.INTEGER,
"5222", false, "Port using for connecting. Defaults to 5222"));
options.add(new ConfigOption(USERNAME, IConfigOptionType.STRING, null,
true, "Jabber account name"));
options.add(new ConfigOption(PASSWORD, IConfigOptionType.STRING,
null, true, "Jabber account password"));
options.add(new ConfigOption(RECIPIENTS, IConfigOptionType.STRING,
null, false, "Comma separated list of recipients that should receive IM"));
options.add(new ConfigOption(CHATROOM,
IConfigOptionType.STRING, null, false, "Name of chatroom that should receive IM"));
options.add(new ConfigOption(NICKNAME,
IConfigOptionType.STRING, null, false, "Nickname used for chatrooms"));
options.add(new ConfigOption(SSL,
IConfigOptionType.BOOLEAN, "false", false, "Use ssl connections"));
return options;
}
});
}
/* (non-Javadoc)
* @see com.babeldoc.core.pipeline.PipelineStage#process()
*/
public PipelineStageResult[] process() throws PipelineException
{
String host = this.getOptions(HOST);
int port = 5222;
String username = null;
String password = null;
String[] recipients = StringUtils.split(this.getOptions(RECIPIENTS), ",");
String chatroom = null;
String nickname = null;
boolean useSSL = false;
XMPPConnection conn = null;
GroupChat groupChat = null;
String message = this.getContent();
try {
if (useSSL) {
conn = new SSLXMPPConnection(host, port);
} else {
conn = new XMPPConnection(host, port);
}
conn.login(username, password);
for (int i = 0; i < recipients.length; i++) {
Chat chat = conn.createChat(recipients[i]);
chat.sendMessage(message);
}
if (chatroom != null && !"".equals(chatroom)) {
GroupChat chat = conn.createGroupChat(chatroom);
chat.sendMessage(message);
}
conn.close();
} catch (XMPPException xme) {
xme.printStackTrace();
}
return null;
}
}
|