use of org.dom4j.Element in project Openfire by igniterealtime.
the class ProcessPacketTask method readExternal.
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
if (ExternalizableUtil.getInstance().readBoolean(in)) {
address = (JID) ExternalizableUtil.getInstance().readSerializable(in);
}
if (ExternalizableUtil.getInstance().readBoolean(in)) {
streamID = BasicStreamIDFactory.createStreamID(ExternalizableUtil.getInstance().readSafeUTF(in));
}
sessionType = SessionType.values()[ExternalizableUtil.getInstance().readInt(in)];
int packetType = ExternalizableUtil.getInstance().readInt(in);
Element packetElement = (Element) ExternalizableUtil.getInstance().readSerializable(in);
switch(packetType) {
case 1:
packet = new IQ(packetElement, true);
break;
case 2:
packet = new Message(packetElement, true);
break;
case 3:
packet = new Presence(packetElement, true);
break;
}
}
use of org.dom4j.Element in project Openfire by igniterealtime.
the class BookmarkInterceptor method addBookmarkElement.
/**
* Adds a Bookmark to the users defined list of bookmarks.
*
* @param jid the users jid.
* @param bookmark the bookmark to be added.
* @param element the storage element to append to.
*/
private void addBookmarkElement(JID jid, Bookmark bookmark, Element element) {
final UserManager userManager = UserManager.getInstance();
try {
userManager.getUser(jid.getNode());
} catch (UserNotFoundException e) {
return;
}
// do not add duplicate bookmarks.
if (bookmark.getType() == Bookmark.Type.url) {
Element urlBookmarkElement = urlExists(element, bookmark.getValue());
if (urlBookmarkElement == null) {
urlBookmarkElement = element.addElement("url");
urlBookmarkElement.addAttribute("name", bookmark.getName());
urlBookmarkElement.addAttribute("url", bookmark.getValue());
// Add an RSS attribute to the bookmark if it's defined. RSS isn't an
// official part of the Bookmark JEP, but we define it as a logical
// extension.
boolean rss = Boolean.valueOf(bookmark.getProperty("rss"));
if (rss) {
urlBookmarkElement.addAttribute("rss", Boolean.toString(rss));
}
}
appendSharedElement(urlBookmarkElement);
} else // Otherwise it's a conference bookmark.
{
try {
Element conferenceElement = conferenceExists(element, bookmark.getValue());
// reply.
if (conferenceElement == null) {
conferenceElement = element.addElement("conference");
conferenceElement.addAttribute("name", bookmark.getName());
boolean autojoin = Boolean.valueOf(bookmark.getProperty("autojoin"));
conferenceElement.addAttribute("autojoin", Boolean.toString(autojoin));
conferenceElement.addAttribute("jid", bookmark.getValue());
boolean nameasnick = Boolean.valueOf(bookmark.getProperty("nameasnick"));
if (nameasnick) {
User currentUser = userManager.getUser(jid.getNode());
Element nick = conferenceElement.addElement("nick");
nick.addText(currentUser.getName());
}
}
appendSharedElement(conferenceElement);
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
}
use of org.dom4j.Element in project Openfire by igniterealtime.
the class BroadcastPlugin method processIQ.
private void processIQ(IQ iq, boolean targetAll, Group group, boolean canProceed) {
IQ reply = IQ.createResultIQ(iq);
Element childElement = iq.getChildElement();
String namespace = childElement.getNamespaceURI();
Element childElementCopy = iq.getChildElement().createCopy();
reply.setChildElement(childElementCopy);
if ("http://jabber.org/protocol/disco#info".equals(namespace)) {
if (iq.getTo().getNode() == null) {
// Return service identity and features
Element identity = childElementCopy.addElement("identity");
identity.addAttribute("category", "component");
identity.addAttribute("type", "generic");
identity.addAttribute("name", "Broadcast service");
childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#info");
childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#items");
} else {
if (targetAll) {
// Return identity and features of the "all" group
Element identity = childElementCopy.addElement("identity");
identity.addAttribute("category", "component");
identity.addAttribute("type", "generic");
identity.addAttribute("name", "Broadcast all connected users");
childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#info");
} else if (group != null && canProceed) {
// Return identity and features of the "all" group
Element identity = childElementCopy.addElement("identity");
identity.addAttribute("category", "component");
identity.addAttribute("type", "generic");
identity.addAttribute("name", "Broadcast " + group.getName());
childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#info");
} else {
// Group not found or not allowed to use that group so
// answer item_not_found error
reply.setError(PacketError.Condition.item_not_found);
}
}
} else if ("http://jabber.org/protocol/disco#items".equals(namespace)) {
if (iq.getTo().getNode() == null) {
// Return the list of groups hosted by the service that can be used by the user
Collection<Group> groups;
JID address = new JID(iq.getFrom().toBareJID());
if (allowedUsers.contains(address)) {
groups = groupManager.getGroups();
} else {
groups = groupManager.getGroups(iq.getFrom());
}
for (Group userGroup : groups) {
try {
JID groupJID = new JID(userGroup.getName() + "@" + serviceName + "." + componentManager.getServerName());
childElementCopy.addElement("item").addAttribute("jid", groupJID.toString());
} catch (Exception e) {
// Group name is not valid to be used as a JID
}
}
if (allowedUsers.isEmpty() || allowedUsers.contains(address)) {
// Add the "all" group to the list
childElementCopy.addElement("item").addAttribute("jid", "all@" + serviceName + "." + componentManager.getServerName());
}
}
} else {
// Answer an error since the server can't handle the requested namespace
reply.setError(PacketError.Condition.service_unavailable);
}
try {
componentManager.sendPacket(this, reply);
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
use of org.dom4j.Element in project Openfire by igniterealtime.
the class SparkManager method processPacket.
/**
* Client features are detected using Service Discovery, allowing
* for ease of use within the client. When a client "discovers" the
* manager, they can query for related features within that discovered item.
*
* @param packet the packet
*/
public void processPacket(Packet packet) {
if (packet instanceof IQ) {
IQ iqPacket = (IQ) packet;
Element childElement = (iqPacket).getChildElement();
String namespace = null;
if (childElement != null) {
namespace = childElement.getNamespaceURI();
}
if (IQ.Type.get == iqPacket.getType()) {
// Handle any disco info requests.
if ("http://jabber.org/protocol/disco#info".equals(namespace)) {
handleDiscoInfo(iqPacket);
} else // Handle any disco item requests.
if ("http://jabber.org/protocol/disco#items".equals(namespace)) {
handleDiscoItems(iqPacket);
} else if ("jabber:iq:version".equals(namespace)) {
IQ reply = IQ.createResultIQ(iqPacket);
Element version = reply.setChildElement("query", "jabber:iq:version");
version.addElement("name").setText("Client Control Manager");
version.addElement("version").setText("3.5");
sendPacket(reply);
} else {
// Return error since this is an unknown service request
IQ reply = IQ.createResultIQ(iqPacket);
reply.setError(PacketError.Condition.service_unavailable);
sendPacket(reply);
}
} else if (IQ.Type.error == iqPacket.getType() || IQ.Type.result == iqPacket.getType()) {
if ("jabber:iq:version".equals(namespace)) {
handleClientVersion(iqPacket);
}
} else {
// Return error since this is an unknown service request
IQ reply = IQ.createResultIQ(iqPacket);
reply.setError(PacketError.Condition.service_unavailable);
sendPacket(reply);
}
}
}
use of org.dom4j.Element in project Openfire by igniterealtime.
the class DeleteWorkgroup method execute.
@Override
public void execute(SessionData data, Element command) {
Element note = command.addElement("note");
// Get requested group
WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
// Load the workgroup
try {
Workgroup workgroup = workgroupManager.getWorkgroup(new JID(data.getData().get("workgroup").get(0)));
workgroupManager.deleteWorkgroup(workgroup);
} catch (UserNotFoundException e) {
// Group not found
note.addAttribute("type", "error");
note.setText("Workgroup not found");
return;
} catch (Exception e) {
// Group not found
note.addAttribute("type", "error");
note.setText("Error executing the command");
return;
}
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
Aggregations