code: public static String getResourceName(Resource resource) {
          String result = null;
          if (resource != null) {
              String name = resource.getName();
              if (ResourceUtil.CONTENT_NODE.equals(name)) {
                  result = getResourceName(resource.getParent());
              } else {
                  result = name;
              }
          }
          return result;
      }
docs: Retrieves the name of a resource as base for a filename;
  uses the parent of a 'jcr:content' resource automatically.