Methods Summary |
---|
public void | appendToRegistry(java.lang.String mime_types)Appends string of entries to the types registry, must be valid
.mime.types format.
A mime.types entry is one of two forms:
type/subtype ext1 ext2 ...
or
type=type/subtype desc="description of type" exts=ext1,ext2,...
Example:
# this is a test
audio/basic au
text/plain txt text
type=application/postscript exts=ps,eps
try {
parse(new BufferedReader(new StringReader(mime_types)));
} catch (IOException ex) {
// can't happen
}
|
public java.lang.String | getMIMETypeString(java.lang.String file_ext)Get the MIME type string corresponding to the file extension.
MimeTypeEntry entry = this.getMimeTypeEntry(file_ext);
if (entry != null)
return entry.getMIMEType();
else
return null;
|
public com.sun.activation.registries.MimeTypeEntry | getMimeTypeEntry(java.lang.String file_ext)get the MimeTypeEntry based on the file extension
return (MimeTypeEntry)type_hash.get((Object)file_ext);
|
private void | parse(java.io.BufferedReader buf_reader)Parse a stream of mime.types entries.
String line = null, prev = null;
while ((line = buf_reader.readLine()) != null) {
if (prev == null)
prev = line;
else
prev += line;
int end = prev.length();
if (prev.length() > 0 && prev.charAt(end - 1) == '\\") {
prev = prev.substring(0, end - 1);
continue;
}
this.parseEntry(prev);
prev = null;
}
if (prev != null)
this.parseEntry(prev);
|
private void | parseEntry(java.lang.String line)Parse single mime.types entry.
String mime_type = null;
String file_ext = null;
line = line.trim();
if (line.length() == 0) // empty line...
return; // BAIL!
// check to see if this is a comment line?
if (line.charAt(0) == '#")
return; // then we are done!
// is it a new format line or old format?
if (line.indexOf('=") > 0) {
// new format
LineTokenizer lt = new LineTokenizer(line);
while (lt.hasMoreTokens()) {
String name = lt.nextToken();
String value = null;
if (lt.hasMoreTokens() && lt.nextToken().equals("=") &&
lt.hasMoreTokens())
value = lt.nextToken();
if (value == null) {
if (LogSupport.isLoggable())
LogSupport.log("Bad .mime.types entry: " + line);
return;
}
if (name.equals("type"))
mime_type = value;
else if (name.equals("exts")) {
StringTokenizer st = new StringTokenizer(value, ",");
while (st.hasMoreTokens()) {
file_ext = st.nextToken();
MimeTypeEntry entry =
new MimeTypeEntry(mime_type, file_ext);
type_hash.put(file_ext, entry);
if (LogSupport.isLoggable())
LogSupport.log("Added: " + entry.toString());
}
}
}
} else {
// old format
// count the tokens
StringTokenizer strtok = new StringTokenizer(line);
int num_tok = strtok.countTokens();
if (num_tok == 0) // empty line
return;
mime_type = strtok.nextToken(); // get the MIME type
while (strtok.hasMoreTokens()) {
MimeTypeEntry entry = null;
file_ext = strtok.nextToken();
entry = new MimeTypeEntry(mime_type, file_ext);
type_hash.put(file_ext, entry);
if (LogSupport.isLoggable())
LogSupport.log("Added: " + entry.toString());
}
}
|