use of org.eclipse.ecf.provider.xmpp.identity.XMPPID in project ecf by eclipse.
the class XMPPUserSearchManager method createResultList.
/**
* Create a result list from ReportedData. Identify dynamically columns and
* rows and create users adding it to a {@link IResultList}
*
* @param data
* ReportedData
* @return {@link IResultList} a list of users
* @throws
*/
protected IResultList createResultList(ReportedData data) {
ResultList result = new ResultList();
Iterator rows = data.getRows();
while (rows.hasNext()) {
Row row = (Row) rows.next();
Iterator jids = row.getValues(JID);
Iterator names = row.getValues(NAME);
String jid = null;
String name = null;
// XMPP server returns the same length for both
while (jids.hasNext() && names.hasNext()) {
try {
jid = (String) jids.next();
name = (String) names.next();
IUser user = new User(new XMPPID(connectNamespace, jid), name);
result.add(new XMPPResultItem(user));
} catch (URISyntaxException e) {
throw new RuntimeException(// $NON-NLS-1$
"cannot create connect id for client " + jid + " , name = " + name, // $NON-NLS-1$
e);
}
}
}
return result;
}
use of org.eclipse.ecf.provider.xmpp.identity.XMPPID in project ecf by eclipse.
the class ECFConnection method connect.
public synchronized Object connect(ID remote, Object data, int timeout) throws ECFException {
if (connection != null)
throw new ECFException("already connected");
if (timeout > 0)
SmackConfiguration.setPacketReplyTimeout(timeout);
Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);
final XMPPID jabberURI = getXMPPID(remote);
String username = jabberURI.getNodename();
String hostname = jabberURI.getHostname();
String hostnameOverride = null;
// Check for the URI form of "joe@bloggs.org;talk.google.com", which
// would at this point would have
// - username = "joe"
// - hostname = "blogs.org;talk.google.com"
// - hostnameOverride = null
//
// We need to turn this into:
// - username = "joe"
// - hostname = "bloggs.org"
// - hostnameOverride = "talk.google.com"
int semiColonIdx = hostname.lastIndexOf(';');
if (semiColonIdx != -1) {
hostnameOverride = hostname.substring(semiColonIdx + 1);
hostname = hostname.substring(0, semiColonIdx);
}
if (google && hostnameOverride == null) {
hostnameOverride = GOOGLE_TALK_HOST;
}
final String serviceName = hostname;
serverPort = jabberURI.getPort();
serverResource = jabberURI.getResourceName();
if (serverResource == null || serverResource.equals(XMPPID.PATH_DELIMITER)) {
serverResource = getClientIdentifier();
jabberURI.setResourceName(serverResource);
}
try {
ConnectionConfiguration config;
if (hostnameOverride != null) {
config = new ConnectionConfiguration(hostnameOverride, XMPP_DEFAULT_PORT, serviceName);
} else if (serverPort == -1) {
config = new ConnectionConfiguration(serviceName);
} else {
config = new ConnectionConfiguration(serviceName, serverPort);
}
config.setSendPresence(true);
// authentication; handler should provide keystore password:
if (callbackHandler instanceof javax.security.auth.callback.CallbackHandler) {
config.setCallbackHandler((javax.security.auth.callback.CallbackHandler) callbackHandler);
}
connection = new XMPPConnection(config);
connection.connect();
SASLAuthentication.supportSASLMechanism("PLAIN", 0);
if (google || GOOGLE_TALK_HOST.equals(hostnameOverride)) {
username = username + "@" + serviceName;
}
connection.addPacketListener(packetListener, null);
connection.addConnectionListener(connectionListener);
// Login
connection.login(username, (String) data, serverResource);
waitForBindResult();
} catch (final XMPPException e) {
throw new ContainerConnectException("Login attempt failed", e);
}
return jid;
}
use of org.eclipse.ecf.provider.xmpp.identity.XMPPID in project ecf by eclipse.
the class XMPPContainer method isGoogle.
protected boolean isGoogle(ID remoteSpace) {
if (remoteSpace instanceof XMPPID) {
final XMPPID theID = (XMPPID) remoteSpace;
final String host = theID.getHostname();
if (host == null)
return false;
return googleNames.contains(host.toLowerCase());
}
return false;
}
use of org.eclipse.ecf.provider.xmpp.identity.XMPPID in project ecf by eclipse.
the class ECFConnection method sendMessage.
protected void sendMessage(ID receiver, Message aMsg) throws IOException {
synchronized (this) {
if (!isConnected())
throw new IOException("not connected");
try {
if (receiver == null)
throw new IOException("receiver cannot be null for xmpp instant messaging");
else if (receiver instanceof XMPPID) {
final XMPPID rcvr = (XMPPID) receiver;
aMsg.setType(Message.Type.chat);
final String receiverName = rcvr.getFQName();
final Chat localChat = connection.getChatManager().createChat(receiverName, new MessageListener() {
public void processMessage(Chat chat, Message message) {
}
});
localChat.sendMessage(aMsg);
} else if (receiver instanceof XMPPRoomID) {
final XMPPRoomID roomID = (XMPPRoomID) receiver;
aMsg.setType(Message.Type.groupchat);
final String to = roomID.getMucString();
aMsg.setTo(to);
connection.sendPacket(aMsg);
} else
throw new IOException("receiver must be of type XMPPID or XMPPRoomID");
} catch (final XMPPException e) {
final IOException result = new IOException("XMPPException in sendMessage: " + e.getMessage());
result.setStackTrace(e.getStackTrace());
throw result;
}
}
}
use of org.eclipse.ecf.provider.xmpp.identity.XMPPID in project ecf by eclipse.
the class XMPPContainer method resetTargetResource.
private void resetTargetResource(ID originalTarget, Object serverData) {
// Reset resource to that given by server
if (originalTarget instanceof XMPPID) {
XMPPID xmppOriginalTarget = (XMPPID) originalTarget;
if (serverData != null && serverData instanceof String) {
String jid = (String) serverData;
String jidResource = trimResourceFromJid(jid);
if (jidResource != null) {
xmppOriginalTarget.setResourceName(jidResource);
}
}
}
}
Aggregations