// 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();
}
}
}
/*
* Now respond to button presses, other than "Remove" or "Delete" button
* presses which were dealt with in the above loop.
*/
if (button.equals("submit_addfield"))
{
// Adding a metadata field
int dcTypeID = UIUtil.getIntParameter(request, "addfield_dctype");
String value = request.getParameter("addfield_value").trim();
String lang = request.getParameter("addfield_language");
// trim language and set empty string language = null
if (lang != null)
{
lang = lang.trim();
if (lang.equals(""))
{
lang = null;
}
}
MetadataField field = MetadataField.find(context, dcTypeID);
MetadataSchema schema = MetadataSchema.find(context, field
.getSchemaID());
item.addMetadata(schema.getName(), field.getElement(), field
.getQualifier(), lang, value);
}
item.update();
if (button.equals("submit_addcc"))
{
// Show cc-edit page
request.setAttribute("item", item);
JSPManager
.showJSP(request, response, "/tools/creative-commons-edit.jsp");
}
if (button.equals("submit_addbitstream"))
{
// Show upload bitstream page
request.setAttribute("item", item);
JSPManager
.showJSP(request, response, "/tools/upload-bitstream.jsp");
}else
if(button.equals("submit_update_order") || button.startsWith("submit_order_"))
{
Bundle[] bundles = item.getBundles("ORIGINAL");
for (Bundle bundle : bundles) {
Bitstream[] bitstreams = bundle.getBitstreams();
int[] newBitstreamOrder = new int[bitstreams.length];
if (button.equals("submit_update_order")) {
for (Bitstream bitstream : bitstreams) {
//The order is determined by javascript
//For each of our bitstream retrieve the order value
int order = Util.getIntParameter(request, "order_" + bitstream.getID());
//-1 the order since the order needed to start from one
order--;
//Place the bitstream identifier in the correct order
newBitstreamOrder[order] = bitstream.getID();
}
}else{
//Javascript isn't operational retrieve the value from the hidden field
//Retrieve the button key
String inputKey = button.replace("submit_order_", "") + "_value";
if(inputKey.startsWith(bundle.getID() + "_")){
String[] vals = request.getParameter(inputKey).split(",");
for (int i = 0; i < vals.length; i++) {
String val = vals[i];
newBitstreamOrder[i] = Integer.parseInt(val);
}
}else{
newBitstreamOrder = null;
}
}
if(newBitstreamOrder != null){
//Set the new order in our bundle !
bundle.setOrder(newBitstreamOrder);
bundle.update();
}
}
// Show edit page again
showEditForm(context, request, response, item);