< prev index next >
src/java.activation/share/classes/javax/activation/MailcapCommandMap.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * 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
@@ -27,10 +27,12 @@
package javax.activation;
import java.util.*;
import java.io.*;
import java.net.*;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import com.sun.activation.registries.MailcapFile;
import com.sun.activation.registries.LogSupport;
/**
* MailcapCommandMap extends the CommandMap
@@ -46,16 +48,23 @@
* to search for commands in the MailcapCommandMap, it searches
* mailcap files in the following order:
* <ol>
* <li> Programatically added entries to the MailcapCommandMap instance.
* <li> The file {@code .mailcap} in the user's home directory.
- * <li> The file {@literal <}<i>java.home</i>{@literal >}{@code /lib/mailcap}.
+ * <li> The file {@code mailcap} in the Java runtime.
* <li> The file or resources named {@code META-INF/mailcap}.
* <li> The file or resource named {@code META-INF/mailcap.default}
* (usually found only in the {@code activation.jar} file).
* </ol>
* <p>
+ * (The current implementation looks for the {@code mailcap} 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>Mailcap file format:</b><p>
*
* Mailcap files must conform to the mailcap
* file specification (RFC 1524, <i>A User Agent Configuration Mechanism
* For Multimedia Mail Format Information</i>).
@@ -118,10 +127,33 @@
* We manage a collection of databases, searched in order.
*/
private MailcapFile[] DB;
private static final int PROG = 0; // programmatically added entries
+ 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 MailcapCommandMap() {
super();
@@ -142,15 +174,15 @@
} catch (SecurityException ex) {}
LogSupport.log("MailcapCommandMap: load SYS");
try {
// check system's home
- String system_mailcap = System.getProperty("java.home") +
- File.separator + "lib" + File.separator + "mailcap";
- mf = loadFile(system_mailcap);
+ if (confDir != null) {
+ mf = loadFile(confDir + "mailcap");
if (mf != null)
dbv.add(mf);
+ }
} catch (SecurityException ex) {}
LogSupport.log("MailcapCommandMap: load JAR");
// load from the app's jar file
loadAllResources(dbv, "META-INF/mailcap");
@@ -631,10 +663,11 @@
* <A HREF="http://www.ietf.org/rfc/rfc1524.txt">RFC 1524</A>
* for details of the mailcap entry syntax. Only mailcap
* entries that specify a view command for the specified
* MIME type are returned.
*
+ * @param mimeType the MIME type
* @return array of native command entries
* @since 1.6, JAF 1.1
*/
public synchronized String[] getNativeCommands(String mimeType) {
List cmdList = new ArrayList();
< prev index next >