pid + "+" + dmc.DatastreamID + "+" +
dmc.DSVersionID;
// if it's a url, we need to grab content for this
// version
if (URL_PROTOCOL.matcher(dmc.DSLocation).matches()) {
MIMETypedStream mimeTypedStream;
if (dmc.DSLocation
.startsWith(DatastreamManagedContent.UPLOADED_SCHEME)) {
mimeTypedStream =
new MIMETypedStream(
null,
m_management
.getTempStream(dmc.DSLocation),
null, dmc.DSSize);
logger.info("Getting managed datastream from internal uploaded " +
"location: " +
dmc.DSLocation +
" for " + pid);
} else if (dmc.DSLocation
.startsWith(DatastreamManagedContent.COPY_SCHEME)) {
// make a copy of the pre-existing content
mimeTypedStream =
new MIMETypedStream(
null,
m_permanentStore.retrieveDatastream(dmc.DSLocation
.substring(7)),
null, dmc.DSSize);
} else if (dmc.DSLocation
.startsWith(DatastreamManagedContent.TEMP_SCHEME)) {
File file =
new File(dmc.DSLocation
.substring(7));
logger.info("Getting base64 decoded datastream spooled from archive for datastream " +
dsID + " (" + pid + ")");
try {
InputStream str =
new FileInputStream(file);
mimeTypedStream =
new MIMETypedStream(dmc.DSMIME,
str, null, file
.length());
} catch (FileNotFoundException fnfe) {
logger.error(
"Unable to read temp file created for datastream from archive for " +
pid + " / " + dsID,
fnfe);
throw new StreamIOException(
"Error reading from temporary file created for binary content for " +
pid + " / " + dsID);
}
} else {
ContentManagerParams params =
new ContentManagerParams(
DOTranslationUtility
.makeAbsoluteURLs(dmc.DSLocation
.toString()),
dmc.DSMIME, null, null);
params.setContext(context);
mimeTypedStream =
m_contentManager
.getExternalContent(params);
logger.info("Getting managed datastream from remote location: " +
dmc.DSLocation +
" (" +
pid +
" / " + dsID + ")");
}
Map<String, String> dsHints =
m_hintProvider
.getHintsForAboutToBeStoredDatastream(
obj, dmc.DatastreamID);
if (obj.isNew()) {
dmc.DSSize =
m_permanentStore.addDatastream(
internalId, mimeTypedStream
.getStream(),
dsHints);
} else {
// object already existed...so we may need
// to call
// replace if "add" indicates that it was
// already there
try {
dmc.DSSize =
m_permanentStore.addDatastream(
internalId,
mimeTypedStream
.getStream(),
dsHints);
} catch (ObjectAlreadyInLowlevelStorageException oailse) {
dmc.DSSize =
m_permanentStore.replaceDatastream(
internalId,
mimeTypedStream
.getStream(),
dsHints);
}
}
if (mimeTypedStream != null) {
mimeTypedStream.close();
if (dmc.DSLocation
.startsWith(DatastreamManagedContent.TEMP_SCHEME)) {
// delete the temp file created to store
// the binary content from archive
File file =