1 16 package org.apache.commons.vfs.impl; 17 18 import org.apache.commons.vfs.FileContent; 19 import org.apache.commons.vfs.FileObject; 20 import org.apache.commons.vfs.FileSystemException; 21 22 import java.util.HashMap ; 23 import java.util.Map ; 24 25 30 class FileTypeMap 31 { 32 private final Map mimeTypeMap = new HashMap (); 33 private final Map extensionMap = new HashMap (); 34 35 38 public void addMimeType(final String mimeType, final String scheme) 39 { 40 mimeTypeMap.put(mimeType, scheme); 41 } 42 43 46 public void addExtension(final String extension, final String scheme) 47 { 48 extensionMap.put(extension, scheme); 49 } 50 51 54 public String getScheme(final FileObject file) throws FileSystemException 55 { 56 final FileContent content = file.getContent(); 58 final String mimeType = content.getContentInfo().getContentType(); 60 if (mimeType != null) 61 { 62 return (String ) mimeTypeMap.get(mimeType); 63 } 64 65 final String extension = file.getName().getExtension(); 67 return (String ) extensionMap.get(extension); 68 } 69 } 70 | Popular Tags |