/**
 * 
 */
package com.trendrr.strest;

import java.util.HashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.trendrr.oss.StringHelper;


/**
 * @author Dustin Norlander
 * @created Apr 1, 2011
 * 
 */
public class ContentTypes {

	protected Log log = LogFactory.getLog(ContentTypes.class);
	
	public static final String TEXT = "text/plain";
	public static final String JSON = "application/json";
	public static final String JAVASCRIPT = "text/javascript";
	public static final String BINARY = "application/octet-stream";
	public static final String HTML = "text/html";
	public static final String CSV = "text/csv";
	public static final String CSS = "text/css";
	public static final String XML = "text/xml";
	
	
	private static HashMap<String,String> mappings = new HashMap<String,String>();
	static {
		mappings.put("txt", TEXT);
		mappings.put("json", JSON);
		mappings.put("js", JAVASCRIPT);
		mappings.put("html", HTML);
		mappings.put("csv", CSV);
		mappings.put("css", CSS);
		mappings.put("xml", XML);
	}
	
	
	/**
	 * attempts to find a mime type based on the file extension
	 * ex:
	 * csv would return "text/csv"
	 * 
	 * @param ext the extension to search
	 * @return the mime type or null
	 */
	public static String fromFileExtension(String ext) {
		if (ext == null)
			return null;
		String e = StringHelper.trim(ext.toLowerCase(), ".");
		return mappings.get(e);
	}
	
}

@@ -756,18 +756,87 @@
 t/xml%22;%0A
+%09public static final String FLASH = %22application/x-shockwave-flash%22;%0A
 %09%0A
-
 %09%0A%09priva
@@ -1042,16 +1042,75 @@
  HTML);%0A
+%09%09mappings.put(%22htm%22, HTML);%0A%09%09mappings.put(%22swf%22, FLASH);%0A
 %09%09mappin
@@ -1371,20 +1371,28 @@
 type or 
-null
+empty string
 %0A%09 */%0A%09p
@@ -1472,20 +1472,18 @@
 %09return 
-null
+%22%22
 ;%0A%09%09Stri
@@ -1534,22 +1534,29 @@
 %22.%22);%0A%09%09
-return
+String type =
  mapping
@@ -1565,15 +1565,64 @@
 get(e);%0A
+%09%09if (type == null)%0A%09%09%09return %22%22;%0A%09%09return type;%0A
 %09%7D%0A%09%0A%7D%0A

Add more standard content types