boolean found = false;  Item item = (Item) HandleManager.resolveToObject(context, handle);  if (item == null) { log.info(LogManager.getHeader(context, "invalid_id", "path=" + handle)); JSPManager.showInvalidIDError(request, response, handle, -1); return; }  Bundle[] bundles = item.getBundles(); for (int i = 0; i < bundles.length; i++) { Bitstream[] bitstreams = bundles[i].getBitstreams(); if (!found) { for (int k = 0; k < bitstreams.length; k++) { if (filename.equals(bitstreams[k].getName())) { bitstream = bitstreams[k]; found = true; } } } }
boolean found = false;  Item item = null;   if (handle.startsWith("db-id")) { String dbIDString = handle.substring(handle.indexOf('/') + 1); int dbID = Integer.parseInt(dbIDString); item = Item.find(context, dbID); } else { item = (Item) HandleManager.resolveToObject(context, handle); }   if (item == null) { log.info(LogManager.getHeader(context, "invalid_id", "path=" + handle)); JSPManager.showInvalidIDError(request, response, handle, -1); return; }  Bundle[] bundles = item.getBundles(); for (int i = 0; i < bundles.length; i++) { Bitstream[] bitstreams = bundles[i].getBitstreams(); if (!found) { for (int k = 0; k < bitstreams.length; k++) { if (filename.equals(bitstreams[k].getName())) { bitstream = bitstreams[k]; found = true; } } } }
    protected void doDSGet(Context context,        HttpServletRequest request,        HttpServletResponse response)        throws ServletException, IOException, SQLException, AuthorizeException    {        Bitstream bitstream = null;            // Get the ID from the URL        String idString = request.getPathInfo();	String filename = "";	String handle = "";        if (idString != null)        {            // Remove leading slash            if (idString.startsWith("/"))            {                idString = idString.substring(1);            }            // Get filename            int slashIndex = idString.lastIndexOf('/');            if (slashIndex != -1)            {		filename = idString.substring(slashIndex + 1);		filename = URLDecoder.decode(filename);                handle = idString.substring(0, slashIndex);            }            // If there's still a second slash, remove it and anything after it,            // it might be a relative directory name            slashIndex = handle.indexOf('/');	    slashIndex = handle.indexOf('/', slashIndex + 1);            if (slashIndex != -1)	    {		handle = handle.substring(0, slashIndex);	    }            // Find the corresponding bitstream            try            {		boolean found = false;		Item item = (Item) HandleManager.resolveToObject(context, handle);		if (item == null)		{		    log.info(LogManager.getHeader(context,						  "invalid_id",						  "path=" + handle));		    JSPManager.showInvalidIDError(request, response, handle, -1);		    return;		}		Bundle[] bundles = item.getBundles();		for (int i = 0; i < bundles.length; i++) {		    Bitstream[] bitstreams = bundles[i].getBitstreams();		    if (!found) {			for (int k = 0; k < bitstreams.length; k++) {			    if (filename.equals(bitstreams[k].getName())) {				bitstream = bitstreams[k];				found = true;			    }			}		    }		}            }            catch (NumberFormatException nfe)            {                // Invalid ID - this will be dealt with below            }	}        // Did we get a bitstream?        if (bitstream != null)        {	    	              log.info(LogManager.getHeader(context,                "view_bitstream",                "bitstream_id=" + bitstream.getID()));            // Set the response MIME type            response.setContentType(bitstream.getFormat().getMIMEType());                        // Response length            response.setHeader("Content-Length",	      String.valueOf(bitstream.getSize()));                        // Pipe the bits            InputStream is = bitstream.retrieve();                        Utils.bufferedCopy(is, response.getOutputStream());            is.close();            response.getOutputStream().flush();        }        else        {            // No bitstream - we got an invalid ID            log.info(LogManager.getHeader(context,                "view_bitstream",                "invalid_bitstream_id=" + idString));                        JSPManager.showInvalidIDError(request,                response,                idString,                Constants.BITSTREAM);        }    }