use of org.dom4j.Element in project Openfire by igniterealtime.
the class ClientToComponentUpdateProcessor method process.
@Override
public void process(Packet packet, String subdomain, String to, String from) throws PacketRejectedException {
Log.debug("Processing packet in ClientToComponentUpdateProcessor: " + packet.toString());
Element query = ((IQ) packet).getChildElement();
List<Node> nodes = findNodesInDocument(query.getDocument(), "//roster:item");
if (nodes.size() > 0) {
// against our valid subdomains.
for (Node n : nodes) {
String jid = n.valueOf("@jid");
// TODO: We ignore remove iq packets for now. There might be
// conflicts
// when we remove our legacy network registration.
String found_subdomain = searchJIDforSubdomain(jid);
if (found_subdomain.length() > 0 && !n.valueOf("@subscription").equals("remove")) {
Log.debug("Mirroring packet from local network to legacy component " + found_subdomain);
IQ forward = (IQ) packet.createCopy();
forward.setTo(found_subdomain);
dispatchPacket(forward);
}
}
}
}
use of org.dom4j.Element in project Openfire by igniterealtime.
the class DiscoIQRegisteredProcessor method process.
@Override
public void process(Packet packet, final String subdomain, String to, String from) throws PacketRejectedException {
Log.debug("Processing packet in DiscoIQRegisteredProcessor for " + subdomain);
// Check if the jabber:iq:register is enabled in admin panel
boolean isFeatureEnabled = JiveGlobals.getBooleanProperty("plugin.remoteroster.sparkDiscoInfo", false);
if (!isFeatureEnabled) {
Log.debug("Spark extension is deactivated. Won't change the disco#info");
return;
}
final InterceptorManager interceptorManager = InterceptorManager.getInstance();
final PacketInterceptor interceptor = new PacketInterceptor() {
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) throws PacketRejectedException {
if (!processed && incoming) {
if (packet instanceof IQ) {
IQ iqPacket = (IQ) packet;
Element packetElement = iqPacket.getChildElement();
if (packetElement == null)
return;
String ns = iqPacket.getChildElement().getNamespace().getURI();
if (iqPacket.getType().equals(IQ.Type.result) && ns.equals("jabber:iq:register") && iqPacket.getFrom().toString().equals(subdomain)) {
// Check if we are already registered
setRegistered(iqPacket.toString().contains("<registered/>"));
throw new PacketRejectedException();
} else if (iqPacket.getType().equals(IQ.Type.result) && ns.equals("http://jabber.org/protocol/disco#info") && iqPacket.getFrom().toString().equals(subdomain)) {
/*
* This is the answer of the disco#info from spark
* to our component. add the jabber:iq:register
* feature if we are registered
*/
if (isRegistered()) {
Log.debug("Modifying disco#info packge to send registered iq feature to Spark user " + iqPacket.getTo().toString());
Attribute attribut = new DefaultAttribute("var", "jabber:iq:registered");
iqPacket.getChildElement().addElement("feature").add(attribut);
}
}
}
}
}
};
Log.debug("Creating my own listener for jabber:iq:register result to external component " + subdomain);
interceptorManager.addInterceptor(interceptor);
IQ askComponent = new IQ();
askComponent.setTo(to);
askComponent.setFrom(from);
askComponent.setType(IQ.Type.get);
Element query = new DefaultElement(QName.get("query", "jabber:iq:register"));
askComponent.setChildElement(query);
// Remove the package intercepter in 1sec
TimerTask removeInterceptorTask = new TimerTask() {
@Override
public void run() {
Log.debug("Removing my created listener for jabber:iq:register. Component " + subdomain);
interceptorManager.removeInterceptor(interceptor);
}
};
Timer timer = new Timer();
timer.schedule(removeInterceptorTask, 1000);
// Send the register query to component
dispatchPacket(askComponent);
}
use of org.dom4j.Element in project Openfire by igniterealtime.
the class IQRosterPayloadProcessor method sendRosterToComponent.
private void sendRosterToComponent(IQ requestPacket, Collection<RosterItem> items, String subdomain) {
IQ response = IQ.createResultIQ(requestPacket);
response.setTo(subdomain);
Element query = new DefaultElement(QName.get("query", "jabber:iq:roster"));
for (RosterItem i : items) {
String jid = i.getJid().toString();
if (!jid.equals(subdomain) && jid.contains(subdomain)) {
Log.debug("Roster exchange for external component " + subdomain + ". Sending user " + i.getJid().toString());
Element item = new DefaultElement("item", null);
item.add(new DefaultAttribute("jid", i.getJid().toString()));
item.add(new DefaultAttribute("name", i.getNickname()));
item.add(new DefaultAttribute("subscription", "both"));
for (String s : i.getGroups()) {
Element group = new DefaultElement("group");
group.setText(s);
item.add(group);
}
query.add(item);
}
}
response.setChildElement(query);
dispatchPacket(response);
}
use of org.dom4j.Element in project Openfire by igniterealtime.
the class WorkgroupPresence method sendPresence.
/**
* Sends the presence of the workgroup to the specified JID address.
*
* @param address the XMPP address that will receive the presence of the workgroup.
*/
public void sendPresence(JID address) {
Presence presence = new Presence();
presence.setTo(address);
presence.setFrom(workgroup.getJID());
Presence.Type type;
if (workgroup.isAvailable()) {
type = null;
// Add the a child element that will contain information about the workgroup
Element child = presence.addChildElement("workgroup", "http://jivesoftware.com/protocol/workgroup");
// Add the last modification date of the workgroup
child.addElement("lastModified").setText(UTC_FORMAT.format(workgroup.getModificationDate()));
} else {
type = Presence.Type.unavailable;
// Add the a child element that will contain information about the workgroup
Element child = presence.addChildElement("workgroup", "http://jivesoftware.com/protocol/workgroup");
// Add the last modification date of the workgroup
child.addElement("lastModified").setText(UTC_FORMAT.format(workgroup.getModificationDate()));
}
presence.setType(type);
workgroup.send(presence);
}
use of org.dom4j.Element in project Openfire by igniterealtime.
the class IQRosterPayloadProcessor method sendEmptyRoster.
private void sendEmptyRoster(Packet requestPacket, String subdomain) {
IQ iq = (IQ) requestPacket;
IQ response = IQ.createResultIQ(iq);
response.setTo(subdomain);
Element query = new DefaultElement(QName.get("query", "jabber:iq:roster"));
response.setChildElement(query);
dispatchPacket(response);
}
Aggregations