The attached patch augments the hardcoded extension-to-mime-type table with information parsed from /etc/mime.types (if that exists).
So if you find that you must specify image/x-djvu manually for your *.djvu files, simply add the following line to that file: image/x-djvu djvu djv Honing of the parsing code will be appreciated. One more question to the Freenet experts: this thing is being called both from fproxy (where logging is good) and from fclient (where logging seems to go nowhere). How should I report problems?
Index: MimeTypeUtils.java =================================================================== RCS file: /cvsroot/freenet/freenet/src/freenet/client/metadata/MimeTypeUtils.java,v retrieving revision 1.2 diff -u -r1.2 MimeTypeUtils.java --- MimeTypeUtils.java 2 Sep 2002 16:39:54 -0000 1.2 +++ MimeTypeUtils.java 7 Sep 2002 17:54:59 -0000 @@ -1,4 +1,5 @@ // Copyright 2000, Mr. Bad of Pigdog Journal (http://www.pigdog.org/). +// Copyright 2002 Robert Bihlmeyer // All Rights Reserved. // This software is distributed under the GNU Public License, which @@ -11,11 +12,16 @@ package freenet.client.metadata; import java.util.Hashtable; +import java.io.*; +import freenet.Core; +import freenet.support.Logger; public class MimeTypeUtils { static Hashtable typeMap = new Hashtable(); + static String MIME_TYPES = "/etc/mime.types"; + // Ruthlessly ripped off from apache mime types. static { @@ -191,6 +197,52 @@ typeMap.put("vrm", "x-world/x-vrml"); typeMap.put("vrml", "x-world/x-vrml"); typeMap.put("wrl", "x-world/x-vrml"); + + try { + BufferedReader in = + new BufferedReader(new FileReader(MIME_TYPES)); + try { + String line; + while ((line = in.readLine()) != null) { + int i, j; + for (i = 0; i < line.length() + && Character.isWhitespace(line.charAt(i)); ++i) + ; + if (i >= line.length() || line.charAt(i) == '#') + continue; // ignore empty/comment lines + for (j = i; j < line.length() + && !Character.isWhitespace(line.charAt(j)); ++j) + ; + String type = line.substring(i, j); + while ((i = j + 1) < line.length()) { + for (; i < line.length() + && Character.isWhitespace(line.charAt(i)); + ++i) + ; + for (j = i; j < line.length() + && !Character.isWhitespace(line.charAt(j)); + ++j) + ; + typeMap.put(line.substring(i,j), type); + } + } + } catch (IOException e) { + Core.logger.log(MimeTypeUtils.class, + "Error reading "+MIME_TYPES+": "+e, + Logger.NORMAL); + } + try { + in.close(); + } catch (IOException e) { + // closing a r/o file should not fail + Core.logger.log(MimeTypeUtils.class, + "Error closing "+MIME_TYPES+": "+e, + Logger.ERROR); + } + } catch (FileNotFoundException e) { + Core.logger.log(MimeTypeUtils.class, MIME_TYPES+" not found", + Logger.DEBUG); + } } static public String getMimeType(String extension) {
-- Robbe
signature.ng
Description: PGP signature
