11/*
2- * Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 1997, 2025 Oracle and/or its affiliates. All rights reserved.
33 *
44 * This program and the accompanying materials are made available under the
55 * terms of the Eclipse Distribution License v. 1.0, which is available at
2121/**
2222 * MailcapCommandMap extends the CommandMap
2323 * abstract class. It implements a CommandMap whose configuration
24- * is based on mailcap files
24+ * is based on jakarta. mailcap files
2525 * (<A HREF="http://www.ietf.org/rfc/rfc1524.txt">RFC 1524</A>).
2626 * The MailcapCommandMap can be configured both programmatically
2727 * and via configuration files.
2828 * <p>
2929 * <b>Mailcap file search order:</b><p>
3030 * The MailcapCommandMap looks in various places in the user's
31- * system for mailcap file entries. When requests are made
31+ * system for jakarta. mailcap file entries. When requests are made
3232 * to search for commands in the MailcapCommandMap, it searches
33- * mailcap files in the following order:
33+ * jakarta. mailcap files in the following order:
3434 * <ol>
3535 * <li> Programatically added entries to the MailcapCommandMap instance.
36- * <li> The file <code>.mailcap</code> in the user's home directory.
37- * <li> The file <code>mailcap</code> in the Java runtime.
38- * <li> The file or resources named <code>META-INF/mailcap</code>.
39- * <li> The file or resource named <code>META-INF/mailcap.default</code>
36+ * <li> The file <code>.jakarta. mailcap</code> in the user's home directory.
37+ * <li> The file <code>jakarta. mailcap</code> in the Java runtime.
38+ * <li> The file or resources named <code>META-INF/jakarta. mailcap</code>.
39+ * <li> The file or resource named <code>META-INF/jakarta. mailcap.default</code>
4040 * (usually found only in the <code>activation.jar</code> file).
4141 * </ol>
4242 * <p>
43- * (The current implementation looks for the <code>mailcap</code> file
43+ * (The current implementation looks for the <code>jakarta. mailcap</code> file
4444 * in the Java runtime in the directory <code><i>java.home</i>/conf</code>
4545 * if it exists, and otherwise in the directory
4646 * <code><i>java.home</i>/lib</code>, where <i>java.home</i> is the value
4949 * <p>
5050 * <b>Mailcap file format:</b><p>
5151 *
52- * Mailcap files must conform to the mailcap
52+ * Mailcap files must conform to the jakarta. mailcap
5353 * file specification (RFC 1524, <i>A User Agent Configuration Mechanism
5454 * For Multimedia Mail Format Information</i>).
5555 * The file format consists of entries corresponding to
5656 * particular MIME types. In general, the specification
5757 * specifies <i>applications</i> for clients to use when they
5858 * themselves cannot operate on the specified MIME type. The
5959 * MailcapCommandMap extends this specification by using a parameter mechanism
60- * in mailcap files that allows JavaBeans(tm) components to be specified as
60+ * in jakarta. mailcap files that allows JavaBeans(tm) components to be specified as
6161 * corresponding to particular commands for a MIME type.<p>
6262 *
63- * When a mailcap file is
63+ * When a jakarta. mailcap file is
6464 * parsed, the MailcapCommandMap recognizes certain parameter signatures,
6565 * specifically those parameter names that begin with <code>x-java-</code>.
6666 * The MailcapCommandMap uses this signature to find
8686 * view command would only be used if a non-fallback view command for
8787 * the MIME type could not be found.<p>
8888 *
89- * MailcapCommandMap aware mailcap files have the
89+ * MailcapCommandMap aware jakarta. mailcap files have the
9090 * following general form:<p>
9191 * <code>
9292 * # Comments begin with a '#' and continue to the end of the line.<br>
9696 * # and a parameter list looks like: <br>
9797 * text/plain; ; x-java-view=com.sun.TextViewer; x-java-edit=com.sun.TextEdit
9898 * <br>
99- * # Note that mailcap entries that do not contain 'x-java' parameters<br>
99+ * # Note that jakarta. mailcap entries that do not contain 'x-java' parameters<br>
100100 * # and comply to RFC 1524 are simply ignored:<br>
101101 * image/gif; /usr/dt/bin/sdtimage %s<br>
102102 *
@@ -150,29 +150,38 @@ public MailcapCommandMap() {
150150 String user_home = System .getProperty ("user.home" );
151151
152152 if (user_home != null ) {
153- String path = user_home + File .separator + ".mailcap" ;
153+ String [] paths = new String [] {user_home + File .separator + ".jakarta.mailcap" , user_home + File .separator + ".mailcap" };
154+ for (String path : paths ) {
154155 mf = loadFile (path );
155- if (mf != null )
156+ if (mf != null ) {
156157 dbv .add (mf );
158+ break ;
159+ }
160+ }
157161 }
158162 } catch (SecurityException ex ) {}
159163
160164 LogSupport .log ("MailcapCommandMap: load SYS" );
161165 try {
162166 // check system's home
163167 if (confDir != null ) {
164- mf = loadFile (confDir + "mailcap" );
165- if (mf != null )
168+ String [] confs = new String [] {"jakarta.mailcap" , "mailcap" };
169+ for (String conf : confs ) {
170+ mf = loadFile (confDir + conf );
171+ if (mf != null ) {
166172 dbv .add (mf );
173+ break ;
174+ }
175+ }
167176 }
168177 } catch (SecurityException ex ) {}
169178
170179 LogSupport .log ("MailcapCommandMap: load JAR" );
171180 // load from the app's jar file
172- loadAllResources (dbv , "META-INF/mailcap" );
181+ loadAllResources (dbv , "META-INF/jakarta.mailcap" , "META-INF/mailcap" );
173182
174183 LogSupport .log ("MailcapCommandMap: load DEF" );
175- mf = loadResource ("/META-INF/mailcap.default" );
184+ mf = loadResource ("/META-INF/jakarta.mailcap.default" , "/META-INF/mailcap.default" );
176185
177186 if (mf != null )
178187 dbv .add (mf );
@@ -184,18 +193,19 @@ public MailcapCommandMap() {
184193 /**
185194 * Load from the named resource.
186195 */
187- private MailcapRegistry loadResource (String name ) {
196+ private MailcapRegistry loadResource (String ... names ) {
197+ for (String name : names ) {
188198 try (InputStream clis = SecuritySupport .getResourceAsStream (this .getClass (), name )) {
189199 if (clis != null ) {
190200 MailcapRegistry mf = getImplementation ().getByInputStream (clis );
191201 if (LogSupport .isLoggable ())
192202 LogSupport .log ("MailcapCommandMap: successfully loaded " +
193- " mailcap file: " + name );
203+ "jakarta. mailcap file: " + name );
194204 return mf ;
195205 } else {
196206 if (LogSupport .isLoggable ())
197207 LogSupport .log ("MailcapCommandMap: not loading " +
198- " mailcap file: " + name );
208+ "jakarta. mailcap file: " + name );
199209 }
200210 } catch (IOException | SecurityException e ) {
201211 if (LogSupport .isLoggable ())
@@ -206,14 +216,16 @@ private MailcapRegistry loadResource(String name) {
206216 "MailcapRegistry: can't load " + name , e );
207217 }
208218 }
219+ }
209220 return null ;
210221 }
211222
212223 /**
213224 * Load all of the named resource.
214225 */
215- private void loadAllResources (List <MailcapRegistry > v , String name ) {
226+ private void loadAllResources (List <MailcapRegistry > v , String ... names ) {
216227 boolean anyLoaded = false ;
228+ for (String name : names ) {
217229 try {
218230 URL [] urls ;
219231 ClassLoader cld = null ;
@@ -239,12 +251,12 @@ private void loadAllResources(List<MailcapRegistry> v, String name) {
239251 if (LogSupport .isLoggable ())
240252 LogSupport .log ("MailcapCommandMap: " +
241253 "successfully loaded " +
242- " mailcap file from URL: " +
254+ "jakarta. mailcap file from URL: " +
243255 url );
244256 } else {
245257 if (LogSupport .isLoggable ())
246258 LogSupport .log ("MailcapCommandMap: " +
247- "not loading mailcap " +
259+ "not loading jakarta. mailcap " +
248260 "file from URL: " + url );
249261 }
250262 } catch (IOException | SecurityException ioex ) {
@@ -258,17 +270,24 @@ private void loadAllResources(List<MailcapRegistry> v, String name) {
258270 }
259271 }
260272 }
273+ // Even if nothing was loaded, we stop it because resources were found.
274+ break ;
261275 }
262276 } catch (Exception ex ) {
263277 if (LogSupport .isLoggable ())
264278 LogSupport .log ("MailcapCommandMap: can't load " + name , ex );
265279 }
280+ }
266281
267282 // if failed to load anything, fall back to old technique, just in case
268283 if (!anyLoaded ) {
269284 if (LogSupport .isLoggable ())
270285 LogSupport .log ("MailcapCommandMap: !anyLoaded" );
271- MailcapRegistry mf = loadResource ("/" + name );
286+ String [] resources = new String [names .length ];
287+ for (int i = 0 ; i < names .length ; i ++) {
288+ resources [i ] = "/" + names [i ];
289+ }
290+ MailcapRegistry mf = loadResource (resources );
272291 if (mf != null )
273292 v .add (mf );
274293 }
@@ -297,9 +316,9 @@ private MailcapRegistry loadFile(String name) {
297316
298317 /**
299318 * Constructor that allows the caller to specify the path
300- * of a <i>mailcap</i> file.
319+ * of a <i>jakarta. mailcap</i> file.
301320 *
302- * @param fileName The name of the <i>mailcap</i> file to open
321+ * @param fileName The name of the <i>jakarta. mailcap</i> file to open
303322 * @exception IOException if the file can't be accessed
304323 */
305324 public MailcapCommandMap (String fileName ) throws IOException {
@@ -324,9 +343,9 @@ public MailcapCommandMap(String fileName) throws IOException {
324343
325344 /**
326345 * Constructor that allows the caller to specify an <i>InputStream</i>
327- * containing a mailcap file.
346+ * containing a jakarta. mailcap file.
328347 *
329- * @param is InputStream of the <i>mailcap</i> file to open
348+ * @param is InputStream of the <i>jakarta. mailcap</i> file to open
330349 */
331350 public MailcapCommandMap (InputStream is ) {
332351 this ();
@@ -350,11 +369,11 @@ public MailcapCommandMap(InputStream is) {
350369
351370 /**
352371 * Get the preferred command list for a MIME Type. The MailcapCommandMap
353- * searches the mailcap files as described above under
372+ * searches the jakarta. mailcap files as described above under
354373 * <i>Mailcap file search order</i>.<p>
355374 *
356375 * The result of the search is a proper subset of available
357- * commands in all mailcap files known to this instance of
376+ * commands in all jakarta. mailcap files known to this instance of
358377 * MailcapCommandMap. The first entry for a particular command
359378 * is considered the preferred command.
360379 *
@@ -420,7 +439,7 @@ private boolean checkForVerb(List<CommandInfo> cmdList, String verb) {
420439 }
421440
422441 /**
423- * Get all the available commands in all mailcap files known to
442+ * Get all the available commands in all jakarta. mailcap files known to
424443 * this instance of MailcapCommandMap for this MIME type.
425444 *
426445 * @param mimeType the MIME type
@@ -524,10 +543,10 @@ public synchronized CommandInfo getCommand(String mimeType,
524543 * Add entries to the registry. Programmatically
525544 * added entries are searched before other entries.<p>
526545 *
527- * The string that is passed in should be in mailcap
546+ * The string that is passed in should be in jakarta. mailcap
528547 * format.
529548 *
530- * @param mail_cap a correctly formatted mailcap string
549+ * @param mail_cap a correctly formatted jakarta. mailcap string
531550 */
532551 public synchronized void addMailcap (String mail_cap ) {
533552 // check to see if one exists
@@ -656,11 +675,11 @@ public synchronized String[] getMimeTypes() {
656675 /**
657676 * Get the native commands for the given MIME type.
658677 * Returns an array of strings where each string is
659- * an entire mailcap file entry. The application
678+ * an entire jakarta. mailcap file entry. The application
660679 * will need to parse the entry to extract the actual
661680 * command as well as any attributes it needs. See
662681 * <A HREF="http://www.ietf.org/rfc/rfc1524.txt">RFC 1524</A>
663- * for details of the mailcap entry syntax. Only mailcap
682+ * for details of the jakarta. mailcap entry syntax. Only jakarta. mailcap
664683 * entries that specify a view command for the specified
665684 * MIME type are returned.
666685 *
0 commit comments