Ejemplo n.º 1
0
  /**
   * Get a Entry from the cache. Get either a valid entry object or create a new one if possible.
   *
   * @param pathInContext The key into the cache
   * @return The entry matching <code>pathInContext</code>, or a new entry if no matching entry was
   *     found. If the content exists but is not cachable, then a {@link ResourceAsHttpContent}
   *     instance is return. If the resource does not exist, then null is returned.
   * @throws IOException Problem loading the resource
   */
  public HttpContent lookup(String pathInContext) throws IOException {
    // Is the content in this cache?
    Content content = _cache.get(pathInContext);
    if (content != null && (content).isValid()) return content;

    // try loading the content from our factory.
    Resource resource = _factory.getResource(pathInContext);
    HttpContent loaded = load(pathInContext, resource);
    if (loaded != null) return loaded;

    // Is the content in the parent cache?
    if (_parent != null) {
      HttpContent httpContent = _parent.lookup(pathInContext);
      if (httpContent != null) return httpContent;
    }

    return null;
  }