/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
public class MailcapFile {
/**
* A Map indexed by MIME type (string) that references
* a Map of commands for each type. The comand Map
* is indexed by the command name and references a List of
* class names (strings) for each command.
*/
/**
* Another Map like above, but for fallback entries.
*/
/**
* A Map indexed by MIME type (string) that references
* a List of native commands (string) corresponding to the type.
*/
private static boolean addReverse = false;
static {
try {
} catch (Throwable t) {
// ignore any errors
}
}
/**
* The constructor that takes a filename as an argument.
*
* @param new_fname The file name of the mailcap file.
*/
if (LogSupport.isLoggable())
try {
} finally {
try {
} catch (IOException ex) { }
}
}
}
/**
* The constructor that takes an input stream as an argument.
*
* @param is the input stream
*/
if (LogSupport.isLoggable())
}
/**
* Mailcap file default constructor.
*/
public MailcapFile() {
if (LogSupport.isLoggable())
}
/**
* Get the Map of MailcapEntries based on the MIME type.
*
* <p>
* <strong>Semantics:</strong> First check for the literal mime type,
* if that fails looks for wildcard <type>/\* and return that. Return the
* list of all that hit.
*/
// first try the literal
// ok, now try the wildcard
if (search_result != null)
else
}
}
return search_result;
}
/**
* Get the Map of fallback MailcapEntries based on the MIME type.
*
* <p>
* <strong>Semantics:</strong> First check for the literal mime type,
* if that fails looks for wildcard <type>/\* and return that. Return the
* list of all that hit.
*/
// first try the literal
// ok, now try the wildcard
if (search_result != null)
else
}
}
return search_result;
}
/**
* Return all the MIME types known to this mailcap file.
*/
return mts;
}
/**
* Return all the native comands for the given MIME type.
*/
List v =
if (v != null) {
}
return cmds;
}
/**
* Merge the first hash into the second.
* This merge will only effect the hashtable that is
* returned, we don't want to touch the one passed in since
* its integrity must be maintained.
*/
// iterate through the verbs in the second map
} else {
// merge the two
}
}
return clonedHash;
}
/**
* appendToMailcap: Append to this Mailcap DB, use the mailcap
* format:
* Comment == "# <i>comment string</i>
* Entry == "mimetype; javabeanclass<nl>
*
* Example:
* # this is a comment
*/
if (LogSupport.isLoggable())
try {
} catch (IOException ex) {
// can't happen
}
}
/**
* parse file into a hash table of MC Type Entry Obj
*/
// LogSupport.log("parsing line: " + line);
try {
continue;
else
// handle the two strings
// LogSupport.log("parse: " + continued);
try {
} catch (MailcapParseException e) {
//e.printStackTrace();
}
}
else {
// LogSupport.log("parse: " + line);
try {
// LogSupport.log("hash.size = " + type_hash.size());
} catch (MailcapParseException e) {
//e.printStackTrace();
}
}
} catch (StringIndexOutOfBoundsException e) {}
}
}
/**
* A routine to parse individual entries in a Mailcap file.
*
* Note that this routine does not handle line continuations.
* They should have been handled prior to calling this routine.
*/
throws MailcapParseException, IOException {
tokenizer.setIsAutoquoting(false);
if (LogSupport.isLoggable())
// parse the primary type
}
// parse the '/' between primary and sub
// if it's not present that's ok, we just don't have a subtype
}
// only need to look for a sub type if we got a '/'
// parse the sub type
}
subType =
// get the next token to simplify the next step
}
if (LogSupport.isLoggable())
// now setup the commands hashtable
// parse the ';' that separates the type from the parameters
}
// eat it
// parse the required view command
tokenizer.setIsAutoquoting(true);
tokenizer.setIsAutoquoting(false);
}
// have a native comand, save the entire mailcap entry
//String nativeCommand = tokenizer.getCurrentTokenValue();
if (v == null) {
v = new ArrayList();
v.add(mailcapEntry);
} else {
// XXX - check for duplicates?
v.add(mailcapEntry);
}
}
// only have to get the next token if the current one isn't a ';'
}
// look for a ';' which will indicate whether
// a parameter list is present or not
boolean isFallback = false;
do {
// eat the ';'
// parse the parameter name
}
// parse the '=' which separates the name from the value
}
// we only have a useful command if it is named
// eat it
// parse the parameter value (which is autoquoted)
tokenizer.setIsAutoquoting(true);
tokenizer.setIsAutoquoting(false);
}
// add the class to the list iff it is one we care about
// 7 == "x-java-".length
isFallback = true;
} else {
// setup the class entry list
if (LogSupport.isLoggable())
", Class: " + paramValue);
}
if (addReverse)
else
}
}
// set up the next iteration
}
if (curcommands == null) {
} else {
if (LogSupport.isLoggable())
// have to merge current and new commands
// first, merge list of classes for commands already known
continue;
// add everything in cv to ccv, if it's not already there
if (addReverse)
else
}
}
// now, add commands not previously known
continue;
}
}
}
}
throw new MailcapParseException("Encountered a " +
actualTokenValue + ") while expecting a " +
}
throws MailcapParseException {
throw new MailcapParseException("Encountered a " +
actualTokenValue + ") while expecting a " +
}
if (LogSupport.isLoggable())
actualTokenValue + ") while expecting a " +
throw new MailcapParseException("Encountered a " +
actualTokenValue + ") while expecting a " +
}
/** for debugging
public static void main(String[] args) throws Exception {
Map masterHash = new HashMap();
for (int i = 0; i < args.length; ++i) {
System.out.println("Entry " + i + ": " + args[i]);
parseLine(args[i], masterHash);
}
Enumeration types = masterHash.keys();
while (types.hasMoreElements()) {
String key = (String)types.nextElement();
System.out.println("MIME Type: " + key);
Map commandHash = (Map)masterHash.get(key);
Enumeration commands = commandHash.keys();
while (commands.hasMoreElements()) {
String command = (String)commands.nextElement();
System.out.println(" Command: " + command);
Vector classes = (Vector)commandHash.get(command);
for (int i = 0; i < classes.size(); ++i) {
System.out.println(" Class: " +
(String)classes.elementAt(i));
}
}
System.out.println("");
}
}
*/
}