final AttributesImpl attr = new AttributesImpl();
//The name should have come from an XmldbURI.toString() call
attr.addAttribute( Namespaces.EXIST_NS, "name", "name", "CDATA", current.getName() );
writeUnixStylePermissionAttributes(attr, currentPerms);
attr.addAttribute( Namespaces.EXIST_NS, "created", "created", "CDATA", "" + new DateTimeValue( cur.getCreationTime() ) );
attr.addAttribute( Namespaces.EXIST_NS, "version", "version", "CDATA", String.valueOf( currVersion ) );
serializer.startElement( Namespaces.EXIST_NS, "collection", "collection", attr );
if(currentPerms instanceof ACLPermission) {
writeACLPermission(serializer, (ACLPermission)currentPerms);
}
// scan through resources
Resource resource;
OutputStream os;
BufferedWriter writer;
SAXSerializer contentSerializer;
for( int i = 0; i < resources.length; i++ ) {
try {
if( "__contents__.xml".equals(resources[i]) ) {
//Skipping resources[i]
continue;
}
resource = current.getResource( resources[i] );
if( dialog != null ) {
dialog.setResource( resources[i] );
dialog.setProgress( i );
}
final String name = resources[i];
String filename = encode( URIUtils.urlDecodeUtf8( resources[i] ) );
// Check for special resource names which cause problems as filenames, and if so, replace the filename with a generated filename
if( ".".equals(name.trim()) ) {
filename = EXIST_GENERATED_FILENAME_DOT_FILENAME + i;
} else if( "..".equals(name.trim()) ) {
filename = EXIST_GENERATED_FILENAME_DOTDOT_FILENAME + i;
}
os = output.newEntry( filename );
if( resource instanceof ExtendedResource ) {
( (ExtendedResource)resource ).getContentIntoAStream( os );
} else {
writer = new BufferedWriter( new OutputStreamWriter( os, "UTF-8" ) );
// write resource to contentSerializer
contentSerializer = (SAXSerializer)SerializerPool.getInstance().borrowObject( SAXSerializer.class );
contentSerializer.setOutput( writer, defaultOutputProperties );
( (EXistResource)resource ).setLexicalHandler( contentSerializer );
( (XMLResource)resource ).getContentAsSAX( contentSerializer );
SerializerPool.getInstance().returnObject( contentSerializer );
writer.flush();
}
output.closeEntry();
final EXistResource ris = (EXistResource)resource;
//store permissions
attr.clear();
attr.addAttribute( Namespaces.EXIST_NS, "type", "type", "CDATA", resource.getResourceType() );
attr.addAttribute( Namespaces.EXIST_NS, "name", "name", "CDATA", name );
writeUnixStylePermissionAttributes(attr, perms[i]);
Date date = ris.getCreationTime();
if( date != null ) {
attr.addAttribute( Namespaces.EXIST_NS, "created", "created", "CDATA", "" + new DateTimeValue( date ) );
}
date = ris.getLastModificationTime();
if( date != null ) {
attr.addAttribute( Namespaces.EXIST_NS, "modified", "modified", "CDATA", "" + new DateTimeValue( date ) );
}
attr.addAttribute( Namespaces.EXIST_NS, "filename", "filename", "CDATA", filename );
attr.addAttribute( Namespaces.EXIST_NS, "mimetype", "mimetype", "CDATA", encode( ( (EXistResource)resource ).getMimeType() ) );