Single file type for multiple content types?

Is there any way to register a single file type with IDEA that corresponds to multiple file types?  I'm creating a plugin for a system that has a class of files with a single extension where each file has a companion XML file that contains the main file's content type.  It'd be great if I could register a single file type for the extension that, on a per-file basis, returns the appropriate response for FileType.getIcon(), FileType.isBinary(), FileType.isReadOnly(), etc., as well as the language of the file if the content type can be resolved to a different locally-registered file type, e.g., Javascript, HTML, PNG, etc.  Unfortunately right now I'm not really seeing any good way to do that, though.  Thoughts?

0
4 comments

You can use the FileTypeDetector extension point to dynamically determine the content type of a file.

0

Thanks!  That definitely looks promising.  I'm trying to implement this now but my implementation is never getting invoked.  Debugging a bit I see that in FileTypeManagerImpl.getOrDetectFromContent(), these files are being auto-detected as text or binary before it would consult my implementation.  Is there something I need to do to force it to skip auto-detection on these files and invoke my detector?

0

Try to invalidate caches? I think the detected file type is persisted and not updated when a new detector is registered.

0

That seems to have done it!  One more question along these lines...is there any common facility in IDEA to resolve a MIME type/content type to a file type (or even a file extension)?

Thanks again!!!

UPDATE: I do see HtmlUtil.CONTENT_TYPES which uses MimeTypeDictionary, but that's just a list of MIME/content types, not a map from them to standard extensions.  I saw a few third-party libs that can do this, but before I pull one into my project, I wanted to see if this IDEA had this out-of-the-box.

UPDATE 2: I went ahead and used Apache Tika 1.8 (just the core jar) for this purpose and it's working wonderfully.  Obviously if IDEA has such a provision internally, that would be even better, but at this point I think I'm good to go!

0

Please sign in to leave a comment.