Skip to content

Commit

Permalink
provide version of getTypeForFile method that allows explicit default…
Browse files Browse the repository at this point in the history
…Type
  • Loading branch information
jjallaire committed Sep 20, 2012
1 parent f47e4d2 commit 4c44ba8
Showing 1 changed file with 21 additions and 10 deletions.
Expand Up @@ -298,8 +298,23 @@ public FileType getTypeByTypeName(String name)
{
return fileTypesByTypeName_.get(name);
}




public FileType getTypeForFile(FileSystemItem file)
{
// last ditch default type -- 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";
return getTypeForFile(file, defaultType);
}

public FileType getTypeForFile(FileSystemItem file, String defaultType)
{
if (file != null)
{
Expand All @@ -313,16 +328,12 @@ public FileType getTypeForFile(FileSystemItem file)
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 (defaultType != null)
{
String mimeType = file.mimeType(defaultType);
if (mimeType.startsWith("text/"))
return TEXT;
}
}

return null;
Expand Down

0 comments on commit 4c44ba8

Please sign in to comment.