.getContentFiles();
List<Element> manifestBundleFiles = manifest
.getBundleFiles();
boolean setPrimaryBitstream = false;
BitstreamFormat unknownFormat = BitstreamFormat.findUnknown(context);
for (Iterator<Element> mi = manifestContentFiles.iterator(); mi
.hasNext();)
{
Element mfile = mi.next();
// basic validation -- check that it has an ID attribute
String mfileID = mfile.getAttributeValue("ID");
if (mfileID == null)
{
throw new PackageValidationException(
"Invalid METS Manifest: file element without ID attribute.");
}
// retrieve path/name of file in manifest
String path = METSManifest.getFileName(mfile);
// extract the file input stream from package (or retrieve
// externally, if it is an externally referenced file)
InputStream fileStream = getFileInputStream(pkgFile, params, path);
// retrieve bundle name from manifest
String bundleName = METSManifest.getBundleName(mfile);
// Find or create the bundle where bitstream should be attached
Bundle bundle;
Bundle bns[] = item.getBundles(bundleName);
if (bns != null && bns.length > 0)
{
bundle = bns[0];
}
else
{
bundle = item.createBundle(bundleName);
}
// Create the bitstream in the bundle & initialize its name
Bitstream bitstream = bundle.createBitstream(fileStream);
bitstream.setName(path);
// Set bitstream sequence id, if known
String seqID = mfile.getAttributeValue("SEQ");
if(seqID!=null && !seqID.isEmpty())
bitstream.setSequenceID(Integer.parseInt(seqID));
// crosswalk this bitstream's administrative metadata located in
// METS manifest (or referenced externally)
manifest.crosswalkBitstream(context, params, bitstream, mfileID,
mdRefCallback);
// is this the primary bitstream?
if (primaryID != null && mfileID.equals(primaryID))
{
bundle.setPrimaryBitstreamID(bitstream.getID());
bundle.update();
setPrimaryBitstream = true;
}
// Run any finishing activities -- this allows subclasses to
// change default bitstream information
finishBitstream(context, bitstream, mfile, manifest, params);
// Last-ditch attempt to divine the format, if crosswalk failed to
// set it:
// 1. attempt to guess from MIME type
// 2. if that fails, guess from "name" extension.
if (bitstream.getFormat().equals(unknownFormat))
{
if (log.isDebugEnabled())
{
log.debug("Guessing format of Bitstream left un-set: "
+ bitstream.toString());
}
String mimeType = mfile.getAttributeValue("MIMETYPE");
BitstreamFormat bf = (mimeType == null) ? null
: BitstreamFormat.findByMIMEType(context, mimeType);
if (bf == null)
{
bf = FormatIdentifier.guessFormat(context, bitstream);
}