this.isSpider = par.getParameter("userAgent", "").equals("spider");
// Reslove the bitstream
Bitstream bitstream = null;
DSpaceObject dso = null;
if (bitstreamID > -1)
{
// Direct refrence to the individual bitstream ID.
bitstream = Bitstream.find(context, bitstreamID);
}
else if (itemID > -1)
{
// Referenced by internal itemID
item = Item.find(context, itemID);
if (sequence > -1)
{
bitstream = findBitstreamBySequence(item, sequence);
}
else if (name != null)
{
bitstream = findBitstreamByName(item, name);
}
}
else if (handle != null)
{
// Reference by an item's handle.
dso = HandleManager.resolveToObject(context,handle);
if (dso instanceof Item)
{
item = (Item)dso;
if (sequence > -1)
{
bitstream = findBitstreamBySequence(item,sequence);
}
else if (name != null)
{
bitstream = findBitstreamByName(item,name);
}
}
}
//if initial search was by sequence number and found nothing,
//then try to find bitstream by name (assuming we have a file name)
if((sequence > -1 && bitstream==null) && name!=null)
{
bitstream = findBitstreamByName(item,name);
//if we found bitstream by name, send a redirect to its new sequence number location
if(bitstream!=null)
{
String redirectURL = "";
//build redirect URL based on whether item has a handle assigned yet
if(item.getHandle()!=null && item.getHandle().length()>0)
redirectURL = request.getContextPath() + "/bitstream/handle/" + item.getHandle();
else
redirectURL = request.getContextPath() + "/bitstream/item/" + item.getID();
redirectURL += "/" + name + "?sequence=" + bitstream.getSequenceID();
HttpServletResponse httpResponse = (HttpServletResponse)
objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
httpResponse.sendRedirect(redirectURL);
return;
}
}
// Was a bitstream found?
if (bitstream == null)
{
throw new ResourceNotFoundException("Unable to locate bitstream");
}
// Is there a User logged in and does the user have access to read it?
boolean isAuthorized = AuthorizeManager.authorizeActionBoolean(context, bitstream, Constants.READ);
if (item != null && item.isWithdrawn() && !AuthorizeManager.isAdmin(context))
{
isAuthorized = false;
log.info(LogManager.getHeader(context, "view_bitstream", "handle=" + item.getHandle() + ",withdrawn=true"));
}
if (!isAuthorized)
{
if(context.getCurrentUser() != null){
// A user is logged in, but they are not authorized to read this bitstream,
// instead of asking them to login again we'll point them to a friendly error
// message that tells them the bitstream is restricted.
String redictURL = request.getContextPath() + "/handle/";
if (item!=null){
redictURL += item.getHandle();
}
else if(dso!=null){
redictURL += dso.getHandle();
}
redictURL += "/restricted-resource?bitstreamId=" + bitstream.getID();
HttpServletResponse httpResponse = (HttpServletResponse)
objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);