ro.isdc.wro.http.support
Class ContentTypeResolver

java.lang.Object
  extended by ro.isdc.wro.http.support.ContentTypeResolver

public class ContentTypeResolver
extends Object

Responseible for resolving a content based on file name.

Author:
Alex Objelean

Constructor Summary
ContentTypeResolver()
           
 
Method Summary
static String get(String fileName)
          Returns a valid HTTP contentType's for a given filename.
static String get(String fileName, String encoding)
          Returns a valid HTTP contentType's for a given filename with charset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContentTypeResolver

public ContentTypeResolver()
Method Detail

get

public static String get(String fileName)
Returns a valid HTTP contentType's for a given filename. It first relies on the custom defaultContentTypeMap and if not found it will fall back to defaultFileTypeMap from javax.activation.FileTypeMap. Examples: - "somefile.css" resolves to "text/css". - "somefile.js.png" resolves to "image/png" - "/blah/index.html resolves to "text/html".

The implementation uses reflection to load javax.activation.FileTypeMap class (available in jdk6) in order to be compatible with jdk5. If this class is not available, the default content type is returned.

Parameters:
fileName - with an filename extension
Returns:
contentType

get

public static String get(String fileName,
                         String encoding)
Returns a valid HTTP contentType's for a given filename with charset. It first relies on the custom defaultContentTypeMap and if not found it will fall back to defaultFileTypeMap from javax.activation.FileTypeMap. Examples: - ("somefile.css", "UTF-8") resolves to "text/css"; charset=UTF-8". - ("somefile.js.png", "UTF-8") resolves to "image/png" - ("/blah/index.html, "UTF-8") resolves to "text/html; charset=8"

Parameters:
fileName - with an filename extension
encoding - which encoding to use
Returns:
contentType


Copyright © 2008-2013. All Rights Reserved.