/**
   * Returns the relative path to the document directory in the request environment. If the document
   * or one of it's parent sections aren't found in the request environment, null is returned. The
   * path is relative to the request URL and may be empty if the request environment points to the
   * document. Otherwise the path ends with an "/" character.
   *
   * @param content the content document
   * @return the relative path to the document directory, or null if not in the request environment
   */
  private String getDocEnvPath(Content content) {
    RequestEnvironment env = context.getRequest().getEnvironment();
    ContentSection section = env.getSection();
    ContentDocument doc = env.getDocument();
    String path = "";

    if (doc != null) {
      if (doc.getId() == content.getId()) {
        return "";
      }
    } else if (section != null) {
      while (content != null) {
        if (section.getId() == content.getId()) {
          return path;
        }
        path = content.getName() + "/" + path;
        try {
          content = content.getParent();
        } catch (ContentException e) {
          LOG.error(e.getMessage());
          return null;
        }
      }
    }
    return null;
  }
  /**
   * Returns the relative path to the document directory. The path is relative to the request URL
   * and may be empty if the request refers to an object in the document directory. Otherwise the
   * path ends with an "/" character.
   *
   * @param document the content document, or null
   * @return the relative path to the document directory
   */
  private String getDocPath(ContentDocument document) {
    String path;

    if (document == null) {
      return "";
    } else {
      path = getDocEnvPath(document);
      if (path == null) {
        path = context.getSitePath() + "liquidsite/content/" + document.getId() + "/";
      }
      return path;
    }
  }