[ 
https://issues.apache.org/jira/browse/TIKA-1692?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14636901#comment-14636901
 ] 

Tim Allison commented on TIKA-1692:
-----------------------------------

Hmmm....
If we modify {{getRegisteredMimeType}} to this:
{noformat}
        if (type != null) {
            MediaType normalisedType = registry.normalize(type);
            MimeType candidate = types.get(normalisedType);
            if (candidate != null) {
                return candidate;
            }
            if (normalisedType.hasParameters()) {
                return types.get(normalisedType.getBaseType());
            }
            return null;
        } else {
            throw new MimeTypeException("Invalid media type name: " + name);
        }
{noformat}

then we lose the parameters in the returned value:
{noformat}
    @Test
    public void testGetExtensionForMimesWithParameters() throws Exception {
        MimeType mt = this.mimeTypes.getRegisteredMimeType("text/html; 
charset=UTF-8");
        assertEquals("text/html", mt.toString());
        assertEquals("text/html", mt.getName());
        assertEquals(".html", mt.getExtension());
{noformat}

I don't think this is what you were expecting in your test above, however, I 
guess it could make sense.  If you want the one that is actually registered, it 
often isn't the one with parameters.  However if you want the full MimeType 
from a string, use {{forName}}. 

Another option is to move this logic into a static getExtension(String) and/or 
getExtension(MediaType)...

> Enable getExtension() for texty file types that include encoding information
> ----------------------------------------------------------------------------
>
>                 Key: TIKA-1692
>                 URL: https://issues.apache.org/jira/browse/TIKA-1692
>             Project: Tika
>          Issue Type: Improvement
>          Components: core
>            Reporter: Tim Allison
>            Priority: Trivial
>             Fix For: 1.10
>
>         Attachments: MimeUtilTest.java
>
>
> {{getExtension()}} offers a handy way to add a "detected" extension from a 
> {{MimeType}} for a file that didn't come with an extension.  However, this 
> functionality doesn't work with texty files: html, xml, css, csv, etc.  
> Let's add a static helper class (or build it into {{MimeType}}?) that will 
> output an extension for all mime types including texty mime types. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to