Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2008-06-11 17:03:24 -0400
committerslewis2008-06-11 17:03:24 -0400
commit035b43d894464ee44fc2fd8d4e3dd0a6ce26d36d (patch)
treeed3527055c07c484e81f0c1d1d5430e9622aa115 /providers/bundles/org.eclipse.ecf.provider.xmpp
parent0fa22ec811ff9b58775531035fc69c4624ff9066 (diff)
downloadorg.eclipse.ecf-035b43d894464ee44fc2fd8d4e3dd0a6ce26d36d.tar.gz
org.eclipse.ecf-035b43d894464ee44fc2fd8d4e3dd0a6ce26d36d.tar.xz
org.eclipse.ecf-035b43d894464ee44fc2fd8d4e3dd0a6ce26d36d.zip
Fix for bugs 236318, and 236568.v20080611-1514
Diffstat (limited to 'providers/bundles/org.eclipse.ecf.provider.xmpp')
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatManager.java57
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatRoomContainerHelper.java10
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatRoomManager.java225
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPContainerPresenceHelper.java10
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XmppPlugin.java30
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/filetransfer/XMPPFileTransferRequestListener.java9
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/filetransfer/XMPPIncomingFileTransfer.java8
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/filetransfer/XMPPOutgoingFileTransfer.java242
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/filetransfer/XMPPOutgoingFileTransferHelper.java32
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/smack/ECFConnection.java25
10 files changed, 367 insertions, 281 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatManager.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatManager.java
index 11df2b90f..79ed911bf 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatManager.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatManager.java
@@ -16,6 +16,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.util.ECFException;
import org.eclipse.ecf.presence.IIMMessageEvent;
@@ -41,11 +42,11 @@ import org.jivesoftware.smack.packet.Message.Type;
*/
public class XMPPChatManager implements IChatManager {
- private List messageListeners = new ArrayList();
+ private final List messageListeners = new ArrayList();
- private XMPPContainerPresenceHelper presenceHelper;
+ private final XMPPContainerPresenceHelper presenceHelper;
- private IChatMessageSender chatMessageSender = new IChatMessageSender() {
+ private final IChatMessageSender chatMessageSender = new IChatMessageSender() {
/*
* (non-Javadoc)
@@ -55,17 +56,12 @@ public class XMPPChatManager implements IChatManager {
* org.eclipse.ecf.presence.im.IChatMessage.Type, java.lang.String,
* java.lang.String)
*/
- public void sendChatMessage(ID toID, ID threadID,
- org.eclipse.ecf.presence.im.IChatMessage.Type type,
- String subject, String body, Map properties)
- throws ECFException {
+ public void sendChatMessage(ID toID, ID threadID, org.eclipse.ecf.presence.im.IChatMessage.Type type, String subject, String body, Map properties) throws ECFException {
if (toID == null)
throw new ECFException("receiver cannot be null");
try {
- presenceHelper.getConnectionOrThrowIfNull().sendMessage(toID,
- threadID, XMPPChatManager.this.createMessageType(type),
- subject, body, properties);
- } catch (Exception e) {
+ presenceHelper.getConnectionOrThrowIfNull().sendMessage(toID, threadID, XMPPChatManager.this.createMessageType(type), subject, body, properties);
+ } catch (final Exception e) {
throw new ECFException("sendChatMessage exception", e);
}
@@ -78,21 +74,19 @@ public class XMPPChatManager implements IChatManager {
* java.lang.String)
*/
public void sendChatMessage(ID toID, String body) throws ECFException {
- sendChatMessage(toID, null, IChatMessage.Type.CHAT, null, body,
- null);
+ sendChatMessage(toID, null, IChatMessage.Type.CHAT, null, body, null);
}
};
protected ITypingMessageSender typingMessageSender = new ITypingMessageSender() {
- public void sendTypingMessage(ID toID, boolean isTyping, String body)
- throws ECFException {
+ public void sendTypingMessage(ID toID, boolean isTyping, String body) throws ECFException {
if (toID == null)
throw new ECFException("receiver cannot be null");
try {
presenceHelper.sendTypingMessage(toID, isTyping, body);
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new ECFException("sendChatMessage exception", e);
}
}
@@ -113,7 +107,12 @@ public class XMPPChatManager implements IChatManager {
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
*/
public Object getAdapter(Class adapter) {
- return null;
+ if (adapter == null)
+ return null;
+ if (adapter.isInstance(this))
+ return this;
+ final IAdapterManager adapterManager = XmppPlugin.getDefault().getAdapterManager();
+ return (adapterManager == null) ? null : adapterManager.loadAdapter(this, adapter.getName());
}
public boolean isActive() {
@@ -122,10 +121,9 @@ public class XMPPChatManager implements IChatManager {
public void setActive(boolean active) {
// TODO Auto-generated method stub
-
+
}
};
-
public XMPPChatManager(XMPPContainerPresenceHelper presenceHelper) {
this.presenceHelper = presenceHelper;
@@ -180,7 +178,7 @@ public class XMPPChatManager implements IChatManager {
*/
public void removeMessageListener(IIMMessageListener listener) {
synchronized (messageListeners) {
- messageListeners.remove(listener);
+ messageListeners.remove(listener);
}
}
@@ -189,16 +187,14 @@ public class XMPPChatManager implements IChatManager {
synchronized (messageListeners) {
toNotify = new ArrayList(messageListeners);
}
- for (Iterator i = toNotify.iterator(); i.hasNext();) {
- IIMMessageListener l = (IIMMessageListener) i.next();
+ for (final Iterator i = toNotify.iterator(); i.hasNext();) {
+ final IIMMessageListener l = (IIMMessageListener) i.next();
l.handleMessageEvent(event);
}
}
- protected void fireChatMessage(ID fromID, ID threadID, Type type,
- String subject, String body, Map properties) {
- fireMessageEvent(new ChatMessageEvent(fromID, new ChatMessage(fromID,
- threadID, createMessageType(type), subject, body, properties)));
+ protected void fireChatMessage(ID fromID, ID threadID, Type type, String subject, String body, Map properties) {
+ fireMessageEvent(new ChatMessageEvent(fromID, new ChatMessage(fromID, threadID, createMessageType(type), subject, body, properties)));
}
protected void fireTypingMessage(ID fromID, ITypingMessage typingMessage) {
@@ -214,18 +210,15 @@ public class XMPPChatManager implements IChatManager {
return typingMessageSender;
}
- protected void fireXHTMLChatMessage(ID fromID, ID threadID, Type type,
- String subject, String body, Map properties, List xhtmlbodylist) {
- fireMessageEvent(new XHTMLChatMessageEvent(fromID,
- new XHTMLChatMessage(fromID, threadID, createMessageType(type),
- subject, body, properties, xhtmlbodylist)));
+ protected void fireXHTMLChatMessage(ID fromID, ID threadID, Type type, String subject, String body, Map properties, List xhtmlbodylist) {
+ fireMessageEvent(new XHTMLChatMessageEvent(fromID, new XHTMLChatMessage(fromID, threadID, createMessageType(type), subject, body, properties, xhtmlbodylist)));
}
public IHistoryManager getHistoryManager() {
return historyManager;
}
-
+
public void disconnect() {
synchronized (messageListeners) {
messageListeners.clear();
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatRoomContainerHelper.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatRoomContainerHelper.java
index 99cf2c997..9b71d921f 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatRoomContainerHelper.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatRoomContainerHelper.java
@@ -16,6 +16,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.core.sharedobject.ISharedObject;
@@ -309,8 +310,13 @@ public class XMPPChatRoomContainerHelper implements ISharedObject {
*
* @see org.eclipse.ecf.core.ISharedObject#getAdapter(java.lang.Class)
*/
- public Object getAdapter(Class clazz) {
- return null;
+ public Object getAdapter(Class adapter) {
+ if (adapter == null)
+ return null;
+ if (adapter.isInstance(this))
+ return this;
+ final IAdapterManager adapterManager = XmppPlugin.getDefault().getAdapterManager();
+ return (adapterManager == null) ? null : adapterManager.loadAdapter(this, adapter.getName());
}
/**
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatRoomManager.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatRoomManager.java
index 1dc87e449..a4a397d08 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatRoomManager.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatRoomManager.java
@@ -18,6 +18,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.ecf.core.ContainerCreateException;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDCreateException;
@@ -58,20 +59,18 @@ public class XMPPChatRoomManager implements IChatRoomManager {
private Namespace connectNamespace = null;
- private List invitationListeners = new ArrayList();
+ private final List invitationListeners = new ArrayList();
private ECFConnection ecfConnection = null;
- private List chatrooms = new ArrayList();
+ private final List chatrooms = new ArrayList();
private ID connectedID = null;
- private IChatRoomInvitationSender invitationSender = new IChatRoomInvitationSender() {
+ private final IChatRoomInvitationSender invitationSender = new IChatRoomInvitationSender() {
- public void sendInvitation(ID room, ID targetUser, String subject,
- String body) throws ECFException {
- XMPPChatRoomManager.this.sendInvitation(room, targetUser, subject,
- body);
+ public void sendInvitation(ID room, ID targetUser, String subject, String body) throws ECFException {
+ XMPPChatRoomManager.this.sendInvitation(room, targetUser, subject, body);
}
};
@@ -86,12 +85,10 @@ public class XMPPChatRoomManager implements IChatRoomManager {
* @param subject
* @param body
*/
- protected void sendInvitation(ID room, ID targetUser, String subject,
- String body) throws ECFException {
- XMPPChatRoomContainer chatRoomContainer = getChatRoomContainer(room);
+ protected void sendInvitation(ID room, ID targetUser, String subject, String body) throws ECFException {
+ final XMPPChatRoomContainer chatRoomContainer = getChatRoomContainer(room);
if (chatRoomContainer == null)
- throw new ECFException(NLS
- .bind(Messages.XMPPChatRoomManager_ROOM_NOT_FOUND, room.getName()));
+ throw new ECFException(NLS.bind(Messages.XMPPChatRoomManager_ROOM_NOT_FOUND, room.getName()));
chatRoomContainer.sendInvitation(targetUser, subject, body);
}
@@ -115,9 +112,9 @@ public class XMPPChatRoomManager implements IChatRoomManager {
toNotify = new ArrayList(chatrooms);
}
- for (Iterator i = toNotify.iterator(); i.hasNext();) {
- XMPPChatRoomContainer container = (XMPPChatRoomContainer) i.next();
- ID containerRoomID = container.getConnectedID();
+ for (final Iterator i = toNotify.iterator(); i.hasNext();) {
+ final XMPPChatRoomContainer container = (XMPPChatRoomContainer) i.next();
+ final ID containerRoomID = container.getConnectedID();
if (containerRoomID == null)
continue;
if (containerRoomID.equals(roomID))
@@ -128,9 +125,8 @@ public class XMPPChatRoomManager implements IChatRoomManager {
protected ID createRoomIDFromName(String from) {
try {
- return new XMPPRoomID(connectNamespace, ecfConnection
- .getXMPPConnection(), from);
- } catch (URISyntaxException e) {
+ return new XMPPRoomID(connectNamespace, ecfConnection.getXMPPConnection(), from);
+ } catch (final URISyntaxException e) {
return null;
}
}
@@ -140,27 +136,20 @@ public class XMPPChatRoomManager implements IChatRoomManager {
try {
result = new XMPPID(connectNamespace, name);
return result;
- } catch (Exception e) {
+ } catch (final Exception e) {
return null;
}
}
- public void setConnection(Namespace connectNamespace, ID connectedID,
- ECFConnection connection) {
+ public void setConnection(Namespace connectNamespace, ID connectedID, ECFConnection connection) {
this.connectNamespace = connectNamespace;
this.connectedID = connectedID;
this.ecfConnection = connection;
if (connection != null) {
// Setup invitation requestListener
- MultiUserChat.addInvitationListener(ecfConnection
- .getXMPPConnection(), new InvitationListener() {
- public void invitationReceived(XMPPConnection arg0,
- String arg1, String arg2, String arg3, String arg4,
- Message arg5) {
- fireInvitationReceived(createRoomIDFromName(arg1),
- createUserIDFromName(arg2),
- createUserIDFromName(arg5.getTo()), arg5
- .getSubject(), arg3);
+ MultiUserChat.addInvitationListener(ecfConnection.getXMPPConnection(), new InvitationListener() {
+ public void invitationReceived(XMPPConnection arg0, String arg1, String arg2, String arg3, String arg4, Message arg5) {
+ fireInvitationReceived(createRoomIDFromName(arg1), createUserIDFromName(arg2), createUserIDFromName(arg5.getTo()), arg5.getSubject(), arg3);
}
});
} else {
@@ -174,15 +163,15 @@ public class XMPPChatRoomManager implements IChatRoomManager {
toNotify = new ArrayList(chatrooms);
chatrooms.clear();
}
- for (Iterator i = toNotify.iterator(); i.hasNext();) {
- IChatRoomContainer cc = (IChatRoomContainer) i.next();
+ for (final Iterator i = toNotify.iterator(); i.hasNext();) {
+ final IChatRoomContainer cc = (IChatRoomContainer) i.next();
cc.dispose();
}
}
public void dispose() {
synchronized (invitationListeners) {
- invitationListeners.clear();
+ invitationListeners.clear();
}
containerID = null;
connectNamespace = null;
@@ -240,28 +229,33 @@ public class XMPPChatRoomManager implements IChatRoomManager {
return roomID;
}
- public Object getAdapter(Class clazz) {
- return null;
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter(Class adapter) {
+ if (adapter == null)
+ return null;
+ if (adapter.isInstance(this))
+ return this;
+ final IAdapterManager adapterManager = XmppPlugin.getDefault().getAdapterManager();
+ return (adapterManager == null) ? null : adapterManager.loadAdapter(this, adapter.getName());
}
- public IChatRoomContainer createChatRoomContainer()
- throws ContainerCreateException {
+ public IChatRoomContainer createChatRoomContainer() throws ContainerCreateException {
XMPPChatRoomContainer chatContainer = null;
if (ecfConnection == null)
throw new ContainerCreateException(Messages.XMPPChatRoomManager_EXCEPTION_CONTAINER_DISCONNECTED);
try {
- chatContainer = new XMPPChatRoomContainer(ecfConnection,
- connectNamespace);
+ chatContainer = new XMPPChatRoomContainer(ecfConnection, connectNamespace);
addChat(chatContainer);
return chatContainer;
- } catch (IDCreateException e) {
- throw new ContainerCreateException(
- Messages.XMPPChatRoomManager_EXCEPTION_CREATING_CHAT_CONTAINER, e);
+ } catch (final IDCreateException e) {
+ throw new ContainerCreateException(Messages.XMPPChatRoomManager_EXCEPTION_CREATING_CHAT_CONTAINER, e);
}
}
public String toString() {
- StringBuffer buf = new StringBuffer("ECFRoomInfo["); //$NON-NLS-1$
+ final StringBuffer buf = new StringBuffer("ECFRoomInfo["); //$NON-NLS-1$
buf.append("id=").append(containerID).append(";name=" + getName()); //$NON-NLS-1$ //$NON-NLS-2$
buf.append(";service=" + getConnectedID()); //$NON-NLS-1$
buf.append(";count=" + getParticipantsCount()); //$NON-NLS-1$
@@ -280,9 +274,8 @@ public class XMPPChatRoomManager implements IChatRoomManager {
protected ID createIDFromHostedRoom(HostedRoom room) {
try {
- return new XMPPRoomID(connectNamespace, ecfConnection
- .getXMPPConnection(), room.getJid(), room.getName());
- } catch (URISyntaxException e) {
+ return new XMPPRoomID(connectNamespace, ecfConnection.getXMPPConnection(), room.getJid(), room.getName());
+ } catch (final URISyntaxException e) {
// debug output
return null;
}
@@ -294,19 +287,19 @@ public class XMPPChatRoomManager implements IChatRoomManager {
XMPPRoomID roomID = null;
if (toID instanceof XMPPRoomID) {
roomID = (XMPPRoomID) toID;
- String mucname = roomID.getMucString();
+ final String mucname = roomID.getMucString();
List toNotify = null;
synchronized (chatrooms) {
toNotify = new ArrayList(chatrooms);
}
- for (Iterator i = toNotify.iterator(); i.hasNext();) {
- IChatRoomContainer cont = (IChatRoomContainer) i.next();
+ for (final Iterator i = toNotify.iterator(); i.hasNext();) {
+ final IChatRoomContainer cont = (IChatRoomContainer) i.next();
if (cont == null)
continue;
- ID tid = cont.getConnectedID();
+ final ID tid = cont.getConnectedID();
if (tid != null && tid instanceof XMPPRoomID) {
- XMPPRoomID targetID = (XMPPRoomID) tid;
- String tmuc = targetID.getMucString();
+ final XMPPRoomID targetID = (XMPPRoomID) tid;
+ final String tmuc = targetID.getMucString();
if (tmuc.equals(mucname)) {
return cont;
}
@@ -319,23 +312,23 @@ public class XMPPChatRoomManager implements IChatRoomManager {
protected ID[] getChatRooms() {
if (ecfConnection == null)
return null;
- XMPPConnection conn = ecfConnection.getXMPPConnection();
+ final XMPPConnection conn = ecfConnection.getXMPPConnection();
if (conn == null)
return null;
- Collection result = new ArrayList();
+ final Collection result = new ArrayList();
try {
- Collection svcs = MultiUserChat.getServiceNames(conn);
- for (Iterator svcsi = svcs.iterator(); svcsi.hasNext();) {
- String svc = (String) svcsi.next();
- Collection rooms = MultiUserChat.getHostedRooms(conn, svc);
- for (Iterator roomsi = rooms.iterator(); roomsi.hasNext();) {
- HostedRoom room = (HostedRoom) roomsi.next();
- ID roomID = createIDFromHostedRoom(room);
+ final Collection svcs = MultiUserChat.getServiceNames(conn);
+ for (final Iterator svcsi = svcs.iterator(); svcsi.hasNext();) {
+ final String svc = (String) svcsi.next();
+ final Collection rooms = MultiUserChat.getHostedRooms(conn, svc);
+ for (final Iterator roomsi = rooms.iterator(); roomsi.hasNext();) {
+ final HostedRoom room = (HostedRoom) roomsi.next();
+ final ID roomID = createIDFromHostedRoom(room);
if (roomID != null)
result.add(roomID);
}
}
- } catch (XMPPException e) {
+ } catch (final XMPPException e) {
return null;
}
return (ID[]) result.toArray(new ID[] {});
@@ -344,14 +337,13 @@ public class XMPPChatRoomManager implements IChatRoomManager {
protected IChatRoomInfo getChatRoomInfo(ID roomID) {
if (!(roomID instanceof XMPPRoomID))
return null;
- XMPPRoomID cRoomID = (XMPPRoomID) roomID;
+ final XMPPRoomID cRoomID = (XMPPRoomID) roomID;
try {
- RoomInfo info = MultiUserChat.getRoomInfo(ecfConnection
- .getXMPPConnection(), cRoomID.getMucString());
+ final RoomInfo info = MultiUserChat.getRoomInfo(ecfConnection.getXMPPConnection(), cRoomID.getMucString());
if (info != null) {
return new ECFRoomInfo(cRoomID, info, connectedID);
}
- } catch (XMPPException e) {
+ } catch (final XMPPException e) {
return null;
}
return null;
@@ -362,40 +354,48 @@ public class XMPPChatRoomManager implements IChatRoomManager {
if (ecfConnection == null)
return null;
// Create roomid
- XMPPConnection conn = ecfConnection.getXMPPConnection();
- XMPPRoomID roomID = new XMPPRoomID(connectNamespace, conn, roomname);
- String mucName = roomID.getMucString();
- RoomInfo info = MultiUserChat.getRoomInfo(conn, mucName);
+ final XMPPConnection conn = ecfConnection.getXMPPConnection();
+ final XMPPRoomID roomID = new XMPPRoomID(connectNamespace, conn, roomname);
+ final String mucName = roomID.getMucString();
+ final RoomInfo info = MultiUserChat.getRoomInfo(conn, mucName);
if (info != null) {
return new ECFRoomInfo(roomID, info, connectedID);
}
- } catch (Exception e) {
+ } catch (final Exception e) {
return null;
}
return null;
}
public IChatRoomInfo[] getChatRoomInfos() {
- ID[] chatRooms = getChatRooms();
+ final ID[] chatRooms = getChatRooms();
if (chatRooms == null)
return new IChatRoomInfo[0];
- IChatRoomInfo[] res = new IChatRoomInfo[chatRooms.length];
+ final IChatRoomInfo[] res = new IChatRoomInfo[chatRooms.length];
int count = 0;
for (int i = 0; i < chatRooms.length; i++) {
- IChatRoomInfo infoResult = getChatRoomInfo(chatRooms[i]);
+ final IChatRoomInfo infoResult = getChatRoomInfo(chatRooms[i]);
if (infoResult != null) {
res[count++] = infoResult;
}
}
- IChatRoomInfo[] results = new IChatRoomInfo[count];
+ final IChatRoomInfo[] results = new IChatRoomInfo[count];
for (int i = 0; i < count; i++) {
results[i] = res[i];
}
return results;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
public Object getAdapter(Class adapter) {
- return null;
+ if (adapter == null)
+ return null;
+ if (adapter.isInstance(this))
+ return this;
+ final IAdapterManager adapterManager = XmppPlugin.getDefault().getAdapterManager();
+ return (adapterManager == null) ? null : adapterManager.loadAdapter(this, adapter.getName());
}
public void addInvitationListener(IChatRoomInvitationListener listener) {
@@ -406,19 +406,17 @@ public class XMPPChatRoomManager implements IChatRoomManager {
public void removeInvitationListener(IChatRoomInvitationListener listener) {
synchronized (invitationListeners) {
- invitationListeners.remove(listener);
+ invitationListeners.remove(listener);
}
}
- protected void fireInvitationReceived(ID roomID, ID fromID, ID toID,
- String subject, String body) {
+ protected void fireInvitationReceived(ID roomID, ID fromID, ID toID, String subject, String body) {
List toNotify = null;
synchronized (invitationListeners) {
toNotify = new ArrayList(invitationListeners);
}
- for (Iterator i = toNotify.iterator(); i.hasNext();) {
- IChatRoomInvitationListener l = (IChatRoomInvitationListener) i
- .next();
+ for (final Iterator i = toNotify.iterator(); i.hasNext();) {
+ final IChatRoomInvitationListener l = (IChatRoomInvitationListener) i.next();
l.handleInvitationReceived(roomID, fromID, subject, body);
}
}
@@ -433,28 +431,23 @@ public class XMPPChatRoomManager implements IChatRoomManager {
* @see org.eclipse.ecf.presence.chatroom.IChatRoomManager#createChatRoom(java.lang.String,
* java.util.Map)
*/
- public IChatRoomInfo createChatRoom(String roomname, Map properties)
- throws ChatRoomCreateException {
+ public IChatRoomInfo createChatRoom(String roomname, Map properties) throws ChatRoomCreateException {
if (roomname == null)
- throw new ChatRoomCreateException(roomname,
- Messages.XMPPChatRoomManager_EXCEPTION_ROOM_CANNOT_BE_NULL);
+ throw new ChatRoomCreateException(roomname, Messages.XMPPChatRoomManager_EXCEPTION_ROOM_CANNOT_BE_NULL);
try {
- String nickname = ecfConnection.getXMPPConnection().getUser();
- String server = ecfConnection.getXMPPConnection().getHost();
- String domain = (properties == null) ? XMPPRoomID.DOMAIN_DEFAULT
- : (String) properties.get(PROP_XMPP_CONFERENCE);
- String conference = XMPPRoomID.fixConferenceDomain(domain, server);
- String roomID = roomname + XMPPRoomID.AT_SIGN + conference;
+ final String nickname = ecfConnection.getXMPPConnection().getUser();
+ final String server = ecfConnection.getXMPPConnection().getHost();
+ final String domain = (properties == null) ? XMPPRoomID.DOMAIN_DEFAULT : (String) properties.get(PROP_XMPP_CONFERENCE);
+ final String conference = XMPPRoomID.fixConferenceDomain(domain, server);
+ final String roomID = roomname + XMPPRoomID.AT_SIGN + conference;
// create proxy to the room
- MultiUserChat muc = new MultiUserChat(ecfConnection
- .getXMPPConnection(), roomID);
+ final MultiUserChat muc = new MultiUserChat(ecfConnection.getXMPPConnection(), roomID);
if (!checkRoom(conference, roomID)) {
// otherwise create a new one
muc.create(nickname);
muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
- String subject = (properties == null) ? null
- : (String) properties.get(PROP_XMPP_SUBJECT);
+ final String subject = (properties == null) ? null : (String) properties.get(PROP_XMPP_SUBJECT);
if (subject != null)
muc.changeSubject(subject);
}
@@ -464,18 +457,16 @@ public class XMPPChatRoomManager implements IChatRoomManager {
longname = roomID;
}
- RoomInfo info = MultiUserChat.getRoomInfo(ecfConnection
- .getXMPPConnection(), roomID);
+ final RoomInfo info = MultiUserChat.getRoomInfo(ecfConnection.getXMPPConnection(), roomID);
if (info != null) {
- XMPPRoomID xid = new XMPPRoomID(connectedID.getNamespace(),
- ecfConnection.getXMPPConnection(), roomID, longname);
+ final XMPPRoomID xid = new XMPPRoomID(connectedID.getNamespace(), ecfConnection.getXMPPConnection(), roomID, longname);
return new ECFRoomInfo(xid, info, connectedID);
} else
- throw new XMPPException(NLS.bind(Messages.XMPPChatRoomManager_EXCEPTION_NO_ROOM_INFO,roomID));
- } catch (XMPPException e) {
+ throw new XMPPException(NLS.bind(Messages.XMPPChatRoomManager_EXCEPTION_NO_ROOM_INFO, roomID));
+ } catch (final XMPPException e) {
throw new ChatRoomCreateException(roomname, e.getMessage(), e);
- } catch (URISyntaxException e) {
+ } catch (final URISyntaxException e) {
throw new ChatRoomCreateException(roomname, e.getMessage(), e);
}
}
@@ -489,16 +480,13 @@ public class XMPPChatRoomManager implements IChatRoomManager {
* @return true, if the room exists, false otherwise
* @throws XMPPException
*/
- protected boolean checkRoom(String conference, String room)
- throws XMPPException {
- XMPPConnection conn = ecfConnection.getXMPPConnection();
- ServiceDiscoveryManager serviceDiscoveryManager = new ServiceDiscoveryManager(
- conn);
- DiscoverItems result = serviceDiscoveryManager
- .discoverItems(conference);
-
- for (Iterator items = result.getItems(); items.hasNext();) {
- DiscoverItems.Item item = ((DiscoverItems.Item) items.next());
+ protected boolean checkRoom(String conference, String room) throws XMPPException {
+ final XMPPConnection conn = ecfConnection.getXMPPConnection();
+ final ServiceDiscoveryManager serviceDiscoveryManager = new ServiceDiscoveryManager(conn);
+ final DiscoverItems result = serviceDiscoveryManager.discoverItems(conference);
+
+ for (final Iterator items = result.getItems(); items.hasNext();) {
+ final DiscoverItems.Item item = ((DiscoverItems.Item) items.next());
if (room.equals(item.getEntityID())) {
return true;
}
@@ -523,9 +511,16 @@ public class XMPPChatRoomManager implements IChatRoomManager {
}
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
public Object getAdapter(Class adapter) {
- // TODO Auto-generated method stub
- return null;
+ if (adapter == null)
+ return null;
+ if (adapter.isInstance(this))
+ return this;
+ final IAdapterManager adapterManager = XmppPlugin.getDefault().getAdapterManager();
+ return (adapterManager == null) ? null : adapterManager.loadAdapter(this, adapter.getName());
}
};
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPContainerPresenceHelper.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPContainerPresenceHelper.java
index 66e9ac542..67e7ea86d 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPContainerPresenceHelper.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPContainerPresenceHelper.java
@@ -16,6 +16,7 @@ import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
+import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.core.sharedobject.ISharedObject;
@@ -168,8 +169,13 @@ public class XMPPContainerPresenceHelper implements ISharedObject {
*
* @see org.eclipse.ecf.core.ISharedObject#getAdapter(java.lang.Class)
*/
- public Object getAdapter(Class clazz) {
- return null;
+ public Object getAdapter(Class adapter) {
+ if (adapter == null)
+ return null;
+ if (adapter.isInstance(this))
+ return this;
+ final IAdapterManager adapterManager = XmppPlugin.getDefault().getAdapterManager();
+ return (adapterManager == null) ? null : adapterManager.loadAdapter(this, adapter.getName());
}
// end ISharedObject implementation
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XmppPlugin.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XmppPlugin.java
index 2b3d34d3a..0828a124b 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XmppPlugin.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XmppPlugin.java
@@ -11,9 +11,11 @@ package org.eclipse.ecf.internal.provider.xmpp;
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ecf.core.util.LogHelper;
+import org.eclipse.ecf.core.util.PlatformHelper;
import org.eclipse.ecf.presence.service.IPresenceService;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -38,6 +40,8 @@ public class XmppPlugin implements BundleActivator {
private Map services;
+ private ServiceTracker adapterManagerTracker = null;
+
public static void log(String message) {
getDefault().log(new Status(IStatus.OK, PLUGIN_ID, IStatus.OK, message, null));
}
@@ -46,6 +50,22 @@ public class XmppPlugin implements BundleActivator {
getDefault().log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, message, e));
}
+ public IAdapterManager getAdapterManager() {
+ // First, try to get the adapter manager via
+ if (adapterManagerTracker == null) {
+ adapterManagerTracker = new ServiceTracker(this.context, IAdapterManager.class.getName(), null);
+ adapterManagerTracker.open();
+ }
+ IAdapterManager adapterManager = (IAdapterManager) adapterManagerTracker.getService();
+ // Then, if the service isn't there, try to get from Platform class via
+ // PlatformHelper class
+ if (adapterManager == null)
+ adapterManager = PlatformHelper.getPlatformAdapterManager();
+ if (adapterManager == null)
+ getDefault().log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "Cannot get adapter manager", null)); //$NON-NLS-1$
+ return adapterManager;
+ }
+
/**
* The constructor.
*/
@@ -89,20 +109,22 @@ public class XmppPlugin implements BundleActivator {
logServiceTracker.close();
logServiceTracker = null;
}
+ if (adapterManagerTracker != null) {
+ adapterManagerTracker.close();
+ adapterManagerTracker = null;
+ }
this.context = null;
plugin = null;
}
public void registerService(IPresenceService service) {
if (context != null) {
- services.put(service, context.registerService(IPresenceService.class
- .getName(), service, null));
+ services.put(service, context.registerService(IPresenceService.class.getName(), service, null));
}
}
public void unregisterService(IPresenceService service) {
- ServiceRegistration registration = (ServiceRegistration) services
- .remove(service);
+ final ServiceRegistration registration = (ServiceRegistration) services.remove(service);
if (registration != null) {
registration.unregister();
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/filetransfer/XMPPFileTransferRequestListener.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/filetransfer/XMPPFileTransferRequestListener.java
index 5f4957248..8d172183d 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/filetransfer/XMPPFileTransferRequestListener.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/filetransfer/XMPPFileTransferRequestListener.java
@@ -19,6 +19,7 @@ import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDFactory;
@@ -30,6 +31,7 @@ import org.eclipse.ecf.filetransfer.IncomingFileTransferException;
import org.eclipse.ecf.filetransfer.events.IFileTransferEvent;
import org.eclipse.ecf.filetransfer.events.IFileTransferRequestEvent;
import org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent;
+import org.eclipse.ecf.internal.provider.xmpp.XmppPlugin;
import org.eclipse.ecf.provider.xmpp.identity.XMPPID;
import org.jivesoftware.smackx.filetransfer.FileTransferListener;
import org.jivesoftware.smackx.filetransfer.FileTransferRequest;
@@ -81,7 +83,12 @@ public class XMPPFileTransferRequestListener implements FileTransferListener {
}
public Object getAdapter(Class adapter) {
- return null;
+ if (adapter == null)
+ return null;
+ if (adapter.isInstance(this))
+ return this;
+ final IAdapterManager adapterManager = XmppPlugin.getDefault().getAdapterManager();
+ return (adapterManager == null) ? null : adapterManager.loadAdapter(this, adapter.getName());
}
public long getFileSize() {
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/filetransfer/XMPPIncomingFileTransfer.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/filetransfer/XMPPIncomingFileTransfer.java
index 8277a6896..53524a310 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/filetransfer/XMPPIncomingFileTransfer.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/filetransfer/XMPPIncomingFileTransfer.java
@@ -16,6 +16,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
+import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -230,7 +231,12 @@ public class XMPPIncomingFileTransfer implements IIncomingFileTransfer {
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
*/
public Object getAdapter(Class adapter) {
- return null;
+ if (adapter == null)
+ return null;
+ if (adapter.isInstance(this))
+ return this;
+ final IAdapterManager adapterManager = XmppPlugin.getDefault().getAdapterManager();
+ return (adapterManager == null) ? null : adapterManager.loadAdapter(this, adapter.getName());
}
/*
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/filetransfer/XMPPOutgoingFileTransfer.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/filetransfer/XMPPOutgoingFileTransfer.java
index f9005ee9d..780b3c72c 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/filetransfer/XMPPOutgoingFileTransfer.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/filetransfer/XMPPOutgoingFileTransfer.java
@@ -12,11 +12,11 @@ package org.eclipse.ecf.internal.provider.xmpp.filetransfer;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDCreateException;
import org.eclipse.ecf.core.identity.IDFactory;
@@ -24,11 +24,14 @@ import org.eclipse.ecf.filetransfer.FileTransferJob;
import org.eclipse.ecf.filetransfer.IFileTransferInfo;
import org.eclipse.ecf.filetransfer.IFileTransferListener;
import org.eclipse.ecf.filetransfer.IOutgoingFileTransfer;
+import org.eclipse.ecf.filetransfer.UserCancelledException;
import org.eclipse.ecf.filetransfer.events.IFileTransferEvent;
import org.eclipse.ecf.filetransfer.events.IOutgoingFileTransferResponseEvent;
import org.eclipse.ecf.filetransfer.events.IOutgoingFileTransferSendDataEvent;
import org.eclipse.ecf.filetransfer.events.IOutgoingFileTransferSendDoneEvent;
+import org.eclipse.ecf.internal.provider.xmpp.XmppPlugin;
import org.eclipse.ecf.provider.xmpp.identity.XMPPID;
+import org.eclipse.osgi.util.NLS;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.filetransfer.FileTransfer;
import org.jivesoftware.smackx.filetransfer.FileTransferManager;
@@ -40,31 +43,36 @@ public class XMPPOutgoingFileTransfer implements IOutgoingFileTransfer {
private static final int BUFFER_SIZE = 4096;
- ID sessionID;
- XMPPID remoteTarget;
- IFileTransferInfo transferInfo;
- IFileTransferListener listener;
- FileTransferManager manager;
+ private final ID sessionID;
+ private final XMPPID remoteTarget;
+ private final IFileTransferListener listener;
- File localFile;
+ private File localFile;
- long fileSize;
+ private long fileSize;
- OutgoingFileTransfer outgoingFileTransfer;
+ private final OutgoingFileTransfer outgoingFileTransfer;
- long amountWritten = 0;
+ private long amountWritten = 0;
- Status status;
+ private Status status;
- Exception exception;
+ private Exception exception;
- public XMPPOutgoingFileTransfer(FileTransferManager manager, XMPPID remoteTarget, IFileTransferInfo fileTransferInfo, IFileTransferListener listener) {
- this.manager = manager;
+ private int originalOutputRequestTimeout = -1;
+
+ private boolean localCancelled = false;
+
+ public XMPPOutgoingFileTransfer(FileTransferManager manager, XMPPID remoteTarget, IFileTransferInfo fileTransferInfo, IFileTransferListener listener, int outgoingRequestTimeout) {
this.remoteTarget = remoteTarget;
- this.transferInfo = fileTransferInfo;
this.listener = listener;
this.sessionID = createSessionID();
final String fullyQualifiedName = remoteTarget.getFQName();
+ // Set request timeout if we have a new value
+ if (outgoingRequestTimeout != -1) {
+ originalOutputRequestTimeout = OutgoingFileTransfer.getResponseTimeout();
+ OutgoingFileTransfer.setResponseTimeout(outgoingRequestTimeout);
+ }
outgoingFileTransfer = manager.createOutgoingFileTransfer(fullyQualifiedName);
}
@@ -72,7 +80,7 @@ public class XMPPOutgoingFileTransfer implements IOutgoingFileTransfer {
try {
return IDFactory.getDefault().createGUID();
} catch (final IDCreateException e) {
- throw new NullPointerException("cannot create id for XMPPOutgoingFileTransfer");
+ throw new NullPointerException("cannot create id for XMPPOutgoingFileTransfer"); //$NON-NLS-1$
}
}
@@ -100,86 +108,83 @@ public class XMPPOutgoingFileTransfer implements IOutgoingFileTransfer {
return this.status;
}
- NegotiationProgress progress = new NegotiationProgress();
+ private void setErrorStatus(Exception e) {
+ setStatus(FileTransfer.Status.ERROR);
+ setException(e);
+ }
public synchronized void startSend(File localFile, String description) throws XMPPException {
this.localFile = localFile;
this.fileSize = localFile.length();
setStatus(Status.INITIAL);
- // outgoingFileTransfer.sendFile(localFile, description);
+ final NegotiationProgress progress = new NegotiationProgress();
+
outgoingFileTransfer.sendFile(localFile.getAbsolutePath(), this.fileSize, description, progress);
final Thread transferThread = new Thread(new Runnable() {
public void run() {
setStatus(outgoingFileTransfer.getStatus());
boolean negotiation = true;
- while (negotiation) {
- // check the state of the progress
- try {
- Thread.sleep(300);
- } catch (final InterruptedException e) {
- return;
- }
- final Status s = progress.getStatus();
- setStatus(s);
- final boolean negotiated = getStatus().equals(Status.NEGOTIATED);
- if (s.equals(Status.NEGOTIATED) || s.equals(Status.CANCLED) || s.equals(Status.COMPLETE) || s.equals(Status.ERROR) || s.equals(Status.REFUSED)) {
- fireTransferListenerEvent(new IOutgoingFileTransferResponseEvent() {
- private static final long serialVersionUID = -5940612388464073240L;
-
- public boolean requestAccepted() {
- return negotiated;
- }
-
- public IOutgoingFileTransfer getSource() {
- return XMPPOutgoingFileTransfer.this;
- }
-
- public String toString() {
- final StringBuffer buf = new StringBuffer("OutgoingFileTransferResponseEvent[");
- buf.append("requestAccepted=").append(requestAccepted()).append("]");
- return buf.toString();
- }
-
- public void setFileTransferJob(FileTransferJob job) {
- // does nothing with this implementation
- }
- });
- // And negotiation is over
- negotiation = false;
+ try {
+ while (negotiation && !localCancelled) {
+ // check the state of the progress
+ try {
+ Thread.sleep(300);
+ } catch (final InterruptedException e) {
+ setErrorStatus(e);
+ return;
+ }
+ final Status s = progress.getStatus();
+ setStatus(s);
+ final boolean negotiated = getStatus().equals(Status.NEGOTIATED);
+ if (s.equals(Status.NEGOTIATED) || s.equals(Status.CANCLED) || s.equals(Status.COMPLETE) || s.equals(Status.ERROR) || s.equals(Status.REFUSED)) {
+ fireTransferListenerEvent(new IOutgoingFileTransferResponseEvent() {
+ private static final long serialVersionUID = -5940612388464073240L;
+
+ public boolean requestAccepted() {
+ return negotiated;
+ }
+
+ public IOutgoingFileTransfer getSource() {
+ return XMPPOutgoingFileTransfer.this;
+ }
+
+ public String toString() {
+ final StringBuffer buf = new StringBuffer("OutgoingFileTransferResponseEvent["); //$NON-NLS-1$
+ buf.append("requestAccepted=").append(requestAccepted()).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
+ return buf.toString();
+ }
+
+ public void setFileTransferJob(FileTransferJob job) {
+ // does nothing with this implementation
+ }
+ });
+ // And negotiation is over
+ negotiation = false;
+ }
}
- }
- final OutputStream outs = progress.getOutputStream();
+ if (localCancelled) {
+ setErrorStatus(new UserCancelledException("Transfer cancelled by sender")); //$NON-NLS-1$
+ return;
+ }
- if (outs == null)
- return;
+ final OutputStream outs = progress.getOutputStream();
- InputStream inputStream = null;
+ if (outs == null) {
+ setErrorStatus(new IOException("No output stream available")); //$NON-NLS-1$
+ return;
+ }
- try {
- inputStream = new FileInputStream(XMPPOutgoingFileTransfer.this.localFile);
- writeToStream(inputStream, outs);
- } catch (final FileNotFoundException e) {
- setStatus(FileTransfer.Status.ERROR);
- setException(e);
- } catch (final XMPPException e) {
+ writeToStream(new FileInputStream(XMPPOutgoingFileTransfer.this.localFile), outs);
+ setStatus(Status.COMPLETE);
+ } catch (final Exception e) {
setStatus(FileTransfer.Status.ERROR);
setException(e);
} finally {
- setStatus(Status.COMPLETE);
- try {
- if (inputStream != null) {
- inputStream.close();
- }
- } catch (final IOException e) {
- /* Do Nothing */
- }
- try {
- outs.flush();
- outs.close();
- } catch (final IOException e) {
- /* Do Nothing */
+ // Reset request timeout
+ if (originalOutputRequestTimeout != -1) {
+ OutgoingFileTransfer.setResponseTimeout(originalOutputRequestTimeout);
}
// Then notify that the sending is done
fireTransferListenerEvent(new IOutgoingFileTransferSendDoneEvent() {
@@ -190,30 +195,38 @@ public class XMPPOutgoingFileTransfer implements IOutgoingFileTransfer {
}
public String toString() {
- final StringBuffer buf = new StringBuffer("IOutgoingFileTransferSendDoneEvent[");
- buf.append("isDone=" + getSource().isDone());
- buf.append(";bytesSent=").append(getSource().getBytesSent()).append("]");
+ final StringBuffer buf = new StringBuffer("IOutgoingFileTransferSendDoneEvent["); //$NON-NLS-1$
+ buf.append("isDone=" + getSource().isDone()); //$NON-NLS-1$
+ buf.append(";bytesSent=").append(getSource().getBytesSent()); //$NON-NLS-1$
+ buf.append(";exception=").append(getException()).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
return buf.toString();
}
-
});
}
}
- }, "ECF XMPP file send");
+ }, NLS.bind("XMPP send {0}", remoteTarget.toExternalForm())); //$NON-NLS-1$
transferThread.start();
}
public synchronized void cancel() {
- setStatus(Status.CANCLED);
+ localCancelled = true;
}
public synchronized File getLocalFile() {
return localFile;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
public Object getAdapter(Class adapter) {
- return null;
+ if (adapter == null)
+ return null;
+ if (adapter.isInstance(this))
+ return this;
+ final IAdapterManager adapterManager = XmppPlugin.getDefault().getAdapterManager();
+ return (adapterManager == null) ? null : adapterManager.loadAdapter(this, adapter.getName());
}
public long getBytesSent() {
@@ -236,48 +249,49 @@ public class XMPPOutgoingFileTransfer implements IOutgoingFileTransfer {
return sessionID;
}
- protected void writeToStream(final InputStream in, final OutputStream out) throws XMPPException {
+ protected void writeToStream(final InputStream in, final OutputStream out) throws XMPPException, IOException, UserCancelledException {
final byte[] b = new byte[BUFFER_SIZE];
int count = 0;
amountWritten = 0;
+ try {
+ do {
+
+ if (localCancelled)
+ throw new UserCancelledException("Transfer cancelled by sender"); //$NON-NLS-1$
- do {
- try {
out.write(b, 0, count);
- } catch (final IOException e) {
- throw new XMPPException("error writing to output stream", e);
- }
- amountWritten += count;
+ amountWritten += count;
- if (count > 0) {
- fireTransferListenerEvent(new IOutgoingFileTransferSendDataEvent() {
- private static final long serialVersionUID = 2327297070577249812L;
+ if (count > 0) {
+ fireTransferListenerEvent(new IOutgoingFileTransferSendDataEvent() {
+ private static final long serialVersionUID = 2327297070577249812L;
- public IOutgoingFileTransfer getSource() {
- return XMPPOutgoingFileTransfer.this;
- }
+ public IOutgoingFileTransfer getSource() {
+ return XMPPOutgoingFileTransfer.this;
+ }
- public String toString() {
- final StringBuffer buf = new StringBuffer("IOutgoingFileTransferSendDataEvent[");
- buf.append("bytesSent=").append(getSource().getBytesSent());
- buf.append(";percentComplete=").append(getSource().getPercentComplete()).append("]");
- return buf.toString();
- }
+ public String toString() {
+ final StringBuffer buf = new StringBuffer("IOutgoingFileTransferSendDataEvent["); //$NON-NLS-1$
+ buf.append("bytesSent=").append(getSource().getBytesSent()); //$NON-NLS-1$
+ buf.append(";percentComplete=").append(getSource().getPercentComplete()).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
+ return buf.toString();
+ }
- });
- }
- // read more bytes from the input stream
- try {
+ });
+ }
+ // read more bytes from the input stream
count = in.read(b);
- } catch (final IOException e) {
- throw new XMPPException("error reading from input stream", e);
- }
- } while (count != -1 && !getStatus().equals(Status.CANCLED));
+ } while (count != -1 && !getStatus().equals(Status.CANCLED));
- // the connection was likely terminated abrubtly if these are not equal
- if (!getStatus().equals(Status.CANCLED) && amountWritten != fileSize) {
- setStatus(Status.ERROR);
+ // the connection was likely terminated abruptly if these are not equal
+ if (!getStatus().equals(Status.CANCLED) && amountWritten != fileSize) {
+ setStatus(Status.ERROR);
+ }
+ } finally {
+ out.flush();
+ out.close();
+ in.close();
}
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/filetransfer/XMPPOutgoingFileTransferHelper.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/filetransfer/XMPPOutgoingFileTransferHelper.java
index 5a8f15f19..a8057fa04 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/filetransfer/XMPPOutgoingFileTransferHelper.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/filetransfer/XMPPOutgoingFileTransferHelper.java
@@ -17,6 +17,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.core.security.IConnectContext;
@@ -29,6 +30,7 @@ import org.eclipse.ecf.filetransfer.ISendFileTransferContainerAdapter;
import org.eclipse.ecf.filetransfer.SendFileTransferException;
import org.eclipse.ecf.filetransfer.events.IFileTransferEvent;
import org.eclipse.ecf.filetransfer.identity.IFileID;
+import org.eclipse.ecf.internal.provider.xmpp.XmppPlugin;
import org.eclipse.ecf.provider.xmpp.XMPPContainer;
import org.eclipse.ecf.provider.xmpp.identity.XMPPFileID;
import org.eclipse.ecf.provider.xmpp.identity.XMPPFileNamespace;
@@ -38,6 +40,11 @@ import org.jivesoftware.smackx.filetransfer.FileTransferManager;
public class XMPPOutgoingFileTransferHelper implements ISendFileTransferContainerAdapter {
+ /**
+ *
+ */
+ private static final String OUTGOING_REQUEST_TIMEOUT = "outgoingRequestTimeout";
+
List transferListeners = new ArrayList();
List incomingListeners = new ArrayList();
@@ -88,7 +95,23 @@ public class XMPPOutgoingFileTransferHelper implements ISendFileTransferContaine
final XMPPFileID fileID = (XMPPFileID) targetReceiver;
- final XMPPOutgoingFileTransfer fileTransfer = new XMPPOutgoingFileTransfer(manager, fileID.getXMPPID(), localFileToSend, progressListener);
+ int requestTimeout = -1;
+ if (options != null) {
+ final Object option = options.get(OUTGOING_REQUEST_TIMEOUT);
+ if (option != null) {
+ if (option instanceof String) {
+ try {
+ requestTimeout = Integer.valueOf((String) option).intValue();
+ } catch (final NumberFormatException e) {
+ // Ignore
+ }
+ } else if (option instanceof Integer) {
+ requestTimeout = ((Integer) option).intValue();
+ }
+ }
+ }
+
+ final XMPPOutgoingFileTransfer fileTransfer = new XMPPOutgoingFileTransfer(manager, fileID.getXMPPID(), localFileToSend, progressListener, requestTimeout);
try {
fileTransfer.startSend(localFileToSend.getFile(), localFileToSend.getDescription());
@@ -177,7 +200,12 @@ public class XMPPOutgoingFileTransferHelper implements ISendFileTransferContaine
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
*/
public Object getAdapter(Class adapter) {
- return null;
+ if (adapter == null)
+ return null;
+ if (adapter.isInstance(this))
+ return this;
+ final IAdapterManager adapterManager = XmppPlugin.getDefault().getAdapterManager();
+ return (adapterManager == null) ? null : adapterManager.loadAdapter(this, adapter.getName());
}
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/smack/ECFConnection.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/smack/ECFConnection.java
index e0f6672dd..e55ecde8d 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/smack/ECFConnection.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/smack/ECFConnection.java
@@ -13,6 +13,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.ecf.core.ContainerAuthenticationException;
import org.eclipse.ecf.core.ContainerConnectException;
import org.eclipse.ecf.core.identity.ID;
@@ -93,8 +94,16 @@ public class ECFConnection implements ISynchAsynchConnection {
return properties;
}
- public Object getAdapter(Class clazz) {
- return null;
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter(Class adapter) {
+ if (adapter == null)
+ return null;
+ if (adapter.isInstance(this))
+ return this;
+ final IAdapterManager adapterManager = XmppPlugin.getDefault().getAdapterManager();
+ return (adapterManager == null) ? null : adapterManager.loadAdapter(this, adapter.getName());
}
public XMPPConnection getXMPPConnection() {
@@ -146,14 +155,14 @@ public class ECFConnection implements ISynchAsynchConnection {
try {
if (google) {
if (secure) {
- if(serverPort == -1){
- serverPort = XMPPS_DEFAULT_PORT;
- }
+ if (serverPort == -1) {
+ serverPort = XMPPS_DEFAULT_PORT;
+ }
connection = new SSLXMPPConnection(GOOGLE_TALK_HOST, serverPort, jabberURI.getHostname());
} else {
- if(serverPort == -1){
- serverPort = XMPP_DEFAULT_PORT;
- }
+ if (serverPort == -1) {
+ serverPort = XMPP_DEFAULT_PORT;
+ }
connection = new XMPPConnection(GOOGLE_TALK_HOST, serverPort, jabberURI.getHostname());
}
} else if (serverPort == -1) {

Back to the top