class ResourceDetailsJaxrsService {

    protected String extractType(String mimeType, String name) {
        String type = null;
        if(mimeType == null){
            throw new MandatoryParameterNotFoundException("Content-Type");
        }
        if (mimeType.contains(";")) {
            mimeType = mimeType.split(";")[0].trim();
        }

        if (mimeType.equals(MediaType.APPLICATION_OCTET_STREAM)) {
            type = ContentResource.TYPE_UNSPECIFIED;
        } else {
            String wildcardMimeType = mimeType.replaceFirst("/.*", "/*");
            for (ClientFile.FileType eType : ClientFile.FileType.values()) {
                if (eType.getMimeType().equalsIgnoreCase(mimeType) || eType.getMimeType()
                        .equalsIgnoreCase(wildcardMimeType)) {
                    type = eType.toString();
                }
            }

            // let's try to analyse extension
            if (type == null && name.contains(".") && !name.endsWith(".")) {
                String extension = name.substring(name.lastIndexOf(".") + 1);
                if (contentTypeMapping.containsKey(extension)) {
                    type = extension;
                }
            }
        }

        return type == null ? ContentResource.TYPE_UNSPECIFIED : type;
    }

}