// Bundle ID and bitstream ID next
int bundleID = Integer.parseInt(st.nextToken());
int bitstreamID = Integer.parseInt(st.nextToken());
Bundle bundle = Bundle.find(context, bundleID);
Bitstream bitstream = Bitstream.find(context, bitstreamID);
// Get the string "(bundleID)_(bitstreamID)" for finding other
// parameters related to this bitstream
String key = String.valueOf(bundleID) + "_" + bitstreamID;
// Update bitstream metadata, or delete?
if (button.equals("submit_delete_bitstream_" + key))
{
// "delete" button pressed
bundle.removeBitstream(bitstream);
// Delete bundle too, if empty
if (bundle.getBitstreams().length == 0)
{
item.removeBundle(bundle);
}
}
else
{
// Update the bitstream metadata
String name = request.getParameter(p);
String source = request.getParameter("bitstream_source_"
+ key);
String desc = request.getParameter("bitstream_description_"
+ key);
int formatID = UIUtil.getIntParameter(request,
"bitstream_format_id_" + key);
String userFormatDesc = request
.getParameter("bitstream_user_format_description_"
+ key);
int primaryBitstreamID = UIUtil.getIntParameter(request,
bundleID + "_primary_bitstream_id");
// Empty strings become non-null
if (source.equals(""))
{
source = null;
}
if (desc.equals(""))
{
desc = null;
}
if (userFormatDesc.equals(""))
{
userFormatDesc = null;
}
bitstream.setName(name);
bitstream.setSource(source);
bitstream.setDescription(desc);
bitstream
.setFormat(BitstreamFormat.find(context, formatID));
if (primaryBitstreamID > 0)
{
bundle.setPrimaryBitstreamID(primaryBitstreamID);
}
if (userFormatDesc != null)
{
bitstream.setUserFormatDescription(userFormatDesc);
}
bitstream.update();
bundle.update();
}
}
}