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
2727/**
2828 * MailcapCommandMap extends the CommandMap
2929 * abstract class. It implements a CommandMap whose configuration
30- * is based on mailcap files
30+ * is based on jakarta. mailcap files
3131 * (<A HREF="http://www.ietf.org/rfc/rfc1524.txt">RFC 1524</A>).
3232 * The MailcapCommandMap can be configured both programmatically
3333 * and via configuration files.
3434 * <p>
3535 * <b>Mailcap file search order:</b><p>
3636 * The MailcapCommandMap looks in various places in the user's
37- * system for mailcap file entries. When requests are made
37+ * system for jakarta. mailcap file entries. When requests are made
3838 * to search for commands in the MailcapCommandMap, it searches
39- * mailcap files in the following order:
39+ * jakarta. mailcap files in the following order:
4040 * <ol>
4141 * <li> Programatically added entries to the MailcapCommandMap instance.
42- * <li> The file <code>.mailcap</code> in the user's home directory.
43- * <li> The file <code>mailcap</code> in the Java runtime.
44- * <li> The file or resources named <code>META-INF/mailcap</code>.
45- * <li> The file or resource named <code>META-INF/mailcap.default</code>
42+ * <li> The file <code>.jakarta. mailcap</code> in the user's home directory.
43+ * <li> The file <code>jakarta. mailcap</code> in the Java runtime.
44+ * <li> The file or resources named <code>META-INF/jakarta. mailcap</code>.
45+ * <li> The file or resource named <code>META-INF/jakarta. mailcap.default</code>
4646 * (usually found only in the <code>activation.jar</code> file).
4747 * </ol>
4848 * <p>
49- * (The current implementation looks for the <code>mailcap</code> file
49+ * (The current implementation looks for the <code>jakarta. mailcap</code> file
5050 * in the Java runtime in the directory <code><i>java.home</i>/conf</code>
5151 * if it exists, and otherwise in the directory
5252 * <code><i>java.home</i>/lib</code>, where <i>java.home</i> is the value
5555 * <p>
5656 * <b>Mailcap file format:</b><p>
5757 *
58- * Mailcap files must conform to the mailcap
58+ * Mailcap files must conform to the jakarta. mailcap
5959 * file specification (RFC 1524, <i>A User Agent Configuration Mechanism
6060 * For Multimedia Mail Format Information</i>).
6161 * The file format consists of entries corresponding to
6262 * particular MIME types. In general, the specification
6363 * specifies <i>applications</i> for clients to use when they
6464 * themselves cannot operate on the specified MIME type. The
6565 * MailcapCommandMap extends this specification by using a parameter mechanism
66- * in mailcap files that allows JavaBeans(tm) components to be specified as
66+ * in jakarta. mailcap files that allows JavaBeans(tm) components to be specified as
6767 * corresponding to particular commands for a MIME type.<p>
6868 *
69- * When a mailcap file is
69+ * When a jakarta. mailcap file is
7070 * parsed, the MailcapCommandMap recognizes certain parameter signatures,
7171 * specifically those parameter names that begin with <code>x-java-</code>.
7272 * The MailcapCommandMap uses this signature to find
9292 * view command would only be used if a non-fallback view command for
9393 * the MIME type could not be found.<p>
9494 *
95- * MailcapCommandMap aware mailcap files have the
95+ * MailcapCommandMap aware jakarta. mailcap files have the
9696 * following general form:<p>
9797 * <code>
9898 * # Comments begin with a '#' and continue to the end of the line.<br>
102102 * # and a parameter list looks like: <br>
103103 * text/plain; ; x-java-view=com.sun.TextViewer; x-java-edit=com.sun.TextEdit
104104 * <br>
105- * # Note that mailcap entries that do not contain 'x-java' parameters<br>
105+ * # Note that jakarta. mailcap entries that do not contain 'x-java' parameters<br>
106106 * # and comply to RFC 1524 are simply ignored:<br>
107107 * image/gif; /usr/dt/bin/sdtimage %s<br>
108108 *
@@ -149,10 +149,14 @@ public MailcapCommandMap() {
149149 String user_home = System .getProperty ("user.home" );
150150
151151 if (user_home != null ) {
152- String path = user_home + File .separator + ".mailcap" ;
152+ String [] paths = new String [] {user_home + File .separator + ".jakarta.mailcap" , user_home + File .separator + ".mailcap" };
153+ for (String path : paths ) {
153154 mf = loadFile (path );
154- if (mf != null )
155+ if (mf != null ) {
155156 dbv .add (mf );
157+ break ;
158+ }
159+ }
156160 }
157161 } catch (SecurityException ex ) {
158162 }
@@ -161,19 +165,24 @@ public MailcapCommandMap() {
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
171180 LogSupport .log ("MailcapCommandMap: load JAR" );
172181 // load from the app's jar file
173- loadAllResources (dbv , "META-INF/mailcap" );
182+ loadAllResources (dbv , "META-INF/jakarta.mailcap" , "META-INF/ mailcap" );
174183
175184 LogSupport .log ("MailcapCommandMap: load DEF" );
176- mf = loadResource ("/META-INF/mailcap.default" );
185+ mf = loadResource ("/META-INF/jakarta.mailcap.default" , "/META-INF/ mailcap.default" );
177186
178187 if (mf != null )
179188 dbv .add (mf );
@@ -185,18 +194,19 @@ public MailcapCommandMap() {
185194 /**
186195 * Load from the named resource.
187196 */
188- private MailcapRegistry loadResource (String name ) {
197+ private MailcapRegistry loadResource (String ... names ) {
198+ for (String name : names ) {
189199 try (InputStream clis = this .getClass ().getResourceAsStream (name )) {
190200 if (clis != null ) {
191201 MailcapRegistry mf = getImplementation ().getByInputStream (clis );
192202 if (LogSupport .isLoggable ())
193203 LogSupport .log ("MailcapCommandMap: successfully loaded " +
194- " mailcap file: " + name );
204+ "jakarta. mailcap file: " + name );
195205 return mf ;
196206 } else {
197207 if (LogSupport .isLoggable ())
198208 LogSupport .log ("MailcapCommandMap: not loading " +
199- " mailcap file: " + name );
209+ "jakarta. mailcap file: " + name );
200210 }
201211 } catch (IOException | SecurityException e ) {
202212 if (LogSupport .isLoggable ())
@@ -207,14 +217,16 @@ private MailcapRegistry loadResource(String name) {
207217 "MailcapRegistry: can't load " + name , e );
208218 }
209219 }
220+ }
210221 return null ;
211222 }
212223
213224 /**
214225 * Load all of the named resource.
215226 */
216- private void loadAllResources (List <MailcapRegistry > v , String name ) {
227+ private void loadAllResources (List <MailcapRegistry > v , String ... names ) {
217228 boolean anyLoaded = false ;
229+ for (String name : names ) {
218230 try {
219231 URL [] urls ;
220232 ClassLoader cld = null ;
@@ -240,12 +252,12 @@ private void loadAllResources(List<MailcapRegistry> v, String name) {
240252 if (LogSupport .isLoggable ())
241253 LogSupport .log ("MailcapCommandMap: " +
242254 "successfully loaded " +
243- " mailcap file from URL: " +
255+ "jakarta. mailcap file from URL: " +
244256 url );
245257 } else {
246258 if (LogSupport .isLoggable ())
247259 LogSupport .log ("MailcapCommandMap: " +
248- "not loading mailcap " +
260+ "not loading jakarta. mailcap " +
249261 "file from URL: " + url );
250262 }
251263 } catch (IOException | SecurityException ioex ) {
@@ -259,17 +271,24 @@ private void loadAllResources(List<MailcapRegistry> v, String name) {
259271 }
260272 }
261273 }
274+ // Even if nothing was loaded, we stop it because resources were found.
275+ break ;
262276 }
263277 } catch (Exception ex ) {
264278 if (LogSupport .isLoggable ())
265279 LogSupport .log ("MailcapCommandMap: can't load " + name , ex );
266280 }
281+ }
267282
268283 // if failed to load anything, fall back to old technique, just in case
269284 if (!anyLoaded ) {
270285 if (LogSupport .isLoggable ())
271286 LogSupport .log ("MailcapCommandMap: !anyLoaded" );
272- MailcapRegistry mf = loadResource ("/" + name );
287+ String [] resources = new String [names .length ];
288+ for (int i = 0 ; i < names .length ; i ++) {
289+ resources [i ] = "/" + names [i ];
290+ }
291+ MailcapRegistry mf = loadResource (resources );
273292 if (mf != null )
274293 v .add (mf );
275294 }
@@ -298,9 +317,9 @@ private MailcapRegistry loadFile(String name) {
298317
299318 /**
300319 * Constructor that allows the caller to specify the path
301- * of a <i>mailcap</i> file.
320+ * of a <i>jakarta. mailcap</i> file.
302321 *
303- * @param fileName The name of the <i>mailcap</i> file to open
322+ * @param fileName The name of the <i>jakarta. mailcap</i> file to open
304323 * @throws IOException if the file can't be accessed
305324 */
306325 public MailcapCommandMap (String fileName ) throws IOException {
@@ -325,9 +344,9 @@ public MailcapCommandMap(String fileName) throws IOException {
325344
326345 /**
327346 * Constructor that allows the caller to specify an <i>InputStream</i>
328- * containing a mailcap file.
347+ * containing a jakarta. mailcap file.
329348 *
330- * @param is InputStream of the <i>mailcap</i> file to open
349+ * @param is InputStream of the <i>jakarta. mailcap</i> file to open
331350 */
332351 public MailcapCommandMap (InputStream is ) {
333352 this ();
@@ -351,11 +370,11 @@ public MailcapCommandMap(InputStream is) {
351370
352371 /**
353372 * Get the preferred command list for a MIME Type. The MailcapCommandMap
354- * searches the mailcap files as described above under
373+ * searches the jakarta. mailcap files as described above under
355374 * <i>Mailcap file search order</i>.<p>
356375 *
357376 * The result of the search is a proper subset of available
358- * commands in all mailcap files known to this instance of
377+ * commands in all jakarta. mailcap files known to this instance of
359378 * MailcapCommandMap. The first entry for a particular command
360379 * is considered the preferred command.
361380 *
@@ -421,7 +440,7 @@ private boolean checkForVerb(List<CommandInfo> cmdList, String verb) {
421440 }
422441
423442 /**
424- * Get all the available commands in all mailcap files known to
443+ * Get all the available commands in all jakarta. mailcap files known to
425444 * this instance of MailcapCommandMap for this MIME type.
426445 *
427446 * @param mimeType the MIME type
@@ -525,10 +544,10 @@ public synchronized CommandInfo getCommand(String mimeType,
525544 * Add entries to the registry. Programmatically
526545 * added entries are searched before other entries.<p>
527546 *
528- * The string that is passed in should be in mailcap
547+ * The string that is passed in should be in jakarta. mailcap
529548 * format.
530549 *
531- * @param mail_cap a correctly formatted mailcap string
550+ * @param mail_cap a correctly formatted jakarta. mailcap string
532551 */
533552 public synchronized void addMailcap (String mail_cap ) {
534553 // check to see if one exists
@@ -657,11 +676,11 @@ public synchronized String[] getMimeTypes() {
657676 /**
658677 * Get the native commands for the given MIME type.
659678 * Returns an array of strings where each string is
660- * an entire mailcap file entry. The application
679+ * an entire jakarta. mailcap file entry. The application
661680 * will need to parse the entry to extract the actual
662681 * command as well as any attributes it needs. See
663682 * <A HREF="http://www.ietf.org/rfc/rfc1524.txt">RFC 1524</A>
664- * for details of the mailcap entry syntax. Only mailcap
683+ * for details of the jakarta. mailcap entry syntax. Only jakarta. mailcap
665684 * entries that specify a view command for the specified
666685 * MIME type are returned.
667686 *
0 commit comments