Commit 47d52817 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

Simple code cleanup (tabs to spaces)

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@4382 b35dd754-fafc-0310-a699-88a17e54d16e
parent 009225d2
......@@ -2,7 +2,7 @@
<html>
<head>
<title>IM Gateway Changelog</title>
<title>IM Gateway Changelog</title>
<style type="text/css">
BODY {
font-size : 100%;
......
......@@ -2,7 +2,7 @@
<html>
<head>
<title>IM Gateway Readme</title>
<title>IM Gateway Readme</title>
<style type="text/css">
BODY {
font-size : 100%;
......
login.title=Admin Console
externalgateway.startup=Started external gateway {0}.
externalgateway.filenotfound=Configuration file {0} not found: {1}
externalgateway.invalidconfig=Invalid configuratino file: {0}
externalgateway.missingconfig=Unable to locate config.properties in classpath. \
Either specify on the command line the config properties or include it in the proper jar file.
Either specify on the command line the config properties or include it in the proper jar file.
externalgateway.invalidcommandline=Invalid command line option. {0}
externalgateway.usingdefaultgateway=Using default gateway "{0}" with secret passphrase "{1}".
externalgateway.addcomponentfailed=Unable to add component. Please ensure that the domain ({0}) is correct and matches the secret phrase ({1}) on the server. Error from server: {2}
......
STATUS_AVAILABLE = "Available";
STATUS_BRB = "Be right back";
STATUS_BUSY = "Busy";
STATUS_NOTATHOME = "Not at home";
STATUS_NOTATDESK = "Not at desk";
STATUS_NOTINOFFICE = "Not in office";
STATUS_ONPHONE = "On the phone";
STATUS_ONVACATION = "On vacation";
STATUS_OUTTOLUNCH = "Out to lunch";
STATUS_STEPPEDOUT = "Stepped out";
STATUS_INVISIBLE = "Invisible";
STATUS_CUSTOM = "<custom>";
STATUS_IDLE = "Zzz";
STATUS_OFFLINE = "Offline";
STATUS_TYPING = "Typing";
\ No newline at end of file
STATUS_AVAILABLE = "Available";
STATUS_BRB = "Be right back";
STATUS_BUSY = "Busy";
STATUS_NOTATHOME = "Not at home";
STATUS_NOTATDESK = "Not at desk";
STATUS_NOTINOFFICE = "Not in office";
STATUS_ONPHONE = "On the phone";
STATUS_ONVACATION = "On vacation";
STATUS_OUTTOLUNCH = "Out to lunch";
STATUS_STEPPEDOUT = "Stepped out";
STATUS_INVISIBLE = "Invisible";
STATUS_CUSTOM = "<custom>";
STATUS_IDLE = "Zzz";
STATUS_OFFLINE = "Offline";
STATUS_TYPING = "Typing";
......@@ -115,13 +115,13 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
* @return namespace The namespaceUri.
*/
private String getNS(IQ packet) {
Element childElement = (packet).getChildElement();
Element childElement = (packet).getChildElement();
String namespace = null;
if (childElement != null) {
namespace = childElement.getNamespaceURI();
}
return namespace;
return namespace;
}
/**
......@@ -133,22 +133,22 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
* @see org.xmpp.packet.IQ
*/
private List<Packet> processPacket(IQ iq) {
String namespace = getNS(iq);
List<Packet> response = new ArrayList<Packet>();
if("http://jabber.org/protocol/disco#info".equals(namespace)) {
response.add(handleServiceDiscovery(iq));
} else if("jabber:iq:agents".equals(namespace)) {
response.add(handleLegacyServiceDiscovery(iq));
} else if("http://jabber.org/protocol/disco#items".equals(namespace)) {
response.add(handleDiscoveryItems(iq));
} else if("jabber:iq:register".equals(namespace)) {
response.addAll(handleRegisterInBand(iq));
} else if("jabber:iq:version".equals(namespace)) {
response.add(handleVersion(iq));
} else if("jabber:iq:browse".equals(namespace)) {
response.add(handleBrowse(iq));
}
return response;
String namespace = getNS(iq);
List<Packet> response = new ArrayList<Packet>();
if("http://jabber.org/protocol/disco#info".equals(namespace)) {
response.add(handleServiceDiscovery(iq));
} else if("jabber:iq:agents".equals(namespace)) {
response.add(handleLegacyServiceDiscovery(iq));
} else if("http://jabber.org/protocol/disco#items".equals(namespace)) {
response.add(handleDiscoveryItems(iq));
} else if("jabber:iq:register".equals(namespace)) {
response.addAll(handleRegisterInBand(iq));
} else if("jabber:iq:version".equals(namespace)) {
response.add(handleVersion(iq));
} else if("jabber:iq:browse".equals(namespace)) {
response.add(handleBrowse(iq));
}
return response;
}
/**
......@@ -158,23 +158,23 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
* @return iq The response IQ packet.
*/
private IQ handleBrowse(IQ iq) {
IQ reply = IQ.createResultIQ(iq);
Element responseElement = DocumentHelper.createElement(QName.get(
IQ reply = IQ.createResultIQ(iq);
Element responseElement = DocumentHelper.createElement(QName.get(
"query", "jabber:iq:browse"));
try {
for(ForeignContact fc : PersistenceManager.Factory.get(this).getRegistrar().getGatewaySession(iq.getFrom()).getContacts()) {
Element item = DocumentHelper.createElement("item");
item.addAttribute("category", "user");
item.addAttribute("jid", fc + "@" + this.getName() + "." + this.getDomain());
item.addAttribute("type", "client");
responseElement.add(item);
}
for(ForeignContact fc : PersistenceManager.Factory.get(this).getRegistrar().getGatewaySession(iq.getFrom()).getContacts()) {
Element item = DocumentHelper.createElement("item");
item.addAttribute("category", "user");
item.addAttribute("jid", fc + "@" + this.getName() + "." + this.getDomain());
item.addAttribute("type", "client");
responseElement.add(item);
}
reply.setChildElement(responseElement);
reply.setChildElement(responseElement);
} catch (Exception e) {
logger.log(Level.WARNING, "basegateway.notfound", iq.getFrom().toBareJID());
}
......@@ -189,14 +189,14 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
* @return iq The response to the client.
*/
private IQ handleVersion(IQ iq) {
IQ reply = IQ.createResultIQ(iq);
Element responseElement = DocumentHelper.createElement(QName.get(
IQ reply = IQ.createResultIQ(iq);
Element responseElement = DocumentHelper.createElement(QName.get(
"query", "jabber:iq:version"));
responseElement.addElement("name").addText(this.getName());
responseElement.addElement("version").addText(this.getVersion());
responseElement.addElement("os").addText(System.getProperty("os.name"));
reply.setChildElement(responseElement);
return reply;
responseElement.addElement("name").addText(this.getName());
responseElement.addElement("version").addText(this.getVersion());
responseElement.addElement("os").addText(System.getProperty("os.name"));
reply.setChildElement(responseElement);
return reply;
}
/**
......@@ -208,13 +208,13 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
* make up the response.
*/
private Collection<Packet> handleRegisterInBand(final IQ iq) {
Element remove = iq.getChildElement().element("remove");
Collection<Packet> response = new ArrayList<Packet>();
if(remove != null) {
response.addAll(unregister(iq));
} else {
response.addAll(register(iq));
}
Element remove = iq.getChildElement().element("remove");
Collection<Packet> response = new ArrayList<Packet>();
if(remove != null) {
response.addAll(unregister(iq));
} else {
response.addAll(register(iq));
}
return response;
}
......@@ -226,7 +226,7 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
* @return response The packets that make up the response.
*/
private Collection<Packet> unregister(IQ iq) {
IQ reply = IQ.createResultIQ(iq);
IQ reply = IQ.createResultIQ(iq);
PersistenceManager.Factory.get(this).remove(iq.getFrom());
Collection<Packet> results = new ArrayList<Packet>();
......@@ -252,7 +252,7 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
logger.log(Level.INFO, "basegateway.unregister", iq.getFrom());
return results;
return results;
}
/**
......@@ -261,14 +261,14 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
* @param iq The client's IQ packet.
* @return response A <code>Collection</code> of <code>Packet</code>s that make up the response.
*/
private Collection<Packet> register(IQ iq) {
private Collection<Packet> register(IQ iq) {
Collection<Packet> response = new ArrayList<Packet>();
IQ reply = IQ.createResultIQ(iq);
Element responseElement = DocumentHelper.createElement(QName.get(
"query", "jabber:iq:register"));
if(iq.getType().equals(IQ.Type.set)) {
if(iq.getType().equals(IQ.Type.set)) {
String username = null;
String password = null;
......@@ -319,9 +319,9 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
logger.log(Level.INFO, "basegateway.register", username.trim());
SubscriptionInfo info = new SubscriptionInfo(username.trim(), password);
PersistenceManager.Factory.get(this).getRegistrar().add(iq.getFrom(), info);
reply.setChildElement(responseElement);
response.add( reply );
PersistenceManager.Factory.get(this).getRegistrar().add(iq.getFrom(), info);
reply.setChildElement(responseElement);
response.add( reply );
Presence subscribe = new Presence(Presence.Type.subscribe);
subscribe.setTo(iq.getFrom());
......@@ -329,7 +329,7 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
response.add(subscribe);
}
} else if(iq.getType().equals(IQ.Type.get)) {
} else if(iq.getType().equals(IQ.Type.get)) {
DataForm form = new DataForm(DataForm.Type.form);
......@@ -338,7 +338,7 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
usernameField.setLabel("Username");
usernameField.setVariable("username");
usernameField.setType(FormField.Type.text_single);
FormField passwordField = form.addField();
FormField passwordField = form.addField();
passwordField.setLabel("Password");
passwordField.setVariable("password");
passwordField.setType(FormField.Type.text_private);
......@@ -356,8 +356,8 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
responseElement.add(form.getElement());
reply.setChildElement(responseElement);
response.add( reply );
}
response.add( reply );
}
return response;
}
......@@ -369,8 +369,8 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
* @return response The IQ packet response.
*/
private IQ handleDiscoveryItems(IQ iq) {
IQ reply = IQ.createResultIQ(iq);
Element responseElement = DocumentHelper.createElement(QName.get(
IQ reply = IQ.createResultIQ(iq);
Element responseElement = DocumentHelper.createElement(QName.get(
"query", "http://jabber.org/protocol/disco#info"));
Roster roster = this.rosterManager.getContactManager().getRoster(iq.getFrom());
......@@ -392,8 +392,8 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
* @return response
*/
private IQ handleLegacyServiceDiscovery(IQ iq) {
return IQ.createResultIQ(iq);
// TODO: Implement Legacy Service Discovery.
return IQ.createResultIQ(iq);
// TODO: Implement Legacy Service Discovery.
}
/**
* Handle service discovery.
......@@ -402,18 +402,18 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
* @return respones The IQ response.
*/
private IQ handleServiceDiscovery(IQ iq) {
IQ reply = IQ.createResultIQ(iq);
IQ reply = IQ.createResultIQ(iq);
Element responseElement = DocumentHelper.createElement(QName.get(
"query", "http://jabber.org/protocol/disco#info"));
responseElement.addElement("identity").addAttribute("category", "gateway")
.addAttribute("type", this.getType())
.addAttribute("name", this.getDescription());
responseElement.addElement("feature").addAttribute("var", "jabber:iq:time");
responseElement.addElement("feature").addAttribute("var", "jabber:iq:version");
responseElement.addElement("feature").addAttribute("var", "jabber:iq:register");
responseElement.addElement("feature").addAttribute("var", "jabber:iq:version");
responseElement.addElement("feature").addAttribute("var", "jabber:iq:register");
reply.setChildElement(responseElement);
return reply;
return reply;
}
/**
......@@ -422,31 +422,31 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
* @param packet The packet to process.
*/
public void processPacket(Packet packet) {
try {
List<Packet> response = new ArrayList<Packet>();
if(packet instanceof IQ) {
response.addAll( processPacket((IQ)packet) );
} else if (packet instanceof Presence) {
response.addAll( processPacket((Presence)packet) );
} else if (packet instanceof Message) {
processPacket((Message)packet);
} else {
System.out.println("UNHANDLED: " + packet.toString());
}
// process
if(response.size() > 0) {
for(Packet p : response) {
componentManager.sendPacket(this, p);
}
} else {
//System.out.println("Request[" + packet.toString() + "] with no response");
}
try {
List<Packet> response = new ArrayList<Packet>();
if(packet instanceof IQ) {
response.addAll( processPacket((IQ)packet) );
} else if (packet instanceof Presence) {
response.addAll( processPacket((Presence)packet) );
} else if (packet instanceof Message) {
processPacket((Message)packet);
} else {
System.out.println("UNHANDLED: " + packet.toString());
}
// process
if(response.size() > 0) {
for(Packet p : response) {
componentManager.sendPacket(this, p);
}
} else {
//System.out.println("Request[" + packet.toString() + "] with no response");
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
/**
* Process a message from the client.
......@@ -458,8 +458,8 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
private void processPacket(Message message) throws Exception {
logger.finer(message.toString());
GatewaySession session = PersistenceManager.Factory.get(this).getRegistrar().getGatewaySession(message.getFrom());
session.getLegacyEndpoint().sendPacket(message);
GatewaySession session = PersistenceManager.Factory.get(this).getRegistrar().getGatewaySession(message.getFrom());
session.getLegacyEndpoint().sendPacket(message);
}
/**
......@@ -470,15 +470,15 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
* @throws Exception
*/
private List<Presence> processPacket(Presence presence) throws Exception {
List<Presence> p = new ArrayList<Presence>();
JID from = presence.getFrom();
List<Presence> p = new ArrayList<Presence>();
JID from = presence.getFrom();
logger.finest(presence.toString());
/*
* Unknown entity is trying to access the gateway.
*/
if(!rosterManager.getRegistrar().isRegistered(NormalizedJID.wrap(from))) {
if(!rosterManager.getRegistrar().isRegistered(NormalizedJID.wrap(from))) {
logger.log(Level.INFO, "basegateway.unabletofind", from);
// silently ignore a delete request
if(!Presence.Type.unavailable.equals(presence.getType())) {
......@@ -488,13 +488,13 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
result.setStatus(LocaleUtils.getLocalizedString("basegateway.registerfirst", "gateway"));
p.add(result);
}
return p;
}
return p;
}
/*
* Get the underlying session for this JID and handle accordingly.
*/
GatewaySession sessionInfo = rosterManager.getRegistrar().getGatewaySession(from);
GatewaySession sessionInfo = rosterManager.getRegistrar().getGatewaySession(from);
if(sessionInfo == null) {
logger.log(Level.WARNING, "basegateway.unabletolocatesession" , from);
return p;
......@@ -514,29 +514,29 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
reply.setFrom(presence.getTo());
p.add(reply);
}
}
else if (Presence.Type.subscribed.equals(presence.getType())) {
if(presence.getTo().equals(this.jid)) { // subscribed to server
sessionInfo.getSubscriptionInfo().clientRegistered = true;
} else { // subscribe to legacy user
logger.log(Level.FINE,"basegateway.subscribed");
}
}
}
else if (Presence.Type.unavailable.equals(presence.getType())){
/**
* If an unavailable presence stanza is received then logout the
* current user and send back and unavailable stanza.
*/
if(sessionInfo.isConnected()) {
sessionInfo.logout();
}
if(sessionInfo.isConnected()) {
sessionInfo.logout();
}
Presence reply = new Presence(Presence.Type.unavailable);
reply.setTo(presence.getFrom());
reply.setFrom(presence.getTo());
p.add(reply);
}
}
else if (presence.getTo().getNode() == null) { // this is a request to the gateway only.
Presence result = new Presence();
result.setTo(presence.getFrom());
......@@ -565,8 +565,8 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
logger.log(Level.WARNING, "basegateway.statusexception",
new Object[]{presence.getTo(), presence.getFrom(), e.getLocalizedMessage()});
}
}
return p;
}
return p;
}
/**
......@@ -589,7 +589,7 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
* @see org.xmpp.component.Component#initialize(JID, ComponentManager)
*/
public void initialize(JID jid, ComponentManager componentManager) throws ComponentException {
this.jid = jid;
this.jid = jid;
EndpointValve jabberEndpointValve = new EndpointValve(false);
this.jabberEndpoint = new JabberEndpoint(componentManager, this, jabberEndpointValve);
}
......@@ -602,9 +602,9 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
* @return jid The JID associated with this contact.
*/
public JID whois(String foreignContact) {
JID jid = new JID(foreignContact, this.getName() + "." + this.getDomain(), null);
foreignContacts.put(jid, foreignContact);
return jid;
JID jid = new JID(foreignContact, this.getName() + "." + this.getDomain(), null);
foreignContacts.put(jid, foreignContact);
return jid;
}
/**
......@@ -614,7 +614,7 @@ public abstract class BaseGateway implements Gateway, Component, Runnable {
* @return contact A String for the foreign contact or null if non is regestered.
*/
public String whois(JID jid) {
return foreignContacts.get(jid);
return foreignContacts.get(jid);
}
/**
......
......@@ -25,40 +25,40 @@ public interface Gateway extends Endpoint {
* Node naming coventions
* @return Name The gateway name (JID Node)
*/
public String getName();
public String getName();
/**
* Sets the name, or node, of the gateway. This should comply with JID
* Node naming coventions
*/
public void setName(String newname);
public void setName(String newname);
/**
* A textual description of the gateway
* @return description
*/
public String getDescription();
public String getDescription();
/**
* The domain name
* @return domain
*/
public String getDomain();
public String getDomain();
/**
* Lookup a contact name for the JID
* @param jid The jabber id
* @return contact The legacy name
*/
public String whois(JID jid);
public String whois(JID jid);
/**
* Lookup a JID for a legacy contact name
* @param contact The name of legacy contact
* @return JID
*/
public JID whois(String contact);
public JID whois(String contact);
/**
* The JID of the gateway
* @return JID
......
......@@ -47,201 +47,201 @@ public class NoopSessionListener implements SessionListener {
* @see ymsg.network.event.SessionListener#fileTransferReceived(ymsg.network.event.SessionFileTransferEvent)
*/
public void fileTransferReceived(SessionFileTransferEvent arg0) {
logger.info(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#connectionClosed(ymsg.network.event.SessionEvent)
*/
public void connectionClosed(SessionEvent arg0) {
logger.info(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#listReceived(ymsg.network.event.SessionEvent)
*/
public void listReceived(SessionEvent arg0) {
logger.info(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#messageReceived(ymsg.network.event.SessionEvent)
*/
public void messageReceived(SessionEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#buzzReceived(ymsg.network.event.SessionEvent)
*/
public void buzzReceived(SessionEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#offlineMessageReceived(ymsg.network.event.SessionEvent)
*/
public void offlineMessageReceived(SessionEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#errorPacketReceived(ymsg.network.event.SessionErrorEvent)
*/
public void errorPacketReceived(SessionErrorEvent arg0) {
logger.severe(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#inputExceptionThrown(ymsg.network.event.SessionExceptionEvent)
*/
public void inputExceptionThrown(SessionExceptionEvent arg0) {
arg0.getException().printStackTrace();
logger.info(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#connectionClosed(ymsg.network.event.SessionEvent)
*/
public void connectionClosed(SessionEvent arg0) {
logger.info(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#listReceived(ymsg.network.event.SessionEvent)
*/
public void listReceived(SessionEvent arg0) {
logger.info(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#messageReceived(ymsg.network.event.SessionEvent)
*/
public void messageReceived(SessionEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#buzzReceived(ymsg.network.event.SessionEvent)
*/
public void buzzReceived(SessionEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#offlineMessageReceived(ymsg.network.event.SessionEvent)
*/
public void offlineMessageReceived(SessionEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#errorPacketReceived(ymsg.network.event.SessionErrorEvent)
*/
public void errorPacketReceived(SessionErrorEvent arg0) {
logger.severe(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#inputExceptionThrown(ymsg.network.event.SessionExceptionEvent)
*/
public void inputExceptionThrown(SessionExceptionEvent arg0) {
arg0.getException().printStackTrace();
logger.severe(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#newMailReceived(ymsg.network.event.SessionNewMailEvent)
*/
public void newMailReceived(SessionNewMailEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#notifyReceived(ymsg.network.event.SessionNotifyEvent)
*/
public void notifyReceived(SessionNotifyEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#contactRequestReceived(ymsg.network.event.SessionEvent)
*/
public void contactRequestReceived(SessionEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#contactRejectionReceived(ymsg.network.event.SessionEvent)
*/
public void contactRejectionReceived(SessionEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#conferenceInviteReceived(ymsg.network.event.SessionConferenceEvent)
*/
public void conferenceInviteReceived(SessionConferenceEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#conferenceInviteDeclinedReceived(ymsg.network.event.SessionConferenceEvent)
*/
public void conferenceInviteDeclinedReceived(SessionConferenceEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#conferenceLogonReceived(ymsg.network.event.SessionConferenceEvent)
*/
public void conferenceLogonReceived(SessionConferenceEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#conferenceLogoffReceived(ymsg.network.event.SessionConferenceEvent)
*/
/**
* @see ymsg.network.event.SessionListener#conferenceLogoffReceived(ymsg.network.event.SessionConferenceEvent)
*/
public void conferenceLogoffReceived(SessionConferenceEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#conferenceMessageReceived(ymsg.network.event.SessionConferenceEvent)
*/
public void conferenceMessageReceived(SessionConferenceEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#friendsUpdateReceived(ymsg.network.event.SessionFriendEvent)
*/
public void friendsUpdateReceived(SessionFriendEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#friendAddedReceived(ymsg.network.event.SessionFriendEvent)
*/
public void friendAddedReceived(SessionFriendEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#friendRemovedReceived(ymsg.network.event.SessionFriendEvent)
*/
public void friendRemovedReceived(SessionFriendEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#chatLogonReceived(ymsg.network.event.SessionChatEvent)
*/
public void chatLogonReceived(SessionChatEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#chatLogoffReceived(ymsg.network.event.SessionChatEvent)
*/
public void chatLogoffReceived(SessionChatEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#chatMessageReceived(ymsg.network.event.SessionChatEvent)
*/
public void chatMessageReceived(SessionChatEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#chatUserUpdateReceived(ymsg.network.event.SessionChatEvent)
*/
public void chatUserUpdateReceived(SessionChatEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#chatConnectionClosed(ymsg.network.event.SessionEvent)
*/
public void chatConnectionClosed(SessionEvent arg0) {
logger.finest(arg0.toString());
}
}
/**
* @see ymsg.network.event.SessionListener#newMailReceived(ymsg.network.event.SessionNewMailEvent)
*/
public void newMailReceived(SessionNewMailEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#notifyReceived(ymsg.network.event.SessionNotifyEvent)
*/
public void notifyReceived(SessionNotifyEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#contactRequestReceived(ymsg.network.event.SessionEvent)
*/
public void contactRequestReceived(SessionEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#contactRejectionReceived(ymsg.network.event.SessionEvent)
*/
public void contactRejectionReceived(SessionEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#conferenceInviteReceived(ymsg.network.event.SessionConferenceEvent)
*/
public void conferenceInviteReceived(SessionConferenceEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#conferenceInviteDeclinedReceived(ymsg.network.event.SessionConferenceEvent)
*/
public void conferenceInviteDeclinedReceived(SessionConferenceEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#conferenceLogonReceived(ymsg.network.event.SessionConferenceEvent)
*/
public void conferenceLogonReceived(SessionConferenceEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#conferenceLogoffReceived(ymsg.network.event.SessionConferenceEvent)
*/
/**
* @see ymsg.network.event.SessionListener#conferenceLogoffReceived(ymsg.network.event.SessionConferenceEvent)
*/
public void conferenceLogoffReceived(SessionConferenceEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#conferenceMessageReceived(ymsg.network.event.SessionConferenceEvent)
*/
public void conferenceMessageReceived(SessionConferenceEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#friendsUpdateReceived(ymsg.network.event.SessionFriendEvent)
*/
public void friendsUpdateReceived(SessionFriendEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#friendAddedReceived(ymsg.network.event.SessionFriendEvent)
*/
public void friendAddedReceived(SessionFriendEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#friendRemovedReceived(ymsg.network.event.SessionFriendEvent)
*/
public void friendRemovedReceived(SessionFriendEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#chatLogonReceived(ymsg.network.event.SessionChatEvent)
*/
public void chatLogonReceived(SessionChatEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#chatLogoffReceived(ymsg.network.event.SessionChatEvent)
*/
public void chatLogoffReceived(SessionChatEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#chatMessageReceived(ymsg.network.event.SessionChatEvent)
*/
public void chatMessageReceived(SessionChatEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#chatUserUpdateReceived(ymsg.network.event.SessionChatEvent)
*/
public void chatUserUpdateReceived(SessionChatEvent arg0) {
logger.finest(arg0.toString());
}
/**
* @see ymsg.network.event.SessionListener#chatConnectionClosed(ymsg.network.event.SessionEvent)
*/
public void chatConnectionClosed(SessionEvent arg0) {
logger.finest(arg0.toString());
}
}
......@@ -26,45 +26,45 @@ import org.xmpp.packet.Packet;
*/
public class YahooGateway extends BaseGateway {
/** The YAHOO. */
private static String YAHOO = "yahoo";
/**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#getName()
*/
@Override
/** The YAHOO. */
private static String YAHOO = "yahoo";
/**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#getName()
*/
@Override
public String getName() {
return YAHOO;
}
return YAHOO;
}
/**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#setName(String)
*/
@Override
/**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#setName(String)
*/
@Override
public void setName(String newname) {
YAHOO = newname;
}
}
/**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#getDescription()
*/
@Override
/**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#getDescription()
*/
@Override
public String getDescription() {
return "Yahoo! Gateway (ymsg9)";
}
/** The logger. @see java.util.logging.Logger */
static public final Logger logger = Logger.getLogger("YahooGateway");
return "Yahoo! Gateway (ymsg9)";
}
/** The logger. @see java.util.logging.Logger */
static public final Logger logger = Logger.getLogger("YahooGateway");
/**
* @see org.jivesoftware.wildfire.gateway.Endpoint#sendPacket(Packet)
*/
@SuppressWarnings("unused")
* @see org.jivesoftware.wildfire.gateway.Endpoint#sendPacket(Packet)
*/
@SuppressWarnings("unused")
public void sendPacket(@SuppressWarnings("unused") Packet packet) throws ComponentException {
// do nothing.
}
// do nothing.
}
/**
* @param jid
......
......@@ -57,11 +57,11 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
/** The logger. */
private static Logger logger = Logger.getLogger("YahooGatewaySession", "gateway_i18n");
/**
* Yahoo Session
*/
public final Session session;
public final Session session;
/**
* The JID associated with this session.
......@@ -84,30 +84,30 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
session.addSessionListener(new YahooSessionListener(this));
}
/** The attemptingLogin. */
private boolean attemptingLogin = false;
/** The loginFailed. */
private boolean loginFailed = false;
/** The loginFailedCount. */
private int loginFailedCount = 0;
/** The attemptingLogin. */
private boolean attemptingLogin = false;
/** The loginFailed. */
private boolean loginFailed = false;
/** The loginFailedCount. */
private int loginFailedCount = 0;
/**
* Manage presense information.
*/
// public void updatePresence() {
/**
* Manage presense information.
*/
// public void updatePresence() {
// if(isConnected()) {
//
// for(YahooGroup group : session.getGroups()) {
// Vector members = group.getMembers();
// for(Object member : members) {
// YahooUser user = (YahooUser)member;
// for(YahooGroup group : session.getGroups()) {
// Vector members = group.getMembers();
// for(Object member : members) {
// YahooUser user = (YahooUser)member;
// logger.info("Adding foreign contact: " + user.getId());
// String foreignId = user.getId();
// String foreignId = user.getId();
// NormalizedJID whois = NormalizedJID.wrap(gateway.whois(foreignId));
// AbstractForeignContact fc = PersistenceManager.Factory.get(gateway)
// .getContactManager().getRoster(this.jid)
......@@ -121,90 +121,90 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
// logger.warning("Invalid Yahoo user");
// continue;
// }
// if(fc.status.getValue() != null && !fc.status.getValue().equalsIgnoreCase(user.getCustomStatusMessage())) {
// logger.log(Level.FINE, "yahoogatewaysession.status", new Object[] {fc.status});
// if(fc.status.getValue() != null && !fc.status.getValue().equalsIgnoreCase(user.getCustomStatusMessage())) {
// logger.log(Level.FINE, "yahoogatewaysession.status", new Object[] {fc.status});
// try {
// Presence p = new Presence();
// if(!fc.status.isSubscribed()) {
// p.setType(Presence.Type.subscribe);
// fc.status.setSubscribed(true);
// }
// p.setFrom(user.getId() + "@" + gateway.getName() + "." + gateway.getDomain());
// p.setTo(this.jid);
// gateway.sendPacket(p);
//
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// Presence p = new Presence();
// if(!fc.status.isSubscribed()) {
// p.setType(Presence.Type.subscribe);
// fc.status.setSubscribed(true);
// }
// p.setFrom(user.getId() + "@" + gateway.getName() + "." + gateway.getDomain());
// p.setTo(this.jid);
// gateway.sendPacket(p);
//
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// }
// }
// }
// }
// }
// }
// }
// }
/**
* Login to the Yahoo! Messenger serverice
* @throws Exception
*/
public synchronized void login() throws Exception {
if(!isConnected() && !loginFailed && !attemptingLogin) {
attemptingLogin = true;
new Thread() {
@Override
public synchronized void login() throws Exception {
if(!isConnected() && !loginFailed && !attemptingLogin) {
attemptingLogin = true;
new Thread() {
@Override
public void run() {
try {
session.login(getSubscriptionInfo().username,
try {
session.login(getSubscriptionInfo().username,
new String(getSubscriptionInfo().password));
/**
* Password is stored in the JVM as a string in JVM
* util termination.
*/
logger.log(Level.INFO, "yahoogatewaysession.login", new Object[]{jid, getSubscriptionInfo().username});
getJabberEndpoint().getValve().open(); // allow any buffered messages to pass through
logger.log(Level.INFO, "yahoogatewaysession.login", new Object[]{jid, getSubscriptionInfo().username});
getJabberEndpoint().getValve().open(); // allow any buffered messages to pass through
// updatePresence();
} catch (LoginRefusedException lre) {
session.reset();
if( loginFailedCount++ > 3) {
loginFailed = true;
}
logger.warning("Login failed for " + getSubscriptionInfo().username);
} catch (IOException ioe) {
ioe.printStackTrace();
}
attemptingLogin = false;
} catch (LoginRefusedException lre) {
session.reset();
if( loginFailedCount++ > 3) {
loginFailed = true;
}
logger.warning("Login failed for " + getSubscriptionInfo().username);
} catch (IOException ioe) {
ioe.printStackTrace();
}
attemptingLogin = false;
}
}.run(); // intentionally not forked.
} else {
logger.warning(this.jid + " is already logged in");
}
}.run(); // intentionally not forked.
} else {
logger.warning(this.jid + " is already logged in");
}
}
}
/**
* Is the connection connected?
* @return connected is the session connected?
*/
public boolean isConnected() {
return session.getSessionStatus() == Session.MESSAGING;
}
public boolean isConnected() {
return session.getSessionStatus() == Session.MESSAGING;
}
/**
* Logout from Yahoo!
* @throws Exception
*/
public synchronized void logout() throws Exception {
public synchronized void logout() throws Exception {
logger.info("[" + this.jid + "]" + getSubscriptionInfo().username + " logged out.");
session.logout();
session.reset();
}
/**
session.reset();
}
/**
* @see java.lang.Object#toString()
*/
@Override
*/
@Override
public String toString() { return "[" + this.getSubscriptionInfo().username + " CR:" + clientRegistered + " SR:" + serverRegistered + "]"; }
/**
......@@ -212,23 +212,23 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
* @return ID the jid for this session.
* @see org.xmpp.packet.JID
*/
public String getId() {
return this.jid.toBareJID();
}
public String getId() {
return this.jid.toBareJID();
}
/**
* Returns all the contacts associated with this Session.
* @return contacts A list of <code>String</code>s.
*/
@SuppressWarnings("unchecked")
@SuppressWarnings("unchecked")
public List<ForeignContact> getContacts() {
Map users = session.getUsers();
Map users = session.getUsers();
ArrayList<ForeignContact> contacts = new ArrayList<ForeignContact>(users.size());
for(YahooUser user : (Collection<YahooUser>)session.getUsers().values()) {
contacts.add(new YahooForeignContact(user, this.gateway));
}
return contacts;
}
return contacts;
}
/**
* Return the <code>JID</code> for this session.
......
......@@ -27,30 +27,30 @@ import org.xmpp.packet.JID;
* @version 1.0
*/
public abstract class AbstractForeignContact implements Serializable, ForeignContact {
/**
* The serialVersionUID
*/
private static final long serialVersionUID = 1L;
/**
* The id for this contact. This maps directly to the legacy userid.
*/
public final String id;
/**
* The serialVersionUID
*/
private static final long serialVersionUID = 1L;
/**
* The id for this contact. This maps directly to the legacy userid.
*/
public final String id;
/**
* The status of this contact.
*
* @see Status
*/
public final Status status;
/**
* The jid associated with this foreign contact.
*
* @see JID
*/
private transient JID jid;
* The status of this contact.
*
* @see Status
*/
public final Status status;
/**
* The jid associated with this foreign contact.
*
* @see JID
*/
private transient JID jid;
/**
* The gatewayDomain.
*/
......@@ -67,14 +67,14 @@ public abstract class AbstractForeignContact implements Serializable, ForeignCon
* @see java.util.Set
*/
private transient Set<GatewaySession> associatedSessions = new HashSet<GatewaySession>();
/**
* The format for a JID
*
* @see java.text.MessageFormat
*/
private static final MessageFormat mf = new MessageFormat("{0}@{1}.{2}");
/**
* The format for a JID
*
* @see java.text.MessageFormat
*/
private static final MessageFormat mf = new MessageFormat("{0}@{1}.{2}");
/**
* Create a ForeignContact relating to the gateway it originated from.
*
......@@ -82,24 +82,24 @@ public abstract class AbstractForeignContact implements Serializable, ForeignCon
* @param status the current status of the contact.
* @param gateway the gateway the foreign contact is associated with.
*/
public AbstractForeignContact(String id, Status status, Gateway gateway) {
this.id = id;
this.status = status;
this.gatewayDomain = gateway.getDomain();
public AbstractForeignContact(String id, Status status, Gateway gateway) {
this.id = id;
this.status = status;
this.gatewayDomain = gateway.getDomain();
this.gatewayName = gateway.getName();
}
}
/**
/**
* @see org.jivesoftware.wildfire.gateway.roster.ForeignContact#getJid()
*/
public JID getJid() {
if(jid == null) {
jid = new JID(mf.format(new Object[]{id, gatewayName, gatewayDomain}));
}
return jid;
}
public JID getJid() {
if(jid == null) {
jid = new JID(mf.format(new Object[]{id, gatewayName, gatewayDomain}));
}
return jid;
}
/**
/**
* @param in
* @throws IOException
* @throws ClassNotFoundException
......
......@@ -31,11 +31,11 @@ public class ContactManager implements Serializable {
*/
ContactManager() { }
/**
* The serialVersionUID
*/
private static final long serialVersionUID = 1L;
/**
* The serialVersionUID
*/
private static final long serialVersionUID = 1L;
/**
* The fcs
*
......@@ -43,27 +43,27 @@ public class ContactManager implements Serializable {
*/
private final Set<AbstractForeignContact> fcs = new HashSet<AbstractForeignContact>();
/**
* Maintain a mapping of JIDs to their contact list.
*/
private final Map<NormalizedJID, Roster> contactLists =
new HashMap<NormalizedJID, Roster>();
/**
* Return a roster for a JID.
/**
* Maintain a mapping of JIDs to their contact list.
*/
private final Map<NormalizedJID, Roster> contactLists =
new HashMap<NormalizedJID, Roster>();
/**
* Return a roster for a JID.
*
* @param name The <code>JID</code> to lookup.
* @return roster The roster for the <code>JID</code>.
*/
public synchronized Roster getRoster(JID name) {
Roster r = contactLists.get(NormalizedJID.wrap(name));
if(r == null) {
r = new Roster();
contactLists.put(NormalizedJID.wrap(name), r);
}
return r;
}
* @param name The <code>JID</code> to lookup.
* @return roster The roster for the <code>JID</code>.
*/
public synchronized Roster getRoster(JID name) {
Roster r = contactLists.get(NormalizedJID.wrap(name));
if(r == null) {
r = new Roster();
contactLists.put(NormalizedJID.wrap(name), r);
}
return r;
}
/**
* @return foreignContacts A {@code java.util.Set} of {@code ForeignContact}s.
......@@ -73,12 +73,12 @@ public class ContactManager implements Serializable {
}
/**
/**
* Remove the <code>JID</code> from the contact list.
*
* @param jid
*/
void remove(NormalizedJID jid) {
contactLists.remove(jid);
}
* @param jid
*/
void remove(NormalizedJID jid) {
contactLists.remove(jid);
}
}
......@@ -28,12 +28,12 @@ import org.xmpp.packet.JID;
*/
public final class NormalizedJID implements Serializable {
/**
* The JID.
*
* @see JID
*/
public final String JID;
/**
* The JID.
*
* @see JID
*/
public final String JID;
/**
* The toStringValue. Stored to increase efficiency.
......@@ -42,65 +42,65 @@ public final class NormalizedJID implements Serializable {
*/
private final String toStringValue;
/**
* The serialVersionUID.
*/
private static final long serialVersionUID = 1L;
/**
* The serialVersionUID.
*/
private static final long serialVersionUID = 1L;
/**
* Construct a new <code>NormalizedJID</code>
* @param jid
*/
private NormalizedJID(JID jid) {
JID = jid.toBareJID();
/**
* Construct a new <code>NormalizedJID</code>
* @param jid
*/
private NormalizedJID(JID jid) {
JID = jid.toBareJID();
toStringValue = JID + " (normalized)";
}
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if(obj instanceof NormalizedJID) {
NormalizedJID jid = (NormalizedJID)obj;
return JID.equalsIgnoreCase(jid.JID);
} else if(obj instanceof JID) {
JID jid = new JID( ((JID)obj).toBareJID() );
return JID.equalsIgnoreCase(jid.toBareJID());
} else if( obj instanceof String) {
JID jid = new JID((String)obj);
jid = new JID(jid.toBareJID());
return JID.equalsIgnoreCase(jid.toBareJID());
} else {
return super.equals(obj);
}
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if(obj instanceof NormalizedJID) {
NormalizedJID jid = (NormalizedJID)obj;
return JID.equalsIgnoreCase(jid.JID);
} else if(obj instanceof JID) {
JID jid = new JID( ((JID)obj).toBareJID() );
return JID.equalsIgnoreCase(jid.toBareJID());
} else if( obj instanceof String) {
JID jid = new JID((String)obj);
jid = new JID(jid.toBareJID());
return JID.equalsIgnoreCase(jid.toBareJID());
} else {
return super.equals(obj);
}
}
/**
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return JID.hashCode();
}
/**
/**
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return JID.hashCode();
}
/**
* Wrap a <code>JID</code> and return a <code>NormalizedJID</code>. If the
* <code>JID</code> has already been wrapped, then the cached version is returned.
*
* @param jid
* @return normalizedJID
*/
public static NormalizedJID wrap(JID jid) {
if(cache.containsKey(jid)) {
return cache.get(jid);
} else {
NormalizedJID nJID = new NormalizedJID(jid);
cache.put(jid, nJID);
return nJID;
}
}
* @param jid
* @return normalizedJID
*/
public static NormalizedJID wrap(JID jid) {
if(cache.containsKey(jid)) {
return cache.get(jid);
} else {
NormalizedJID nJID = new NormalizedJID(jid);
cache.put(jid, nJID);
return nJID;
}
}
/**
* @see java.lang.Object#toString()
......@@ -109,12 +109,12 @@ public final class NormalizedJID implements Serializable {
public String toString() {
return toStringValue;
}
/**
* The cache of <code>NormailzedJID</code>s.
*
* @see java.util.Map
*/
private transient static final Map<JID, NormalizedJID> cache = new ConcurrentHashMap<JID, NormalizedJID>();
/**
* The cache of <code>NormailzedJID</code>s.
*
* @see java.util.Map
*/
private transient static final Map<JID, NormalizedJID> cache = new ConcurrentHashMap<JID, NormalizedJID>();
}
......@@ -47,102 +47,102 @@ import org.xmpp.packet.JID;
*
*/
public class PersistenceManager implements Serializable {
/**
* The contactManager.
*
* @see ContactManager
*/
private ContactManager contactManager = null;
/**
* The contactManager.
*
* @see ContactManager
*/
private ContactManager contactManager = null;
/**
* The registrar.
*
* @see Registrar
*/
private Registrar registrar = null;
/**
* The registrar.
*
* @see Registrar
*/
private Registrar registrar = null;
/**
* The gateway.
*
* @see Gateway
*/
@SuppressWarnings("unused")
/**
* The gateway.
*
* @see Gateway
*/
@SuppressWarnings("unused")
private Gateway gateway;
/**
* Factory for accessing the various RosterManagers.
/**
* Factory for accessing the various RosterManagers.
*
* @author Noah Campbell
*/
public final static class Factory {
/**
* The <code>PersistanceManager</code> associated with a particular
* @author Noah Campbell
*/
public final static class Factory {
/**
* The <code>PersistanceManager</code> associated with a particular
* <code>Gateway</code>
*
* @see Factory
*/
private final static Map<Gateway, PersistenceManager> instances =
new HashMap<Gateway, PersistenceManager>();
*
* @see Factory
*/
private final static Map<Gateway, PersistenceManager> instances =
new HashMap<Gateway, PersistenceManager>();
/**
* Given a <code>Gateway</code> return a <code>PersistenceManager</code>
* @param gateway
* @return persistenceManager returns a <code>PersistenceManager</code>
* @see PersistenceManager
*/
public static synchronized PersistenceManager get(Gateway gateway) {
PersistenceManager rm = instances.get(gateway);
if(rm == null) {
rm = new PersistenceManager(gateway);
instances.put(gateway, rm);
}
return rm;
}
}
public static synchronized PersistenceManager get(Gateway gateway) {
PersistenceManager rm = instances.get(gateway);
if(rm == null) {
rm = new PersistenceManager(gateway);
instances.put(gateway, rm);
}
return rm;
}
}
/** The db file. */
private final File db;
/**
* Construct a new <code>PersistanceManager</code>.
/**
* Construct a new <code>PersistanceManager</code>.
*
* @param gateway
*/
private PersistenceManager(Gateway gateway) {
this.gateway = gateway;
* @param gateway
*/
private PersistenceManager(Gateway gateway) {
this.gateway = gateway;
db = new File("/tmp/." + this.gateway.getName().toLowerCase() + ".dat");
load(gateway);
timer.scheduleAtFixedRate(archiver, 5, 5, TimeUnit.SECONDS);
timer.scheduleAtFixedRate(archiver, 5, 5, TimeUnit.SECONDS);
}
/**
* Unregister a JID.
* @param jid
*/
public void remove(JID jid) {
String bareJID = jid.toBareJID();
try {
NormalizedJID njid = NormalizedJID.wrap(jid);
contactManager.remove(njid);
registrar.remove(jid);
} catch (Exception e) {
logger.severe("Unable to remove " + bareJID + ": " + e.getLocalizedMessage());
}
}
}
/**
* Unregister a JID.
* @param jid
*/
public void remove(JID jid) {
String bareJID = jid.toBareJID();
try {
NormalizedJID njid = NormalizedJID.wrap(jid);
contactManager.remove(njid);
registrar.remove(jid);
} catch (Exception e) {
logger.severe("Unable to remove " + bareJID + ": " + e.getLocalizedMessage());
}
}
/**
* Load the roster manager (we simply read a binary file from the file system).
* @param gateway
*/
private void load(Gateway gateway) {
/**
* Load the roster manager (we simply read a binary file from the file system).
* @param gateway
*/
private void load(Gateway gateway) {
ContactManager contactManager = null;
Registrar registrar = null;
try {
try {
/**
* The key is stored in the registry so the key is as secure as the
* registry is secure.
......@@ -160,62 +160,62 @@ public class PersistenceManager implements Serializable {
CipherInputStream cis = new CipherInputStream(new FileInputStream(db), c);
ObjectInputStream is = new ObjectInputStream(cis);
contactManager = (ContactManager)is.readObject() ;
registrar = (Registrar) is.readObject() ;
is.close();
} catch (Exception e) {
if(db.exists()) {
db.delete();
}
logger.log(Level.WARNING, "persistencemanager.loadrosterfailed",e);
} finally {
ObjectInputStream is = new ObjectInputStream(cis);
contactManager = (ContactManager)is.readObject() ;
registrar = (Registrar) is.readObject() ;
is.close();
} catch (Exception e) {
if(db.exists()) {
db.delete();
}
logger.log(Level.WARNING, "persistencemanager.loadrosterfailed",e);
} finally {
this.contactManager = (contactManager != null) ? contactManager : new ContactManager();
this.registrar = (registrar != null) ? registrar : new Registrar();
this.registrar.setGateway(gateway); // re-vitialize the registrar.
}
}
/**
* A timer for executing tasks related to PersistanceManager.
*
* @see java.util.concurrent.ScheduledExecutorService
*/
private final ScheduledExecutorService timer = Executors.newScheduledThreadPool(1, new BackgroundThreadFactory());
/**
* The serialVersionUID.
*
* @see PersistenceManager
*/
private static final long serialVersionUID = 1L;
/**
* The logger.
*
* @see PersistenceManager
*/
private static final Logger logger = Logger.getLogger("PersistenceManager", "gateway_i18n");
}
/**
* Responsible for flushing the in-memory database.
*/
private final Runnable archiver = new Runnable() {
public void run() {
try {
store();
} catch (Exception e) {
/**
* A timer for executing tasks related to PersistanceManager.
*
* @see java.util.concurrent.ScheduledExecutorService
*/
private final ScheduledExecutorService timer = Executors.newScheduledThreadPool(1, new BackgroundThreadFactory());
/**
* The serialVersionUID.
*
* @see PersistenceManager
*/
private static final long serialVersionUID = 1L;
/**
* The logger.
*
* @see PersistenceManager
*/
private static final Logger logger = Logger.getLogger("PersistenceManager", "gateway_i18n");
/**
* Responsible for flushing the in-memory database.
*/
private final Runnable archiver = new Runnable() {
public void run() {
try {
store();
} catch (Exception e) {
logger.log(Level.WARNING, "persistencemanager.unabletoflush", e);
e.printStackTrace();
}
}
};
/**
e.printStackTrace();
}
}
};
/**
* Write the contact manager and registrar to the file system.
*
* @throws Exception
*/
public synchronized void store() throws Exception {
* @throws Exception
*/
public synchronized void store() throws Exception {
Preferences prefs = Preferences.systemNodeForPackage(this.getClass());
......@@ -234,28 +234,28 @@ public class PersistenceManager implements Serializable {
c.init(Cipher.ENCRYPT_MODE, key);
CipherOutputStream os = new CipherOutputStream(new FileOutputStream(db), c);
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(contactManager);
oos.writeObject(contactManager);
oos.writeObject(registrar);
oos.flush();
oos.close();
oos.flush();
oos.close();
}
}
/**
* @return Returns the contactManager.
*/
public ContactManager getContactManager() {
return contactManager;
}
/**
* @return Returns the contactManager.
*/
public ContactManager getContactManager() {
return contactManager;
}
/**
* @return Returns the registrar.
*/
public Registrar getRegistrar() {
return registrar;
}
/**
* @return Returns the registrar.
*/
public Registrar getRegistrar() {
return registrar;
}
/**
......
......@@ -32,13 +32,13 @@ import org.xmpp.packet.JID;
* @version 1.0
*/
public class Registrar implements Serializable {
/**
* The serialVersionUID.
*
* @see Registrar
*/
private static final long serialVersionUID = 1L;
/**
* The serialVersionUID.
*
* @see Registrar
*/
private static final long serialVersionUID = 1L;
/**
* Construct a new <code>Registrar</code>.
*/
......@@ -46,52 +46,52 @@ public class Registrar implements Serializable {
createSessionCache();
}
/**
* Initializes a new session cache
*/
private void createSessionCache() {
/**
* Initializes a new session cache
*/
private void createSessionCache() {
sessions = new HashMap<JID, GatewaySession>();
}
/**
* GatewaySessions are maintained in the registration
*/
private final Map<NormalizedJID, SubscriptionInfo> registrar = new HashMap<NormalizedJID, SubscriptionInfo>();
/**
* The <code>GatewaySessions</code> mapped by <code>JID</code>
*
* @see java.util.Map
*/
private transient Map<JID, GatewaySession> sessions;
* GatewaySessions are maintained in the registration
*/
private final Map<NormalizedJID, SubscriptionInfo> registrar = new HashMap<NormalizedJID, SubscriptionInfo>();
/**
* The <code>GatewaySessions</code> mapped by <code>JID</code>
*
* @see java.util.Map
*/
private transient Map<JID, GatewaySession> sessions;
/**
* Determine if the JID is registered (based on the bare JID)
* @param id
* @return true/false
*/
public boolean isRegistered(NormalizedJID id) {
return registrar.containsKey(id);
}
/**
* Determine if the JID is registered (based on the bare JID)
* @param id
* @return true/false
*/
public boolean isRegistered(NormalizedJID id) {
return registrar.containsKey(id);
}
/**
* Add a JID to the registrar.
* @param id
* @param info
*/
public void add(JID id, SubscriptionInfo info) {
registrar.put(NormalizedJID.wrap(id), info);
//timer.scheduleAtFixedRate(info, 10, 10, TimeUnit.SECONDS);
}
/**
* Get the Session for a JID.
* Add a JID to the registrar.
* @param id
* @param info
*/
public void add(JID id, SubscriptionInfo info) {
registrar.put(NormalizedJID.wrap(id), info);
//timer.scheduleAtFixedRate(info, 10, 10, TimeUnit.SECONDS);
}
/**
* Get the Session for a JID.
*
* @param jid the <code>JID</code>
* @return session the gateway session
* @throws Exception
*/
public GatewaySession getGatewaySession(JID jid) throws Exception {
SubscriptionInfo info = registrar.get(NormalizedJID.wrap(jid));
* @param jid the <code>JID</code>
* @return session the gateway session
* @throws Exception
*/
public GatewaySession getGatewaySession(JID jid) throws Exception {
SubscriptionInfo info = registrar.get(NormalizedJID.wrap(jid));
if(info == null) {
throw new IllegalStateException("Please register before attempting to get a session");
}
......@@ -104,21 +104,21 @@ public class Registrar implements Serializable {
sessions.put(jid, session);
}
return sessions.get(jid);
}
}
/**
* @return collection of subscriptionInfos
*/
public Collection<SubscriptionInfo> getAllGatewaySessions() {
return registrar.values();
}
/**
* @return collection of subscriptionInfos
*/
public Collection<SubscriptionInfo> getAllGatewaySessions() {
return registrar.values();
}
/**
* @param gateway
*/
void setGateway(Gateway gateway) {
/**
* @param gateway
*/
void setGateway(Gateway gateway) {
this.gateway = gateway;
}
}
/**
* The gateway.
......@@ -126,21 +126,21 @@ public class Registrar implements Serializable {
* @see Gateway
*/
private transient Gateway gateway;
/**
* The logger.
*
* @see Registrar
*/
private static final Logger logger = Logger.getLogger("Registrar");
/**
* The logger.
*
* @see Registrar
*/
private static final Logger logger = Logger.getLogger("Registrar");
/**
* Removes the NormalizedJID from the registrar.
* @param jid
*/
void remove(JID jid) {
void remove(JID jid) {
NormalizedJID wrapped = NormalizedJID.wrap(jid);
registrar.remove(wrapped);
registrar.remove(wrapped);
GatewaySession session = sessions.get(jid);
if(session.isConnected()) {
try {
......@@ -149,7 +149,7 @@ public class Registrar implements Serializable {
// silently ignore
}
}
}
}
/**
* @param ois
......
......@@ -18,40 +18,40 @@ import java.io.Serializable;
* @author Noah Campbell
*/
public final class Status implements Serializable {
/** The serialVersionUID. */
private static final long serialVersionUID = 1L;
/** The subscribed. */
private boolean subscribed = false;
/** The serialVersionUID. */
private static final long serialVersionUID = 1L;
/** The subscribed. */
private boolean subscribed = false;
/** The online. */
private boolean online = false;
/** The value. */
private String value;
/**
* @return status a string representation of the status's state.
*/
public String getValue() { return value; }
/**
* @param value the new value of the status
*/
public void updateValue(String value) { this.value = value; }
/**
* @return Returns the subscribed.
*/
public boolean isSubscribed() {
return subscribed;
}
/**
* @param subscribed The subscribed to set.
*/
public void setSubscribed(boolean subscribed) {
this.subscribed = subscribed;
}
/** The value. */
private String value;
/**
* @return status a string representation of the status's state.
*/
public String getValue() { return value; }
/**
* @param value the new value of the status
*/
public void updateValue(String value) { this.value = value; }
/**
* @return Returns the subscribed.
*/
public boolean isSubscribed() {
return subscribed;
}
/**
* @param subscribed The subscribed to set.
*/
public void setSubscribed(boolean subscribed) {
this.subscribed = subscribed;
}
/**
* @return Returns the online.
*/
......@@ -64,5 +64,5 @@ public final class Status implements Serializable {
public void setOnline(boolean online) {
this.online = online;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment