简体   繁体   English

NetBeans平台:如何注册隐藏的文件类型

[英]NetBeans Platform: How to register hidden file types

I'm writing a NetBeans plugin and would like to register a file type. 我正在编写一个NetBeans插件,想要注册一个文件类型。 The file type is a hidden file (eg ".something") with mime-type text/plain and a settled name (".something"). 文件类型是隐藏文件(例如“.something”),具有mime-type text / plain和固定名称(“.something”)。 The 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 NetBeans will only recognize the filetype if the name of the file has a name, a point and an extension (eg "name.something"). 这样做的问题是,如果文件名具有名称,点和扩展名(例如“name.something”),NetBeans将只识别文件类型。 Just a point and an extension (eg ".something") is not recognized properly. 只是一个点和一个扩展(例如“.something”)无法正确识别。 Is there a solution for this kind of problem? 有这种问题的解决方案吗?

I solved the problem by implementing a custom non-declarative MIMEResolver. 我通过实现自定义非声明性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's a declarative MIMEResolver too. 还有一个声明性的MIMEResolver Note that the declarative way seems to be preferred by NetBeans-Devs. 请注意,NetBeans-Devs似乎首选声明方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM