Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/.classpath10
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/.cvsignore1
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/.options7
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/.project28
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/META-INF/MANIFEST.MF18
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/about.html39
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/asl-v20.txt202
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/build.properties15
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/lib/smack.jarbin0 -> 175252 bytes
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/lib/smackx-debug.jarbin0 -> 34530 bytes
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/lib/smackx.jarbin0 -> 221006 bytes
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/plugin.xml39
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/Trace.java110
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/XmppPlugin.java81
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/ContainerInstantiator.java88
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/IGroupChatContainerConfig.java16
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/IIMMessageSender.java25
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/SharedObjectMsg.java25
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPClientSOContainer.java330
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPContainerContext.java41
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPGroupChatSOContainer.java239
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPGroupChatSharedObject.java68
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPPresenceSharedObject.java441
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPSharedObject.java538
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/events/IQEvent.java34
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/events/MessageEvent.java35
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/events/PresenceEvent.java34
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPID.java71
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPIDInstantiator.java26
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPNamespace.java14
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/smack/ChatConnection.java309
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/smack/ChatConnectionObjectPacketEvent.java37
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/smack/ChatConnectionPacketEvent.java31
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/smack/test/TestGroupChat.java39
34 files changed, 2991 insertions, 0 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/.classpath b/providers/bundles/org.eclipse.ecf.provider.xmpp/.classpath
new file mode 100644
index 000000000..f6df51f0f
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/.classpath
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="lib" path="lib/smack.jar"/>
+ <classpathentry kind="lib" path="lib/smackx.jar"/>
+ <classpathentry kind="lib" path="lib/smackx-debug.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/.cvsignore b/providers/bundles/org.eclipse.ecf.provider.xmpp/.cvsignore
new file mode 100644
index 000000000..ba077a403
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/.cvsignore
@@ -0,0 +1 @@
+bin
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/.options b/providers/bundles/org.eclipse.ecf.provider.xmpp/.options
new file mode 100644
index 000000000..2acff57ac
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/.options
@@ -0,0 +1,7 @@
+org.eclipse.ecf.provider.xmpp/debug = true
+org.eclipse.ecf.provider.xmpp/debug/filter = *
+org.eclipse.ecf.provider.xmpp/debug/flag = true
+org.eclipse.ecf.provider.xmpp/debug/smackconnection = true
+org.eclipse.ecf.provider.xmpp/debug/xmppsharedobject = true
+org.eclipse.ecf.provider.xmpp/debug/xmpppresencesharedobject = true
+org.eclipse.ecf.provider.xmpp/debug/smackdebug = true \ No newline at end of file
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/.project b/providers/bundles/org.eclipse.ecf.provider.xmpp/.project
new file mode 100644
index 000000000..c82c01c6f
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.ecf.provider.xmpp</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/META-INF/MANIFEST.MF b/providers/bundles/org.eclipse.ecf.provider.xmpp/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..65e59d6f9
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/META-INF/MANIFEST.MF
@@ -0,0 +1,18 @@
+Manifest-Version: 1.0
+Bundle-Name: ECF XMPP Provider Plug-in
+Bundle-SymbolicName: org.eclipse.ecf.provider.xmpp
+Bundle-Version: 1.0.0
+Bundle-ClassPath: xmpp.jar,lib/smack.jar,lib/smackx.jar,lib/smackx-debug.jar
+Bundle-Activator: org.eclipse.ecf.provider.xmpp.XmppPlugin
+Bundle-Vendor: Eclipse.org
+Bundle-Localization: plugin
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.ecf,
+ org.eclipse.ecf.provider,
+ org.junit,
+ org.eclipse.ecf.ui,
+ org.eclipse.ecf.presence
+Eclipse-AutoStart: true
+Export-Package: org.eclipse.ecf.provider.xmpp.container, org.eclipse.ecf.provider.xmpp.identity
+Provide-Package: org.eclipse.ecf.provider.xmpp, org.eclipse.ecf.provider.xmpp.container, org.eclipse.ecf.provider.xmpp.smack, org.eclipse.ecf.provider.xmpp.identity, org.eclipse.ecf.provider.xmpp.ui.views
+DynamicImport-Package: * \ No newline at end of file
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/about.html b/providers/bundles/org.eclipse.ecf.provider.xmpp/about.html
new file mode 100644
index 000000000..1d77777cb
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/about.html
@@ -0,0 +1,39 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<html>
+<head>
+<title>About</title>
+<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>February 24, 2005</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content.</p>
+
+<h3>Third Party Content</h3>
+
+<p>The Content includes items that have been sourced from third parties as follows:</p>
+
+<p><b>Smack API v1.4.1</b></p>
+<p>The plug-in includes software developed by Jive Software as part of the Smack open source client library.</p>
+
+<p>The Ant binary code in smack.jar, smackx.jar, and smackx-debug.jar are included with the plug-in with modification to remove certain images from the original library.
+
+The Smack source code is located <a href="http://www.jivesoftware.org/smack/">Jive Software Smack Library</a></p>
+
+<p>Your use of the Smack libraries is subject to the terms and conditions of the Apache Software License 2.0. A copy of the license is contained
+in the file <a href="asl-v20.txt">asl-v20.txt</a> and is also available at <a href="http://www.apache.org/licenses/LICENSE-2.0.html">http://www.apache.org/licenses/LICENSE-2.0.html</a>.
+
+<p>The names &quot;Smack&quot;, &quot;Jive Software&quot; and &quot;Apache Software Foundation&quot; must not be used to endorse or promote products derived from this
+software without prior written permission. For written permission, please contact <a href="mailto:apache@apache.org">apache@apache.org</a> and <a href="mailto:info@jivesoftware.com">info@jivesoftware.com</a>.</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/asl-v20.txt b/providers/bundles/org.eclipse.ecf.provider.xmpp/asl-v20.txt
new file mode 100644
index 000000000..d64569567
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/asl-v20.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/build.properties b/providers/bundles/org.eclipse.ecf.provider.xmpp/build.properties
new file mode 100644
index 000000000..141ad850f
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/build.properties
@@ -0,0 +1,15 @@
+source.xmpp.jar = src/
+output.xmpp.jar = bin/
+bin.includes = plugin.xml,\
+ META-INF/,\
+ xmpp.jar,\
+ icons/,\
+ lib/smack.jar,\
+ lib/smackx.jar,\
+ lib/smackx-debug.jar
+jars.compile.order = xmpp.jar
+src.includes = icons/,\
+ META-INF/,\
+ plugin.xml,\
+ src/,\
+ lib/
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/lib/smack.jar b/providers/bundles/org.eclipse.ecf.provider.xmpp/lib/smack.jar
new file mode 100644
index 000000000..71491d6a4
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/lib/smack.jar
Binary files differ
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/lib/smackx-debug.jar b/providers/bundles/org.eclipse.ecf.provider.xmpp/lib/smackx-debug.jar
new file mode 100644
index 000000000..dfc67c999
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/lib/smackx-debug.jar
Binary files differ
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/lib/smackx.jar b/providers/bundles/org.eclipse.ecf.provider.xmpp/lib/smackx.jar
new file mode 100644
index 000000000..1e29fd33a
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/lib/smackx.jar
Binary files differ
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/plugin.xml b/providers/bundles/org.eclipse.ecf.provider.xmpp/plugin.xml
new file mode 100644
index 000000000..eb338fccd
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/plugin.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+<plugin>
+ <extension
+ point="org.eclipse.ecf.containerFactory">
+ <containerFactory
+ class="org.eclipse.ecf.provider.xmpp.container.ContainerInstantiator"
+ description="Jabber/XMPP Client"
+ name="org.eclipse.ecf.provider.xmpp.Client">
+ <property
+ value="true"
+ name="org.eclipse.ecf.example.collab.ui.JoinGroupWizardPage.usepassword"/>
+ <property
+ value="&lt;user&gt;@&lt;jabberserver&gt;"
+ name="org.eclipse.ecf.example.collab.ui.JoinGroupWizardPage.examplegroupid"/>
+ <property
+ name="org.eclipse.ecf.example.collab.ui.JoinGroupWizardPage.defaultgroupid"
+ value=""/>
+ <property
+ value="xmpp:"
+ name="org.eclipse.ecf.example.collab.ui.JoinGroupWizardPage.urlprefix"/>
+ <property
+ value="Account:"
+ name="org.eclipse.ecf.example.collab.ui.JoinGroupWizardPage.groupIDLabel"/>
+ <property
+ name="org.eclipse.ecf.example.collab.ui.JoinGroupWizardPage.namespace"
+ value="xmpp"/>
+ </containerFactory>
+ </extension>
+ <extension
+ point="org.eclipse.ecf.namespace">
+ <namespace
+ description="XMPP ID Namespace"
+ instantiatorClass="org.eclipse.ecf.provider.xmpp.identity.XMPPIDInstantiator"
+ name="xmpp"
+ namespaceClass="org.eclipse.ecf.provider.xmpp.identity.XMPPNamespace"/>
+ </extension>
+
+</plugin>
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/Trace.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/Trace.java
new file mode 100644
index 000000000..c92a32335
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/Trace.java
@@ -0,0 +1,110 @@
+/****************************************************************************
+* Copyright (c) 2004 Composent, Inc. and others.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+* http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors:
+* Composent, Inc. - initial API and implementation
+*****************************************************************************/
+
+package org.eclipse.ecf.provider.xmpp;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import org.eclipse.core.runtime.Platform;
+
+public class Trace {
+ public static final String tracePrefix = "(trace)";
+
+ public static boolean ON = false;
+ protected static boolean isEclipse = false;
+ protected static String pluginName = "";
+ protected static String debugPrefix = "/debug/";
+ static {
+ try {
+ ON = Platform.inDebugMode();
+ isEclipse = true;
+ pluginName = XmppPlugin.XMPPPLUGIN_NAME;
+ } catch (Exception e) {
+ try {
+ String val = System.getProperty(XmppPlugin.XMPPPLUGIN_NAME+".Trace");
+ if (val != null) {
+ setTrace(true);
+ isEclipse = false;
+ // No eclipse Platform available
+ System.out.println("WARNING: Eclipse platform not available for trace...using system.out for org.eclipse.ecf");
+ } else {
+ System.out.println(Trace.class.getName()+": OFF");
+ }
+ } catch (Exception except) {
+ }
+ }
+ }
+ public static void setTrace(boolean on) {
+ ON = on;
+ }
+
+ public static Trace create(String key) {
+ if (isEclipse) {
+ String res = Platform
+ .getDebugOption(pluginName + debugPrefix + key);
+ if (res != null) {
+ Boolean on = new Boolean(res);
+ if (on.booleanValue())
+ return new Trace(pluginName + "(" + key + ")");
+ else
+ return null;
+ } else {
+ return null;
+ }
+ } else
+ return new Trace(key);
+ }
+
+ String name;
+
+ public void dumpStack(Throwable e, String msg) {
+ msg(msg);
+ e.printStackTrace(System.err);
+ }
+
+ public void msg(String msg) {
+ StringBuffer sb = new StringBuffer(name);
+ sb.append(getTimeString()).append(msg);
+ System.out.println(sb.toString());
+ }
+
+ protected static String getTimeString() {
+ Date d = new Date();
+ SimpleDateFormat df = new SimpleDateFormat("[MM/dd/yy;HH:mm:ss:SSS]");
+ return df.format(d);
+ }
+
+ protected Trace(String str) {
+ name = tracePrefix+str;
+ }
+ public static String convertStringAToString(String [] strings) {
+ if (strings==null) return "";
+ StringBuffer sb = new StringBuffer();
+ for(int i=0; i < strings.length; i++) {
+ sb.append(strings[i]);
+ if (i != (strings.length-1)) sb.append(";");
+ }
+ return sb.toString();
+ }
+ public static String convertObjectAToString(Object [] objs) {
+ if (objs==null) return "";
+ StringBuffer sb = new StringBuffer();
+ for(int i=0; i < objs.length; i++) {
+ sb.append(objs[i].toString());
+ if (i != (objs.length-1)) sb.append(";");
+ }
+ return sb.toString();
+ }
+
+ public static void setThreadDebugGroup(Object obj) {
+ // Do nothing
+ }
+} \ No newline at end of file
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/XmppPlugin.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/XmppPlugin.java
new file mode 100644
index 000000000..575d4e2c3
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/XmppPlugin.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Composent, Inc. and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Composent, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.provider.xmpp;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The main plugin class to be used in the desktop.
+ */
+public class XmppPlugin extends Plugin {
+ public static final String XMPPPLUGIN_NAME = "org.eclipse.ecf.provider.xmpp";
+
+ //The shared instance.
+ private static XmppPlugin plugin;
+ //Resource bundle.
+ private ResourceBundle resourceBundle;
+
+ /**
+ * The constructor.
+ */
+ public XmppPlugin() {
+ super();
+ plugin = this;
+ try {
+ resourceBundle = ResourceBundle.getBundle("org.eclipse.ecf.provider.xmpp.XmppPluginResources");
+ } catch (MissingResourceException x) {
+ resourceBundle = null;
+ }
+ }
+
+ /**
+ * This method is called upon plug-in activation
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ }
+
+ /**
+ * This method is called when the plug-in is stopped
+ */
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance.
+ */
+ public static XmppPlugin getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns the string from the plugin's resource bundle,
+ * or 'key' if not found.
+ */
+ public static String getResourceString(String key) {
+ ResourceBundle bundle = XmppPlugin.getDefault().getResourceBundle();
+ try {
+ return (bundle != null) ? bundle.getString(key) : key;
+ } catch (MissingResourceException e) {
+ return key;
+ }
+ }
+
+ /**
+ * Returns the plugin's resource bundle,
+ */
+ public ResourceBundle getResourceBundle() {
+ return resourceBundle;
+ }
+
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/ContainerInstantiator.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/ContainerInstantiator.java
new file mode 100644
index 000000000..61fdd6aca
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/ContainerInstantiator.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Composent, Inc. and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Composent, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.provider.xmpp.container;
+
+import org.eclipse.ecf.core.ISharedObjectContainer;
+import org.eclipse.ecf.core.SharedObjectContainerDescription;
+import org.eclipse.ecf.core.SharedObjectContainerInstantiationException;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.core.identity.IDInstantiationException;
+import org.eclipse.ecf.core.provider.ISharedObjectContainerInstantiator;
+
+
+public class ContainerInstantiator implements ISharedObjectContainerInstantiator {
+ public ContainerInstantiator() {
+
+ }
+ protected ID getIDFromArg(Class type, Object arg)
+ throws IDInstantiationException {
+ if (arg instanceof ID)
+ return (ID) arg;
+ if (arg instanceof String) {
+ String val = (String) arg;
+ if (val == null || val.equals("")) {
+ return IDFactory.makeGUID();
+ } else
+ return IDFactory.makeStringID((String) arg);
+ } else if (arg instanceof Integer) {
+ return IDFactory.makeGUID(((Integer) arg).intValue());
+ } else
+ return IDFactory.makeGUID();
+ }
+
+ protected Integer getIntegerFromArg(Class type, Object arg)
+ throws NumberFormatException {
+ if (arg instanceof Integer)
+ return (Integer) arg;
+ else if (arg != null) {
+ return new Integer((String) arg);
+ } else
+ return new Integer(-1);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.core.provider.ISharedObjectContainerInstantiator#makeInstance(org.eclipse.ecf.core.SharedObjectContainerDescription,
+ * java.lang.Class[], java.lang.Object[])
+ */
+ public ISharedObjectContainer makeInstance(
+ SharedObjectContainerDescription description, Class[] argTypes,
+ Object[] args)
+ throws SharedObjectContainerInstantiationException {
+ try {
+ Integer ka = new Integer(XMPPClientSOContainer.DEFAULT_KEEPALIVE);
+ String name = null;
+ if (args != null) {
+ if (args.length > 0) {
+ name = (String) args[0];
+ if (args.length > 1) {
+ ka = getIntegerFromArg(argTypes[1], args[1]);
+ }
+ }
+ }
+ if (name == null) {
+ if (ka == null) {
+ return new XMPPClientSOContainer();
+ } else {
+ return new XMPPClientSOContainer(ka.intValue());
+ }
+ } else {
+ if (ka == null) {
+ ka = new Integer(XMPPClientSOContainer.DEFAULT_KEEPALIVE);
+ }
+ return new XMPPClientSOContainer(name,ka.intValue());
+ }
+ } catch (Exception e) {
+ throw new SharedObjectContainerInstantiationException(
+ "Exception creating generic container", e);
+ }
+ }
+} \ No newline at end of file
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/IGroupChatContainerConfig.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/IGroupChatContainerConfig.java
new file mode 100644
index 000000000..8ca11a778
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/IGroupChatContainerConfig.java
@@ -0,0 +1,16 @@
+/*
+ * Created on Mar 21, 2005
+ *
+ */
+package org.eclipse.ecf.provider.xmpp.container;
+
+import org.eclipse.ecf.core.ISharedObjectContainerConfig;
+
+public interface IGroupChatContainerConfig extends ISharedObjectContainerConfig {
+
+ public String getRoomName();
+ public String getOwnerName();
+ public String getNickname();
+ public String getPassword();
+
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/IIMMessageSender.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/IIMMessageSender.java
new file mode 100644
index 000000000..d750cc140
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/IIMMessageSender.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Composent, Inc. and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Composent, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.provider.xmpp.container;
+
+import java.io.IOException;
+import org.eclipse.ecf.core.identity.ID;
+import org.jivesoftware.smack.Roster;
+
+/**
+ * @author slewis
+ *
+ */
+public interface IIMMessageSender {
+
+ public void sendMessage(ID target, String message) throws IOException;
+
+ public Roster getRoster() throws IOException;
+
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/SharedObjectMsg.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/SharedObjectMsg.java
new file mode 100644
index 000000000..e9ebfd138
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/SharedObjectMsg.java
@@ -0,0 +1,25 @@
+/*
+ * Created on Mar 10, 2005
+ *
+ */
+package org.eclipse.ecf.provider.xmpp.container;
+
+import java.io.Serializable;
+
+public class SharedObjectMsg implements Serializable {
+
+ private static final long serialVersionUID = 3257002168199360564L;
+ String msg;
+ String param;
+
+ public SharedObjectMsg(String msg, String param) {
+ this.msg = msg;
+ this.param = param;
+ }
+ public String getMsg() {
+ return msg;
+ }
+ public String getParam() {
+ return param;
+ }
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPClientSOContainer.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPClientSOContainer.java
new file mode 100644
index 000000000..c1c5877be
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPClientSOContainer.java
@@ -0,0 +1,330 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Composent, Inc. and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Composent, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.provider.xmpp.container;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.HashMap;
+import org.eclipse.ecf.core.ISharedObjectContainer;
+import org.eclipse.ecf.core.SharedObjectAddException;
+import org.eclipse.ecf.core.SharedObjectContainerInstantiationException;
+import org.eclipse.ecf.core.SharedObjectContainerJoinException;
+import org.eclipse.ecf.core.comm.AsynchConnectionEvent;
+import org.eclipse.ecf.core.comm.ConnectionInstantiationException;
+import org.eclipse.ecf.core.comm.ISynchAsynchConnection;
+import org.eclipse.ecf.core.events.SharedObjectContainerDepartedEvent;
+import org.eclipse.ecf.core.events.SharedObjectContainerJoinedEvent;
+import org.eclipse.ecf.core.events.SharedObjectContainerLeaveGroupEvent;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.core.util.IQueueEnqueue;
+import org.eclipse.ecf.presence.IMessageListener;
+import org.eclipse.ecf.presence.IMessageSender;
+import org.eclipse.ecf.presence.IPresenceContainer;
+import org.eclipse.ecf.presence.IPresenceListener;
+import org.eclipse.ecf.presence.ISharedObjectMessageListener;
+import org.eclipse.ecf.presence.IMessageListener.Type;
+import org.eclipse.ecf.provider.generic.ClientSOContainer;
+import org.eclipse.ecf.provider.generic.ContainerMessage;
+import org.eclipse.ecf.provider.generic.SOConfig;
+import org.eclipse.ecf.provider.generic.SOContainerConfig;
+import org.eclipse.ecf.provider.generic.SOContext;
+import org.eclipse.ecf.provider.generic.SOWrapper;
+import org.eclipse.ecf.provider.xmpp.events.IQEvent;
+import org.eclipse.ecf.provider.xmpp.events.MessageEvent;
+import org.eclipse.ecf.provider.xmpp.events.PresenceEvent;
+import org.eclipse.ecf.provider.xmpp.smack.ChatConnection;
+import org.eclipse.ecf.provider.xmpp.smack.ChatConnectionObjectPacketEvent;
+import org.eclipse.ecf.provider.xmpp.smack.ChatConnectionPacketEvent;
+import org.jivesoftware.smack.Roster;
+import org.jivesoftware.smack.packet.IQ;
+import org.jivesoftware.smack.packet.Message;
+import org.jivesoftware.smack.packet.Packet;
+import org.jivesoftware.smack.packet.Presence;
+
+public class XMPPClientSOContainer extends ClientSOContainer {
+
+ public static final int DEFAULT_KEEPALIVE = 10000;
+ public static final String XMPP_SHARED_OBJECT_ID = XMPPClientSOContainer.class
+ .getName()
+ + ".xmpphandler";
+ int keepAlive = 0;
+ protected IIMMessageSender messageSender = null;
+ protected XMPPPresenceSharedObject sharedObject = null;
+ protected ID sharedObjectID = null;
+
+ public XMPPClientSOContainer() throws Exception {
+ this(DEFAULT_KEEPALIVE);
+ }
+
+ public XMPPClientSOContainer(int ka) throws Exception {
+ super(new SOContainerConfig(IDFactory.makeGUID()));
+ keepAlive = ka;
+ initializeSharedObject();
+ }
+
+ public XMPPClientSOContainer(String userhost, int ka) throws Exception {
+ super(new SOContainerConfig(IDFactory.makeStringID(userhost)));
+ keepAlive = ka;
+ initializeSharedObject();
+ }
+
+ protected ID acceptNewServer(ID originalTarget, Object serverData)
+ throws Exception {
+ if (originalTarget != null && !originalTarget.equals(getID())) {
+ addNewRemoteMember(originalTarget, null);
+ // notify listeners
+ fireContainerEvent(new SharedObjectContainerJoinedEvent(this
+ .getID(), originalTarget));
+ }
+ // If we've got roster data then pass it onto shared object
+ if (serverData != null && serverData instanceof Roster) {
+ Roster roster = (Roster) serverData;
+ if (sharedObject != null) {
+ sharedObject.handleRoster(roster);
+ }
+ }
+ // If we've got the connection then pass it onto shared object also
+ ChatConnection conn = (ChatConnection) getConnection();
+ if (conn != null && sharedObject != null) {
+ sharedObject.setConnection(conn.getXMPPConnection());
+ }
+ return originalTarget;
+ }
+
+ protected void addSharedObjectToContainer(ID remote)
+ throws SharedObjectAddException {
+ getSharedObjectManager().addSharedObject(sharedObjectID, sharedObject,
+ new HashMap(), null);
+ }
+
+ protected void cleanUpConnectFail() {
+ if (sharedObject != null) {
+ getSharedObjectManager().removeSharedObject(sharedObjectID);
+ }
+ dispose(0);
+ }
+
+ public void dispose(long time) {
+ super.dispose(time);
+ sharedObjectID = null;
+ sharedObject = null;
+ messageSender = null;
+ }
+
+ protected ISynchAsynchConnection getClientConnection(ID remoteSpace,
+ Object data) throws ConnectionInstantiationException {
+ Object[] args = { new Integer(keepAlive) };
+ ISynchAsynchConnection conn = null;
+ conn = new ChatConnection(receiver);
+ Object res = conn.getAdapter(IIMMessageSender.class);
+ if (res != null) {
+ // got it
+ messageSender = (IIMMessageSender) res;
+ }
+ return conn;
+ }
+
+ protected Serializable getConnectData(ID target, Object data) {
+ return (Serializable) data;
+ }
+
+ protected int getConnectTimeout() {
+ return keepAlive;
+ }
+
+ public Roster getRoster() throws IOException {
+ if (messageSender != null) {
+ return messageSender.getRoster();
+ } else
+ return null;
+ }
+
+ protected void handleChatMessage(Message mess) throws IOException {
+ SOWrapper wrap = getSharedObjectWrapper(sharedObjectID);
+ if (wrap != null) {
+ wrap.deliverEvent(new MessageEvent(mess));
+ }
+ }
+
+ protected void handleContainerMessage(ContainerMessage mess)
+ throws IOException {
+ if (mess == null) {
+ debug("got null container message...ignoring");
+ return;
+ }
+ Object data = mess.getData();
+ if (data instanceof ContainerMessage.CreateMessage) {
+ handleCreateMessage(mess);
+ } else if (data instanceof ContainerMessage.CreateResponseMessage) {
+ handleCreateResponseMessage(mess);
+ } else if (data instanceof ContainerMessage.SharedObjectMessage) {
+ handleSharedObjectMessage(mess);
+ } else if (data instanceof ContainerMessage.SharedObjectDisposeMessage) {
+ handleSharedObjectDisposeMessage(mess);
+ } else {
+ debug("got unrecognized container message...ignoring: " + mess);
+ }
+ }
+
+ protected void handleIQMessage(IQ mess) throws IOException {
+ SOWrapper wrap = getSharedObjectWrapper(sharedObjectID);
+ if (wrap != null) {
+ wrap.deliverEvent(new IQEvent(mess));
+ }
+ }
+
+ protected void handlePresenceMessage(Presence mess) throws IOException {
+ SOWrapper wrap = getSharedObjectWrapper(sharedObjectID);
+ if (wrap != null) {
+ wrap.deliverEvent(new PresenceEvent(mess));
+ }
+ }
+
+ protected void handleXMPPMessage(Packet aPacket) throws IOException {
+ if (aPacket instanceof IQ) {
+ handleIQMessage((IQ) aPacket);
+ } else if (aPacket instanceof Message) {
+ handleChatMessage((Message) aPacket);
+ } else if (aPacket instanceof Presence) {
+ handlePresenceMessage((Presence) aPacket);
+ } else {
+ // unexpected message
+ debug("got unexpected packet " + aPacket);
+ }
+ }
+
+ protected void initializeSharedObject() throws Exception {
+ sharedObjectID = IDFactory.makeStringID(XMPP_SHARED_OBJECT_ID);
+ sharedObject = new XMPPPresenceSharedObject();
+ }
+
+ public void joinGroup(ID remote, Object data)
+ throws SharedObjectContainerJoinException {
+ try {
+ addSharedObjectToContainer(remote);
+ super.joinGroup(remote, data);
+ } catch (SharedObjectContainerJoinException e) {
+ cleanUpConnectFail();
+ throw e;
+ } catch (SharedObjectAddException e1) {
+ cleanUpConnectFail();
+ throw new SharedObjectContainerJoinException(
+ "Exception adding shared object " + sharedObjectID, e1);
+ }
+ }
+
+ public void leaveGroup() {
+ ID groupID = getGroupID();
+ fireContainerEvent(new SharedObjectContainerLeaveGroupEvent(this
+ .getID(), groupID));
+ synchronized (getConnectLock()) {
+ // If we are currently connected
+ if (isConnected()) {
+ ISynchAsynchConnection connection = getConnection();
+ synchronized (connection) {
+ synchronized (getGroupMembershipLock()) {
+ memberLeave(groupID, null);
+ }
+ try {
+ connection.disconnect();
+ } catch (IOException e) {
+ dumpStack("Exception disconnecting", e);
+ }
+ }
+ }
+ connectionState = UNCONNECTED;
+ connection = null;
+ remoteServerID = null;
+ }
+ // notify listeners
+ fireContainerEvent(new SharedObjectContainerDepartedEvent(this.getID(),
+ groupID));
+ }
+
+ protected SOContext makeNewSharedObjectContext(SOConfig config,
+ IQueueEnqueue queue) {
+ return new XMPPContainerContext(config.getSharedObjectID(), config
+ .getHomeContainerID(), this, config.getProperties(), queue);
+ }
+
+ protected void processAsynch(AsynchConnectionEvent e) {
+ try {
+ if (e instanceof ChatConnectionPacketEvent) {
+ // It's a regular message...just print for now
+ ChatConnectionPacketEvent evt = (ChatConnectionPacketEvent) e;
+ Packet chatMess = (Packet) e.getData();
+ handleXMPPMessage(chatMess);
+ return;
+ } else if (e instanceof ChatConnectionObjectPacketEvent) {
+ ChatConnectionObjectPacketEvent evt = (ChatConnectionObjectPacketEvent) e;
+ Object obj = evt.getObjectValue();
+ // this should be a ContainerMessage
+ Object cm = deserializeContainerMessage((byte[]) obj);
+ if (cm == null) throw new IOException("deserialized object is null");
+ ContainerMessage contMessage = (ContainerMessage) cm;
+ Object cmdata = contMessage.getData();
+ handleContainerMessage(contMessage);
+ } else {
+ // Unexpected type...
+ debug("got unexpected event: " + e);
+ }
+ } catch (Exception except) {
+ System.err.println("Exception in processAsynch");
+ except.printStackTrace(System.err);
+ dumpStack("Exception processing event " + e, except);
+ }
+ }
+
+ public void sendMessage(ID target, String message) throws IOException {
+ if (messageSender != null) {
+ messageSender.sendMessage(target, message);
+ }
+ }
+
+ public Object getAdapter(Class clazz) {
+ if (clazz.equals(IPresenceContainer.class)) {
+ return new IPresenceContainer() {
+
+ public void addPresenceListener(IPresenceListener listener) {
+ sharedObject.addPresenceListener(listener);
+ }
+
+ public void addMessageListener(IMessageListener listener) {
+ sharedObject.addMessageListener(listener);
+ }
+
+ public void addSharedObjectMessageListener(ISharedObjectMessageListener listener) {
+ sharedObject.addSharedObjectMessageListener(listener);
+ }
+
+ public IMessageSender getMessageSender() {
+ return new IMessageSender() {
+
+ public void sendMessage(ID fromID, ID toID, Type type, String subject, String message) {
+ try {
+ XMPPClientSOContainer.this.sendMessage(toID,message);
+ } catch (IOException e) {
+ dumpStack("Exception in sendmessage to "+toID+" with message "+message,e);
+ }
+
+ }
+
+ };
+ }
+
+ public ISharedObjectContainer makeSharedObjectContainer(Class[] types, Object[] args) throws SharedObjectContainerInstantiationException {
+ return null;
+ }
+
+ };
+ }
+ return null;
+ }
+} \ No newline at end of file
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPContainerContext.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPContainerContext.java
new file mode 100644
index 000000000..c92b5d9f8
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPContainerContext.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Composent, Inc. and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Composent, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.provider.xmpp.container;
+
+import java.io.IOException;
+import java.util.Map;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.util.IQueueEnqueue;
+import org.eclipse.ecf.provider.generic.SOContainer;
+import org.eclipse.ecf.provider.generic.SOContext;
+import org.jivesoftware.smack.Roster;
+
+/**
+ * @author slewis
+ *
+ */
+public class XMPPContainerContext extends SOContext {
+
+ public XMPPContainerContext(ID objID, ID homeID, SOContainer cont, Map props, IQueueEnqueue queue) {
+ super(objID, homeID, cont, props, queue);
+ }
+
+ public Object getAdapter(Class clazz) {
+ if (clazz.equals(IIMMessageSender.class)) {
+ return new IIMMessageSender() {
+ public void sendMessage(ID target, String message) throws IOException {
+ ((XMPPClientSOContainer) container).sendMessage(target,message);
+ }
+ public Roster getRoster() throws IOException {
+ return ((XMPPClientSOContainer) container).getRoster();
+ }
+ };
+ } else return null;
+ }
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPGroupChatSOContainer.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPGroupChatSOContainer.java
new file mode 100644
index 000000000..0c9a24fe7
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPGroupChatSOContainer.java
@@ -0,0 +1,239 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Composent, Inc. and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Composent, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.provider.xmpp.container;
+
+import java.io.IOException;
+import java.util.HashMap;
+import org.eclipse.ecf.core.SharedObjectAddException;
+import org.eclipse.ecf.core.SharedObjectContainerJoinException;
+import org.eclipse.ecf.core.comm.AsynchConnectionEvent;
+import org.eclipse.ecf.core.comm.ConnectionInstantiationException;
+import org.eclipse.ecf.core.comm.ISynchAsynchConnection;
+import org.eclipse.ecf.core.events.SharedObjectContainerDepartedEvent;
+import org.eclipse.ecf.core.events.SharedObjectContainerLeaveGroupEvent;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.core.util.IQueueEnqueue;
+import org.eclipse.ecf.provider.generic.ClientSOContainer;
+import org.eclipse.ecf.provider.generic.ContainerMessage;
+import org.eclipse.ecf.provider.generic.SOConfig;
+import org.eclipse.ecf.provider.generic.SOContext;
+import org.eclipse.ecf.provider.generic.SOWrapper;
+import org.eclipse.ecf.provider.xmpp.events.IQEvent;
+import org.eclipse.ecf.provider.xmpp.events.MessageEvent;
+import org.eclipse.ecf.provider.xmpp.events.PresenceEvent;
+import org.eclipse.ecf.provider.xmpp.smack.ChatConnectionObjectPacketEvent;
+import org.eclipse.ecf.provider.xmpp.smack.ChatConnectionPacketEvent;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.XMPPException;
+import org.jivesoftware.smack.packet.IQ;
+import org.jivesoftware.smack.packet.Message;
+import org.jivesoftware.smack.packet.Packet;
+import org.jivesoftware.smack.packet.Presence;
+import org.jivesoftware.smackx.muc.MultiUserChat;
+
+public class XMPPGroupChatSOContainer extends ClientSOContainer {
+ public static final String XMPP_GROUP_CHAT_SHARED_OBJECT_ID = XMPPClientSOContainer.class
+ .getName()
+ + ".xmppgroupchathandler";
+ XMPPConnection connection;
+ ID sharedObjectID;
+ XMPPGroupChatSharedObject sharedObject;
+ MultiUserChat multiuserchat;
+ IGroupChatContainerConfig gcconfig;
+
+ public XMPPGroupChatSOContainer(IGroupChatContainerConfig config,
+ XMPPConnection conn) throws Exception {
+ super(config);
+ this.connection = conn;
+ this.gcconfig = config;
+ initializeSharedObject();
+ initializeGroupChat();
+ }
+ protected IGroupChatContainerConfig getGroupChatConfig() {
+ return gcconfig;
+ }
+ protected void initializeGroupChat() throws XMPPException {
+ multiuserchat = new MultiUserChat(connection,getGroupChatConfig().getRoomName());
+ multiuserchat.create(getGroupChatConfig().getOwnerName());
+ }
+ public void dispose(long time) {
+ super.dispose(time);
+ connection = null;
+ }
+
+ protected void handleChatMessage(Message mess) throws IOException {
+ SOWrapper wrap = getSharedObjectWrapper(sharedObjectID);
+ if (wrap != null) {
+ wrap.deliverEvent(new MessageEvent(mess));
+ }
+ }
+
+ protected void handleContainerMessage(ContainerMessage mess)
+ throws IOException {
+ if (mess == null) {
+ debug("got null container message...ignoring");
+ return;
+ }
+ Object data = mess.getData();
+ if (data instanceof ContainerMessage.CreateMessage) {
+ handleCreateMessage(mess);
+ } else if (data instanceof ContainerMessage.CreateResponseMessage) {
+ handleCreateResponseMessage(mess);
+ } else if (data instanceof ContainerMessage.SharedObjectMessage) {
+ handleSharedObjectMessage(mess);
+ } else if (data instanceof ContainerMessage.SharedObjectDisposeMessage) {
+ handleSharedObjectDisposeMessage(mess);
+ } else {
+ debug("got unrecognized container message...ignoring: " + mess);
+ }
+ }
+
+ protected void handleIQMessage(IQ mess) throws IOException {
+ SOWrapper wrap = getSharedObjectWrapper(sharedObjectID);
+ if (wrap != null) {
+ wrap.deliverEvent(new IQEvent(mess));
+ }
+ }
+
+ protected void handlePresenceMessage(Presence mess) throws IOException {
+ SOWrapper wrap = getSharedObjectWrapper(sharedObjectID);
+ if (wrap != null) {
+ wrap.deliverEvent(new PresenceEvent(mess));
+ }
+ }
+
+ protected void handleXMPPMessage(Packet aPacket) throws IOException {
+ if (aPacket instanceof IQ) {
+ handleIQMessage((IQ) aPacket);
+ } else if (aPacket instanceof Message) {
+ handleChatMessage((Message) aPacket);
+ } else if (aPacket instanceof Presence) {
+ handlePresenceMessage((Presence) aPacket);
+ } else {
+ // unexpected message
+ debug("got unexpected packet " + aPacket);
+ }
+ }
+
+ protected void initializeSharedObject() throws Exception {
+ sharedObjectID = IDFactory.makeStringID(XMPP_GROUP_CHAT_SHARED_OBJECT_ID);
+ sharedObject = new XMPPGroupChatSharedObject();
+ }
+
+ protected void addSharedObjectToContainer(ID remote)
+ throws SharedObjectAddException {
+ getSharedObjectManager().addSharedObject(sharedObjectID, sharedObject,
+ new HashMap(), null);
+ }
+
+ protected void cleanUpConnectFail() {
+ if (sharedObject != null) {
+ getSharedObjectManager().removeSharedObject(sharedObjectID);
+ }
+ dispose(0);
+ }
+
+ public void joinGroup(ID remote, Object data)
+ throws SharedObjectContainerJoinException {
+ String nickname = "";
+ String password = "";
+ try {
+ addSharedObjectToContainer(remote);
+ IGroupChatContainerConfig config = getGroupChatConfig();
+ nickname = config.getNickname();
+ password = config.getPassword();
+ multiuserchat.join(nickname,password);
+ } catch (XMPPException e) {
+ cleanUpConnectFail();
+ SharedObjectContainerJoinException ce = new SharedObjectContainerJoinException("Exception joining with nickname "+nickname);
+ ce.setStackTrace(e.getStackTrace());
+ throw ce;
+ } catch (SharedObjectAddException e1) {
+ cleanUpConnectFail();
+ SharedObjectContainerJoinException ce = new SharedObjectContainerJoinException("Exception adding shared object " + sharedObjectID);
+ ce.setStackTrace(e1.getStackTrace());
+ throw ce;
+ }
+ }
+
+ public void leaveGroup() {
+ ID groupID = getGroupID();
+ fireContainerEvent(new SharedObjectContainerLeaveGroupEvent(this
+ .getID(), groupID));
+ synchronized (getConnectLock()) {
+ // If we are currently connected
+ if (isConnected()) {
+ ISynchAsynchConnection connection = getConnection();
+ synchronized (connection) {
+ synchronized (getGroupMembershipLock()) {
+ memberLeave(groupID, null);
+ }
+ try {
+ connection.disconnect();
+ } catch (IOException e) {
+ dumpStack("Exception disconnecting", e);
+ }
+ }
+ }
+ connectionState = UNCONNECTED;
+ connection = null;
+ remoteServerID = null;
+ }
+ // notify listeners
+ fireContainerEvent(new SharedObjectContainerDepartedEvent(this.getID(),
+ groupID));
+ }
+
+ protected SOContext makeNewSharedObjectContext(SOConfig config,
+ IQueueEnqueue queue) {
+ return new XMPPContainerContext(config.getSharedObjectID(), config
+ .getHomeContainerID(), this, config.getProperties(), queue);
+ }
+
+ protected void processAsynch(AsynchConnectionEvent e) {
+ try {
+ if (e instanceof ChatConnectionPacketEvent) {
+ // It's a regular message...just print for now
+ ChatConnectionPacketEvent evt = (ChatConnectionPacketEvent) e;
+ Packet chatMess = (Packet) e.getData();
+ handleXMPPMessage(chatMess);
+ return;
+ } else if (e instanceof ChatConnectionObjectPacketEvent) {
+ ChatConnectionObjectPacketEvent evt = (ChatConnectionObjectPacketEvent) e;
+ Object obj = evt.getObjectValue();
+ // this should be a ContainerMessage
+ Object cm = deserializeContainerMessage((byte[]) obj);
+ if (cm == null)
+ throw new IOException("deserialized object is null");
+ ContainerMessage contMessage = (ContainerMessage) cm;
+ Object cmdata = contMessage.getData();
+ handleContainerMessage(contMessage);
+ } else {
+ // Unexpected type...
+ debug("got unexpected event: " + e);
+ }
+ } catch (Exception except) {
+ System.err.println("Exception in processAsynch");
+ except.printStackTrace(System.err);
+ dumpStack("Exception processing event " + e, except);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.provider.generic.ClientSOContainer#getClientConnection(org.eclipse.ecf.core.identity.ID,
+ * java.lang.Object)
+ */
+ protected ISynchAsynchConnection getClientConnection(ID remoteSpace,
+ Object data) throws ConnectionInstantiationException {
+ return null;
+ }
+} \ No newline at end of file
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPGroupChatSharedObject.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPGroupChatSharedObject.java
new file mode 100644
index 000000000..c3e6720c8
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPGroupChatSharedObject.java
@@ -0,0 +1,68 @@
+/*
+ * Created on Mar 21, 2005
+ *
+ */
+package org.eclipse.ecf.provider.xmpp.container;
+
+import org.eclipse.ecf.core.ISharedObject;
+import org.eclipse.ecf.core.ISharedObjectConfig;
+import org.eclipse.ecf.core.SharedObjectInitException;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.util.Event;
+import org.eclipse.ecf.provider.xmpp.Trace;
+
+public class XMPPGroupChatSharedObject implements ISharedObject {
+
+ public static Trace trace = Trace.create("xmppgroupchatsharedobject");
+
+ ISharedObjectConfig config = null;
+
+ protected void debug(String msg) {
+ if (Trace.ON && trace != null) {
+ trace.msg(config.getSharedObjectID() + ":" + msg);
+ }
+ }
+
+ public XMPPGroupChatSharedObject() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.core.ISharedObject#init(org.eclipse.ecf.core.ISharedObjectConfig)
+ */
+ public void init(ISharedObjectConfig initData)
+ throws SharedObjectInitException {
+ this.config = initData;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.core.ISharedObject#handleEvent(org.eclipse.ecf.core.util.Event)
+ */
+ public void handleEvent(Event event) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.core.ISharedObject#handleEvents(org.eclipse.ecf.core.util.Event[])
+ */
+ public void handleEvents(Event[] events) {
+ for(int i=0; i < events.length; i++) {
+ this.handleEvent(events[i]);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.core.ISharedObject#dispose(org.eclipse.ecf.core.identity.ID)
+ */
+ public void dispose(ID containerID) {
+ this.config = null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.core.ISharedObject#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter(Class clazz) {
+ return null;
+ }
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPPresenceSharedObject.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPPresenceSharedObject.java
new file mode 100644
index 000000000..95c999aa9
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPPresenceSharedObject.java
@@ -0,0 +1,441 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Composent, Inc. and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Composent, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.provider.xmpp.container;
+
+import java.util.Iterator;
+import java.util.Vector;
+import org.eclipse.ecf.core.ISharedObject;
+import org.eclipse.ecf.core.ISharedObjectConfig;
+import org.eclipse.ecf.core.ISharedObjectContext;
+import org.eclipse.ecf.core.SharedObjectInitException;
+import org.eclipse.ecf.core.events.ISharedObjectActivatedEvent;
+import org.eclipse.ecf.core.events.ISharedObjectContainerDepartedEvent;
+import org.eclipse.ecf.core.events.ISharedObjectContainerJoinedEvent;
+import org.eclipse.ecf.core.events.ISharedObjectDeactivatedEvent;
+import org.eclipse.ecf.core.events.ISharedObjectMessageEvent;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.core.util.Event;
+import org.eclipse.ecf.presence.IMessageListener;
+import org.eclipse.ecf.presence.IPresence;
+import org.eclipse.ecf.presence.IPresenceListener;
+import org.eclipse.ecf.presence.IRosterEntry;
+import org.eclipse.ecf.presence.IRosterGroup;
+import org.eclipse.ecf.presence.ISharedObjectMessageListener;
+import org.eclipse.ecf.provider.xmpp.Trace;
+import org.eclipse.ecf.provider.xmpp.events.IQEvent;
+import org.eclipse.ecf.provider.xmpp.events.MessageEvent;
+import org.eclipse.ecf.provider.xmpp.events.PresenceEvent;
+import org.eclipse.ecf.provider.xmpp.identity.XMPPID;
+import org.jivesoftware.smack.Roster;
+import org.jivesoftware.smack.RosterEntry;
+import org.jivesoftware.smack.RosterGroup;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.packet.IQ;
+import org.jivesoftware.smack.packet.Message;
+import org.jivesoftware.smack.packet.Presence;
+import org.jivesoftware.smack.packet.RosterPacket;
+import org.jivesoftware.smack.packet.Presence.Mode;
+import org.jivesoftware.smack.packet.Presence.Type;
+
+/**
+ * @author slewis
+ *
+ */
+public class XMPPPresenceSharedObject implements ISharedObject {
+
+ public static Trace trace = Trace.create("xmpppresencesharedobject");
+ ISharedObjectConfig config = null;
+ XMPPConnection connection = null;
+ Vector messageListeners = new Vector();
+ Vector presenceListeners = new Vector();
+ Vector sharedObjectMessageListeners = new Vector();
+
+ protected void addPresenceListener(IPresenceListener listener) {
+ presenceListeners.add(listener);
+ }
+ protected void removePresenceListener(IPresenceListener listener) {
+ presenceListeners.remove(listener);
+ }
+ protected void addMessageListener(IMessageListener listener) {
+ messageListeners.add(listener);
+ }
+ protected void removeMessageListener(IMessageListener listener) {
+ messageListeners.add(listener);
+ }
+ protected void addSharedObjectMessageListener(ISharedObjectMessageListener listener) {
+ sharedObjectMessageListeners.add(listener);
+ }
+ protected void removeSharedObjectMessageListener(ISharedObjectMessageListener listener) {
+ sharedObjectMessageListeners.remove(listener);
+ }
+ protected String canonicalizePresenceFrom(String from) {
+ if (from == null)
+ return null;
+ int index = from.indexOf("/");
+ if (index > 0) {
+ return from.substring(0, index);
+ } else
+ return from;
+ }
+
+ protected void debug(String msg) {
+ if (Trace.ON && trace != null) {
+ trace.msg(config.getSharedObjectID() + ":" + msg);
+ }
+ }
+
+ protected void disconnect() {
+ ISharedObjectContext context = getContext();
+ if (context != null) {
+ context.leaveGroup();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.core.ISharedObject#dispose(org.eclipse.ecf.core.identity.ID)
+ */
+ public void dispose(ID containerID) {
+ config = null;
+ }
+
+ protected void dumpStack(String msg, Throwable e) {
+ if (Trace.ON && trace != null) {
+ trace.dumpStack(e, config.getSharedObjectID() + ":" + msg);
+ }
+ }
+
+ protected void fireContainerDeparted(ID departed) {
+ for (Iterator i = presenceListeners.iterator(); i.hasNext();) {
+ IPresenceListener l = (IPresenceListener) i.next();
+ l.handleContainerDeparted(departed);
+ }
+ }
+
+ protected void fireContainerJoined(ID containerJoined) {
+ for (Iterator i = presenceListeners.iterator(); i.hasNext();) {
+ IPresenceListener l = (IPresenceListener) i.next();
+ l.handleContainerJoined(containerJoined);
+ }
+ }
+
+ protected void fireMessage(ID from, ID to, IMessageListener.Type type,
+ String subject, String body) {
+ for (Iterator i = messageListeners.iterator(); i.hasNext();) {
+ IMessageListener l = (IMessageListener) i.next();
+ l.handleMessage(from, to, type, subject, body);
+ }
+ }
+
+ protected void firePresence(ID fromID, IPresence presence) {
+ for (Iterator i = presenceListeners.iterator(); i.hasNext();) {
+ IPresenceListener l = (IPresenceListener) i.next();
+ l.handlePresence(fromID, presence);
+ }
+ }
+
+ protected void fireRosterEntry(IRosterEntry entry) {
+ for (Iterator i = presenceListeners.iterator(); i.hasNext();) {
+ IPresenceListener l = (IPresenceListener) i.next();
+ l.handleRosterEntry(entry);
+ }
+ }
+
+ protected void fireSharedObjectMessage(ISharedObjectMessageEvent event) {
+ for (Iterator i = sharedObjectMessageListeners.iterator(); i.hasNext();) {
+ ISharedObjectMessageListener l = (ISharedObjectMessageListener) i.next();
+ l.handleSharedObjectMessage(event);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.core.ISharedObject#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter(Class clazz) {
+ return null;
+ }
+
+ protected XMPPConnection getConnection() {
+ return connection;
+ }
+
+ protected ISharedObjectContext getContext() {
+ return config.getContext();
+ }
+
+ protected String getUserNameFromXMPPAddress(XMPPID userID) {
+ return userID.getUsername();
+ }
+
+ protected void handleContainerDepartedEvent(
+ ISharedObjectContainerDepartedEvent event) {
+ ID departedID = event.getDepartedContainerID();
+ if (departedID != null) {
+ fireContainerDeparted(departedID);
+ }
+ }
+
+ protected void handleDeactivatedEvent(ISharedObjectDeactivatedEvent event) {
+ debug("Got deactivated event: " + event);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.core.ISharedObject#handleEvent(org.eclipse.ecf.core.util.Event)
+ */
+ public void handleEvent(Event event) {
+ debug("handleEvent(" + event + ")");
+ if (event instanceof ISharedObjectActivatedEvent) {
+ } else if (event instanceof ISharedObjectContainerJoinedEvent) {
+ handleJoin((ISharedObjectContainerJoinedEvent) event);
+ } else if (event instanceof IQEvent) {
+ handleIQEvent((IQEvent) event);
+ } else if (event instanceof MessageEvent) {
+ handleMessageEvent((MessageEvent) event);
+ } else if (event instanceof PresenceEvent) {
+ handlePresenceEvent((PresenceEvent) event);
+ } else if (event instanceof ISharedObjectDeactivatedEvent) {
+ handleDeactivatedEvent((ISharedObjectDeactivatedEvent) event);
+ } else if (event instanceof ISharedObjectContainerDepartedEvent) {
+ handleContainerDepartedEvent((ISharedObjectContainerDepartedEvent) event);
+ } else if (event instanceof ISharedObjectMessageEvent) {
+ fireSharedObjectMessage((ISharedObjectMessageEvent) event);
+ } else {
+ debug("unrecognized event " + event);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.core.ISharedObject#handleEvents(org.eclipse.ecf.core.util.Event[])
+ */
+ public void handleEvents(Event[] events) {
+ for (int i = 0; i < events.length; i++) {
+ handleEvent(events[i]);
+ }
+ }
+
+ protected void handleIQEvent(IQEvent evt) {
+ IQ iq = evt.getIQ();
+ if (iq instanceof RosterPacket) {
+ // Roster packet...report to UI
+ RosterPacket rosterPacket = (RosterPacket) iq;
+ for (Iterator i = rosterPacket.getRosterItems(); i.hasNext();) {
+ IRosterEntry entry = makeRosterEntry((RosterPacket.Item) i
+ .next());
+ fireRosterEntry(entry);
+ }
+ } else {
+ debug("Received unknown IQ message: " + iq.toXML());
+ }
+ }
+
+ protected void handleJoin(ISharedObjectContainerJoinedEvent event) {
+ fireContainerJoined(event.getJoinedContainerID());
+ }
+
+ protected void handleMessageEvent(MessageEvent evt) {
+ Message msg = evt.getMessage();
+ String from = msg.getFrom();
+ String to = msg.getTo();
+ String body = msg.getBody();
+ String subject = msg.getSubject();
+ ID fromID = makeIDFromName(canonicalizePresenceFrom(from));
+ ID toID = makeIDFromName(canonicalizePresenceFrom(to));
+ fireMessage(fromID, toID, makeMessageType(msg.getType()), subject, body);
+ }
+
+ protected void handlePresenceEvent(PresenceEvent evt) {
+ Presence xmppPresence = evt.getPresence();
+ String from = canonicalizePresenceFrom(xmppPresence.getFrom());
+ String to = xmppPresence.getTo();
+ Mode mode = xmppPresence.getMode();
+ Type type = xmppPresence.getType();
+ int priority = xmppPresence.getPriority();
+ String status = xmppPresence.getStatus();
+ IPresence newPresence = makePresence(xmppPresence);
+ ID fromID = makeIDFromName(from);
+ firePresence(fromID, newPresence);
+ }
+
+ protected void handleRoster(Roster roster) {
+ for (Iterator i = roster.getEntries(); i.hasNext();) {
+ IRosterEntry entry = makeRosterEntry((RosterEntry) i.next());
+ fireRosterEntry(entry);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.core.ISharedObject#init(org.eclipse.ecf.core.ISharedObjectConfig)
+ */
+ public void init(ISharedObjectConfig initData)
+ throws SharedObjectInitException {
+ this.config = initData;
+ }
+
+ protected ID makeIDFromName(String name) {
+ ID result = null;
+ try {
+ result = IDFactory.makeID(XMPPID.PROTOCOL, new Object[] { name });
+ return result;
+ } catch (Exception e) {
+ dumpStack("Exception in makeIDFromName", e);
+ return null;
+ }
+ }
+
+ protected IRosterEntry.InterestType makeInterestType(
+ RosterPacket.ItemType itemType) {
+ if (itemType == RosterPacket.ItemType.BOTH) {
+ return IRosterEntry.InterestType.BOTH;
+ } else if (itemType == RosterPacket.ItemType.FROM) {
+ return IRosterEntry.InterestType.BOTH;
+ } else if (itemType == RosterPacket.ItemType.NONE) {
+ return IRosterEntry.InterestType.NONE;
+ } else if (itemType == RosterPacket.ItemType.REMOVE) {
+ return IRosterEntry.InterestType.REMOVE;
+ } else if (itemType == RosterPacket.ItemType.TO) {
+ return IRosterEntry.InterestType.TO;
+ } else
+ return IRosterEntry.InterestType.BOTH;
+ }
+
+ protected IMessageListener.Type makeMessageType(Message.Type type) {
+ if (type == null)
+ return IMessageListener.Type.NORMAL;
+ if (type == Message.Type.CHAT) {
+ return IMessageListener.Type.CHAT;
+ } else if (type == Message.Type.NORMAL) {
+ return IMessageListener.Type.NORMAL;
+ } else if (type == Message.Type.GROUP_CHAT) {
+ return IMessageListener.Type.GROUP_CHAT;
+ } else if (type == Message.Type.HEADLINE) {
+ return IMessageListener.Type.HEADLINE;
+ } else if (type == Message.Type.HEADLINE) {
+ return IMessageListener.Type.HEADLINE;
+ } else
+ return IMessageListener.Type.NORMAL;
+ }
+
+ protected IPresence makePresence(Presence xmppPresence) {
+ Mode mode = xmppPresence.getMode();
+ Type type = xmppPresence.getType();
+ int priority = xmppPresence.getPriority();
+ String status = xmppPresence.getStatus();
+ IPresence newPresence = new org.eclipse.ecf.presence.impl.Presence(
+ makePresenceType(xmppPresence), priority, status,
+ makePresenceMode(xmppPresence));
+ return newPresence;
+ }
+
+ protected IPresence.Mode makePresenceMode(Presence xmppPresence) {
+ if (xmppPresence == null)
+ return IPresence.Mode.AVAILABLE;
+ Mode mode = xmppPresence.getMode();
+ if (mode == Presence.Mode.AVAILABLE) {
+ return IPresence.Mode.AVAILABLE;
+ } else if (mode == Presence.Mode.AWAY) {
+ return IPresence.Mode.AWAY;
+ } else if (mode == Presence.Mode.CHAT) {
+ return IPresence.Mode.CHAT;
+ } else if (mode == Presence.Mode.DO_NOT_DISTURB) {
+ return IPresence.Mode.DND;
+ } else if (mode == Presence.Mode.EXTENDED_AWAY) {
+ return IPresence.Mode.EXTENDED_AWAY;
+ } else if (mode == Presence.Mode.INVISIBLE) {
+ return IPresence.Mode.INVISIBLE;
+ }
+ return IPresence.Mode.AVAILABLE;
+ }
+
+ protected IPresence.Type makePresenceType(Presence xmppPresence) {
+ if (xmppPresence == null)
+ return IPresence.Type.AVAILABLE;
+ Type type = xmppPresence.getType();
+ if (type == Presence.Type.AVAILABLE) {
+ return IPresence.Type.AVAILABLE;
+ } else if (type == Presence.Type.ERROR) {
+ return IPresence.Type.ERROR;
+ } else if (type == Presence.Type.SUBSCRIBE) {
+ return IPresence.Type.SUBSCRIBE;
+ } else if (type == Presence.Type.SUBSCRIBED) {
+ return IPresence.Type.SUBSCRIBED;
+ } else if (type == Presence.Type.UNSUBSCRIBE) {
+ return IPresence.Type.UNSUBSCRIBE;
+ } else if (type == Presence.Type.UNSUBSCRIBED) {
+ return IPresence.Type.UNSUBSCRIBED;
+ } else if (type == Presence.Type.UNAVAILABLE) {
+ return IPresence.Type.UNAVAILABLE;
+ }
+ return IPresence.Type.AVAILABLE;
+ }
+
+ protected IRosterEntry makeRosterEntry(RosterEntry entry) {
+ try {
+ ID userID = makeIDFromName(entry.getUser());
+ String name = entry.getName();
+ RosterPacket.ItemType itemType = entry.getType();
+ IRosterEntry.InterestType iType = makeInterestType(itemType);
+ IRosterEntry newEntry = new org.eclipse.ecf.presence.impl.RosterEntry(
+ userID, name, iType);
+ Iterator grps = entry.getGroups();
+ for (; grps.hasNext();) {
+ RosterGroup grp = (RosterGroup) grps.next();
+ IRosterGroup localGrp = makeRosterGroup(grp);
+ newEntry.add(localGrp);
+ }
+ return newEntry;
+ } catch (Exception e) {
+ dumpStack("Exception in makeRosterEntry", e);
+ }
+ return null;
+ }
+
+ protected IRosterEntry makeRosterEntry(RosterPacket.Item entry) {
+ try {
+ ID userID = makeIDFromName(entry.getUser());
+ String name = entry.getName();
+ RosterPacket.ItemType itemType = entry.getItemType();
+ IRosterEntry.InterestType iType = makeInterestType(itemType);
+ IRosterEntry newEntry = new org.eclipse.ecf.presence.impl.RosterEntry(
+ userID, name, iType);
+ Iterator grps = entry.getGroupNames();
+ for (; grps.hasNext();) {
+ String grp = (String) grps.next();
+ IRosterGroup localGrp = makeRosterGroup(grp);
+ newEntry.add(localGrp);
+ }
+ return newEntry;
+ } catch (Exception e) {
+ dumpStack("Exception in makeRosterEntry", e);
+ }
+ return null;
+ }
+
+ protected IRosterGroup makeRosterGroup(RosterGroup grp) {
+ return new org.eclipse.ecf.presence.impl.RosterGroup(grp.getName());
+ }
+
+ protected IRosterGroup makeRosterGroup(String grp) {
+ return new org.eclipse.ecf.presence.impl.RosterGroup(grp);
+ }
+
+ protected void setConnection(XMPPConnection connection) {
+ this.connection = connection;
+ }
+
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPSharedObject.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPSharedObject.java
new file mode 100644
index 000000000..c199ecd5c
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/container/XMPPSharedObject.java
@@ -0,0 +1,538 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Composent, Inc. and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Composent, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.provider.xmpp.container;
+
+import org.eclipse.ecf.core.ISharedObject;
+import org.eclipse.ecf.core.ISharedObjectConfig;
+import org.eclipse.ecf.core.ISharedObjectContext;
+import org.eclipse.ecf.core.SharedObjectInitException;
+import org.eclipse.ecf.core.events.ISharedObjectContainerDepartedEvent;
+import org.eclipse.ecf.core.events.ISharedObjectDeactivatedEvent;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.util.Event;
+import org.eclipse.ecf.provider.xmpp.Trace;
+
+/**
+ * @author slewis
+ *
+ */
+public class XMPPSharedObject implements ISharedObject {
+
+ public static final String ROSTER_VIEW_ID = "org.eclipse.ecf.provider.xmpp.ui.view.rosterview";
+
+ public static Trace trace = Trace.create("xmppsharedobject");
+
+ ISharedObjectConfig config = null;
+
+ /*
+ XMPPConnection connection = null;
+ IConfigViewer localUI = null;
+ XMPPID localUserID = null;
+ String localUserNickname = null;
+ IMessageViewer messageViewer = null;
+ IRosterViewer rosterViewer = null;
+ IIMMessageSender sender = null;
+
+ protected String canonicalizePresenceFrom(String from) {
+ if (from == null)
+ return null;
+ int index = from.indexOf("/");
+ if (index > 0) {
+ return from.substring(0, index);
+ } else
+ return from;
+ }
+ */
+ protected void debug(String msg) {
+ if (Trace.ON && trace != null) {
+ trace.msg(config.getSharedObjectID() + ":" + msg);
+ }
+ }
+
+ protected void disconnect() {
+ ISharedObjectContext context = getContext();
+ if (context != null) {
+ context.leaveGroup();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.core.ISharedObject#dispose(org.eclipse.ecf.core.identity.ID)
+ */
+
+ public void dispose(ID containerID) {
+ config = null;
+ /*
+ sender = null;
+ rosterViewer = null;
+ messageViewer = null;
+ localUI = null;
+ */
+ }
+
+ protected void dumpStack(String msg, Throwable e) {
+ if (Trace.ON && trace != null) {
+ trace.dumpStack(e, config.getSharedObjectID() + ":" + msg);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.core.ISharedObject#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter(Class clazz) {
+ return null;
+ }
+ /*
+ protected XMPPConnection getConnection() {
+ return connection;
+ }
+ */
+ protected ISharedObjectContext getContext() {
+ return config.getContext();
+ }
+ /*
+ protected IMessageViewer getMessageViewer() {
+ if (messageViewer != null)
+ return messageViewer;
+ else
+ return new IMessageViewer() {
+ public void showMessage(ID fromID, ID toID,
+ IMessageViewer.Type type, String subject, String message) {
+ debug("Received message from " + fromID + " to " + toID
+ + ", type=" + type + ", subject=" + subject
+ + ", message=" + message);
+ }
+ };
+ }
+
+ protected IRosterViewer getRosterViewer() {
+ if (rosterViewer != null)
+ return rosterViewer;
+ else
+ return new IRosterViewer() {
+
+ public void receivePresence(ID userID, IPresence presence) {
+ debug("Received Presence Entry: "+presence+" for userID: "+userID);
+ }
+ public void receiveRosterEntry(IRosterEntry entry) {
+ debug("Received Roster Entry: " + entry);
+ }
+ };
+ }
+
+ protected ITextInputHandler getTextInputHandler() {
+ return new ITextInputHandler() {
+ public void disconnect() {
+ XMPPSharedObject.this.disconnect();
+ }
+ public void handleStartTyping(ID userID) {
+ }
+ public void handleTextLine(ID userID, String text) {
+ sendIM(userID, text);
+ }
+ };
+ }
+
+ protected String getUserNameFromXMPPAddress(XMPPID userID) {
+ return userID.getUsername();
+ }
+*/
+ protected void handleContainerDepartedEvent(
+ ISharedObjectContainerDepartedEvent event) {
+ debug("Got container departed event: " + event);
+ /*
+ ID departedID = event.getDepartedContainerID();
+ if (departedID != null) {
+ // Notify UI that a member has departed (could be server)
+ if (localUI != null) {
+ localUI.memberDeparted(departedID);
+ }
+ }
+ */
+ }
+
+ protected void handleDeactivatedEvent(ISharedObjectDeactivatedEvent event) {
+ debug("Got deactivated event: " + event);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.core.ISharedObject#handleEvent(org.eclipse.ecf.core.util.Event)
+ */
+ public void handleEvent(Event event) {
+ debug("handleEvent("+event+")");
+ /*
+ if (event instanceof ISharedObjectActivatedEvent) {
+ if (sender == null) {
+ // get context
+ ISharedObjectContext context = getContext();
+ if (context != null) {
+ Object adapter = context.getAdapter(IIMMessageSender.class);
+ if (adapter != null) {
+ sender = (IIMMessageSender) adapter;
+ }
+ }
+ }
+ } else if (event instanceof ISharedObjectContainerJoinedEvent) {
+ handleJoin((ISharedObjectContainerJoinedEvent) event);
+ } else if (event instanceof IQEvent) {
+ handleIQEvent((IQEvent) event);
+ } else if (event instanceof MessageEvent) {
+ handleMessageEvent((MessageEvent) event);
+ } else if (event instanceof PresenceEvent) {
+ handlePresenceEvent((PresenceEvent) event);
+ } else if (event instanceof ISharedObjectDeactivatedEvent) {
+ handleDeactivatedEvent((ISharedObjectDeactivatedEvent) event);
+ } else if (event instanceof ISharedObjectContainerDepartedEvent) {
+ handleContainerDepartedEvent((ISharedObjectContainerDepartedEvent) event);
+ } else if (event instanceof ISharedObjectMessageEvent) {
+ handleSharedObjectMessageEvent((ISharedObjectMessageEvent)event);
+ } else {
+ debug("unrecognized event " + event);
+ }
+ */
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.core.ISharedObject#handleEvents(org.eclipse.ecf.core.util.Event[])
+ */
+ public void handleEvents(Event[] events) {
+ for (int i = 0; i < events.length; i++) {
+ handleEvent(events[i]);
+ }
+ }
+ /*
+ protected void handleIQEvent(IQEvent evt) {
+ IQ iq = evt.getIQ();
+ if (iq instanceof RosterPacket) {
+ // Roster packet...report to UI
+ RosterPacket rosterPacket = (RosterPacket) iq;
+ for (Iterator i = rosterPacket.getRosterItems(); i.hasNext();) {
+ IRosterEntry entry = makeRosterEntry((RosterPacket.Item) i
+ .next());
+ IRosterViewer rv = getRosterViewer();
+ if (rv != null)
+ rv.receiveRosterEntry(entry);
+ }
+ } else {
+ debug("Received unknown IQ message: " + iq.toXML());
+ }
+ }
+
+ protected void handleJoin(ISharedObjectContainerJoinedEvent event) {
+ // show user interface
+ showView();
+ }
+
+ protected void handleMessageEvent(MessageEvent evt) {
+ Message msg = evt.getMessage();
+ String from = msg.getFrom();
+ String to = msg.getTo();
+ String body = msg.getBody();
+ String subject = msg.getSubject();
+ ID fromID = makeIDFromName(canonicalizePresenceFrom(from));
+ ID toID = makeIDFromName(canonicalizePresenceFrom(to));
+ IMessageViewer mv = getMessageViewer();
+ if (mv != null)
+ mv.showMessage(fromID, toID, makeMessageType(msg.getType()),
+ subject, body);
+ }
+
+ protected void handlePresenceEvent(PresenceEvent evt) {
+ Presence xmppPresence = evt.getPresence();
+ String from = canonicalizePresenceFrom(xmppPresence.getFrom());
+ String to = xmppPresence.getTo();
+ Mode mode = xmppPresence.getMode();
+ Type type = xmppPresence.getType();
+ int priority = xmppPresence.getPriority();
+ String status = xmppPresence.getStatus();
+ IPresence newPresence = makePresence(xmppPresence);
+ ID fromID = makeIDFromName(from);
+ IRosterViewer rv = getRosterViewer();
+ if (rv != null)
+ rv.receivePresence(fromID, newPresence);
+ }
+
+ protected void handleRoster(Roster roster) {
+ for (Iterator i = roster.getEntries(); i.hasNext();) {
+ IRosterEntry entry = makeRosterEntry((RosterEntry) i.next());
+ IRosterViewer rv = getRosterViewer();
+ if (rv != null)
+ rv.receiveRosterEntry(entry);
+ }
+ }
+
+ protected void handleSharedObjectMessageEvent(ISharedObjectMessageEvent event) {
+ debug("shared object message event "+event);
+ Object obj = event.getData();
+ if (obj instanceof SharedObjectMsg) {
+ SharedObjectMsg msg = (SharedObjectMsg) obj;
+ String method = msg.getMsg();
+ String param = msg.getParam();
+ lookupAndInvoke(method,param);
+ }
+ }
+
+ public void handleShowView(final String viewid) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ try {
+ IWorkbenchWindow ww = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow();
+ IWorkbenchPage wp = ww.getActivePage();
+ IViewPart view = wp.showView(viewid);
+ } catch (Exception e) {
+ dumpStack("Exception showing view "+viewid, e);
+ }
+ }
+ });
+ }
+ */
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.core.ISharedObject#init(org.eclipse.ecf.core.ISharedObjectConfig)
+ */
+
+ public void init(ISharedObjectConfig initData)
+ throws SharedObjectInitException {
+ this.config = initData;
+ }
+ /*
+ protected void interpret(ID target, String message) {
+ StringTokenizer st = new StringTokenizer(message.substring(1),";");
+ String first = st.nextToken();
+ String second = st.nextToken();
+ send(target,first,second);
+ }
+ protected void lookupAndInvoke(String method, String param) {
+ try {
+ Method m = getClass().getMethod(method,new Class[] { String.class });
+ m.invoke(this, new Object[] { param });
+ } catch (Exception e) {
+ dumpStack("Exception in lookupAndInvoke",e);
+ }
+ }
+
+ protected ID makeIDFromName(String name) {
+ ID result = null;
+ try {
+ result = IDFactory.makeID(XMPPID.PROTOCOL, new Object[] { name });
+ return result;
+ } catch (Exception e) {
+ dumpStack("Exception in makeIDFromName", e);
+ return null;
+ }
+ }
+
+ protected IRosterEntry.InterestType makeInterestType(
+ RosterPacket.ItemType itemType) {
+ if (itemType == RosterPacket.ItemType.BOTH) {
+ return IRosterEntry.InterestType.BOTH;
+ } else if (itemType == RosterPacket.ItemType.FROM) {
+ return IRosterEntry.InterestType.BOTH;
+ } else if (itemType == RosterPacket.ItemType.NONE) {
+ return IRosterEntry.InterestType.NONE;
+ } else if (itemType == RosterPacket.ItemType.REMOVE) {
+ return IRosterEntry.InterestType.REMOVE;
+ } else if (itemType == RosterPacket.ItemType.TO) {
+ return IRosterEntry.InterestType.TO;
+ } else
+ return IRosterEntry.InterestType.BOTH;
+ }
+
+ protected IMessageViewer.Type makeMessageType(Message.Type type) {
+ if (type == null)
+ return IMessageViewer.Type.NORMAL;
+ if (type == Message.Type.CHAT) {
+ return IMessageViewer.Type.CHAT;
+ } else if (type == Message.Type.NORMAL) {
+ return IMessageViewer.Type.NORMAL;
+ } else if (type == Message.Type.GROUP_CHAT) {
+ return IMessageViewer.Type.GROUP_CHAT;
+ } else if (type == Message.Type.HEADLINE) {
+ return IMessageViewer.Type.HEADLINE;
+ } else if (type == Message.Type.HEADLINE) {
+ return IMessageViewer.Type.HEADLINE;
+ } else
+ return IMessageViewer.Type.NORMAL;
+ }
+
+ protected IPresence makePresence(Presence xmppPresence) {
+ Mode mode = xmppPresence.getMode();
+ Type type = xmppPresence.getType();
+ int priority = xmppPresence.getPriority();
+ String status = xmppPresence.getStatus();
+ IPresence newPresence = new org.eclipse.ecf.ui.presence.Presence(
+ makePresenceType(xmppPresence), priority, status, makePresenceMode(xmppPresence));
+ return newPresence;
+ }
+
+ protected IPresence.Mode makePresenceMode(Presence xmppPresence) {
+ if (xmppPresence == null)
+ return IPresence.Mode.AVAILABLE;
+ Mode mode = xmppPresence.getMode();
+ if (mode == Presence.Mode.AVAILABLE) {
+ return IPresence.Mode.AVAILABLE;
+ } else if (mode == Presence.Mode.AWAY) {
+ return IPresence.Mode.AWAY;
+ } else if (mode == Presence.Mode.CHAT) {
+ return IPresence.Mode.CHAT;
+ } else if (mode == Presence.Mode.DO_NOT_DISTURB) {
+ return IPresence.Mode.DND;
+ } else if (mode == Presence.Mode.EXTENDED_AWAY) {
+ return IPresence.Mode.EXTENDED_AWAY;
+ } else if (mode == Presence.Mode.INVISIBLE) {
+ return IPresence.Mode.INVISIBLE;
+ }
+ return IPresence.Mode.AVAILABLE;
+ }
+
+ protected IPresence.Type makePresenceType(Presence xmppPresence) {
+ if (xmppPresence == null)
+ return IPresence.Type.AVAILABLE;
+ Type type = xmppPresence.getType();
+ if (type == Presence.Type.AVAILABLE) {
+ return IPresence.Type.AVAILABLE;
+ } else if (type == Presence.Type.ERROR) {
+ return IPresence.Type.ERROR;
+ } else if (type == Presence.Type.SUBSCRIBE) {
+ return IPresence.Type.SUBSCRIBE;
+ } else if (type == Presence.Type.SUBSCRIBED) {
+ return IPresence.Type.SUBSCRIBED;
+ } else if (type == Presence.Type.UNSUBSCRIBE) {
+ return IPresence.Type.UNSUBSCRIBE;
+ } else if (type == Presence.Type.UNSUBSCRIBED) {
+ return IPresence.Type.UNSUBSCRIBED;
+ } else if (type == Presence.Type.UNAVAILABLE) {
+ return IPresence.Type.UNAVAILABLE;
+ }
+ return IPresence.Type.AVAILABLE;
+ }
+
+ protected IRosterEntry makeRosterEntry(RosterEntry entry) {
+ try {
+ ID userID = makeIDFromName(entry.getUser());
+ String name = entry.getName();
+ RosterPacket.ItemType itemType = entry.getType();
+ IRosterEntry.InterestType iType = makeInterestType(itemType);
+ IRosterEntry newEntry = new org.eclipse.ecf.ui.presence.RosterEntry(
+ userID, name, iType);
+ Iterator grps = entry.getGroups();
+ for (; grps.hasNext();) {
+ RosterGroup grp = (RosterGroup) grps.next();
+ IRosterGroup localGrp = makeRosterGroup(grp);
+ newEntry.add(localGrp);
+ }
+ return newEntry;
+ } catch (Exception e) {
+ dumpStack("Exception in makeRosterEntry", e);
+ }
+ return null;
+ }
+
+ protected IRosterEntry makeRosterEntry(RosterPacket.Item entry) {
+ try {
+ ID userID = makeIDFromName(entry.getUser());
+ String name = entry.getName();
+ RosterPacket.ItemType itemType = entry.getItemType();
+ IRosterEntry.InterestType iType = makeInterestType(itemType);
+ IRosterEntry newEntry = new org.eclipse.ecf.ui.presence.RosterEntry(
+ userID, name, iType);
+ Iterator grps = entry.getGroupNames();
+ for (; grps.hasNext();) {
+ String grp = (String) grps.next();
+ IRosterGroup localGrp = makeRosterGroup(grp);
+ newEntry.add(localGrp);
+ }
+ return newEntry;
+ } catch (Exception e) {
+ dumpStack("Exception in makeRosterEntry", e);
+ }
+ return null;
+ }
+
+ protected IRosterGroup makeRosterGroup(RosterGroup grp) {
+ return new org.eclipse.ecf.ui.presence.RosterGroup(grp.getName());
+ }
+
+ protected IRosterGroup makeRosterGroup(String grp) {
+ return new org.eclipse.ecf.ui.presence.RosterGroup(grp);
+ }
+ */
+ /*
+ * Protocol for launching remote views
+ */
+ public void send(ID target, String cmd, String param) {
+ try {
+ SharedObjectMsg m = new SharedObjectMsg(cmd,param);
+ getContext().sendMessage(target,m);
+ } catch (Exception e) {
+ dumpStack("Exception on send() to "
+ + target,e);
+ }
+ }
+ /*
+ protected void sendIM(ID target, String message) {
+ try {
+ if (message.startsWith(";")) {
+ interpret(target,message);
+ } else sender.sendMessage(target, message);
+ } catch (Exception e) {
+ dumpStack("Exception in sendMessage ", e);
+ }
+ }
+ public void sendShowView(ID target, String viewid) {
+ send(target,"handleShowView",viewid);
+ }
+
+ protected void setConnection(XMPPConnection connection) {
+ this.connection = connection;
+ }
+ protected void setupUI(IViewPart view) {
+ rosterViewer = (IRosterViewer) view.getAdapter(IRosterViewer.class);
+ messageViewer = (IMessageViewer) view.getAdapter(IMessageViewer.class);
+ localUI = (IConfigViewer) view
+ .getAdapter(IConfigViewer.class);
+ localUI.setLocalUser(new User(localUserID, localUserNickname),
+ getTextInputHandler());
+ localUI.setGroup(getContext().getGroupID());
+ }
+
+ protected void setUserID(ID userID, String nickname) {
+ this.localUserID = (XMPPID) userID;
+ if (nickname == null) {
+ nickname = getUserNameFromXMPPAddress(localUserID);
+ }
+ this.localUserNickname = nickname;
+ }
+
+ protected void showView() {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ try {
+ IWorkbenchWindow ww = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow();
+ IWorkbenchPage wp = ww.getActivePage();
+ IViewPart view = wp.showView(ROSTER_VIEW_ID);
+ setupUI(view);
+ } catch (Exception e) {
+ dumpStack("Exception showing view", e);
+ }
+ }
+ });
+ }
+ */
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/events/IQEvent.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/events/IQEvent.java
new file mode 100644
index 000000000..54b26771a
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/events/IQEvent.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Composent, Inc. and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Composent, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.provider.xmpp.events;
+
+import org.eclipse.ecf.core.util.Event;
+import org.jivesoftware.smack.packet.IQ;
+
+/**
+ * @author slewis
+ *
+ */
+public class IQEvent implements Event {
+
+ protected IQ iq = null;
+
+ public IQEvent(IQ iq) {
+ this.iq = iq;
+ }
+
+ public IQ getIQ() {
+ return iq;
+ }
+ public String toString() {
+ StringBuffer buf = new StringBuffer("IQEvent[");
+ buf.append(iq).append(";").append((iq==null)?"":iq.toXML()).append("]");
+ return buf.toString();
+ }
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/events/MessageEvent.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/events/MessageEvent.java
new file mode 100644
index 000000000..7dd1205bd
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/events/MessageEvent.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Composent, Inc. and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Composent, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.provider.xmpp.events;
+
+import org.eclipse.ecf.core.util.Event;
+import org.jivesoftware.smack.packet.Message;
+
+/**
+ * @author slewis
+ *
+ */
+public class MessageEvent implements Event {
+
+ protected Message message = null;
+
+ public MessageEvent(Message message) {
+ this.message = message;
+ }
+
+ public Message getMessage() {
+ return message;
+ }
+
+ public String toString() {
+ StringBuffer buf = new StringBuffer("MessageEvent[");
+ buf.append(message).append(";").append((message==null)?"":message.toXML()).append("]");
+ return buf.toString();
+ }
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/events/PresenceEvent.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/events/PresenceEvent.java
new file mode 100644
index 000000000..f379019aa
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/events/PresenceEvent.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Composent, Inc. and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Composent, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.provider.xmpp.events;
+
+import org.eclipse.ecf.core.util.Event;
+import org.jivesoftware.smack.packet.Presence;
+
+/**
+ * @author slewis
+ *
+ */
+public class PresenceEvent implements Event {
+
+ protected Presence presence = null;
+
+ public PresenceEvent(Presence presence) {
+ this.presence = presence;
+ }
+
+ public Presence getPresence() {
+ return presence;
+ }
+ public String toString() {
+ StringBuffer buf = new StringBuffer("PresenceEvent[");
+ buf.append(presence).append(";").append((presence==null)?"":presence.toXML()).append("]");
+ return buf.toString();
+ }
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPID.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPID.java
new file mode 100644
index 000000000..3494109bb
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPID.java
@@ -0,0 +1,71 @@
+package org.eclipse.ecf.provider.xmpp.identity;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.eclipse.ecf.core.identity.BaseID;
+import org.eclipse.ecf.core.identity.Namespace;
+
+public class XMPPID extends BaseID {
+
+ private static final long serialVersionUID = 3257289140701049140L;
+
+ public static final String ADDRESS_SEPARATOR = "@";
+ public static final String PROTOCOL = "xmpp";
+
+ URI uri;
+
+ protected XMPPID(Namespace namespace, String username, String host, String query) throws URISyntaxException {
+ super(namespace);
+ uri = new URI(PROTOCOL+":"+username+ADDRESS_SEPARATOR+host+((query==null)?"":("?"+query)));
+ }
+ protected XMPPID(Namespace namespace, String username, String host) throws URISyntaxException {
+ this(namespace,username,host,null);
+ }
+ protected XMPPID(Namespace namespace, String unamehost) throws URISyntaxException {
+ super(namespace);
+ uri = new URI(PROTOCOL+":"+unamehost);
+ }
+ protected int namespaceCompareTo(BaseID o) {
+ return getName().compareTo(o.getName());
+ }
+
+ protected boolean namespaceEquals(BaseID o) {
+ if (!(o instanceof XMPPID)) {
+ return false;
+ }
+ XMPPID other = (XMPPID) o;
+ return uri.equals(other.uri);
+ }
+
+ protected String namespaceGetName() {
+ return uri.getSchemeSpecificPart();
+ }
+
+ protected int namespaceHashCode() {
+ return uri.hashCode();
+ }
+
+ protected URI namespaceToURI() throws URISyntaxException {
+ return uri;
+ }
+
+ public String getUsername() {
+ String name = getName();
+ if (name == null) return null;
+ return name.substring(0,name.indexOf(ADDRESS_SEPARATOR));
+ }
+
+ public String getHostname() {
+ String name = getName();
+ if (name == null) return null;
+ return name.substring(name.indexOf(ADDRESS_SEPARATOR)+1,name.length());
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer("XMPPID[");
+ sb.append(uri.toString()).append("]");
+ return sb.toString();
+ }
+
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPIDInstantiator.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPIDInstantiator.java
new file mode 100644
index 000000000..df7b74c74
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPIDInstantiator.java
@@ -0,0 +1,26 @@
+package org.eclipse.ecf.provider.xmpp.identity;
+
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDInstantiationException;
+import org.eclipse.ecf.core.identity.Namespace;
+import org.eclipse.ecf.core.identity.provider.IDInstantiator;
+
+public class XMPPIDInstantiator implements IDInstantiator {
+
+ public ID makeInstance(Namespace ns, Class[] argTypes, Object[] args)
+ throws IDInstantiationException {
+ try {
+ if (args.length == 3) {
+ return new XMPPID(ns,(String)args[0],(String)args[1],(String)args[2]);
+ } else if (args.length == 2) {
+ return new XMPPID(ns,(String)args[0],(String)args[1]);
+ } else if (args.length == 1) {
+ return new XMPPID(ns,(String)args[0]);
+ }
+ throw new IllegalArgumentException("XMPP ID constructor arguments invalid");
+ } catch (Exception e) {
+ throw new IDInstantiationException("XMPP ID creation exception",e);
+ }
+ }
+
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPNamespace.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPNamespace.java
new file mode 100644
index 000000000..e034ba347
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/identity/XMPPNamespace.java
@@ -0,0 +1,14 @@
+package org.eclipse.ecf.provider.xmpp.identity;
+
+import org.eclipse.ecf.core.identity.Namespace;
+import org.eclipse.ecf.core.identity.provider.IDInstantiator;
+
+public class XMPPNamespace extends Namespace {
+
+ public XMPPNamespace(String name, IDInstantiator inst, String desc) {
+ super(name, inst, desc);
+ }
+
+ private static final long serialVersionUID = 3257569499003041590L;
+
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/smack/ChatConnection.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/smack/ChatConnection.java
new file mode 100644
index 000000000..175c71a36
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/smack/ChatConnection.java
@@ -0,0 +1,309 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Composent, Inc. and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Composent, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.provider.xmpp.smack;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.eclipse.ecf.core.comm.DisconnectConnectionEvent;
+import org.eclipse.ecf.core.comm.IAsynchConnectionEventHandler;
+import org.eclipse.ecf.core.comm.IConnectionEventHandler;
+import org.eclipse.ecf.core.comm.ISynchAsynchConnection;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.provider.xmpp.Trace;
+import org.eclipse.ecf.provider.xmpp.container.IIMMessageSender;
+import org.eclipse.ecf.provider.xmpp.identity.XMPPID;
+import org.jivesoftware.smack.Chat;
+import org.jivesoftware.smack.ConnectionListener;
+import org.jivesoftware.smack.PacketListener;
+import org.jivesoftware.smack.Roster;
+import org.jivesoftware.smack.SmackConfiguration;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.XMPPException;
+import org.jivesoftware.smack.packet.Message;
+import org.jivesoftware.smack.packet.Packet;
+
+public class ChatConnection implements ISynchAsynchConnection, IIMMessageSender {
+
+ public static final Trace trace = Trace.create("smackconnection");
+ public static final Trace smack = Trace.create("smackdebug");
+ protected static final String STRING_ENCODING = "UTF-8";
+ public static final String OBJECT_PROPERTY_NAME = ChatConnection.class
+ .getName()
+ + ".object";
+ protected static final int XMPP_NORMAL_PORT = 5222;
+ protected XMPPConnection connection = null;
+ protected IAsynchConnectionEventHandler handler = null;
+ protected ID localID = null;
+ protected boolean isStarted = false;
+ protected String serverName;
+ protected int serverPort = -1;
+ protected Map properties = null;
+ protected boolean isConnected = false;
+
+ protected void debug(String msg) {
+ if (Trace.ON && trace != null) {
+ trace.msg(msg);
+ }
+ }
+
+ protected void dumpStack(String msg, Throwable t) {
+ if (Trace.ON && trace != null) {
+ trace.dumpStack(t, msg);
+ }
+ }
+
+ protected void logException(String msg, Throwable t) {
+ dumpStack(msg, t);
+ }
+
+ public Map getProperties() {
+ return properties;
+ }
+
+ public Object getAdapter(Class clazz) {
+ if (clazz.equals(IIMMessageSender.class)) {
+ return this;
+ }
+ return null;
+ }
+
+ public XMPPConnection getXMPPConnection() {
+ return connection;
+ }
+ public ChatConnection(IAsynchConnectionEventHandler h) {
+ this.handler = h;
+ if (Trace.create("smackdebug") != null) {
+ XMPPConnection.DEBUG_ENABLED = true;
+ }
+ }
+
+ public synchronized Object connect(ID remote, Object data, int timeout)
+ throws IOException {
+ if (connection != null)
+ throw new IOException("Currently connected");
+ debug("connect(" + remote + "," + data + "," + timeout + ")");
+ if (timeout > 0)
+ SmackConfiguration.setPacketReplyTimeout(timeout);
+ XMPPID jabberURI = null;
+ try {
+ jabberURI = (XMPPID) remote;
+ } catch (ClassCastException e) {
+ IOException throwMe = new IOException(e.getMessage());
+ throwMe.setStackTrace(e.getStackTrace());
+ throw throwMe;
+ }
+ String username = jabberURI.getUsername();
+ serverName = jabberURI.getHostname();
+ String password = null;
+ if (data == null)
+ throw new IOException("data parameter (password) must be provided");
+ try {
+ password = (String) data;
+ } catch (ClassCastException e) {
+ IOException throwMe = new IOException(e.getClass().getName()
+ + " wrapped: " + e.getMessage());
+ throwMe.setStackTrace(e.getStackTrace());
+ throw throwMe;
+ }
+ Roster roster = null;
+ try {
+ if (serverPort == -1) {
+ connection = new XMPPConnection(serverName);
+ } else {
+ connection = new XMPPConnection(serverName, serverPort);
+ }
+ // Login
+ connection.login(username, (String) data);
+ isConnected = true;
+ debug("User: " + username + " logged into " + serverName);
+ roster = getRoster();
+ roster.reload();
+ } catch (XMPPException e) {
+ if (connection != null) {
+ connection.close();
+ }
+ IOException result = new IOException(e.getMessage());
+ result.setStackTrace(e.getStackTrace());
+ throw result;
+ }
+ // Now setup listener
+ connection.addConnectionListener(new ConnectionListener() {
+ public void connectionClosed() {
+ handleConnectionClosed(null);
+ }
+
+ public void connectionClosedOnError(Exception e) {
+ handleConnectionClosed(e);
+ }
+ });
+
+ connection.addPacketListener(new PacketListener() {
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jivesoftware.smack.PacketListener#processPacket(org.jivesoftware.smack.packet.Packet)
+ */
+ public void processPacket(Packet arg0) {
+ handlePacket(arg0);
+ }
+ }, null);
+ return roster;
+ }
+
+ public synchronized void disconnect() throws IOException {
+ debug("disconnect()");
+ if (isStarted()) {
+ stop();
+ }
+ if (connection != null) {
+ connection.close();
+ isConnected = false;
+ connection = null;
+ }
+ }
+
+ public synchronized boolean isConnected() {
+ return (isConnected);
+ }
+
+ public synchronized ID getLocalID() {
+ if (!isConnected())
+ return null;
+ try {
+ return IDFactory.makeID(XMPPID.PROTOCOL, new Object[] { connection
+ .getConnectionID() });
+ } catch (Exception e) {
+ logException("Exception in getLocalID", e);
+ return null;
+ }
+ }
+
+ public synchronized void start() {
+ if (isStarted())
+ return;
+ isStarted = true;
+ }
+
+ public boolean isStarted() {
+ return isStarted;
+ }
+
+ public synchronized void stop() {
+ isStarted = false;
+ }
+
+ protected void handleConnectionClosed(Exception e) {
+ handler.handleDisconnectEvent(new DisconnectConnectionEvent(this, e,
+ null));
+ }
+
+ protected void handlePacket(Packet arg0) {
+ debug("handlePacket(" + arg0 + ")");
+ try {
+ Object val = arg0.getProperty(OBJECT_PROPERTY_NAME);
+ if (val != null) {
+ handler.handleAsynchEvent(new ChatConnectionObjectPacketEvent(
+ this, arg0, val));
+ } else {
+ handler.handleAsynchEvent(new ChatConnectionPacketEvent(this,
+ arg0));
+ }
+ } catch (IOException e) {
+ logException("Exception in handleAsynchEvent", e);
+ try {
+ disconnect();
+ } catch (Exception e1) {
+ logException("Exception in disconnect()", e1);
+ }
+ }
+ }
+
+ protected void sendMessage(ID receiver, Message msg) throws IOException {
+ synchronized (this) {
+ if (!isConnected())
+ throw new IOException("not connected");
+ try {
+ if (receiver == null) {
+ throw new IOException(
+ "receiver cannot be null for normal xmpp instant messaging");
+ } else {
+ msg.setType(Message.Type.CHAT);
+ Chat localChat = connection.createChat(receiver.getName());
+ localChat.sendMessage(msg);
+ }
+ } catch (XMPPException e) {
+ IOException result = new IOException(
+ "XMPPException in sendMessage: " + e.getMessage());
+ result.setStackTrace(e.getStackTrace());
+ throw result;
+ }
+ }
+ }
+
+ public synchronized void sendAsynch(ID receiver, byte[] data)
+ throws IOException {
+ if (data == null)
+ throw new IOException("no data");
+ debug("sendAsynch(" + receiver + "," + data + ")");
+ Message aMsg = new Message();
+ aMsg.setProperty(OBJECT_PROPERTY_NAME, data);
+ sendMessage(receiver, aMsg);
+ }
+
+ public synchronized Object sendSynch(ID receiver, byte[] data)
+ throws IOException {
+ if (data == null)
+ throw new IOException("data cannot be null");
+ // This is assumed to be disconnect...so we'll just disconnect
+ // disconnect();
+ return null;
+ }
+
+ public void addCommEventListener(IConnectionEventHandler listener) {
+ // XXX Not yet implemented
+ }
+
+ public void removeCommEventListener(IConnectionEventHandler listener) {
+ // XXX Not yet implemented
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.provider.xmpp.IIMMessageSender#sendMessage(org.eclipse.ecf.core.identity.ID,
+ * java.lang.String)
+ */
+ public void sendMessage(ID target, String message) throws IOException {
+ if (target == null)
+ throw new IOException("target cannot be null");
+ if (message == null)
+ throw new IOException("message cannot be null");
+ debug("sendMessage(" + target + "," + message + ")");
+ Message aMsg = new Message();
+ aMsg.setBody(message);
+ sendMessage(target, aMsg);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.provider.xmpp.IIMMessageSender#getRoster()
+ */
+ public Roster getRoster() throws IOException {
+ if (connection == null)
+ return null;
+ if (!connection.isConnected())
+ return null;
+ Roster roster = connection.getRoster();
+ roster.setSubscriptionMode(Roster.SUBSCRIPTION_ACCEPT_ALL);
+ return roster;
+ }
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/smack/ChatConnectionObjectPacketEvent.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/smack/ChatConnectionObjectPacketEvent.java
new file mode 100644
index 000000000..a2966892b
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/smack/ChatConnectionObjectPacketEvent.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Composent, Inc. and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Composent, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.provider.xmpp.smack;
+
+import org.eclipse.ecf.core.comm.AsynchConnectionEvent;
+import org.eclipse.ecf.core.comm.IAsynchConnection;
+import org.jivesoftware.smack.packet.Packet;
+
+public class ChatConnectionObjectPacketEvent extends AsynchConnectionEvent {
+
+ Object value;
+ /**
+ * @param source
+ * @param param
+ */
+ public ChatConnectionObjectPacketEvent(IAsynchConnection source, Packet p, Object obj) {
+ super(source,p);
+ this.value = obj;
+ }
+
+ public Object getObjectValue() {
+ return value;
+ }
+ public String toString() {
+ StringBuffer sb = new StringBuffer("ChatConnectionPacketEvent[");
+ sb.append(getData()).append(";");
+ sb.append(getConnection()).append(";");
+ sb.append(getObjectValue()).append("]");
+ return sb.toString();
+ }
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/smack/ChatConnectionPacketEvent.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/smack/ChatConnectionPacketEvent.java
new file mode 100644
index 000000000..8c0fc32fe
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/smack/ChatConnectionPacketEvent.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Composent, Inc. and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Composent, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.provider.xmpp.smack;
+
+import org.eclipse.ecf.core.comm.AsynchConnectionEvent;
+import org.eclipse.ecf.core.comm.IAsynchConnection;
+import org.jivesoftware.smack.packet.Packet;
+
+public class ChatConnectionPacketEvent extends AsynchConnectionEvent {
+
+ /**
+ * @param source
+ * @param param
+ */
+ public ChatConnectionPacketEvent(IAsynchConnection source, Packet p) {
+ super(source,p);
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer("ChatConnectionPacketEvent[");
+ sb.append(getData()).append(";");
+ sb.append(getConnection()).append("]");
+ return sb.toString();
+ }
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/smack/test/TestGroupChat.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/smack/test/TestGroupChat.java
new file mode 100644
index 000000000..dfac96503
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/smack/test/TestGroupChat.java
@@ -0,0 +1,39 @@
+/*
+ * Created on Mar 20, 2005
+ *
+ */
+package org.eclipse.ecf.provider.xmpp.smack.test;
+
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smackx.Form;
+import org.jivesoftware.smackx.muc.MultiUserChat;
+
+/**
+ *
+ */
+public class TestGroupChat {
+ public TestGroupChat() {
+ super();
+ }
+
+ public static void main(String[] args) throws Exception {
+ System.out.println("Connecting to server "+args[0]);
+ XMPPConnection conn = new XMPPConnection(args[0]);
+ System.out.println("connected");
+ System.out.println("logging in user "+args[1]);
+ conn.login(args[1],args[2]);
+ System.out.println("logged in user "+args[1]);
+ System.out.println("checking whether service is enabled...");
+ boolean supports = MultiUserChat.isServiceEnabled(conn, args[1]+"@"+args[0]+"/Smack");
+ System.out.println("supports is "+supports);
+ MultiUserChat muc = new MultiUserChat(conn,"myroom@conference.cerf.composent.com");
+ muc.create("testbot");
+ muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
+ System.out.println("created multiuser chat");
+
+
+ muc.join(args[1]);
+ muc.sendMessage("hello there");
+ Thread.sleep(200000);
+ }
+}

Back to the top