String serviceDomain = getServiceDomain();
if (name == null && node == null) {
// Answer all first level nodes
for (Node pubNode : rootCollectionNode.getNodes()) {
if (canDiscoverNode(pubNode)) {
final DiscoItem item = new DiscoItem(
new JID(serviceDomain), pubNode.getName(),
pubNode.getNodeID(), null);
answer.add(item);
}
}
}
else if (name == null) {
Node pubNode = getNode(node);
if (pubNode != null && canDiscoverNode(pubNode)) {
if (pubNode.isCollectionNode()) {
// Answer all nested nodes as items
for (Node nestedNode : pubNode.getNodes()) {
if (canDiscoverNode(nestedNode)) {
final DiscoItem item = new DiscoItem(new JID(serviceDomain), nestedNode.getName(),
nestedNode.getNodeID(), null);
answer.add(item);
}
}
}
else {
// This is a leaf node so answer the published items which exist on the service
for (PublishedItem publishedItem : pubNode.getPublishedItems()) {
answer.add(new DiscoItem(new JID(serviceDomain), publishedItem.getID(), null, null));
}
}
}
else {
// Answer null to indicate that specified item was not found