Commit a0dec522 authored by Derek DeMoro's avatar Derek DeMoro Committed by derek

Refactoring


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@619 b35dd754-fafc-0310-a699-88a17e54d16e
parent 1a3b3462
...@@ -18,8 +18,6 @@ import org.jivesoftware.messenger.auth.UnauthorizedException; ...@@ -18,8 +18,6 @@ import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.net.SocketPacketWriteHandler; import org.jivesoftware.messenger.net.SocketPacketWriteHandler;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
import javax.xml.stream.XMLStreamException;
/** /**
* In-memory implementation of the packet deliverer service * In-memory implementation of the packet deliverer service
* *
...@@ -39,12 +37,12 @@ public class PacketDelivererImpl extends BasicModule implements PacketDeliverer ...@@ -39,12 +37,12 @@ public class PacketDelivererImpl extends BasicModule implements PacketDeliverer
super("Packet Delivery"); super("Packet Delivery");
} }
public void deliver(Packet packet) throws UnauthorizedException, PacketException, XMLStreamException { public void deliver(Packet packet) throws UnauthorizedException, PacketException {
if (packet == null) { if (packet == null) {
throw new PacketException("Packet was null"); throw new PacketException("Packet was null");
} }
if (deliverHandler == null) { if (deliverHandler == null) {
throw new XMLStreamException("Could not send packet - no route" + packet.toString()); throw new PacketException("Could not send packet - no route" + packet.toString());
} }
deliverHandler.process(packet); deliverHandler.process(packet);
} }
......
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.util;
import java.io.StringWriter;
import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
/**
* <p>A convenience for serializing XML to a String similar to StringWriter.</p>
*
* @author Iain Shigeoka
*/
public class StringXMLStreamWriter implements XMLStreamWriter {
private XMLStreamWriter ser;
private StringWriter writer;
public StringXMLStreamWriter() {
writer = new StringWriter();
try {
ser = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
}
catch (Exception e) {
//
}
}
public void setPrefix(String prefix, String namespace) throws
IllegalArgumentException, IllegalStateException, XMLStreamException {
ser.setPrefix(prefix, namespace);
}
public void setDefaultNamespace(String name) throws XMLStreamException {
ser.setDefaultNamespace(name);
}
public void setNamespaceContext(NamespaceContext namespaceContext) throws XMLStreamException {
ser.setNamespaceContext(namespaceContext);
}
public NamespaceContext getNamespaceContext() {
return ser.getNamespaceContext();
}
public Object getProperty(String name) throws IllegalArgumentException {
return ser.getProperty(name);
}
public void writeStartElement(String name) throws XMLStreamException {
ser.writeStartElement(name);
}
public void writeStartElement(String name, String name1) throws XMLStreamException {
ser.writeStartElement(name, name1);
}
public void writeStartElement(String name, String name1, String name2) throws XMLStreamException {
ser.writeStartElement(name, name1, name2);
}
public void writeEmptyElement(String name, String name1) throws XMLStreamException {
ser.writeEmptyElement(name, name1);
}
public void writeEmptyElement(String name, String name1, String name2) throws XMLStreamException {
ser.writeEmptyElement(name, name1, name2);
}
public void writeEmptyElement(String name) throws XMLStreamException {
ser.writeEmptyElement(name);
}
public void writeEndElement() throws XMLStreamException {
ser.writeEndElement();
}
public void writeEndDocument() throws XMLStreamException {
ser.writeEndDocument();
}
public void close() throws XMLStreamException {
ser.close();
}
public void flush() throws XMLStreamException {
ser.flush();
}
public void writeAttribute(String name, String name1) throws XMLStreamException {
ser.writeAttribute(name, name1);
}
public void writeAttribute(String name, String name1, String name2, String name3) throws XMLStreamException {
ser.writeAttribute(name, name1, name2, name3);
}
public void writeAttribute(String name, String name1, String name2) throws XMLStreamException {
ser.writeAttribute(name, name1, name2);
}
public void writeNamespace(String name, String name1) throws XMLStreamException {
ser.writeAttribute(name, name1);
}
public void writeDefaultNamespace(String name) throws XMLStreamException {
ser.writeDefaultNamespace(name);
}
public void writeComment(String name) throws XMLStreamException {
ser.writeComment(name);
}
public void writeProcessingInstruction(String name) throws XMLStreamException {
ser.writeProcessingInstruction(name);
}
public void writeProcessingInstruction(String name, String name1) throws XMLStreamException {
ser.writeProcessingInstruction(name, name1);
}
public void writeCData(String name) throws XMLStreamException {
ser.writeCData(name);
}
public void writeDTD(String name) throws XMLStreamException {
ser.writeDTD(name);
}
public void writeEntityRef(String name) throws XMLStreamException {
ser.writeEntityRef(name);
}
public void writeStartDocument() throws XMLStreamException {
ser.writeStartDocument();
}
public void writeStartDocument(String name) throws XMLStreamException {
ser.writeStartDocument(name);
}
public void writeStartDocument(String name, String name1) throws XMLStreamException {
ser.writeStartDocument(name, name1);
}
public void writeCharacters(String name) throws XMLStreamException {
ser.writeCharacters(name);
}
public void writeCharacters(char[] chars, int i, int i1) throws XMLStreamException {
ser.writeCharacters(chars, i, i1);
}
public String getPrefix(String name) throws XMLStreamException {
return ser.getPrefix(name);
}
public String toString() {
return writer.toString();
}
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.util;
import java.io.Reader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.dom4j.*;
/**
* Creates a document from the current XPP position. This is specialized
* for Jabber packets allowing a depth limit.
* We terminate the Document when we reach the closing tag of a subelement
* that's the depth rather than the end of the real document. This lets us
* extract subdocuments from a running XML stream.
*
* @author Iain Shigeoka
*/
public class XPPReader {
private static XMLInputFactory xmlFactory;
/**
* Empty constructor.
*/
private XPPReader() {
}
public static Document parseDocument(Reader input, Class context)
throws DocumentException, XMLStreamException {
if (xmlFactory == null) {
xmlFactory = XMLInputFactory.newInstance();
xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
}
XMLStreamReader xpp = xmlFactory.createXMLStreamReader(input);
Document document = DocumentHelper.createDocument();
for (int event = xpp.next(); event != XMLStreamConstants.START_ELEMENT; event = xpp.next()) {
if (event == XMLStreamConstants.COMMENT) {
document.addComment(xpp.getText());
}
}
document = parseDocument(xpp, document);
return document;
}
public static Document parseDocument(XMLStreamReader input)
throws DocumentException, XMLStreamException {
Document document = DocumentHelper.createDocument();
document = parseDocument(input, document);
return document;
}
private static Document parseDocument(XMLStreamReader xpp,
Document document) throws
DocumentException, XMLStreamException {
Branch parent = document;
int depth = 0;
int type = xpp.getEventType();
for (boolean endFound = false; ; type = xpp.next()) {
switch (type) {
case XMLStreamConstants.END_DOCUMENT:
throw new DocumentException("End of document");
case XMLStreamConstants.START_ELEMENT:
depth++;
Element newElement;
if (xpp.getNamespaceURI().equals("jabber:client")) {
newElement = DocumentHelper.createElement(xpp.getLocalName());
}
else {
newElement = DocumentHelper.createElement(QName.get(xpp.getLocalName(),
xpp.getNamespaceURI()));
}
for (int i = 0; i < xpp.getAttributeCount(); i++) {
newElement.addAttribute(xpp.getAttributeLocalName(i),
xpp.getAttributeValue(i));
}
parent.add(newElement);
parent = newElement;
break;
case XMLStreamConstants.END_ELEMENT:
depth--;
if (parent != null) {
parent = parent.getParent();
}
if (depth <= 0) {
endFound = true;
}
break;
case XMLStreamConstants.CDATA:
String cdata = xpp.getText();
if (parent != null) {
parent.add(DocumentHelper.createCDATA(cdata));
}
else {
throw new DocumentException(LocaleUtils.getLocalizedString("admin.error.packet.text"));
}
break;
case XMLStreamConstants.CHARACTERS:
String chars = xpp.getText();
if (parent != null) {
parent.add(DocumentHelper.createText(chars));
}
else {
throw new DocumentException(LocaleUtils.getLocalizedString("admin.error.packet.text"));
}
break;
case XMLStreamConstants.COMMENT:
parent.add(DocumentHelper.createComment(xpp.getText()));
break;
case XMLStreamConstants.ENTITY_REFERENCE:
Log.warn("Unexpected entity reference event occurred " + xpp.getText());
break;
default:
Log.warn("Unknown XML event occurred " + type);
}
if (endFound) {
break;
}
}
return document;
}
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.util;
import org.jivesoftware.messenger.XMPPFragment;
import java.io.Writer;
import java.util.Iterator;
import javax.xml.XMLConstants;
import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.dom4j.*;
/**
* <p>Writes out Dom4j documents using the XPP serializer.</p>
*
* @author Iain Shigeoka
*/
public class XPPWriter {
private static XMLOutputFactory xmlFactory;
/**
* <p>Writes out the given document.</p>
*
* @param doc The document to write
* @param out The writer to write to
*/
public static void write(Document doc, Writer out) throws XMLStreamException {
if (xmlFactory == null) {
xmlFactory = XMLOutputFactory.newInstance();
}
XMLStreamWriter serializer = xmlFactory.createXMLStreamWriter(out);
write(doc, serializer);
}
/**
* <p>Writes out the given document.</p>
*
* @param doc The document to write
* @param serializer The writer to write to
*/
public static void write(Document doc, XMLStreamWriter serializer)
throws XMLStreamException {
for (int i = 0, size = doc.nodeCount(); i < size; i++) {
Node node = doc.node(i);
writeNode(node, serializer);
}
serializer.flush();
}
/**
* <p>Writes out the given document.</p>
*
* @param element The element to write
* @param serializer The serializer to write to
*/
public static void write(Element element, XMLStreamWriter serializer)
throws XMLStreamException {
writeElement(element, serializer, null, -1);
serializer.flush();
}
/**
* <p>Writes out the given document.</p>
*
* @param element The element to write
* @param serializer The serializer to write to
*/
public static void write(Element element,
XMLStreamWriter serializer,
Iterator fragments,
int version)
throws XMLStreamException {
writeElement(element, serializer, fragments, version);
serializer.flush();
}
// Implementation methods
//-------------------------------------------------------------------------
private static void writeElement(Element element,
XMLStreamWriter serializer,
Iterator fragments,
int version)
throws XMLStreamException {
int size = element.nodeCount();
String namespace = element.getNamespace().getURI();
NamespaceContext context = serializer.getNamespaceContext();
if (namespace == null || "".equals(namespace)) {
// no namespace - must assume default namespace
serializer.writeStartElement(element.getName());
}
else {
String prefix = context.getPrefix(namespace);
if (prefix == null) {
// Unbound prefix, we'll set to default
serializer.writeStartElement(element.getName());
serializer.writeDefaultNamespace(namespace);
}
else if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
// Already in the default
serializer.writeStartElement(element.getName());
}
else {
// Uses a bound prefix
serializer.writeStartElement(prefix, element.getName());
}
}
writeAttributes(element, serializer);
if (size > 0) {
writeElementContent(element, serializer);
}
if (fragments != null) {
while (fragments.hasNext()) {
((XMPPFragment)fragments.next()).send(serializer, version);
}
}
serializer.writeEndElement();
}
/**
* Outputs the content of the given element. If whitespace trimming is
* enabled then all adjacent text nodes are appended together before
* the whitespace trimming occurs to avoid problems with multiple
* text nodes being created due to text content that spans parser buffers
* in a SAX parser.
*/
private static void writeElementContent(Element element, XMLStreamWriter serializer)
throws XMLStreamException {
for (int i = 0, size = element.nodeCount(); i < size; i++) {
Node node = element.node(i);
writeNode(node, serializer);
}
}
private static void writeNode(Node node, XMLStreamWriter serializer)
throws XMLStreamException {
int nodeType = node.getNodeType();
switch (nodeType) {
case Node.ELEMENT_NODE:
writeElement((Element)node, serializer, null, -1);
break;
case Node.ATTRIBUTE_NODE:
writeAttribute((Attribute)node, serializer);
break;
case Node.TEXT_NODE:
serializer.writeCharacters(node.getText());
break;
case Node.CDATA_SECTION_NODE:
serializer.writeCData(node.getText());
break;
case Node.ENTITY_REFERENCE_NODE:
serializer.writeEntityRef(node.getName());
break;
case Node.PROCESSING_INSTRUCTION_NODE:
serializer.writeProcessingInstruction(node.getText());
break;
case Node.COMMENT_NODE:
serializer.writeComment(node.getText());
break;
case Node.DOCUMENT_NODE:
serializer.writeStartDocument();
break;
case Node.DOCUMENT_TYPE_NODE:
break;
case Node.NAMESPACE_NODE:
// Will be output with attributes
//write((Namespace) node);
break;
default:
throw new XMLStreamException("Invalid node type: " + node);
}
}
/**
* Writes the attributes of the given element
*/
static private void writeAttributes(Element element, XMLStreamWriter serializer)
throws XMLStreamException {
for (int i = 0, size = element.attributeCount(); i < size; i++) {
Attribute attribute = element.attribute(i);
writeAttribute(attribute, serializer);
}
}
private static void writeAttribute(Attribute attribute, XMLStreamWriter serializer)
throws XMLStreamException {
Namespace ns = attribute.getNamespace();
serializer.writeAttribute(ns.getURI(), attribute.getName(), attribute.getValue());
}
}
...@@ -5,18 +5,13 @@ ...@@ -5,18 +5,13 @@
--%> --%>
<%@ page import="org.jivesoftware.util.ParamUtils, <%@ page import="org.jivesoftware.util.ParamUtils,
java.util.Iterator" java.util.Iterator,
org.jivesoftware.messenger.user.User"
errorPage="error.jsp" errorPage="error.jsp"
%> %>
<%@ include file="global.jsp" %> <%@ include file="global.jsp" %>
<% // Check to see if the server is down.
if (xmppServer == null) {
response.sendRedirect("error-serverdown.jsp");
return;
}
%>
<% // Get parameters <% // Get parameters
int start = ParamUtils.getIntParameter(request,"start",0); int start = ParamUtils.getIntParameter(request,"start",0);
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<%@ page import="org.jivesoftware.util.*, <%@ page import="org.jivesoftware.util.*,
org.jivesoftware.messenger.user.*, org.jivesoftware.messenger.user.*,
org.jivesoftware.admin.*, org.jivesoftware.admin.*,
org.jivesoftware.messenger.XMPPAddress" org.xmpp.packet.JID"
errorPage="error.jsp" errorPage="error.jsp"
%> %>
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
// Delete the user // Delete the user
webManager.getUserManager().deleteUser(user); webManager.getUserManager().deleteUser(user);
// Delete the user's roster // Delete the user's roster
XMPPAddress userAddress = new XMPPAddress(username, webManager.getServerInfo().getName(), null); JID userAddress = new JID(username, webManager.getServerInfo().getName(), null);
webManager.getRosterManager().deleteRoster(userAddress); webManager.getRosterManager().deleteRoster(userAddress);
// Deleted your own user account, force login // Deleted your own user account, force login
if (username.equals(webManager.getAuthToken().getUsername())){ if (username.equals(webManager.getAuthToken().getUsername())){
......
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
<%@ page import="org.jivesoftware.util.*, <%@ page import="org.jivesoftware.util.*,
org.jivesoftware.messenger.user.UserManager, org.jivesoftware.messenger.user.UserManager,
java.text.DateFormat" java.text.DateFormat,
org.jivesoftware.messenger.user.User,
org.jivesoftware.messenger.user.spi.UserManagerImpl"
errorPage="error.jsp" errorPage="error.jsp"
%> %>
......
...@@ -17,7 +17,8 @@ ...@@ -17,7 +17,8 @@
java.text.DateFormat, java.text.DateFormat,
java.util.HashMap, java.util.HashMap,
org.jivesoftware.messenger.user.*, org.jivesoftware.messenger.user.*,
java.util.Map" java.util.Map,
org.xmpp.packet.JID"
errorPage="error.jsp" errorPage="error.jsp"
%> %>
...@@ -81,13 +82,13 @@ ...@@ -81,13 +82,13 @@
// loop through all sessions based on the user assoc with the JID, send // loop through all sessions based on the user assoc with the JID, send
// message to all // message to all
for (int i=0; i<jids.length; i++) { for (int i=0; i<jids.length; i++) {
XMPPAddress address = XMPPAddress.parseJID(jids[i]); JID address = new JID(jids[i]);
Session s = sessionManager.getSession(address); Session s = sessionManager.getSession(address);
sessionManager.sendServerMessage(address, null, message); sessionManager.sendServerMessage(address, null, message);
} }
} }
else { else {
sessionManager.sendServerMessage(XMPPAddress.parseJID(jid),null,message); sessionManager.sendServerMessage(new JID(jid),null,message);
} }
} }
if (username != null){ if (username != null){
......
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
java.text.DateFormat, java.text.DateFormat,
java.util.*, java.util.*,
org.jivesoftware.admin.*, org.jivesoftware.admin.*,
org.jivesoftware.messenger.*" org.jivesoftware.messenger.*,
org.xmpp.packet.Presence"
errorPage="error.jsp" errorPage="error.jsp"
%> %>
...@@ -138,23 +139,23 @@ Below is a summary of user properties. To edit properties, click the "Edit" butt ...@@ -138,23 +139,23 @@ Below is a summary of user properties. To edit properties, click the "Edit" butt
<% if (presenceManager.isAvailable(user)) { <% if (presenceManager.isAvailable(user)) {
Presence presence = presenceManager.getPresence(user); Presence presence = presenceManager.getPresence(user);
%> %>
<% if (presence.getShow() == Presence.SHOW_NONE) { %> <% if (presence.getShow() == null) { %>
<img src="images/user-green-16x16.gif" width="16" height="16" border="0" alt="Available"> <img src="images/user-green-16x16.gif" width="16" height="16" border="0" alt="Available">
Available Available
<% } %> <% } %>
<% if (presence.getShow() == Presence.SHOW_CHAT) { %> <% if (presence.getShow() == Presence.Show.chat) { %>
<img src="images/user-green-16x16.gif" width="16" height="16" border="0" alt="Available to Chat"> <img src="images/user-green-16x16.gif" width="16" height="16" border="0" alt="Available to Chat">
Available to Chat Available to Chat
<% } %> <% } %>
<% if (presence.getShow() == Presence.SHOW_AWAY) { %> <% if (presence.getShow() == Presence.Show.away) { %>
<img src="images/user-yellow-16x16.gif" width="16" height="16" border="0" alt="Away"> <img src="images/user-yellow-16x16.gif" width="16" height="16" border="0" alt="Away">
Away Away
<% } %> <% } %>
<% if (presence.getShow() == Presence.SHOW_XA) { %> <% if (presence.getShow() == Presence.Show.xa) { %>
<img src="images/user-yellow-16x16.gif" width="16" height="16" border="0" alt="Extended Away"> <img src="images/user-yellow-16x16.gif" width="16" height="16" border="0" alt="Extended Away">
Extended Away Extended Away
<% } %> <% } %>
<% if (presence.getShow() == Presence.SHOW_DND) { %> <% if (presence.getShow() == Presence.Show.dnd) { %>
<img src="images/user-red-16x16.gif" width="16" height="16" border="0" alt="Do not Disturb"> <img src="images/user-red-16x16.gif" width="16" height="16" border="0" alt="Do not Disturb">
Do not Disturb Do not Disturb
<% } %> <% } %>
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
java.text.DateFormat, java.text.DateFormat,
org.jivesoftware.admin.*, org.jivesoftware.admin.*,
org.jivesoftware.messenger.PresenceManager, org.jivesoftware.messenger.PresenceManager,
org.jivesoftware.messenger.Presence" org.xmpp.packet.Presence"
%> %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %> <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
...@@ -141,19 +141,19 @@ Sorted by Username ...@@ -141,19 +141,19 @@ Sorted by Username
<% if (presenceManager.isAvailable(user)) { <% if (presenceManager.isAvailable(user)) {
Presence presence = presenceManager.getPresence(user); Presence presence = presenceManager.getPresence(user);
%> %>
<% if (presence.getShow() == Presence.SHOW_NONE) { %> <% if (presence.getShow() == null) { %>
<img src="images/user-green-16x16.gif" width="16" height="16" border="0" alt="Available"> <img src="images/user-green-16x16.gif" width="16" height="16" border="0" alt="Available">
<% } %> <% } %>
<% if (presence.getShow() == Presence.SHOW_CHAT) { %> <% if (presence.getShow() == Presence.Show.chat) { %>
<img src="images/user-green-16x16.gif" width="16" height="16" border="0" alt="Available to Chat"> <img src="images/user-green-16x16.gif" width="16" height="16" border="0" alt="Available to Chat">
<% } %> <% } %>
<% if (presence.getShow() == Presence.SHOW_AWAY) { %> <% if (presence.getShow() == Presence.Show.away) { %>
<img src="images/user-yellow-16x16.gif" width="16" height="16" border="0" alt="Away"> <img src="images/user-yellow-16x16.gif" width="16" height="16" border="0" alt="Away">
<% } %> <% } %>
<% if (presence.getShow() == Presence.SHOW_XA) { %> <% if (presence.getShow() == Presence.Show.xa) { %>
<img src="images/user-yellow-16x16.gif" width="16" height="16" border="0" alt="Extended Away"> <img src="images/user-yellow-16x16.gif" width="16" height="16" border="0" alt="Extended Away">
<% } %> <% } %>
<% if (presence.getShow() == Presence.SHOW_DND) { %> <% if (presence.getShow() == Presence.Show.dnd) { %>
<img src="images/user-red-16x16.gif" width="16" height="16" border="0" alt="Do not Disturb"> <img src="images/user-red-16x16.gif" width="16" height="16" border="0" alt="Do not Disturb">
<% } %> <% } %>
......
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