< prev index next >
jaxws/src/java.activation/share/classes/javax/activation/MimetypesFileTypeMap.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 26,35 ****
--- 26,37 ----
package javax.activation;
import java.io.*;
import java.net.*;
import java.util.*;
+ import java.security.AccessController;
+ import java.security.PrivilegedAction;
import com.sun.activation.registries.MimeTypeFile;
import com.sun.activation.registries.LogSupport;
/**
* This class extends FileTypeMap and provides data typing of files
*** 41,56 ****
* to search for MIME types in the MimetypesFileTypeMap, it searches
* MIME types files in the following order:
* <ol>
* <li> Programmatically added entries to the MimetypesFileTypeMap instance.
* <li> The file {@code .mime.types} in the user's home directory.
! * <li> The file {@literal <}<i>java.home</i>{@literal >}{@code /lib/mime.types}.
* <li> The file or resources named {@code META-INF/mime.types}.
* <li> The file or resource named {@code META-INF/mimetypes.default}
* (usually found only in the {@code activation.jar} file).
* </ol>
* <p>
* <b>MIME types file format:</b>
*
* <pre>{@code
* # comments begin with a '#'
* # the format is <mime type> <space separated file extensions>
--- 43,65 ----
* to search for MIME types in the MimetypesFileTypeMap, it searches
* MIME types files in the following order:
* <ol>
* <li> Programmatically added entries to the MimetypesFileTypeMap instance.
* <li> The file {@code .mime.types} in the user's home directory.
! * <li> The file {@code mime.types} in the Java runtime.
* <li> The file or resources named {@code META-INF/mime.types}.
* <li> The file or resource named {@code META-INF/mimetypes.default}
* (usually found only in the {@code activation.jar} file).
* </ol>
* <p>
+ * (The current implementation looks for the {@code mime.types} file
+ * in the Java runtime in the directory <i>java.home</i>{@code /conf}
+ * if it exists, and otherwise in the directory
+ * <i>java.home</i>{@code /lib}, where <i>java.home</i> is the value
+ * of the "java.home" System property. Note that the "conf" directory was
+ * introduced in JDK 9.)
+ * <p>
* <b>MIME types file format:</b>
*
* <pre>{@code
* # comments begin with a '#'
* # the format is <mime type> <space separated file extensions>
*** 70,80 ****
* We manage a collection of databases, searched in order.
*/
private MimeTypeFile[] DB;
private static final int PROG = 0; // programmatically added entries
! private static String defaultType = "application/octet-stream";
/**
* The default constructor.
*/
public MimetypesFileTypeMap() {
--- 79,112 ----
* We manage a collection of databases, searched in order.
*/
private MimeTypeFile[] DB;
private static final int PROG = 0; // programmatically added entries
! private static final String defaultType = "application/octet-stream";
!
! private static final String confDir;
!
! static {
! String dir = null;
! try {
! dir = (String)AccessController.doPrivileged(
! new PrivilegedAction() {
! public Object run() {
! String home = System.getProperty("java.home");
! String newdir = home + File.separator + "conf";
! File conf = new File(newdir);
! if (conf.exists())
! return newdir + File.separator;
! else
! return home + File.separator + "lib" + File.separator;
! }
! });
! } catch (Exception ex) {
! // ignore any exceptions
! }
! confDir = dir;
! }
/**
* The default constructor.
*/
public MimetypesFileTypeMap() {
*** 95,109 ****
} catch (SecurityException ex) {}
LogSupport.log("MimetypesFileTypeMap: load SYS");
try {
// check system's home
! String system_mimetypes = System.getProperty("java.home") +
! File.separator + "lib" + File.separator + "mime.types";
! mf = loadFile(system_mimetypes);
if (mf != null)
dbv.addElement(mf);
} catch (SecurityException ex) {}
LogSupport.log("MimetypesFileTypeMap: load JAR");
// load from the app's jar file
loadAllResources(dbv, "META-INF/mime.types");
--- 127,141 ----
} catch (SecurityException ex) {}
LogSupport.log("MimetypesFileTypeMap: load SYS");
try {
// check system's home
! if (confDir != null) {
! mf = loadFile(confDir + "mime.types");
if (mf != null)
dbv.addElement(mf);
+ }
} catch (SecurityException ex) {}
LogSupport.log("MimetypesFileTypeMap: load JAR");
// load from the app's jar file
loadAllResources(dbv, "META-INF/mime.types");
*** 237,246 ****
--- 269,279 ----
/**
* Construct a MimetypesFileTypeMap with programmatic entries
* added from the named file.
*
* @param mimeTypeFileName the file name
+ * @exception IOException for errors reading the file
*/
public MimetypesFileTypeMap(String mimeTypeFileName) throws IOException {
this();
DB[PROG] = new MimeTypeFile(mimeTypeFileName);
}
< prev index next >