code: public static String getMimeType(Resource resource) {
      if (isNtResource(resource)) {
        return resource.getValueMap().get(JcrConstants.JCR_MIMETYPE, String.class);
      }
      else if (isNtFile(resource)) {
        return getMimeType(resource.getChild(JcrConstants.JCR_CONTENT));
      }
      return null;
    }
docs: Get mime type from the referenced nt:file or nt:resource node.
  @param resource Resource pointing to JCR node with primary type nt:file or nt:resource
  @return Mime type or null if no mime type set or if node is not of type nt:resource or nt:file