NetBeans Platform: How to Register Hidden File Types

I am writing a NetBeans plugin and would like to register a file type. The file type is a hidden file (eg ".something") with the mimetype type / plain and the settled name (".something"). Registration looks like this:

@MIMEResolver.ExtensionRegistration(
        displayName = "#Label",
        mimeType = "text/plain+something",
        extension = {"something"}
)
@DataObject.Registration(
    mimeType = "text/plain+something",
    iconBase = "com/welovecoding/netbeans/plugin/logo.png",
    displayName = "#Label",
    position = 300
)
public class SomethingDataObject extends MultiDataObject {

  public SomethingDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
    super(pf, loader);
    registerEditor("text/plain", true);
  }
  //...
}

      

The problem with this is that NetBeans only recognizes the file type if the filename has a name, period and extension (for example, "name.something"). A simple period and extension (eg ".something") are not recognized properly. Is there a solution for this kind of problem?

+3


source to share


1 answer


I solved the problem by doing a custom non-declarative MIMEResolver. Here's the code:

@ServiceProvider(service = MIMEResolver.class, position = 3214328)
public class FilenameResolver extends MIMEResolver {

  private static final String mimetype = "text/plain+something";

  public FilenameResolver() {
    super(mimetype);
  }

  @Override
  public String findMIMEType(FileObject fo) {
    String nameExt = fo.getNameExt();
    if (".something".equalsIgnoreCase(nameExt)) {
      return mimetype;
    }
    return null;
  }

}

      



There is a declarative MIMEResolver in there . Note that the declarative way seems to be preferred over NetBeans-Devs.

+2


source







All Articles