From: Santi B. <san...@us...> - 2007-12-04 00:27:46
|
Update of /cvsroot/babeldoc/modules/jabber/src/com/babeldoc/jabber/pipeline/stage In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv12375/src/com/babeldoc/jabber/pipeline/stage Modified Files: XmppWriterPipelineStage.java Added Files: XmppPipelineMessageListener.java Messages.java Log Message: Update smack.jar 3.0.4 and related changes. String externalization. Index: XmppWriterPipelineStage.java =================================================================== RCS file: /cvsroot/babeldoc/modules/jabber/src/com/babeldoc/jabber/pipeline/stage/XmppWriterPipelineStage.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** XmppWriterPipelineStage.java 14 Jan 2004 12:24:59 -0000 1.2 --- XmppWriterPipelineStage.java 4 Dec 2007 00:27:42 -0000 1.3 *************** *** 71,77 **** import org.apache.commons.lang.StringUtils; import org.jivesoftware.smack.Chat; ! import org.jivesoftware.smack.GroupChat; ! import org.jivesoftware.smack.SSLXMPPConnection; import org.jivesoftware.smack.XMPPConnection; import com.babeldoc.core.option.ConfigOption; --- 71,78 ---- import org.apache.commons.lang.StringUtils; import org.jivesoftware.smack.Chat; ! import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.smack.XMPPConnection; + import org.jivesoftware.smack.XMPPException; + import org.jivesoftware.smackx.muc.MultiUserChat; import com.babeldoc.core.option.ConfigOption; *************** *** 82,91 **** import com.babeldoc.core.pipeline.stage.GenericWriterPipelineStage; - /** * This class is using for sending messaging using XMPP protocol (jabber). * ! * @author dejank ! * */ public class XmppWriterPipelineStage extends GenericWriterPipelineStage { --- 83,91 ---- import com.babeldoc.core.pipeline.stage.GenericWriterPipelineStage; /** * This class is using for sending messaging using XMPP protocol (jabber). * ! * @author dejank ! * */ public class XmppWriterPipelineStage extends GenericWriterPipelineStage { *************** *** 96,178 **** 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.getInfo().getStrValue(HOST); int port = this.getInfo().getIntValue(PORT); String username = this.getInfo().getStrValue(USERNAME); String password = this.getInfo().getStrValue(PASSWORD); ! String[] recipients = StringUtils.split(this.getInfo().getStrValue(RECIPIENTS), ","); String chatroom = this.getInfo().getStrValue(CHATROOM); String nickname = this.getInfo().getStrValue(NICKNAME); boolean useSSL = this.getInfo().getBooleanValue(SSL); ! 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 (Exception xme) { throw new PipelineException("Error sending message", xme); ! //xme.printStackTrace(); } ! return this.processHelper(); } --- 96,192 ---- public static final String PASSWORD = "password"; public static final String RECIPIENTS = "recipients"; ! public static final String CHATROOM = "chatroom"; //$NON-NLS-1$ public static final String NICKNAME = "nickname"; ! public static final String SSL = Messages.getString("XmppWriterPipelineStage.7"); ! public XmppWriterPipelineStage() { super(new PipelineStageInfo() { public String getName() { ! return "XmppWriter"; } public String getDescription() { ! return Messages.getString("XmppWriterPipelineStage.9"); //$NON-NLS-1$ } public Collection getTypeSpecificOptions() { ! ArrayList options = new ArrayList(); ! options.add(new ConfigOption(HOST, IConfigOptionType.STRING, ! "jabber.org", false, Messages.getString("XmppWriterPipelineStage.11"))); ! options.add(new ConfigOption(PORT, IConfigOptionType.INTEGER, ! "5222", false, ! Messages.getString("XmppWriterPipelineStage.13"))); //$NON-NLS-1$ ! options.add(new ConfigOption(USERNAME, ! IConfigOptionType.STRING, null, true, ! Messages.getString("XmppWriterPipelineStage.14"))); //$NON-NLS-1$ ! options.add(new ConfigOption(PASSWORD, ! IConfigOptionType.STRING, null, true, ! Messages.getString("XmppWriterPipelineStage.15"))); //$NON-NLS-1$ ! options ! .add(new ConfigOption(RECIPIENTS, ! IConfigOptionType.STRING, null, false, ! Messages.getString("XmppWriterPipelineStage.16"))); //$NON-NLS-1$ ! options.add(new ConfigOption(CHATROOM, ! IConfigOptionType.STRING, null, false, ! Messages.getString("XmppWriterPipelineStage.17"))); //$NON-NLS-1$ options.add(new ConfigOption(NICKNAME, ! IConfigOptionType.STRING, null, false, ! Messages.getString("XmppWriterPipelineStage.18"))); //$NON-NLS-1$ ! options.add(new ConfigOption(SSL, IConfigOptionType.BOOLEAN, ! "false", false, Messages.getString("XmppWriterPipelineStage.20"))); //$NON-NLS-1$ //$NON-NLS-2$ ! return options; } ! }); } ! ! /* ! * (non-Javadoc) ! * * @see com.babeldoc.core.pipeline.PipelineStage#process() */ ! public PipelineStageResult[] process() throws PipelineException { String host = this.getInfo().getStrValue(HOST); int port = this.getInfo().getIntValue(PORT); String username = this.getInfo().getStrValue(USERNAME); String password = this.getInfo().getStrValue(PASSWORD); ! String[] recipients = StringUtils.split(this.getInfo().getStrValue( ! RECIPIENTS), ","); String chatroom = this.getInfo().getStrValue(CHATROOM); String nickname = this.getInfo().getStrValue(NICKNAME); boolean useSSL = this.getInfo().getBooleanValue(SSL); ! ConnectionConfiguration connConfig = null; ! XMPPConnection conn = null; ! MultiUserChat groupChat = null; String message = this.getContent(); try { if (useSSL) { ! // conn = new SSLXMPPConnection(host); ! throw new PipelineException("SSL Protocol not supported"); } else { ! connConfig = new ConnectionConfiguration(host,port); ! conn = new XMPPConnection(connConfig); ! } ! conn.login(username, password); ! for (int i = 0; i < recipients.length; i++) { ! Chat chat = conn.getChatManager().createChat(recipients[i], ! new XmppPipelineMessageListener()); chat.sendMessage(message); ! } if (chatroom != null && !"".equals(chatroom)) { ! // GroupChat chat = conn.createGroupChat(chatroom); ! // chat.sendMessage(message); ! groupChat.join(nickname, password); ! groupChat.sendMessage(message); } ! conn.disconnect(); ! } catch (XMPPException xme) { throw new PipelineException("Error sending message", xme); ! // xme.printStackTrace(); } ! return this.processHelper(); } --- NEW FILE: XmppPipelineMessageListener.java --- /** * */ package com.babeldoc.jabber.pipeline.stage; import org.jivesoftware.smack.Chat; import org.jivesoftware.smack.MessageListener; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.Message; import com.babeldoc.core.pipeline.PipelineException; /** * @author santi * */ public class XmppPipelineMessageListener implements MessageListener { /* * (non-Javadoc) * * @see org.jivesoftware.smack.MessageListener#processMessage(org.jivesoftware.smack.Chat, * org.jivesoftware.smack.packet.Message) */ public void processMessage(Chat chat, Message message){ // Simple message processing parrot-bot try { chat.sendMessage(Messages.getString("XmppPipelineMessageListener.0") + message.toString()); //$NON-NLS-1$ } catch (XMPPException e) { // throw new pipeline exception new PipelineException(Messages.getString("XmppPipelineMessageListener.1"),e); //$NON-NLS-1$ } } } --- NEW FILE: Messages.java --- package com.babeldoc.jabber.pipeline.stage; import java.util.MissingResourceException; import java.util.ResourceBundle; public class Messages { private static final String BUNDLE_NAME = "i18n.messages"; //$NON-NLS-1$ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle .getBundle(BUNDLE_NAME); private Messages() { } public static String getString(String key) { try { return RESOURCE_BUNDLE.getString(key); } catch (MissingResourceException e) { return '!' + key + '!'; } } } |