Commit 37c219fc authored by Derek DeMoro's avatar Derek DeMoro Committed by derek

Refactoring work.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@603 b35dd754-fafc-0310-a699-88a17e54d16e
parent 46c0e2a4
...@@ -18,6 +18,7 @@ import org.xmlpull.v1.XmlPullParserException; ...@@ -18,6 +18,7 @@ import org.xmlpull.v1.XmlPullParserException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.io.Writer;
/** /**
* <p>Represents a connection on the server.</p> * <p>Represents a connection on the server.</p>
...@@ -64,6 +65,8 @@ public interface Connection { ...@@ -64,6 +65,8 @@ public interface Connection {
*/ */
XMLWriter getSerializer() throws UnauthorizedException; XMLWriter getSerializer() throws UnauthorizedException;
Writer getWriter() throws UnauthorizedException;
/** /**
* Close this session including associated socket connection. * Close this session including associated socket connection.
* <p/> * <p/>
......
...@@ -24,6 +24,7 @@ import java.net.InetAddress; ...@@ -24,6 +24,7 @@ import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Date; import java.util.Date;
import java.io.IOException; import java.io.IOException;
import java.io.Writer;
public class ServerSession implements Session { public class ServerSession implements Session {
...@@ -145,6 +146,10 @@ public class ServerSession implements Session { ...@@ -145,6 +146,10 @@ public class ServerSession implements Session {
return null; return null;
} }
public Writer getWriter() throws UnauthorizedException {
return null;
}
public void close() throws UnauthorizedException { public void close() throws UnauthorizedException {
} }
......
...@@ -14,11 +14,10 @@ package org.jivesoftware.messenger.net; ...@@ -14,11 +14,10 @@ package org.jivesoftware.messenger.net;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Writer;
import java.net.Socket; import java.net.Socket;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.io.XMLWriter;
import org.dom4j.io.XPPPacketReader; import org.dom4j.io.XPPPacketReader;
import org.jivesoftware.messenger.Connection; import org.jivesoftware.messenger.Connection;
import org.jivesoftware.messenger.PacketRouter; import org.jivesoftware.messenger.PacketRouter;
...@@ -237,21 +236,10 @@ public class SocketReadThread extends Thread { ...@@ -237,21 +236,10 @@ public class SocketReadThread extends Thread {
throw new XmlPullParserException(LocaleUtils.getLocalizedString("admin.error.bad-namespace")); throw new XmlPullParserException(LocaleUtils.getLocalizedString("admin.error.bad-namespace"));
} }
// Flush this to the Connection to start up. Writer writer = connection.getWriter();
XMLWriter xser = connection.getSerializer(); String startPacket = "<?xml version='1.0' encoding='"+charset+"'?><stream:stream xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\"jabber:client\" from=\""+serverName+"\" id=\""+session.getStreamID().toString()+"\">";
String s = "<stream:stream to=\"jivesoftware.com\" xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" version=\"1.0\" >"; writer.write(startPacket);
Element streamElement = null; writer.flush();
try {
streamElement = DocumentHelper.createElement(s);
}
catch (Exception e) {
e.printStackTrace();
}
streamElement.addAttribute("from", serverName);
streamElement.addAttribute("id", session.getStreamID().toString());
xser.write(streamElement);
xser.flush();
// TODO: check for SASL support in opening stream tag // TODO: check for SASL support in opening stream tag
} }
......
...@@ -11,18 +11,14 @@ ...@@ -11,18 +11,14 @@
package org.jivesoftware.messenger.user.spi; package org.jivesoftware.messenger.user.spi;
import org.jivesoftware.util.ConcurrentHashSet;
import org.jivesoftware.messenger.user.BasicRosterItem;
import org.jivesoftware.messenger.user.IQRosterItem;
import org.jivesoftware.messenger.user.RosterItem;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.dom4j.DocumentHelper; import org.dom4j.DocumentHelper;
import org.dom4j.Element; import org.dom4j.Element;
import org.jivesoftware.messenger.user.BasicRosterItem;
import org.jivesoftware.messenger.user.IQRosterItem;
import org.jivesoftware.messenger.user.RosterItem;
import org.jivesoftware.util.ConcurrentHashSet;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
public class IQRosterItemImpl extends BasicRosterItem implements IQRosterItem { public class IQRosterItemImpl extends BasicRosterItem implements IQRosterItem {
...@@ -84,48 +80,6 @@ public class IQRosterItemImpl extends BasicRosterItem implements IQRosterItem { ...@@ -84,48 +80,6 @@ public class IQRosterItemImpl extends BasicRosterItem implements IQRosterItem {
// do nothing // do nothing
} }
public void send(XMLStreamWriter xmlSerializer, int version) throws XMLStreamException {
xmlSerializer.writeStartElement("jabber:iq:roster", "item");
xmlSerializer.writeAttribute("jid", jid.toBareJID());
xmlSerializer.writeAttribute("subscription", subStatus.getName());
if (askStatus != ASK_NONE) {
xmlSerializer.writeAttribute("ask", askStatus.getName());
}
if (nickname != null) {
if (nickname.trim().length() > 0) {
xmlSerializer.writeAttribute("name", nickname.trim());
}
}
if (groups != null) {
Iterator groupsItr = groups.iterator();
while (groupsItr.hasNext()) {
xmlSerializer.writeStartElement("jabber:iq:roster", "group");
xmlSerializer.writeCharacters((String)groupsItr.next());
xmlSerializer.writeEndElement();
}
}
Iterator frags = fragments.iterator();
while (frags.hasNext()) {
Element frag = (Element)frags.next();
frag.send(xmlSerializer, version);
}
xmlSerializer.writeEndElement();
}
public IQRosterItem createDeepCopy() {
IQRosterItemImpl item = new IQRosterItemImpl(new JID(jid.getNode(), jid.getDomain(), jid.getResource()));
item.subStatus = subStatus;
item.askStatus = askStatus;
item.recvStatus = recvStatus;
item.nickname = nickname;
if (groups != null) {
item.groups = new ArrayList(groups.size());
Collections.copy(item.groups, groups);
}
item.fragments = (ConcurrentHashSet)fragments.clone();
return item;
}
private ConcurrentHashSet fragments = new ConcurrentHashSet(); private ConcurrentHashSet fragments = new ConcurrentHashSet();
public void addFragment(Element fragment) { public void addFragment(Element fragment) {
......
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