try {
final Writer contents = output.newContents();
// serializer writes to __contents__.xml
final SAXSerializer serializer = (SAXSerializer)SerializerPool.getInstance().borrowObject( SAXSerializer.class );
serializer.setOutput( contents, contentsOutputProps );
final Permission perm = current.getPermissionsNoLock();
serializer.startDocument();
serializer.startPrefixMapping( "", Namespaces.EXIST_NS );
final XmldbURI uri = current.getURI();
final AttributesImpl attr = new AttributesImpl();
attr.addAttribute( Namespaces.EXIST_NS, "name", "name", "CDATA", uri.toString() );
attr.addAttribute( Namespaces.EXIST_NS, "version", "version", "CDATA", String.valueOf( currVersion ) );
Backup.writeUnixStylePermissionAttributes(attr, perm);
try {
attr.addAttribute( Namespaces.EXIST_NS, "created", "created", "CDATA", new DateTimeValue( new Date( current.getCreationTime() ) ).getStringValue() );
}
catch( final XPathException e ) {
e.printStackTrace();
}
bh.backup(current, attr);
serializer.startElement( Namespaces.EXIST_NS, "collection", "collection", attr );
if(perm instanceof ACLPermission) {
Backup.writeACLPermission(serializer, (ACLPermission)perm);
}
bh.backup(current, serializer);
final int docsCount = current.getDocumentCountNoLock(broker);
int count = 0;
for( final Iterator<DocumentImpl> i = current.iteratorNoLock( broker ); i.hasNext(); count++ ) {
final DocumentImpl doc = i.next();
if( isDamaged( doc, errorList ) ) {
reportError( "Skipping damaged document " + doc.getFileURI(), null );
continue;
}
if( doc.getFileURI().equalsInternal( CONTENTS_URI ) || doc.getFileURI().equalsInternal( LOST_URI ) ) {
continue; // skip __contents__.xml documents
}
exportDocument( bh, output, date, prevBackup, serializer, docsCount, count, doc );
docs.add( doc, false );
}
for( final Iterator<XmldbURI> i = current.collectionIteratorNoLock(broker); i.hasNext(); ) {
final XmldbURI childUri = i.next();
if( childUri.equalsInternal( TEMP_COLLECTION ) ) {
continue;
}
if( isDamagedChild( childUri, errorList ) ) {
reportError( "Skipping damaged child collection " + childUri, null );
continue;
}
attr.clear();
attr.addAttribute( Namespaces.EXIST_NS, "name", "name", "CDATA", childUri.toString() );
attr.addAttribute( Namespaces.EXIST_NS, "filename", "filename", "CDATA", Backup.encode( URIUtils.urlDecodeUtf8( childUri.toString() ) ) );
serializer.startElement( Namespaces.EXIST_NS, "subcollection", "subcollection", attr );
serializer.endElement( Namespaces.EXIST_NS, "subcollection", "subcollection" );
}
if( prevBackup != null ) {
// Check which collections and resources have been deleted since
// the
// last backup
final CheckDeletedHandler check = new CheckDeletedHandler( current, serializer );
try {
prevBackup.parse( check );
}
catch( final Exception e ) {
LOG.error( "Caught exception while trying to parse previous backup descriptor: " + prevBackup.getSymbolicPath(), e );
}
}
// close <collection>
serializer.endElement( Namespaces.EXIST_NS, "collection", "collection" );
serializer.endPrefixMapping( "" );
serializer.endDocument();
output.closeContents();
}
finally {
// if( !current.getURI().equalsInternal( XmldbURI.ROOT_COLLECTION_URI ) ) {