/** {@inheritDoc} */
  public List getCollections(ContentCollection collection) {
    ContentHostingHandler chh = collection.getContentHandler();
    if (chh != null) {
      return chh.getCollections(collection);
    } else {
      List allCollections = storage.getCollections(collection); // the real collections

      // Find any virtual *resources* which are really *collections*
      List l = storage.getResources(collection);
      for (java.util.Iterator i = l.iterator(); i.hasNext(); ) {
        ContentResource o = (ContentResource) i.next();
        ContentResource cr = getResource(o.getId());
        if (cr != null) {
          ResourceProperties p = cr.getProperties();
          if (p != null
              && p.getProperty(CHH_BEAN_NAME) != null
              && p.getProperty(CHH_BEAN_NAME).length() > 0) {
            allCollections.add(
                getVirtualChild(
                    cr.getId() + Entity.SEPARATOR, cr, true)); // this one is a virtual collection!
          }
        }
      }
      return allCollections;
    }
  }
 /**
  * {@inheritDoc}
  *
  * @throws ServerOverloadException
  */
 public InputStream streamResourceBody(ContentResource resource) throws ServerOverloadException {
   ContentHostingHandler chh = resource.getContentHandler();
   if (chh != null) {
     return chh.streamResourceBody(resource);
   } else {
     return storage.streamResourceBody(resource);
   }
 }
 /** {@inheritDoc} */
 public void removeResource(ContentResourceEdit edit) {
   ContentHostingHandler chh = edit.getContentHandler();
   if (chh != null) {
     chh.removeResource(edit);
   } else {
     storage.removeResource(edit);
   }
 }
 /** {@inheritDoc} */
 public void removeCollection(ContentCollectionEdit edit) {
   ContentHostingHandler chh = edit.getContentHandler();
   if (chh != null) {
     chh.removeCollection(edit);
   } else {
     storage.removeCollection(edit);
   }
 }
 /** {@inheritDoc} */
 public void commitResource(ContentResourceEdit edit) throws ServerOverloadException {
   ContentHostingHandler chh = edit.getContentHandler();
   if (chh != null) {
     chh.commit(edit);
   } else {
     storage.commitResource(edit);
   }
 }
 /** {@inheritDoc} */
 public void commitDeleteResource(ContentResourceEdit edit, String uuid) {
   ContentHostingHandler chh = edit.getContentHandler();
   if (chh != null) {
     chh.commitDeleted(edit, uuid);
   } else {
     storage.commitDeleteResource(edit, uuid);
   }
 }
 /* (non-Javadoc)
  * @see org.sakaiproject.content.api.ContentHostingHandlerResolver#getMemberResourceIds(java.lang.String)
  */
 public Collection<String> getMemberResourceIds(String collectionId) {
   ContentEntity ce = getVirtualChild(collectionId, getRealParent(collectionId), false);
   if (ce != null) {
     ContentHostingHandler chh = ce.getContentHandler();
     if (chh != null) {
       return chh.getMemberResourceIds(ce);
     }
   }
   return storage.getMemberResourceIds(collectionId);
 }
 public int getMemberCount(String id) {
   ContentEntity ce = getVirtualChild(id, getRealParent(id), false);
   if (ce != null) {
     ContentHostingHandler chh = ce.getContentHandler();
     if (chh != null) {
       return chh.getMemberCount(ce);
     }
   }
   return storage.getMemberCount(id);
 }
 /** {@inheritDoc} */
 public ContentResourceEdit putResource(String id) {
   ContentEntity ce = getVirtualChild(id, getRealParent(id), false);
   if (ce != null) {
     ContentHostingHandler chh = ce.getContentHandler();
     if (chh != null) {
       ContentResourceEdit cre = chh.getContentResourceEdit(id);
       cre.setVirtualContentEntity(
           getVirtualChild(id, getRealParent(id), false).getVirtualContentEntity());
       return cre;
     }
   }
   return storage.putResource(id);
 }
 /** {@inheritDoc} */
 public ContentCollectionEdit editCollection(String id) {
   ContentEntity ce = getVirtualChild(id, getRealParent(id), false);
   if (ce != null) {
     ContentHostingHandler chh = ce.getContentHandler();
     if (chh != null) {
       ContentCollectionEdit cce = chh.getContentCollectionEdit(id);
       cce.setVirtualContentEntity(
           getVirtualChild(id, getRealParent(id), false).getVirtualContentEntity());
       return cce;
     }
   }
   return storage.editCollection(id);
 }
 /** {@inheritDoc} */
 public List getFlatResources(String id) {
   List l = storage.getFlatResources(id);
   if (l != null) {
     return l;
   }
   ContentEntity ce = getVirtualChild(id, getRealParent(id), true);
   if (ce != null) {
     ContentHostingHandler chh = ce.getContentHandler();
     if (chh != null) {
       return chh.getFlatResources(ce);
     }
   }
   return null;
 }
 /** {@inheritDoc} */
 public boolean checkCollection(String id) {
   if (storage.checkCollection(id)) {
     return true;
   }
   ContentEntity ce = getVirtualChild(id, getRealParent(id), true);
   if (ce != null) {
     if (id.equals(ce.getId())) {
       if (ce instanceof ContentCollection) {
         return true;
       }
     }
   }
   return false;
 }
 /**
  * Find the closest real ancestor to the requested id, this recurses into itself
  *
  * @param id
  * @return the closest ancestor or null if not found (bit unlikely)
  */
 public ContentEntity getRealParent(String id) {
   ContentEntity ce = storage.getCollection(id);
   if (ce == null) {
     try {
       ce = storage.getResource(id);
     } catch (TypeException e) {
       log.debug("Type Exception ", e);
     }
   }
   if (ce == null) {
     if (id.equals(Entity.SEPARATOR)) {
       // If the entity is the root and we didint get anything, there is nothing we can do
       // no root, no content, no point in trying to get annother one
       log.fatal("Unable to get Root node of the repository");
       throw new AssertionError("Unable to Get Root repository " + Entity.SEPARATOR);
     }
     int lastSlash = id.lastIndexOf(Entity.SEPARATOR, id.length() - 2);
     if (lastSlash > 0) {
       String parentId = id.substring(0, lastSlash + 1 /* [email protected] wanted a "- 1" here */);
       ce = getRealParent(parentId);
     }
   }
   return ce;
 }
  /** {@inheritDoc} */
  public ContentCollection getCollection(String id) {
    ContentCollection cc = storage.getCollection(id);
    if (cc != null) {
      return cc;
    }
    ContentEntity rp = getRealParent(id);
    if (rp == null) {
      return null;
    }

    ContentEntity ce = getVirtualChild(id, rp, true);
    if (ce instanceof ContentCollection) {
      return (ContentCollection) ce;
    }
    return null;
  }
  /** {@inheritDoc} */
  public ContentResource getResource(String id) {

    ContentResource cc = null;
    try {
      cc = storage.getResource(id);
    } catch (TypeException e) {
      log.debug("Type Exception ", e);
    }
    if (cc != null) {
      return cc;
    }
    ContentEntity ce = getVirtualChild(id, getRealParent(id), true);
    if (ce instanceof ContentResource) {
      return (ContentResource) ce;
    }
    return null;
  }
 /** {@inheritDoc} */
 public List getResources(ContentCollection collection) {
   ContentHostingHandler chh = collection.getContentHandler();
   if (chh != null) {
     return chh.getResources(collection);
   } else {
     List l = storage.getResources(collection);
     for (java.util.Iterator i = l.iterator(); i.hasNext(); ) {
       ContentResource o = (ContentResource) i.next();
       ContentResource cr = getResource(o.getId());
       if (cr != null) {
         ResourceProperties p = cr.getProperties();
         if (p != null
             && p.getProperty(CHH_BEAN_NAME) != null
             && p.getProperty(CHH_BEAN_NAME).length() > 0)
           i.remove(); // this one is a virtual collection!
       }
     }
     return l;
   }
 }