public FileType getTypeForFile(FileSystemItem file, String defaultType) { if (file != null) { String filename = file.getName().toLowerCase(); FileType result = fileTypesByFilename_.get(filename); if (result != null) return result; String extension = FileSystemItem.getExtensionFromPath(filename); result = fileTypesByFileExtension_.get(extension); if (result != null) return result; if (defaultType != null) { String mimeType = file.mimeType(defaultType); if (mimeType.startsWith("text/")) return TEXT; } } return null; }
public FileType getTypeForFile(FileSystemItem file, boolean canUseDefault) { if (file != null) { String filename = file.getName().toLowerCase(); FileType result = fileTypesByFilename_.get(filename); if (result != null) return result; String extension = FileSystemItem.getExtensionFromPath(filename); result = fileTypesByFileExtension_.get(extension); if (result != null) return result; // last ditch -- see if this either a known text file type // or (for server mode) NOT a known binary type. the result of // this is that unknown files types are treated as text and // opened in the editor (we don't do this on desktop because // in that case users have the recourse of using a local editor) String defaultType = Desktop.isDesktop() ? "application/octet-stream" : "text/plain"; String mimeType = file.mimeType(defaultType); if (mimeType.startsWith("text/")) return TEXT; } if (canUseDefault) return defaultType_; else return null; }