当前位置: 首页>>代码示例>>Java>>正文


Java MIMEResolver类代码示例

本文整理汇总了Java中org.openide.filesystems.MIMEResolver的典型用法代码示例。如果您正苦于以下问题:Java MIMEResolver类的具体用法?Java MIMEResolver怎么用?Java MIMEResolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MIMEResolver类属于org.openide.filesystems包,在下文中一共展示了MIMEResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerExt

import org.openide.filesystems.MIMEResolver; //导入依赖的package包/类
private void registerExt(Element e, ExtensionRegistration r) throws LayerGenerationException {
    final LayerBuilder b = layer(e);
    File f = b.file("Services/MIMEResolver/" + getName(e).replace('.', '-') + "-Extension" + SUFFIX); // NOI18N
    f.methodvalue("instanceCreate", MIMEResolver.class.getName(), "create"); // NOI18N
    f.stringvalue("instanceClass", MIMEResolver.class.getName()); // NOI18N
    f.stringvalue("mimeType", r.mimeType()); // NOI18N
    int cnt = 0;
    for (String ext : r.extension()) {
        f.stringvalue("ext." + (cnt++), ext); // NOI18N
    }
    f.position(r.position());
    int ccnt = 0;
    for (String chooser : r.showInFileChooser()) {
        f.bundlevalue("fileChooser." + (ccnt++), chooser);
    }
    f.bundlevalue("displayName", r.displayName()); // NOI18N
    f.write();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:MIMEResolverProcessor.java

示例2: registerDefinition

import org.openide.filesystems.MIMEResolver; //导入依赖的package包/类
private void registerDefinition(Element e, String relRes, Registration r) throws LayerGenerationException {
    String absRes = LayerBuilder.absolutizeResource(e, relRes);
    final LayerBuilder b = layer(e);
    FileObject fo = b.validateResource(absRes, e, r, null, false);
    File f = b.file("Services/MIMEResolver/" + getName(e).replace('.', '-') + "-Registration" + SUFFIX); // NOI18N
    f.methodvalue("instanceCreate", MIMEResolver.class.getName(), "create"); // NOI18N
    f.stringvalue("instanceClass", MIMEResolver.class.getName()); // NOI18N
    f.serialvalue("bytes", generateInstanceResolver(fo, e, f, r)); // NOI18N
    f.position(r.position());
    int ccnt = 0;
    for (String chooser : r.showInFileChooser()) {
        f.bundlevalue("fileChooser." + (ccnt++), chooser);
    }
    f.bundlevalue("displayName", r.displayName()); // NOI18N
    f.write();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:MIMEResolverProcessor.java

示例3: setFileChooserRelatedAttributes

import org.openide.filesystems.MIMEResolver; //导入依赖的package包/类
private void setFileChooserRelatedAttributes(Registration r,
        MIMEResolver resolver, File f) {

    if (r.showInFileChooser().length > 0) {
        String[] types = MIMEResolverImpl.getMIMETypes(resolver);
        List<String> exts = ((FilterInfo) resolver).getExtensions();
        int cnt = 0;
        for (String ext : unq(exts)) {
            f.stringvalue("ext." + (cnt++), ext);              // NOI18N
        }
        int tcnt = 0;
        for (String type : unq(types)) {
            f.stringvalue("mimeType." + (tcnt++), type);       // NOI18N
        }
        int ncnt = 0;
        for (String name : ((FilterInfo) resolver).getFileNames()) {
            f.stringvalue("fileName." + (ncnt++), name);        //NOI18N
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:MIMEResolverProcessor.java

示例4: forXML

import org.openide.filesystems.MIMEResolver; //导入依赖的package包/类
private static MIMEResolver forXML(FileObject def, 
    String mimeType, List<String> exts, List<String> acceptExts,
    String elem, List<String> namespace, List<String> dtds
) throws IOException {
    FileElement e = new FileElement();
    for (String ext : exts) {
        e.fileCheck.addExt(ext);
    }
    e.rule = new XMLMIMEComponent(elem, namespace, dtds);
    e.setMIME(mimeType);
    if (acceptExts.isEmpty()) {
        return new Impl(def, new FileElement[] { e }, mimeType);
    } else {
        FileElement direct = extensionElem(acceptExts, mimeType);
        return new Impl(def, new FileElement[] { e, direct }, mimeType);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:MIMEResolverImpl.java

示例5: create

import org.openide.filesystems.MIMEResolver; //导入依赖的package包/类
/** factory method for {@link MIMEResolver.Registration} */
public static MIMEResolver create(FileObject fo) throws IOException {
    byte[] arr = (byte[]) fo.getAttribute("bytes");
    if (arr != null) {
        return forStream(fo, arr);
    }
    String mimeType = (String) fo.getAttribute("mimeType"); // NOI18Ns
    String element = (String) fo.getAttribute("element"); // NOI18N
    List<String> exts = readArray(fo, "ext."); // NOI18N
    if (element != null) {
        List<String> accept = readArray(fo, "accept."); // NOI18N
        List<String> nss = readArray(fo, "ns."); // NOI18N
        List<String> dtds = readArray(fo, "doctype."); // NOI18N
        return forXML(fo, mimeType, exts, accept, element, nss, dtds);
    }
    
    if (!exts.isEmpty()) {
        return forExts(fo, mimeType, exts);
    }
    throw new IllegalArgumentException("" + fo);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:MIMEResolverImpl.java

示例6: FileAssociationsModel

import org.openide.filesystems.MIMEResolver; //导入依赖的package包/类
/** Creates new model. */
FileAssociationsModel() {
    // the following code is a dirty trick to allow the UIHelpers class
    // to be a nested class (and thus not be visible in the general javadoc)
    // in the openide.filesystems API
    // It does not matter that you suffer reading this code. The important
    // thing is that millions of users of openide.filesystems are not
    // disturbed by presence of UIHelpers class or its methods
    // in javadoc overview.
    new MIMEResolver() {
        @Override
        public String findMIMEType(FileObject fo) {
            return null;
        }
    }.super();

    FileObject resolvers = FileUtil.getConfigFile(MIME_RESOLVERS_PATH);
    if (resolvers != null) {
        resolvers.addFileChangeListener(FileUtil.weakFileChangeListener(mimeResolversListener, resolvers));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:FileAssociationsModel.java

示例7: getSupportedAnnotationTypes

import org.openide.filesystems.MIMEResolver; //导入依赖的package包/类
@Override
public Set<String> getSupportedAnnotationTypes() {
    Set<String> set = new HashSet<String>();
    set.add(MIMEResolver.Registration.class.getCanonicalName());
    set.add(MIMEResolver.ExtensionRegistration.class.getCanonicalName());
    set.add(MIMEResolver.NamespaceRegistration.class.getCanonicalName());
    return set;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:MIMEResolverProcessor.java

示例8: generateInstanceResolver

import org.openide.filesystems.MIMEResolver; //导入依赖的package包/类
private byte[] generateInstanceResolver(FileObject fo, Element e, File f,
        Registration r) throws LayerGenerationException {
    try {
        InputStream is = fo.openInputStream();
        org.openide.filesystems.FileObject tmp = FileUtil.createMemoryFileSystem().getRoot().createData("resolver.xml");
        OutputStream os = tmp.getOutputStream();
        for (;;) {
            int ch = is.read();
            if (ch == -1) {
                break;
            }
            os.write(ch);
        }
        os.close();
        is.close();
        MIMEResolver resolver = MIMEResolverImpl.forDescriptor(tmp, false);
        setFileChooserRelatedAttributes(r, resolver, f);
        final byte[] almostResult = MIMEResolverImpl.toStream(resolver);
        // XXX: it would be slightly shorter to return the array directly,
        // but the XMLFileSystem insist on deserializing the value, it does
        // not support returning plain byte[]
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(out);
        oos.writeObject(almostResult);
        oos.close();
        return out.toByteArray();
    } catch (IOException ex) {
        final LayerGenerationException le = new LayerGenerationException("Cannot process " + fo, e);
        le.initCause(ex);
        throw le;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:MIMEResolverProcessor.java

示例9: forDescriptor

import org.openide.filesystems.MIMEResolver; //导入依赖的package包/类
static MIMEResolver forDescriptor(FileObject fo, boolean warn) {
    if (warn && !isUserDefined(fo)) {
        ERR.log(Level.WARNING, "Ineffective registration of resolver {0} use @MIMEResolver.Registration! See bug #191777.", fo.getPath());
        if (ERR.isLoggable(Level.FINE)) {
            try {
                ERR.fine(fo.asText());
            } catch (IOException ex) {
                ERR.log(Level.FINE, null, ex);
            }
        }
    }
    return new Impl(fo);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:MIMEResolverImpl.java

示例10: toStream

import org.openide.filesystems.MIMEResolver; //导入依赖的package包/类
static byte[] toStream(MIMEResolver mime) throws IOException {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(os);
    ((Impl)mime).writeExternal(dos);
    dos.close();
    return os.toByteArray();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:MIMEResolverImpl.java

示例11: resolve

import org.openide.filesystems.MIMEResolver; //导入依赖的package包/类
private String resolve(FileObject fo) {
    for (MIMEResolver r : resolvers) {
        String s = r.findMIMEType(fo);
        if (s != null) return s;
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:MIMEResolverImplTest.java

示例12: testPatternElement

import org.openide.filesystems.MIMEResolver; //导入依赖的package包/类
/** Test pattern element in declarative MIME resolver. */
public void testPatternElement() throws Exception {
    MIMEResolver resolver = createResolver(resolversRoot.getFileObject("php-resolver1.xml"));
    assertMimeType(resolver, "text/x-php5", "php.txt");
    assertMimeType(resolver, null, "not-php.txt");
    assertMimeType(resolver, "text/x-php5", "html-php.txt");

    resolver = createResolver(resolversRoot.getFileObject("php-resolver2.xml"));
    assertMimeType(resolver, null, "php.txt");
    assertMimeType(resolver, "text/x-php5", "html-php.txt");

    resolver = createResolver(resolversRoot.getFileObject("php-resolver3.xml"));
    assertMimeType(resolver, null, "php.txt");
    assertMimeType(resolver, null, "html-php.txt");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:MIMEResolverImplTest.java

示例13: testNameElement

import org.openide.filesystems.MIMEResolver; //导入依赖的package包/类
/** Test name element in declarative MIME resolver. */
public void testNameElement() throws Exception {
    MIMEResolver resolver = createResolver(resolversRoot.getFileObject("makefile-resolver.xml"));
    assertMimeType(resolver, "text/x-make", "makefile", "Makefile", "MaKeFiLe", "mymakefile", "gnumakefile", "makefile1", "makefileRakefile", "makefile.Rakefile");

    assertMimeType(resolver, null, "empty.dtd", "rakefile", "Rakefile");

    resolver = createResolver(resolversRoot.getFileObject("rakefile-resolver.xml"));
    assertMimeType(resolver, "text/x-ruby", "rakefile", "Rakefile");
    assertMimeType(resolver, null, "empty.dtd", "makefile", "makefileRakefile", "makefile.Rakefile");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:MIMEResolverImplTest.java

示例14: testNSResolver

import org.openide.filesystems.MIMEResolver; //导入依赖的package包/类
/** Test ns element in xml-rule resolver. */
public void testNSResolver() throws Exception {
    MIMEResolver resolver = createResolver(resolversRoot.getFileObject("ns.xml"));
    assertMimeType(resolver, "ns.xml", "ns.xml");
    // #177443
    resolver = createResolver(resolversRoot.getFileObject("ns1.xml"));
    assertMimeType(resolver, "ns1", "ns.xml");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:MIMEResolverImplTest.java

示例15: testDeadlock163378

import org.openide.filesystems.MIMEResolver; //导入依赖的package包/类
/** Tests concurrent threads accessing MIMEResolverImpl. */
public void testDeadlock163378() throws Exception {
    final MIMEResolver declarativeResolver = createResolver(resolversRoot.getFileObject("pattern-resolver-valid.xml"));
    Handler handler = new Handler() {

        private boolean threadStarted = false;

        @Override
        public void publish(LogRecord record) {
            if (!threadStarted && "findMIMEType - smell.resolve.".equals(record.getMessage())) {
                Thread lockingThread = new Thread(new Runnable() {
                    @Override
                    public void run() {
                        declarativeResolver.findMIMEType(root.getFileObject("empty.dtd"));
                    }
                }, "Locking");
                threadStarted = true;
                lockingThread.start();
                try {
                    lockingThread.join();
                } catch (InterruptedException ex) {
                    Exceptions.printStackTrace(ex);
                }
            }
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() throws SecurityException {
        }
    };
    Logger logger = Logger.getLogger(MIMEResolverImpl.class.getName());
    logger.addHandler(handler);
    logger.setLevel(Level.FINEST);
    declarativeResolver.findMIMEType(root.getFileObject("empty.dtd"));
    logger.removeHandler(handler);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:41,代码来源:MIMEResolverImplTest.java


注:本文中的org.openide.filesystems.MIMEResolver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。