/** * Match the URIs this subclass understands and return the corresponding resource. Since the * "dso_" format can lead to several different resource types, handle it here. * * @param context the context * @param request the request * @param response the response * @param pathElt the path elt * @return the DAV resource * @throws DAVStatusException the DAV status exception * @throws SQLException the SQL exception * @throws AuthorizeException the authorize exception */ protected static DAVResource matchResourceURI( Context context, HttpServletRequest request, HttpServletResponse response, String pathElt[]) throws DAVStatusException, SQLException, AuthorizeException { // Match /dso_<handle>{...} .. look for last "dso_" element if (pathElt[0].startsWith("dso_")) { int i = 1; for (; i < pathElt.length && pathElt[i].startsWith("dso_"); ++i) { // empty } --i; String handle = decodeHandle(pathElt[i].substring(4)); // Replace substituted handle separator char with '/' to // get back a normal handle: (inverse of getPathElt() above) int sepIndex = handle.indexOf(handleSeparator); if (sepIndex >= 0) { char hc[] = handle.toCharArray(); hc[sepIndex] = '/'; handle = String.copyValueOf(hc); } DSpaceObject dso = HandleManager.resolveToObject(context, handle); if (dso == null) { throw new DAVStatusException( HttpServletResponse.SC_NOT_FOUND, "Cannot resolve handle \"" + handle + "\""); } else if (dso.getType() == Constants.ITEM) { if (i + 1 < pathElt.length) { if (pathElt[i + 1].startsWith("bitstream_")) { Bitstream bs = DAVBitstream.findBitstream(context, (Item) dso, pathElt[i + 1]); if (bs == null) { throw new DAVStatusException( HttpServletResponse.SC_NOT_FOUND, "Bitstream \"" + pathElt[i + 1] + "\" not found in item: " + pathElt[i]); } return new DAVBitstream(context, request, response, pathElt, (Item) dso, bs); } else { throw new DAVStatusException( HttpServletResponse.SC_NOT_FOUND, "Illegal resource path, \"" + pathElt[i + 1] + "\" is not a Bitstream identifier for item: " + pathElt[i]); } } else { return new DAVItem(context, request, response, pathElt, (Item) dso); } } else if (dso.getType() == Constants.COLLECTION) { return new DAVCollection(context, request, response, pathElt, (Collection) dso); } else if (dso.getType() == Constants.COMMUNITY) { return new DAVCommunity(context, request, response, pathElt, (Community) dso); } else { throw new DAVStatusException( HttpServletResponse.SC_BAD_REQUEST, "Unrecognized DSpace object type for handle=" + handle); } } return null; }
/** * Match Item URIs that identify the item by a database ID. Handle URIs are matched by * DAVDSpaceObject. * * @param context the context * @param request the request * @param response the response * @param pathElt the path elt * @return the DAV resource * @throws DAVStatusException the DAV status exception * @throws SQLException the SQL exception */ protected static DAVResource matchResourceURI( Context context, HttpServletRequest request, HttpServletResponse response, String pathElt[]) throws DAVStatusException, SQLException { int id = -1; String bsElt = null; try { // The "/item_db_" element in last or next-to-last element if (pathElt[pathElt.length - 1].startsWith("item_db_")) { id = Integer.parseInt(pathElt[pathElt.length - 1].substring(8)); } else if (pathElt[pathElt.length - 1].startsWith("bitstream_") && pathElt.length > 1 && pathElt[pathElt.length - 2].startsWith("item_db_")) { id = Integer.parseInt(pathElt[pathElt.length - 2].substring(8)); bsElt = pathElt[pathElt.length - 1]; } if (id >= 0) { Item item = Item.find(context, id); if (item == null) { throw new DAVStatusException( HttpServletResponse.SC_NOT_FOUND, "Item with ID=" + String.valueOf(id) + " not found."); } if (bsElt != null) { Bitstream bs = DAVBitstream.findBitstream(context, item, bsElt); if (bs == null) { throw new DAVStatusException(HttpServletResponse.SC_NOT_FOUND, "Bitstream not found."); } return new DAVBitstream(context, request, response, pathElt, item, bs); } else { return new DAVItem(context, request, response, pathElt, item); } } return null; } catch (NumberFormatException ne) { throw new DAVStatusException( HttpServletResponse.SC_BAD_REQUEST, "Error parsing number in request URI."); } }