20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.net.www;
27 import java.net.URL;
28 import java.io.*;
29 import java.util.StringJoiner;
30 import java.util.StringTokenizer;
31
32 public class MimeEntry implements Cloneable {
33 private String typeName; // of the form: "type/subtype"
34 private String tempFileNameTemplate;
35
36 private int action;
37 private String command;
38 private String description;
39 private String imageFileName;
40 private String fileExtensions[];
41
42 boolean starred;
43
44 // Actions
45 public static final int UNKNOWN = 0;
46 public static final int LOAD_INTO_BROWSER = 1;
47 public static final int SAVE_TO_FILE = 2;
48 public static final int LAUNCH_APPLICATION = 3;
49
50 static final String[] actionKeywords = {
51 "unknown",
52 "browser",
53 "save",
54 "application",
55 };
56
57 /**
58 * Construct an empty entry of the given type and subtype.
59 */
60 public MimeEntry(String type) {
76 command = null;
77 this.imageFileName = imageFileName;
78 setExtensions(extensionString);
79 starred = isStarred(typeName);
80 }
81
82 // For use with MimeTable::parseMailCap
83 MimeEntry(String typeName, int action, String command,
84 String tempFileNameTemplate) {
85 this.typeName = typeName.toLowerCase();
86 this.action = action;
87 this.command = command;
88 this.imageFileName = null;
89 this.fileExtensions = null;
90
91 this.tempFileNameTemplate = tempFileNameTemplate;
92 }
93
94 // This is the one called by the public constructor.
95 MimeEntry(String typeName, int action, String command,
96 String imageFileName, String fileExtensions[]) {
97
98 this.typeName = typeName.toLowerCase();
99 this.action = action;
100 this.command = command;
101 this.imageFileName = imageFileName;
102 this.fileExtensions = fileExtensions;
103
104 starred = isStarred(typeName);
105
106 }
107
108 public synchronized String getType() {
109 return typeName;
110 }
111
112 public synchronized void setType(String type) {
113 typeName = type.toLowerCase();
114 }
115
116 public synchronized int getAction() {
173 return fileExtensions;
174 }
175
176 public synchronized String getExtensionsAsList() {
177 String extensionsAsString = "";
178 if (fileExtensions != null) {
179 for (int i = 0; i < fileExtensions.length; i++) {
180 extensionsAsString += fileExtensions[i];
181 if (i < (fileExtensions.length - 1)) {
182 extensionsAsString += ",";
183 }
184 }
185 }
186
187 return extensionsAsString;
188 }
189
190 public synchronized void setExtensions(String extensionString) {
191 StringTokenizer extTokens = new StringTokenizer(extensionString, ",");
192 int numExts = extTokens.countTokens();
193 String extensionStrings[] = new String[numExts];
194
195 for (int i = 0; i < numExts; i++) {
196 String ext = (String)extTokens.nextElement();
197 extensionStrings[i] = ext.trim();
198 }
199
200 fileExtensions = extensionStrings;
201 }
202
203 private boolean isStarred(String typeName) {
204 return (typeName != null)
205 && (typeName.length() > 0)
206 && (typeName.endsWith("/*"));
207 }
208
209 /**
210 * Invoke the MIME type specific behavior for this MIME type.
211 * Returned value can be one of several types:
212 * <ol>
213 * <li>A thread -- the caller can choose when to launch this thread.
|
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.net.www;
27 import java.net.URL;
28 import java.io.*;
29 import java.util.StringJoiner;
30 import java.util.StringTokenizer;
31
32 public class MimeEntry implements Cloneable {
33 private String typeName; // of the form: "type/subtype"
34 private String tempFileNameTemplate;
35
36 private int action;
37 private String command;
38 private String description;
39 private String imageFileName;
40 private String[] fileExtensions;
41
42 boolean starred;
43
44 // Actions
45 public static final int UNKNOWN = 0;
46 public static final int LOAD_INTO_BROWSER = 1;
47 public static final int SAVE_TO_FILE = 2;
48 public static final int LAUNCH_APPLICATION = 3;
49
50 static final String[] actionKeywords = {
51 "unknown",
52 "browser",
53 "save",
54 "application",
55 };
56
57 /**
58 * Construct an empty entry of the given type and subtype.
59 */
60 public MimeEntry(String type) {
76 command = null;
77 this.imageFileName = imageFileName;
78 setExtensions(extensionString);
79 starred = isStarred(typeName);
80 }
81
82 // For use with MimeTable::parseMailCap
83 MimeEntry(String typeName, int action, String command,
84 String tempFileNameTemplate) {
85 this.typeName = typeName.toLowerCase();
86 this.action = action;
87 this.command = command;
88 this.imageFileName = null;
89 this.fileExtensions = null;
90
91 this.tempFileNameTemplate = tempFileNameTemplate;
92 }
93
94 // This is the one called by the public constructor.
95 MimeEntry(String typeName, int action, String command,
96 String imageFileName, String[] fileExtensions) {
97
98 this.typeName = typeName.toLowerCase();
99 this.action = action;
100 this.command = command;
101 this.imageFileName = imageFileName;
102 this.fileExtensions = fileExtensions;
103
104 starred = isStarred(typeName);
105
106 }
107
108 public synchronized String getType() {
109 return typeName;
110 }
111
112 public synchronized void setType(String type) {
113 typeName = type.toLowerCase();
114 }
115
116 public synchronized int getAction() {
173 return fileExtensions;
174 }
175
176 public synchronized String getExtensionsAsList() {
177 String extensionsAsString = "";
178 if (fileExtensions != null) {
179 for (int i = 0; i < fileExtensions.length; i++) {
180 extensionsAsString += fileExtensions[i];
181 if (i < (fileExtensions.length - 1)) {
182 extensionsAsString += ",";
183 }
184 }
185 }
186
187 return extensionsAsString;
188 }
189
190 public synchronized void setExtensions(String extensionString) {
191 StringTokenizer extTokens = new StringTokenizer(extensionString, ",");
192 int numExts = extTokens.countTokens();
193 String[] extensionStrings = new String[numExts];
194
195 for (int i = 0; i < numExts; i++) {
196 String ext = (String)extTokens.nextElement();
197 extensionStrings[i] = ext.trim();
198 }
199
200 fileExtensions = extensionStrings;
201 }
202
203 private boolean isStarred(String typeName) {
204 return (typeName != null)
205 && (typeName.length() > 0)
206 && (typeName.endsWith("/*"));
207 }
208
209 /**
210 * Invoke the MIME type specific behavior for this MIME type.
211 * Returned value can be one of several types:
212 * <ol>
213 * <li>A thread -- the caller can choose when to launch this thread.
|