public void collectionToSAX(Collection collection) throws SAXException {
String ncollections;
String nresources;
String[] resources;
String[] collections;
try {
ncollections = Integer.toString(collection.getChildCollectionCount());
nresources = Integer.toString(collection.getResourceCount());
attributes.clear();
attributes.addAttribute("", RESOURCE_COUNT_ATTR,
RESOURCE_COUNT_ATTR, "CDATA", nresources);
attributes.addAttribute("", COLLECTION_COUNT_ATTR,
COLLECTION_COUNT_ATTR, "CDATA", ncollections);
collections = collection.listChildCollections();
resources = collection.listResources();
this.xmlConsumer.startDocument();
this.xmlConsumer.startPrefixMapping(PREFIX, URI);
this.xmlConsumer.startElement(URI, "collections",
"collection:collections", attributes);
// Print child collections
for (int i = 0; i < collections.length; i++) {
attributes.clear();
attributes.addAttribute("", "name", "name", "CDATA", collections[i]);
this.xmlConsumer.startElement(URI, COLLECTION,
QCOLLECTION, attributes);
this.xmlConsumer.endElement(URI, COLLECTION, COLLECTION);
}
// Print child resources
for (int i = 0; i < resources.length; i++) {
attributes.clear();
attributes.addAttribute("", "name", "name", "CDATA", resources[i]);
this.xmlConsumer.startElement(URI, RESOURCE,
QRESOURCE, attributes);
this.xmlConsumer.endElement(URI, RESOURCE, RESOURCE);
}
this.xmlConsumer.endElement(URI, "collections",
"collection:collections");
this.xmlConsumer.endPrefixMapping(PREFIX);
this.xmlConsumer.endDocument();
} catch (XMLDBException xde) {
getLogger().warn("Collection listing failed: " + xde.getMessage());
throw new SAXException("Collection listing failed: " + xde.getMessage());
}
} Deprecated!Output SAX events listing the collection. |