for (final Iterator<DocumentImpl> i = collection.iterator(broker); i.hasNext();) {
final DocumentImpl doc = i.next();
if (doc.getPermissions().validate(broker.getSubject(), Permission.READ)) {
final XmldbURI resource = doc.getFileURI();
final DocumentMetadata metadata = doc.getMetadata();
attrs.clear();
attrs.addAttribute("", "name", "name", "CDATA", resource.toString());
// add an attribute for the creation date as an xs:dateTime
try {
final DateTimeValue dtCreated =
new DateTimeValue(new Date(metadata.getCreated()));
attrs.addAttribute("", "created", "created", "CDATA",
dtCreated.getStringValue());
} catch (final XPathException e) {
// fallback to long value
attrs.addAttribute("", "created", "created", "CDATA",
String.valueOf(metadata.getCreated()));
}
// add an attribute for the last modified date as an
// xs:dateTime
try {
final DateTimeValue dtLastModified = new DateTimeValue(
new Date(metadata.getLastModified()));
attrs.addAttribute("", "last-modified",
"last-modified", "CDATA", dtLastModified.getStringValue());
} catch (final XPathException e) {
// fallback to long value
attrs.addAttribute("", "last-modified",
"last-modified", "CDATA", String.valueOf(metadata.getLastModified()));
}
addPermissionAttributes(attrs, doc.getPermissions());
serializer.startElement(Namespaces.EXIST_NS, "resource", "exist:resource", attrs);
serializer.endElement(Namespaces.EXIST_NS, "resource", "exist:resource");