public StorageItem dereferenceLinkItem( StorageLinkItem item ) throws NoSuchResourceStoreException, ItemNotFoundException, AccessDeniedException, IllegalOperationException, StorageException { return getRootRouter().dereferenceLink( item ); }
@VisibleForTesting Object renderStorageLinkItem(final Context context, final Request req, final Response res, final Variant variant, final ResourceStore store, final StorageLinkItem item) throws ResourceException { // we have a link, dereference it // TODO: we should be able to do HTTP redirects too! (parametrize the dereferencing?) try { return renderItem(context, req, res, variant, store, getRepositoryRouter().dereferenceLink(item)); } catch (Exception e) { handleException(req, res, e); return null; } }
/** * Dereferences the passed in link completely (following link-to-links too) as long as non-link item is found as * target. This method will detect cycles, and will fail if such link constellation is found. If any target during * dereference is not found, the usual {@link ItemNotFoundException} will be thrown (by the method used to * dereference). */ protected StorageItem dereferenceLink(final StorageLinkItem link) throws Exception { final List<String> hops = Lists.newArrayList(); StorageLinkItem currentLink = link; while (true) { final String hop = currentLink.getRepositoryItemUid().getKey(); if (!hops.contains(hop)) { hops.add(hop); final StorageItem item = repositoryRouter.dereferenceLink(currentLink); if (!(item instanceof StorageLinkItem)) { return item; } else { currentLink = (StorageLinkItem) item; } } else { // cycle detected, current link already processed throw new ItemNotFoundException(ItemNotFoundException.reasonFor(link.getResourceStoreRequest(), link .getRepositoryItemUid().getRepository(), "Link item %s introduced a cycle while referencing it, cycle is %s", link.getRepositoryItemUid(), hops)); } } }
repositoryRouter.dereferenceLink((StorageLinkItem) item, request.isRequestLocalOnly(), request.isRequestRemoteOnly());
repositoryRouter.dereferenceLink( (StorageLinkItem) item, request.isRequestLocalOnly(), request.isRequestRemoteOnly() );