jdk/src/java.base/share/classes/sun/net/www/MimeEntry.java
changeset 26219 1a19360ff122
parent 25859 3317bb8137f4
equal deleted inserted replaced
26218:98453f165e21 26219:1a19360ff122
     1 /*
     1 /*
     2  * Copyright (c) 1994, 2002, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1994, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    24  */
    24  */
    25 
    25 
    26 package sun.net.www;
    26 package sun.net.www;
    27 import java.net.URL;
    27 import java.net.URL;
    28 import java.io.*;
    28 import java.io.*;
       
    29 import java.util.StringJoiner;
    29 import java.util.StringTokenizer;
    30 import java.util.StringTokenizer;
    30 
    31 
    31 public class MimeEntry implements Cloneable {
    32 public class MimeEntry implements Cloneable {
    32     private String typeName;    // of the form: "type/subtype"
    33     private String typeName;    // of the form: "type/subtype"
    33     private String tempFileNameTemplate;
    34     private String tempFileNameTemplate;
   279 
   280 
   280         return theClone;
   281         return theClone;
   281     }
   282     }
   282 
   283 
   283     public synchronized String toProperty() {
   284     public synchronized String toProperty() {
   284         StringBuilder sb = new StringBuilder();
   285         StringJoiner sj = new StringJoiner("; ");
   285 
       
   286         String separator = "; ";
       
   287         boolean needSeparator = false;
       
   288 
   286 
   289         int action = getAction();
   287         int action = getAction();
   290         if (action != MimeEntry.UNKNOWN) {
   288         if (action != MimeEntry.UNKNOWN) {
   291             sb.append("action=" + actionKeywords[action]);
   289             sj.add("action=" + actionKeywords[action]);
   292             needSeparator = true;
       
   293         }
   290         }
   294 
   291 
   295         String command = getLaunchString();
   292         String command = getLaunchString();
   296         if (command != null && command.length() > 0) {
   293         if (command != null && command.length() > 0) {
   297             if (needSeparator) {
   294             sj.add("application=" + command);
   298                 sb.append(separator);
   295         }
   299             }
   296 
   300             sb.append("application=" + command);
   297         String image = getImageFileName();
   301             needSeparator = true;
   298         if (image != null) {
   302         }
   299             sj.add("icon=" + image);
   303 
       
   304         if (getImageFileName() != null) {
       
   305             if (needSeparator) {
       
   306                 sb.append(separator);
       
   307             }
       
   308             sb.append("icon=" + getImageFileName());
       
   309             needSeparator = true;
       
   310         }
   300         }
   311 
   301 
   312         String extensions = getExtensionsAsList();
   302         String extensions = getExtensionsAsList();
   313         if (extensions.length() > 0) {
   303         if (extensions.length() > 0) {
   314             if (needSeparator) {
   304             sj.add("file_extensions=" + extensions);
   315                 sb.append(separator);
       
   316             }
       
   317             sb.append("file_extensions=" + extensions);
       
   318             needSeparator = true;
       
   319         }
   305         }
   320 
   306 
   321         String description = getDescription();
   307         String description = getDescription();
   322         if (description != null && !description.equals(getType())) {
   308         if (description != null && !description.equals(getType())) {
   323             if (needSeparator) {
   309             sj.add("description=" + description);
   324                 sb.append(separator);
   310         }
   325             }
   311 
   326             sb.append("description=" + description);
   312         return sj.toString();
   327         }
       
   328 
       
   329         return sb.toString();
       
   330     }
   313     }
   331 
   314 
   332     public String toString() {
   315     public String toString() {
   333         return "MimeEntry[contentType=" + typeName
   316         return "MimeEntry[contentType=" + typeName
   334             + ", image=" + imageFileName
   317             + ", image=" + imageFileName