/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.tika.utils;

import java.io.File;

/**
 * Detect mime type from file
 * 
 * @author Rida Benjelloun (ridabenjelloun@apache.org)
 */
public class MimeTypesUtils {

    public static String getMimeType(File file) {
        // FIXME: See TIKA-8
        String name = file.getName().toLowerCase();
        if (name.endsWith(".txt")) {
            return "text/plain";
        } else if (name.endsWith(".pdf")) {
            return "application/pdf";
        } else if (name.endsWith(".htm")) {
            return "text/html";
        } else if (name.endsWith(".html")) {
            return "text/html";
        } else if (name.endsWith(".xhtml")) {
            return "application/xhtml+xml";
        } else if (name.endsWith(".xml")) {
            return "application/xml";
        } else if (name.endsWith(".doc")) {
            return "application/msword";
        } else if (name.endsWith(".ppt")) {
            return "application/vnd.ms-powerpoint";
        } else if (name.endsWith(".xls")) {
            return "application/vnd.ms-excel";
        } else if (name.endsWith(".zip")) {
            return "application/zip";
        } else {
            return "application/octet-stream";
        }
    }

}

@@ -853,136 +853,364 @@
 le;%0A
-%0A/**%0A * Detect mime type from file%0A * %0A * @author Rida Benjelloun (ridabenjelloun@apache.org)%0A */%0Apublic class MimeTypesUtils %7B%0A
+import java.net.URL;%0A%0A/**%0A * Detect the MIME type of a document from file name given as%0A * a String, a File, or a URL.%0A */%0Apublic class MimeTypesUtils %7B%0A%0A    /**%0A     * Returns the MIME type as specified by the ending of the name.%0A     *%0A     * @param name the resource name, e.g. %22filename.pdf%22%0A     * @return the MIME type, e.g. %22application/pdf%22%0A     */
 %0A   
@@ -1247,16 +1247,18 @@
 ype(
-File fil
+String nam
 e) %7B
@@ -1299,36 +1299,19 @@
     
-String name = file.getN
+name = n
 ame
-()
 .toL
@@ -2234,10 +2234,669 @@
 %0A    %7D%0A%0A
+    /**%0A     * Returns the MIME type as specified by the ending of the file's name.%0A     *%0A     * @param file the file to test, e.g. new File(%22filename.pdf%22)%0A     * @return the MIME type, e.g. %22application/pdf%22%0A     */%0A    public static String getMimeType(File file) %7B%0A        return getMimeType(file.getName());%0A    %7D%0A%0A%0A    /**%0A     * Returns the MIME type as specified by the ending of the URL's file name.%0A     *%0A     * @param url the url to test, e.g. new URL(%22http://mydomain.com/filename.pdf%22)%0A     * @return the MIME type, e.g. %22application/pdf%22%0A     */%0A    public static String getMimeType(URL url) %7B%0A        return getMimeType(url.getPath());%0A    %7D%0A%0A
 %7D%0A

Support MIME type detection based on a URL. Patch from Keith Bennett.