001 /** 002 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved. 003 * 004 * This library is free software; you can redistribute it and/or modify it under 005 * the terms of the GNU Lesser General Public License as published by the Free 006 * Software Foundation; either version 2.1 of the License, or (at your option) 007 * any later version. 008 * 009 * This library is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 011 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 012 * details. 013 */ 014 015 package com.liferay.portal.kernel.util; 016 017 import java.io.File; 018 import java.io.InputStream; 019 020 /** 021 * @author Jorge Ferrer 022 * @author Brian Wing Shun Chan 023 * @author Alexander Chow 024 */ 025 public class MimeTypesUtil { 026 027 public static String getContentType(File file) { 028 return getMimeTypes().getContentType(file); 029 } 030 031 public static String getContentType(File file, String title) { 032 return getMimeTypes().getContentType(file, title); 033 } 034 035 /** 036 * Determine the content type from an input stream and file name. 037 * 038 * @param fileName full name or extension of file (e.g., "Test.doc", 039 * ".doc") 040 * @return content type if it is a supported format or an empty string if it 041 * is an unsupported format 042 */ 043 public static String getContentType( 044 InputStream inputStream, String fileName) { 045 046 return getMimeTypes().getContentType(inputStream, fileName); 047 } 048 049 /** 050 * Determine the content type from a file name. 051 * 052 * @param fileName full name or extension of file (e.g., "Test.doc", 053 * ".doc") 054 * @return content type if it is a supported format or an empty string if it 055 * is an unsupported format 056 */ 057 public static String getContentType(String fileName) { 058 return getMimeTypes().getContentType(fileName); 059 } 060 061 public static MimeTypes getMimeTypes() { 062 return _mimeTypes; 063 } 064 065 public void setMimeTypes(MimeTypes mimeTypes) { 066 _mimeTypes = mimeTypes; 067 } 068 069 private static MimeTypes _mimeTypes; 070 071 }