// Look for the XML:
try {
// All files should have a binary:
// Files without an associated metadata file are patched in like this:
File binFile = new File( this._root.getCanonicalPath() + File.separator + ( new PDURI(pdURI).getDataRegistryPath() ) );
if( ! binFile.exists() ) {
log.info("binFile doesn't exist, throwing Not Found exception");
log.info("looking for file:" + binFile.getAbsolutePath());
throw new DigitalObjectNotFoundException("The DigitalObject was not found!");
}
DigitalObjectContent c = Content.byReference( binFile );
// Look for the XML:
PDURI parsedURI = new PDURI(pdURI);
parsedURI.replaceDecodedPath(parsedURI.getDataRegistryPath() + FilesystemDigitalObjectManagerImpl.DO_EXTENSION);
String fullPath = this._root.getCanonicalPath() + File.separator + parsedURI.getDataRegistryPath();
StringBuilder fileData = new StringBuilder(1024);
File xmlf = new File(fullPath);
if( xmlf.exists() ) {
BufferedReader reader = new BufferedReader(new FileReader(xmlf));
char[] buf = new char[1024];
int numRead = 0;
while((numRead=reader.read(buf)) != -1) {
fileData.append(buf, 0, numRead);
}
reader.close();
// Re-create the digital object metadata.
dob = new DigitalObject.Builder(fileData.toString());
// Attach the content:
dob.content(c);
} else {
dob = new DigitalObject.Builder(c);
}
// If there is no title, add title to the dob.
// TODO Not the originally intended behaviour - if an object has been stored with no title, then that should remain the case. The 'filename' is already in the URI, where it belongs.
if( dob.getTitle() == null ) {
String title = null;
title = new PDURI(pdURI).getLeafname();
dob.title(title);
log.info("Add title: " + title);
}
// Ensure the PDURI is fixed up:
dob.permanentUri(pdURI);