src/java.base/share/classes/sun/net/www/MimeEntry.java
author redestad
Thu, 13 Dec 2018 15:31:05 +0100
changeset 53018 8bf9268df0e2
parent 47866 39db80b32b69
permissions -rw-r--r--
8215281: Use String.isEmpty() when applicable in java.base Reviewed-by: dfuchs, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
26219
1a19360ff122 8054714: Use StringJoiner where it makes the code cleaner
igerasim
parents: 25859
diff changeset
     2
 * Copyright (c) 1994, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.net.www;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
26219
1a19360ff122 8054714: Use StringJoiner where it makes the code cleaner
igerasim
parents: 25859
diff changeset
    29
import java.util.StringJoiner;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
public class MimeEntry implements Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    private String typeName;    // of the form: "type/subtype"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    private String tempFileNameTemplate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    private int action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    private String command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    private String description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private String imageFileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private String fileExtensions[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    boolean starred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    // Actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public static final int             UNKNOWN                 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    public static final int             LOAD_INTO_BROWSER       = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public static final int             SAVE_TO_FILE            = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public static final int             LAUNCH_APPLICATION      = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    static final String[] actionKeywords = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        "unknown",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        "browser",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        "save",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        "application",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Construct an empty entry of the given type and subtype.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public MimeEntry(String type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        // Default action is UNKNOWN so clients can decide what the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        // should be, typically save to file or ask user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        this(type, UNKNOWN, null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // The next two constructors are used only by the deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    // PlatformMimeTable classes or, in last case, is called by the public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    // constructor.  They are kept here anticipating putting support for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    // mailcap formatted config files back in (so BOTH the properties format
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    // and the mailcap formats are supported).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    MimeEntry(String type, String imageFileName, String extensionString) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        typeName = type.toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        action = UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        command = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        this.imageFileName = imageFileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        setExtensions(extensionString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        starred = isStarred(typeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    // For use with MimeTable::parseMailCap
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    MimeEntry(String typeName, int action, String command,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
              String tempFileNameTemplate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        this.typeName = typeName.toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        this.action = action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        this.command = command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        this.imageFileName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        this.fileExtensions = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        this.tempFileNameTemplate = tempFileNameTemplate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // This is the one called by the public constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    MimeEntry(String typeName, int action, String command,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
              String imageFileName, String fileExtensions[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        this.typeName = typeName.toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        this.action = action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        this.command = command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this.imageFileName = imageFileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        this.fileExtensions = fileExtensions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        starred = isStarred(typeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public synchronized String getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        return typeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public synchronized void setType(String type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        typeName = type.toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public synchronized int getAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        return action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public synchronized void setAction(int action, String command) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        this.action = action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        this.command = command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public synchronized void setAction(int action) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        this.action = action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public synchronized String getLaunchString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public synchronized void setCommand(String command) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        this.command = command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public synchronized String getDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        return (description != null ? description : typeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public synchronized void setDescription(String description) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        this.description = description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    // ??? what to return for the image -- the file name or should this return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    // something more advanced like an image source or something?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    // returning the name has the least policy associated with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    // pro tempore, we'll use the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public String getImageFileName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        return imageFileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public synchronized void setImageFileName(String filename) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        File file = new File(filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        if (file.getParent() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            imageFileName = System.getProperty(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                     "java.net.ftp.imagepath."+filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            imageFileName = filename;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (filename.lastIndexOf('.') < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            imageFileName = imageFileName + ".gif";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public String getTempFileTemplate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return tempFileNameTemplate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public synchronized String[] getExtensions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        return fileExtensions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public synchronized String getExtensionsAsList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        String extensionsAsString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if (fileExtensions != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            for (int i = 0; i < fileExtensions.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                extensionsAsString += fileExtensions[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                if (i < (fileExtensions.length - 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    extensionsAsString += ",";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return extensionsAsString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public synchronized void setExtensions(String extensionString) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        StringTokenizer extTokens = new StringTokenizer(extensionString, ",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        int numExts = extTokens.countTokens();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        String extensionStrings[] = new String[numExts];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        for (int i = 0; i < numExts; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            String ext = (String)extTokens.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            extensionStrings[i] = ext.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        fileExtensions = extensionStrings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    private boolean isStarred(String typeName) {
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 47866
diff changeset
   204
        return typeName != null && typeName.endsWith("/*");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Invoke the MIME type specific behavior for this MIME type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Returned value can be one of several types:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * <li>A thread -- the caller can choose when to launch this thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * <li>A string -- the string is loaded into the browser directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * <li>An input stream -- the caller can read from this byte stream and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *     will typically store the results in a file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * <li>A document (?) --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public Object launch(java.net.URLConnection urlc, InputStream is, MimeTable mt) throws ApplicationLaunchException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        switch (action) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        case SAVE_TO_FILE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            // REMIND: is this really the right thing to do?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                return is;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            } catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                // I18N
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                return "Load to file failed:\n" + e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        case LOAD_INTO_BROWSER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            // REMIND: invoke the content handler?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            // may be the right thing to do, may not be -- short term
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            // where docs are not loaded asynch, loading and returning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            // the content is the right thing to do.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                return urlc.getContent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        case LAUNCH_APPLICATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                String threadName = command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                int fst = threadName.indexOf(' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                if (fst > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    threadName = threadName.substring(0, fst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                return new MimeLauncher(this, urlc, is,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                                        mt.getTempFileTemplate(), threadName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        case UNKNOWN:
47866
39db80b32b69 8191632: Typos in comments due to duplicating words
igerasim
parents: 47216
diff changeset
   253
            // REMIND: What to do here?
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public boolean matches(String type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (starred) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
          // REMIND: is this the right thing or not?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
          return type.startsWith(typeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            return type.equals(typeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        // return a shallow copy of this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        MimeEntry theClone = new MimeEntry(typeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        theClone.action = action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        theClone.command = command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        theClone.description = description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        theClone.imageFileName = imageFileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        theClone.tempFileNameTemplate = tempFileNameTemplate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        theClone.fileExtensions = fileExtensions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        return theClone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public synchronized String toProperty() {
26219
1a19360ff122 8054714: Use StringJoiner where it makes the code cleaner
igerasim
parents: 25859
diff changeset
   283
        StringJoiner sj = new StringJoiner("; ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        int action = getAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if (action != MimeEntry.UNKNOWN) {
26219
1a19360ff122 8054714: Use StringJoiner where it makes the code cleaner
igerasim
parents: 25859
diff changeset
   287
            sj.add("action=" + actionKeywords[action]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        String command = getLaunchString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (command != null && command.length() > 0) {
26219
1a19360ff122 8054714: Use StringJoiner where it makes the code cleaner
igerasim
parents: 25859
diff changeset
   292
            sj.add("application=" + command);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
26219
1a19360ff122 8054714: Use StringJoiner where it makes the code cleaner
igerasim
parents: 25859
diff changeset
   295
        String image = getImageFileName();
1a19360ff122 8054714: Use StringJoiner where it makes the code cleaner
igerasim
parents: 25859
diff changeset
   296
        if (image != null) {
1a19360ff122 8054714: Use StringJoiner where it makes the code cleaner
igerasim
parents: 25859
diff changeset
   297
            sj.add("icon=" + image);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        String extensions = getExtensionsAsList();
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 47866
diff changeset
   301
        if (!extensions.isEmpty()) {
26219
1a19360ff122 8054714: Use StringJoiner where it makes the code cleaner
igerasim
parents: 25859
diff changeset
   302
            sj.add("file_extensions=" + extensions);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        String description = getDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        if (description != null && !description.equals(getType())) {
26219
1a19360ff122 8054714: Use StringJoiner where it makes the code cleaner
igerasim
parents: 25859
diff changeset
   307
            sj.add("description=" + description);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
26219
1a19360ff122 8054714: Use StringJoiner where it makes the code cleaner
igerasim
parents: 25859
diff changeset
   310
        return sj.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        return "MimeEntry[contentType=" + typeName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            + ", image=" + imageFileName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            + ", action=" + action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            + ", command=" + command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            + ", extensions=" + getExtensionsAsList()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
}