HttpServletResponse response) throws ServletException, IOException,
SQLException, AuthorizeException
{
// Get the handle requested for the export
String handle = request.getParameter("handle");
MetadataExport exporter = null;
if (handle != null)
{
log.info(LogManager.getHeader(context, "metadataexport", "exporting_handle:" + handle));
DSpaceObject thing = HandleManager.resolveToObject(context, handle);
if (thing != null)
{
if (thing.getType() == Constants.ITEM)
{
List<Integer> item = new ArrayList<Integer>();
item.add(thing.getID());
exporter = new MetadataExport(context, new ItemIterator(context, item), false);
}
else if (thing.getType() == Constants.COLLECTION)
{
Collection collection = (Collection)thing;
ItemIterator toExport = collection.getAllItems();
exporter = new MetadataExport(context, toExport, false);
}
else if (thing.getType() == Constants.COMMUNITY)
{
exporter = new MetadataExport(context, (Community)thing, false);
}
if (exporter != null)
{
// Perform the export
DSpaceCSV csv = exporter.export();
// Return the csv file
response.setContentType("text/csv; charset=UTF-8");
String filename = handle.replaceAll("/", "-") + ".csv";
response.setHeader("Content-Disposition", "attachment; filename=" + filename);