int bitstreamID = parameters.getParameterAsInteger("bitstreamID",-1);
// Get the bitstream and all the various formats
// Administrator is allowed to see internal formats too.
Bitstream bitstream = Bitstream.find(context, bitstreamID);
BitstreamFormat currentFormat = bitstream.getFormat();
BitstreamFormat[] bitstreamFormats = AuthorizeManager.isAdmin(context) ?
BitstreamFormat.findAll(context) :
BitstreamFormat.findNonInternal(context);
boolean primaryBitstream = false;
Bundle[] bundles = bitstream.getBundles();
if (bundles != null && bundles.length > 0)
{
if (bitstreamID == bundles[0].getPrimaryBitstreamID())
{
primaryBitstream = true;
}
}
// File name & url
String fileUrl = contextPath + "/bitstream/id/" +bitstream.getID() + "/" + bitstream.getName();
String fileName = bitstream.getName();
// DIVISION: main
Division div = body.addInteractiveDivision("edit-bitstream", contextPath+"/admin/item", Division.METHOD_MULTIPART, "primary administrative item");
div.setHead(T_head1);
// LIST: edit form
List edit = div.addList("edit-bitstream-list", List.TYPE_FORM);
edit.addLabel(T_file_label);
edit.addItem().addXref(fileUrl, fileName);
Select primarySelect = edit.addItem().addSelect("primary");
primarySelect.setLabel(T_primary_label);
primarySelect.addOption(primaryBitstream,"yes",T_primary_option_yes);
primarySelect.addOption(!primaryBitstream,"no",T_primary_option_no);
Text description = edit.addItem().addText("description");
description.setLabel(T_description_label);
description.setHelp(T_description_help);
description.setValue(bitstream.getDescription());
edit.addItem(T_para1);
// System supported formats
Select format = edit.addItem().addSelect("formatID");
format.setLabel(T_format_label);
// load the options menu, skipping the "Unknown" format since "Not on list" takes its place
int unknownFormatID = BitstreamFormat.findUnknown(context).getID();
format.addOption(-1,T_format_default);
for (BitstreamFormat bitstreamFormat : bitstreamFormats)
{
if (bitstreamFormat.getID() == unknownFormatID)
continue;
String supportLevel = "Unknown";
if (bitstreamFormat.getSupportLevel() == BitstreamFormat.KNOWN)
supportLevel = "known";
else if (bitstreamFormat.getSupportLevel() == BitstreamFormat.SUPPORTED)
supportLevel = "Supported";
String name = bitstreamFormat.getShortDescription()+" ("+supportLevel+")";
if (bitstreamFormat.isInternal())
name += " (Internal)";
int id = bitstreamFormat.getID();
format.addOption(id,name);
}
if (currentFormat != null)
{
format.setOptionSelected(currentFormat.getID());
}
else
{
format.setOptionSelected(-1);
}