Methods Summary |
---|
public synchronized void | addMailcap(java.lang.String mail_cap)Add entries to the registry. Programmatically
added entries are searched before other entries.
The string that is passed in should be in mailcap
format.
// check to see if one exists
LogSupport.log("MailcapCommandMap: add to PROG");
if (DB[PROG] == null)
DB[PROG] = new MailcapFile();
DB[PROG].appendToMailcap(mail_cap);
|
private void | appendCmdsToList(java.util.Map typeHash, java.util.List cmdList)Put the commands that are in the hash table, into the list.
Iterator verb_enum = typeHash.keySet().iterator();
while (verb_enum.hasNext()) {
String verb = (String)verb_enum.next();
List cmdList2 = (List)typeHash.get(verb);
Iterator cmd_enum = ((List)cmdList2).iterator();
while (cmd_enum.hasNext()) {
String cmd = (String)cmd_enum.next();
cmdList.add(new CommandInfo(verb, cmd));
// cmdList.add(0, new CommandInfo(verb, cmd));
}
}
|
private void | appendPrefCmdsToList(java.util.Map cmdHash, java.util.List cmdList)Put the commands that are in the hash table, into the list.
Iterator verb_enum = cmdHash.keySet().iterator();
while (verb_enum.hasNext()) {
String verb = (String)verb_enum.next();
if (!checkForVerb(cmdList, verb)) {
List cmdList2 = (List)cmdHash.get(verb); // get the list
String className = (String)cmdList2.get(0);
cmdList.add(new CommandInfo(verb, className));
}
}
|
private boolean | checkForVerb(java.util.List cmdList, java.lang.String verb)Check the cmdList to see if this command exists, return
true if the verb is there.
Iterator ee = cmdList.iterator();
while (ee.hasNext()) {
String enum_verb =
(String)((CommandInfo)ee.next()).getCommandName();
if (enum_verb.equals(verb))
return true;
}
return false;
|
public synchronized javax.activation.DataContentHandler | createDataContentHandler(java.lang.String mimeType)Return the DataContentHandler for the specified MIME type.
if (LogSupport.isLoggable())
LogSupport.log(
"MailcapCommandMap: createDataContentHandler for " + mimeType);
if (mimeType != null)
mimeType = mimeType.toLowerCase(Locale.ENGLISH);
for (int i = 0; i < DB.length; i++) {
if (DB[i] == null)
continue;
if (LogSupport.isLoggable())
LogSupport.log(" search DB #" + i);
Map cmdMap = DB[i].getMailcapList(mimeType);
if (cmdMap != null) {
List v = (List)cmdMap.get("content-handler");
if (v != null) {
String name = (String)v.get(0);
DataContentHandler dch = getDataContentHandler(name);
if (dch != null)
return dch;
}
}
}
// now try the fallback entries
for (int i = 0; i < DB.length; i++) {
if (DB[i] == null)
continue;
if (LogSupport.isLoggable())
LogSupport.log(" search fallback DB #" + i);
Map cmdMap = DB[i].getMailcapFallbackList(mimeType);
if (cmdMap != null) {
List v = (List)cmdMap.get("content-handler");
if (v != null) {
String name = (String)v.get(0);
DataContentHandler dch = getDataContentHandler(name);
if (dch != null)
return dch;
}
}
}
return null;
|
public synchronized javax.activation.CommandInfo[] | getAllCommands(java.lang.String mimeType)Get all the available commands in all mailcap files known to
this instance of MailcapCommandMap for this MIME type.
List cmdList = new ArrayList();
if (mimeType != null)
mimeType = mimeType.toLowerCase(Locale.ENGLISH);
for (int i = 0; i < DB.length; i++) {
if (DB[i] == null)
continue;
Map cmdMap = DB[i].getMailcapList(mimeType);
if (cmdMap != null)
appendCmdsToList(cmdMap, cmdList);
}
// now add the fallback commands
for (int i = 0; i < DB.length; i++) {
if (DB[i] == null)
continue;
Map cmdMap = DB[i].getMailcapFallbackList(mimeType);
if (cmdMap != null)
appendCmdsToList(cmdMap, cmdList);
}
CommandInfo[] cmdInfos = new CommandInfo[cmdList.size()];
cmdInfos = (CommandInfo[])cmdList.toArray(cmdInfos);
return cmdInfos;
|
public synchronized javax.activation.CommandInfo | getCommand(java.lang.String mimeType, java.lang.String cmdName)Get the command corresponding to cmdName for the MIME type.
if (mimeType != null)
mimeType = mimeType.toLowerCase(Locale.ENGLISH);
for (int i = 0; i < DB.length; i++) {
if (DB[i] == null)
continue;
Map cmdMap = DB[i].getMailcapList(mimeType);
if (cmdMap != null) {
// get the cmd list for the cmd
List v = (List)cmdMap.get(cmdName);
if (v != null) {
String cmdClassName = (String)v.get(0);
if (cmdClassName != null)
return new CommandInfo(cmdName, cmdClassName);
}
}
}
// now try the fallback list
for (int i = 0; i < DB.length; i++) {
if (DB[i] == null)
continue;
Map cmdMap = DB[i].getMailcapFallbackList(mimeType);
if (cmdMap != null) {
// get the cmd list for the cmd
List v = (List)cmdMap.get(cmdName);
if (v != null) {
String cmdClassName = (String)v.get(0);
if (cmdClassName != null)
return new CommandInfo(cmdName, cmdClassName);
}
}
}
return null;
|
private javax.activation.DataContentHandler | getDataContentHandler(java.lang.String name)
if (LogSupport.isLoggable())
LogSupport.log(" got content-handler");
if (LogSupport.isLoggable())
LogSupport.log(" class " + name);
try {
ClassLoader cld = null;
// First try the "application's" class loader.
cld = SecuritySupport.getContextClassLoader();
if (cld == null)
cld = this.getClass().getClassLoader();
Class cl = null;
try {
cl = cld.loadClass(name);
} catch (Exception ex) {
// if anything goes wrong, do it the old way
cl = Class.forName(name);
}
if (cl != null) // XXX - always true?
return (DataContentHandler)cl.newInstance();
} catch (IllegalAccessException e) {
if (LogSupport.isLoggable())
LogSupport.log("Can't load DCH " + name, e);
} catch (ClassNotFoundException e) {
if (LogSupport.isLoggable())
LogSupport.log("Can't load DCH " + name, e);
} catch (InstantiationException e) {
if (LogSupport.isLoggable())
LogSupport.log("Can't load DCH " + name, e);
}
return null;
|
public synchronized java.lang.String[] | getMimeTypes()Get all the MIME types known to this command map.
List mtList = new ArrayList();
for (int i = 0; i < DB.length; i++) {
if (DB[i] == null)
continue;
String[] ts = DB[i].getMimeTypes();
if (ts != null) {
for (int j = 0; j < ts.length; j++) {
// eliminate duplicates
if (!mtList.contains(ts[j]))
mtList.add(ts[j]);
}
}
}
String[] mts = new String[mtList.size()];
mts = (String[])mtList.toArray(mts);
return mts;
|
public synchronized java.lang.String[] | getNativeCommands(java.lang.String mimeType)Get the native commands for the given MIME type.
Returns an array of strings where each string is
an entire mailcap file entry. The application
will need to parse the entry to extract the actual
command as well as any attributes it needs. See
RFC 1524
for details of the mailcap entry syntax. Only mailcap
entries that specify a view command for the specified
MIME type are returned.
List cmdList = new ArrayList();
if (mimeType != null)
mimeType = mimeType.toLowerCase(Locale.ENGLISH);
for (int i = 0; i < DB.length; i++) {
if (DB[i] == null)
continue;
String[] cmds = DB[i].getNativeCommands(mimeType);
if (cmds != null) {
for (int j = 0; j < cmds.length; j++) {
// eliminate duplicates
if (!cmdList.contains(cmds[j]))
cmdList.add(cmds[j]);
}
}
}
String[] cmds = new String[cmdList.size()];
cmds = (String[])cmdList.toArray(cmds);
return cmds;
|
public synchronized javax.activation.CommandInfo[] | getPreferredCommands(java.lang.String mimeType)Get the preferred command list for a MIME Type. The MailcapCommandMap
searches the mailcap files as described above under
Mailcap file search order.
The result of the search is a proper subset of available
commands in all mailcap files known to this instance of
MailcapCommandMap. The first entry for a particular command
is considered the preferred command.
List cmdList = new ArrayList();
if (mimeType != null)
mimeType = mimeType.toLowerCase(Locale.ENGLISH);
for (int i = 0; i < DB.length; i++) {
if (DB[i] == null)
continue;
Map cmdMap = DB[i].getMailcapList(mimeType);
if (cmdMap != null)
appendPrefCmdsToList(cmdMap, cmdList);
}
// now add the fallback commands
for (int i = 0; i < DB.length; i++) {
if (DB[i] == null)
continue;
Map cmdMap = DB[i].getMailcapFallbackList(mimeType);
if (cmdMap != null)
appendPrefCmdsToList(cmdMap, cmdList);
}
CommandInfo[] cmdInfos = new CommandInfo[cmdList.size()];
cmdInfos = (CommandInfo[])cmdList.toArray(cmdInfos);
return cmdInfos;
|
private void | loadAllResources(java.util.List v, java.lang.String name)Load all of the named resource.
boolean anyLoaded = false;
try {
URL[] urls;
ClassLoader cld = null;
// First try the "application's" class loader.
cld = SecuritySupport.getContextClassLoader();
if (cld == null)
cld = this.getClass().getClassLoader();
if (cld != null)
urls = SecuritySupport.getResources(cld, name);
else
urls = SecuritySupport.getSystemResources(name);
if (urls != null) {
if (LogSupport.isLoggable())
LogSupport.log("MailcapCommandMap: getResources");
for (int i = 0; i < urls.length; i++) {
URL url = urls[i];
InputStream clis = null;
if (LogSupport.isLoggable())
LogSupport.log("MailcapCommandMap: URL " + url);
try {
clis = SecuritySupport.openStream(url);
if (clis != null) {
v.add(new MailcapFile(clis));
anyLoaded = true;
if (LogSupport.isLoggable())
LogSupport.log("MailcapCommandMap: " +
"successfully loaded " +
"mailcap file from URL: " +
url);
} else {
if (LogSupport.isLoggable())
LogSupport.log("MailcapCommandMap: " +
"not loading mailcap " +
"file from URL: " + url);
}
} catch (IOException ioex) {
if (LogSupport.isLoggable())
LogSupport.log("MailcapCommandMap: can't load " +
url, ioex);
} catch (SecurityException sex) {
if (LogSupport.isLoggable())
LogSupport.log("MailcapCommandMap: can't load " +
url, sex);
} finally {
try {
if (clis != null)
clis.close();
} catch (IOException cex) { }
}
}
}
} catch (Exception ex) {
if (LogSupport.isLoggable())
LogSupport.log("MailcapCommandMap: can't load " + name, ex);
}
// if failed to load anything, fall back to old technique, just in case
if (!anyLoaded) {
if (LogSupport.isLoggable())
LogSupport.log("MailcapCommandMap: !anyLoaded");
MailcapFile mf = loadResource("/" + name);
if (mf != null)
v.add(mf);
}
|
private com.sun.activation.registries.MailcapFile | loadFile(java.lang.String name)Load from the named file.
MailcapFile mtf = null;
try {
mtf = new MailcapFile(name);
} catch (IOException e) {
// e.printStackTrace();
}
return mtf;
|
private com.sun.activation.registries.MailcapFile | loadResource(java.lang.String name)Load from the named resource.
InputStream clis = null;
try {
clis = SecuritySupport.getResourceAsStream(this.getClass(), name);
if (clis != null) {
MailcapFile mf = new MailcapFile(clis);
if (LogSupport.isLoggable())
LogSupport.log("MailcapCommandMap: successfully loaded " +
"mailcap file: " + name);
return mf;
} else {
if (LogSupport.isLoggable())
LogSupport.log("MailcapCommandMap: not loading " +
"mailcap file: " + name);
}
} catch (IOException e) {
if (LogSupport.isLoggable())
LogSupport.log("MailcapCommandMap: can't load " + name, e);
} catch (SecurityException sex) {
if (LogSupport.isLoggable())
LogSupport.log("MailcapCommandMap: can't load " + name, sex);
} finally {
try {
if (clis != null)
clis.close();
} catch (IOException ex) { } // ignore it
}
return null;
|