Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
   *
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License. You can obtain
  * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
  * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  *
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
  * Sun designates this particular file as subject to the "Classpath" exception
  * as provided by Sun in the GPL Version 2 section of the License file that
  * accompanied this code.  If applicable, add the following below the License
  * Header, with the fields enclosed by brackets [] replaced by your own
  * identifying information: "Portions Copyrighted [year]
  * [name of copyright owner]"
  *
  * Contributor(s):
  *
  * If you wish your version of this file to be governed by only the CDDL or
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
  * elects to include this software in this distribution under the [CDDL or GPL
  * Version 2] license."  If you don't indicate a single choice of license, a
  * recipient has the option to distribute your version of this file under
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
  * its licensees as provided above.  However, if you add GPL Version 2 code
  * and therefore, elected the GPL Version 2 license, then the option applies
  * only if the new code is made subject to such option by the copyright
  * holder.
  *
  *
  * This file incorporates work covered by the following copyright and
  * permission notice:
  *
  * Copyright 2004 The Apache Software Foundation
  *
  * Licensed 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.tomcat.util.http;
 
 import java.net.*;
 import java.util.*;


A mime type map that implements the java.net.FileNameMap interface.

Author(s):
James Duncan Davidson [duncan@eng.sun.com]
Jason Hunter [jch@eng.sun.com]
 
 public class MimeMap implements FileNameMap {
 
     // Defaults - all of them are "well-known" types,
     // you can add using normal web.xml.
     
     public static final Hashtable defaultMap=new Hashtable(101);
     static {
         .put("txt""text/plain");
         .put("html","text/html");
         .put("htm""text/html");
         .put("gif""image/gif");
         .put("jpg""image/jpeg");
         .put("jpe""image/jpeg");
         .put("jpeg""image/jpeg");
         .put("java""text/plain");
         .put("body""text/html");
         .put("rtx""text/richtext");
         .put("tsv""text/tab-separated-values");
         .put("etx""text/x-setext");
         .put("ps""application/x-postscript");
         .put("class""application/java");
         .put("csh""application/x-csh");
         .put("sh""application/x-sh");
         .put("tcl""application/x-tcl");
         .put("tex""application/x-tex");
         .put("texinfo""application/x-texinfo");
         .put("texi""application/x-texinfo");
         .put("t""application/x-troff");
         .put("tr""application/x-troff");
         .put("roff""application/x-troff");
         .put("man""application/x-troff-man");
         .put("me""application/x-troff-me");
        .put("ms""application/x-wais-source");
        .put("src""application/x-wais-source");
        .put("zip""application/zip");
        .put("bcpio""application/x-bcpio");
        .put("cpio""application/x-cpio");
        .put("gtar""application/x-gtar");
        .put("shar""application/x-shar");
        .put("sv4cpio""application/x-sv4cpio");
        .put("sv4crc""application/x-sv4crc");
        .put("tar""application/x-tar");
        .put("ustar""application/x-ustar");
        .put("dvi""application/x-dvi");
        .put("hdf""application/x-hdf");
        .put("latex""application/x-latex");
        .put("bin""application/octet-stream");
        .put("oda""application/oda");
        .put("pdf""application/pdf");
        .put("ps""application/postscript");
        .put("eps""application/postscript");
        .put("ai""application/postscript");
        .put("rtf""application/rtf");
        .put("nc""application/x-netcdf");
        .put("cdf""application/x-netcdf");
        .put("cer""application/x-x509-ca-cert");
        .put("exe""application/octet-stream");
        .put("gz""application/x-gzip");
        .put("Z""application/x-compress");
        .put("z""application/x-compress");
        .put("hqx""application/mac-binhex40");
        .put("mif""application/x-mif");
        .put("ief""image/ief");
        .put("tiff""image/tiff");
        .put("tif""image/tiff");
        .put("ras""image/x-cmu-raster");
        .put("pnm""image/x-portable-anymap");
        .put("pbm""image/x-portable-bitmap");
        .put("pgm""image/x-portable-graymap");
        .put("ppm""image/x-portable-pixmap");
        .put("rgb""image/x-rgb");
        .put("xbm""image/x-xbitmap");
        .put("xpm""image/x-xpixmap");
        .put("xwd""image/x-xwindowdump");
        .put("au""audio/basic");
        .put("snd""audio/basic");
        .put("aif""audio/x-aiff");
        .put("aiff""audio/x-aiff");
        .put("aifc""audio/x-aiff");
        .put("wav""audio/x-wav");
        .put("mpeg""video/mpeg");
        .put("mpg""video/mpeg");
        .put("mpe""video/mpeg");
        .put("qt""video/quicktime");
        .put("mov""video/quicktime");
        .put("avi""video/x-msvideo");
        .put("movie""video/x-sgi-movie");
        .put("avx""video/x-rad-screenplay");
        .put("wrl""x-world/x-vrml");
        .put("mpv2""video/mpeg2");
        
        /* Add XML related MIMEs */
        
        .put("xml""text/xml");
        .put("xsl""text/xml");        
        .put("svg""image/svg+xml");
        .put("svgz""image/svg+xml");
        .put("wbmp""image/vnd.wap.wbmp");
        .put("wml""text/vnd.wap.wml");
        .put("wmlc""application/vnd.wap.wmlc");
        .put("wmls""text/vnd.wap.wmlscript");
        .put("wmlscriptc""application/vnd.wap.wmlscriptc");
    }
    
    private Hashtable map = new Hashtable();
    public void addContentType(String extnString type) {
        .put(extntype.toLowerCase());
    }
    public Enumeration getExtensions() {
        return .keys();
    }
    public String getContentType(String extn) {
        String type = (String).get(extn.toLowerCase());
	iftype == null ) type=(String).getextn );
	return type;
    }
    public void removeContentType(String extn) {
        .remove(extn.toLowerCase());
    }

    
Get extension of file, without fragment id
    public static String getExtensionString fileName ) {
        // play it safe and get rid of any fragment id
        // that might be there
	int length=fileName.length();
        int newEnd = fileName.lastIndexOf('#');
	ifnewEnd== -1 ) newEnd=length;
	// Instead of creating a new string.
	//         if (i != -1) {
	//             fileName = fileName.substring(0, i);
	//         }
        int i = fileName.lastIndexOf('.'newEnd );
        if (i != -1) {
             return  fileName.substring(i + 1, newEnd );
        } else {
            // no extension, no content type
            return null;
        }
    }
    
    public String getContentTypeFor(String fileName) {
	String extn=getExtensionfileName );
        if (extn!=null) {
            return getContentType(extn);
        } else {
            // no extension, no content type
            return null;
        }
    }
New to GrepCode? Check out our FAQ X