setCreatedAndLastModifiedHeaders(response, collection.getCreationTime(), collection.getCreationTime());
final OutputStreamWriter writer =
new OutputStreamWriter(response.getOutputStream(), encoding);
SAXSerializer serializer = null;
try {
serializer = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);
serializer.setOutput(writer, defaultProperties);
final AttributesImpl attrs = new AttributesImpl();
serializer.startDocument();
serializer.startPrefixMapping("exist", Namespaces.EXIST_NS);
serializer.startElement(Namespaces.EXIST_NS, "result",
"exist:result", attrs);
attrs.addAttribute("", "name", "name", "CDATA", collection.getURI()
.toString());
// add an attribute for the creation date as an xs:dateTime
try {
final DateTimeValue dtCreated =
new DateTimeValue(new Date(collection.getCreationTime()));
attrs.addAttribute("", "created", "created", "CDATA",
dtCreated.getStringValue());
} catch (final XPathException e) {
// fallback to long value
attrs.addAttribute("", "created", "created", "CDATA",
String.valueOf(collection.getCreationTime()));
}
addPermissionAttributes(attrs, collection.getPermissionsNoLock());
serializer.startElement(Namespaces.EXIST_NS, "collection",
"exist:collection", attrs);
for (final Iterator<XmldbURI> i = collection.collectionIterator(broker); i.hasNext();) {
final XmldbURI child = i.next();
final Collection childCollection = broker.getCollection(collection
.getURI().append(child));
if (childCollection != null
&& childCollection.getPermissionsNoLock().validate(broker.getSubject(), Permission.READ)) {
attrs.clear();
attrs.addAttribute("", "name", "name", "CDATA", child.toString());
// add an attribute for the creation date as an xs:dateTime
try {
final DateTimeValue dtCreated =
new DateTimeValue(new Date(childCollection.getCreationTime()));
attrs.addAttribute("", "created", "created", "CDATA", dtCreated.getStringValue());
} catch (final XPathException e) {
// fallback to long value
attrs.addAttribute("", "created", "created", "CDATA",
String.valueOf(childCollection.getCreationTime()));
}
addPermissionAttributes(attrs, childCollection.getPermissionsNoLock());
serializer.startElement(Namespaces.EXIST_NS, "collection", "exist:collection", attrs);
serializer.endElement(Namespaces.EXIST_NS, "collection", "exist:collection");
}
}
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");
}
}
serializer.endElement(Namespaces.EXIST_NS, "collection", "exist:collection");
serializer.endElement(Namespaces.EXIST_NS, "result", "exist:result");
serializer.endDocument();
writer.flush();
writer.close();
} catch (final SAXException e) {