String nodeName = publish.getAttributeValue("node"); // MUST
XMLElement item = publish.getFirstInnerElement();
String strID = item.getAttributeValue("id"); // MAY
LeafNode node = root.find(nodeName);
if(node == null) {
// node does not exist - error condition 3 (7.1.3)
return errorStanzaGenerator.generateNoNodeErrorStanza(sender, serverJID, stanza);
}
if(!node.isAuthorized(sender, PubSubPrivilege.PUBLISH)) {
// not enough privileges to publish - error condition 1 (7.1.3)
return errorStanzaGenerator.generateInsufficientPrivilegesErrorStanza(sender, serverJID, stanza);
}
if(strID == null) {
strID = idGenerator.create();
// wrap a new item element with the id attribute
StanzaBuilder itemBuilder = new StanzaBuilder("item");
itemBuilder.addAttribute("id", strID);
itemBuilder.addPreparedElement(item.getFirstInnerElement());
item = itemBuilder.build();
}
StanzaRelay relay = serverRuntimeContext.getStanzaRelay();
node.publish(sender, relay, strID, item);
buildSuccessStanza(sb, nodeName, strID);
sb.endInnerElement(); // pubsub
return new IQStanza(sb.build());