reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.service_unavailable);
return reply;
}
final JID senderJID = packet.getFrom();
if (packet.getTo() == null) {
// packet addressed to service itself (not to a node/user)
if (packet.getType() == IQ.Type.set) {
final String jidFrom = senderJID.toBareJID();
PEPService pepService = pepServiceManager.getPEPService(jidFrom);
// If no service exists yet for jidFrom, create one.
if (pepService == null) {
try {
pepService = pepServiceManager.create(senderJID);
} catch (IllegalArgumentException ex) {
final IQ reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.not_allowed);
return reply;
}
// Probe presences
pepServiceManager.start(pepService);
// Those who already have presence subscriptions to jidFrom
// will now automatically be subscribed to this new
// PEPService.
try {
final RosterManager rm = XMPPServer.getInstance()
.getRosterManager();
final Roster roster = rm.getRoster(senderJID.getNode());
for (final RosterItem item : roster.getRosterItems()) {
if (item.getSubStatus() == RosterItem.SUB_BOTH
|| item.getSubStatus() == RosterItem.SUB_FROM) {
createSubscriptionToPEPService(pepService, item
.getJid(), senderJID);
}
}
} catch (UserNotFoundException e) {
// Do nothing
}
}
// If publishing a node, and the node doesn't exist, create it.
final Element childElement = packet.getChildElement();
final Element publishElement = childElement.element("publish");
if (publishElement != null) {
final String nodeID = publishElement.attributeValue("node");
// Do not allow User Avatar nodes to be created.
// TODO: Implement XEP-0084
if (nodeID.startsWith("http://www.xmpp.org/extensions/xep-0084.html")) {
IQ reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.feature_not_implemented);
return reply;
}
if (pepService.getNode(nodeID) == null) {
// Create the node
final JID creator = new JID(jidFrom);
final LeafNode newNode = new LeafNode(pepService, pepService.getRootCollectionNode(), nodeID, creator);
newNode.addOwner(creator);
newNode.saveToDB();
}
}