code: public static String getExtension(ResourceHandle resource, String extension, boolean detectMimeTypeExtension) {
          if (StringUtils.isBlank(extension) && detectMimeTypeExtension) {
              if (resource.isFile()) {
                  MimeType mimeType = MimeTypeUtil.getMimeType(resource);
                  if (mimeType != null) {
                      extension = mimeType.getExtension();
                  } else {
                      String name = resource.getName();
                      int lastDot = name.lastIndexOf('.');
                      if (lastDot > 0) {
                          extension = name.substring(lastDot + 1);
                      }
                  }
              }
          }
          if (StringUtils.isNotBlank(extension)) {
              String name = resource.getName();
              if (name.toLowerCase().endsWith(extension.toLowerCase())) {
                  extension = ""; // no extension necessary to add
              }
          }
          if (extension == null) {
              String resourceType = resource.getResourceType();
              String primaryType;
              if (resourceType != null &&
                      (primaryType = resource.getPrimaryType()) != null && !primaryType.equals(resourceType)) {
                  extension = EXT_HTML; // use '.html' by default if a real resource type is present
              } else {
                  ResourceHandle content = resource.getContentResource();
                  if (content.isValid() && !ResourceUtil.isNonExistingResource(content)) {
                      resourceType = content.getResourceType();
                      if (resourceType != null &&
                              (primaryType = content.getPrimaryType()) != null && !primaryType.equals(resourceType)) {
                          extension = EXT_HTML; // use '.html' by default if a content resource exists with a real resource type
                      }
                  }
              }
          }
          if (StringUtils.isNotBlank(extension)) {
              if (!extension.startsWith(".")) {
                  extension = "." + extension;
              }
          }
          return extension != null ? extension : "";
      }
docs: Returns the extension for a URL to a resource based on a predefined value (can be null or '').
  The result is always not 'null' and can be added without check; it starts with a '.' if not blank.
  
  @param resource                the referenced resource
  @param extension               the predefined extension (can be 'null' or blank for determination)
  @param detectMimeTypeExtension if 'true' an extension according to the mime type will be detected
  @return the string which has to add to the resources path; '' if nothing should add