001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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            /**
032             * Determine the content type from an input stream and file name.
033             *
034             * @param  fileName full name or extension of file (e.g., "Test.doc",
035             *                 ".doc")
036             * @return content type if it is a supported format or an empty string if it
037             *                 is an unsupported format
038             */
039            public static String getContentType(
040                    InputStream inputStream, String fileName) {
041    
042                    return getMimeTypes().getContentType(inputStream, fileName);
043            }
044    
045            /**
046             * Determine the content type from a file name.
047             *
048             * @param  fileName full name or extension of file (e.g., "Test.doc",
049             *                 ".doc")
050             * @return content type if it is a supported format or an empty string if it
051             *                 is an unsupported format
052             */
053            public static String getContentType(String fileName) {
054                    return getMimeTypes().getContentType(fileName);
055            }
056    
057            public static MimeTypes getMimeTypes() {
058                    return _mimeTypes;
059            }
060    
061            public void setMimeTypes(MimeTypes mimeTypes) {
062                    _mimeTypes = mimeTypes;
063            }
064    
065            private static MimeTypes _mimeTypes;
066    
067    }