src/share/jaf_classes/javax/activation/FileTypeMap.java

Tue, 06 Mar 2012 16:09:35 -0800

author
ohair
date
Tue, 06 Mar 2012 16:09:35 -0800
changeset 286
f50545b5e2f1
child 494
2fcd3ddb57a6
permissions
-rw-r--r--

7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom

     1 /*
     2  * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package javax.activation;
    28 import java.io.File;
    30 /**
    31  * The FileTypeMap is an abstract class that provides a data typing
    32  * interface for files. Implementations of this class will
    33  * implement the getContentType methods which will derive a content
    34  * type from a file name or a File object. FileTypeMaps could use any
    35  * scheme to determine the data type, from examining the file extension
    36  * of a file (like the MimetypesFileTypeMap) to opening the file and
    37  * trying to derive its type from the contents of the file. The
    38  * FileDataSource class uses the default FileTypeMap (a MimetypesFileTypeMap
    39  * unless changed) to determine the content type of files.
    40  *
    41  * @see javax.activation.FileTypeMap
    42  * @see javax.activation.FileDataSource
    43  * @see javax.activation.MimetypesFileTypeMap
    44  *
    45  * @since 1.6
    46  */
    48 public abstract class FileTypeMap {
    50     private static FileTypeMap defaultMap = null;
    52     /**
    53      * The default constructor.
    54      */
    55     public FileTypeMap() {
    56         super();
    57     }
    59     /**
    60      * Return the type of the file object. This method should
    61      * always return a valid MIME type.
    62      *
    63      * @param file A file to be typed.
    64      * @return The content type.
    65      */
    66     abstract public String getContentType(File file);
    68     /**
    69      * Return the type of the file passed in.  This method should
    70      * always return a valid MIME type.
    71      *
    72      * @param filename the pathname of the file.
    73      * @return The content type.
    74      */
    75     abstract public String getContentType(String filename);
    77     /**
    78      * Sets the default FileTypeMap for the system. This instance
    79      * will be returned to callers of getDefaultFileTypeMap.
    80      *
    81      * @param map The FileTypeMap.
    82      * @exception SecurityException if the caller doesn't have permission
    83      *                                  to change the default
    84      */
    85     public static void setDefaultFileTypeMap(FileTypeMap map) {
    86         SecurityManager security = System.getSecurityManager();
    87         if (security != null) {
    88             try {
    89                 // if it's ok with the SecurityManager, it's ok with me...
    90                 security.checkSetFactory();
    91             } catch (SecurityException ex) {
    92                 // otherwise, we also allow it if this code and the
    93                 // factory come from the same class loader (e.g.,
    94                 // the JAF classes were loaded with the applet classes).
    95                 if (FileTypeMap.class.getClassLoader() !=
    96                         map.getClass().getClassLoader())
    97                     throw ex;
    98             }
    99         }
   100         defaultMap = map;
   101     }
   103     /**
   104      * Return the default FileTypeMap for the system.
   105      * If setDefaultFileTypeMap was called, return
   106      * that instance, otherwise return an instance of
   107      * <code>MimetypesFileTypeMap</code>.
   108      *
   109      * @return The default FileTypeMap
   110      * @see javax.activation.FileTypeMap#setDefaultFileTypeMap
   111      */
   112     public static FileTypeMap getDefaultFileTypeMap() {
   113         // XXX - probably should be synchronized
   114         if (defaultMap == null)
   115             defaultMap = new MimetypesFileTypeMap();
   116         return defaultMap;
   117     }
   118 }

mercurial