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


Java FileObject.getMIMEType方法代码示例

本文整理汇总了Java中org.openide.filesystems.FileObject.getMIMEType方法的典型用法代码示例。如果您正苦于以下问题:Java FileObject.getMIMEType方法的具体用法?Java FileObject.getMIMEType怎么用?Java FileObject.getMIMEType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openide.filesystems.FileObject的用法示例。


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

示例1: canRefactor

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private static boolean canRefactor(Lookup lookup) {
    Collection<? extends Node> nodes = lookup.lookupAll(Node.class);
    if (nodes.size() != 1) {
        return false;
    }
    Node node = nodes.iterator().next();

    //can refactor only in less/sass files
    FileObject file = getFileObjectFromNode(node);
    if (file != null) {
        String mimeType = file.getMIMEType();
        if (LessLanguage.getLanguageInstance().mimeType().equals(mimeType) || ScssLanguage.getLanguageInstance().mimeType().equals(mimeType)) {
            return isRefactorableEditorElement(node);
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:CPActionsImplementationProvider.java

示例2: getMimeType

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
 * Uses content analysis to return the mime type for files.
 *
 * @param file file to examine
 * @return String mime type of the file (or best guess)
 */
public static String getMimeType(File file) {
    FileObject fo = FileUtil.toFileObject(file);
    String foMime;
    boolean hasMime = false;
    if (fo == null) {
        foMime = "content/unknown"; // NOI18N
    } else {
        foMime = fo.getMIMEType();
        if ("content/unknown".equals(foMime)) { // NOI18N
            foMime = "text/plain"; // NOI18N
        } else {
            hasMime = true;
        }
    }
    if (!hasMime) {
        return isFileContentBinary(file) ? "application/octet-stream" : foMime; // NOI18N
    } else {
        return foMime;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:GitUtils.java

示例3: findPrimaryFile

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
 * In addition to mimetype list, checks base mime type if the mime is compound.
 * This is a workaround for loaders implementation do not currently support compound MIME types.
 * See defect #
 * 
 * @param fo file object to recognize 
 * @return primary file / null
 */
@Override
protected FileObject findPrimaryFile(FileObject fo) {
    FileObject pf = super.findPrimaryFile(fo);
    if (pf != null) {
        return pf;
    }
    String mime = fo.getMIMEType();
    int slash = -1;
    int l = mime.length();
    for (int i = 0; i < l; i++) {
        char c = mime.charAt(i);
        if (c == '/') { // NOI18N
            slash = i;
        } else if (c == '+') { // NOI18N
            if (slash == -1) {
                return null;
            }
            String baseMime = mime.substring(0, slash + 1) + mime.substring(i + 1);
            if (registeredMimes.contains(baseMime)) {
                return fo;
            }
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:GsfDataLoader.java

示例4: getWebPageMimeType

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public static String getWebPageMimeType(SyntaxAnalyzerResult result) {
    InstanceContent ic = new InstanceContent();
    ic.add(result);
    WebPageMetadata wpmeta = WebPageMetadata.getMetadata(new AbstractLookup(ic));

    if (wpmeta != null) {
        //get an artificial mimetype for the web page, this doesn't have to be equal
        //to the fileObjects mimetype.
        String mimeType = (String) wpmeta.value(WebPageMetadata.MIMETYPE);
        if (mimeType != null) {
            return mimeType;
        }
    }

    FileObject fo = result.getSource().getSourceFileObject();
    if(fo != null) {
        return fo.getMIMEType();
    } else {
        //no fileobject?
        return result.getSource().getSnapshot().getMimeType();
    }

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:Utils.java

示例5: getDocument

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private static  Document getDocument(FileObject fo){
    Document result = null;
    if (result != null) return result;
    try {
        
        File file = FileUtil.toFile(fo);
        FileInputStream fis = new FileInputStream(file);
        byte buffer[] = new byte[fis.available()];
        result = new org.netbeans.editor.BaseDocument(true, fo.getMIMEType());
        result.remove(0, result.getLength());
        fis.read(buffer);
        fis.close();
        String str = new String(buffer);
        result.insertString(0,str,null);
        
    } catch (Exception dObjEx) {
        return null;
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:TestUtil.java

示例6: getDocument

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private Document getDocument(FileObject fo){
    Document result = null;
    try {
        DataObject dObject = DataObject.find(fo);
        EditorCookie ec = (EditorCookie)dObject.getCookie(EditorCookie.class);
        Document doc = ec.openDocument();
        if(doc instanceof BaseDocument)
            return doc;
        result = new org.netbeans.editor.BaseDocument(true, fo.getMIMEType());
        String str = doc.getText(0, doc.getLength());
        result.insertString(0,str,null);
        
    } catch (Exception dObjEx) {
        return null;
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:CatalogModelTest.java

示例7: getMimeType

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
 * Uses content analysis to return the mime type for files.
 *
 * @param file file to examine
 * @return String mime type of the file (or best guess)
 */
public String getMimeType(File file) {
    FileObject fo = FileUtil.toFileObject(file);
    String foMime;
    if (fo == null) {
        foMime = "content/unknown"; // NOI18N
    } else {
        foMime = fo.getMIMEType();
        if ("content/unknown".equals(foMime)) { // NOI18N
            foMime = "text/plain"; // NOI18N
        }
    }
    if ((fileStatusCache.getStatus(file).getStatus() & FileInformation.STATUS_VERSIONED) == 0) {
        return HgUtils.isFileContentBinary(file) ? "application/octet-stream" : foMime; // NOI18N
    } else {
        return foMime;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:Mercurial.java

示例8: isTextFile

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
 * Checks whether the given file is a text file. The current implementation
 * does the check by the file's MIME-type.
 *
 * @param fileObj file to be checked
 * @return {@code true} if the file is a text file; {@code false} if it is a
 * binary file
 */
private static boolean isTextFile(FileObject fileObj) {
    String mimeType = fileObj.getMIMEType();

    if (mimeType.equals("content/unknown")) {                       //NOI18N
        if (searchableExtensions.contains(fileObj.getExt().toLowerCase())) {
            return true;
        } else {
            return fileObj.getSize() <= MAX_UNRECOGNIZED_FILE_SIZE ||
                    hasTextContent(fileObj);
        }
    }

    if (mimeType.startsWith("text/")) {                             //NOI18N
        return true;
    }

    if (mimeType.startsWith("application/")) {                      //NOI18N
        final String subtype = mimeType.substring(12);
        return subtype.equals("rtf") //NOI18N
                || subtype.equals("sgml") //NOI18N
                || subtype.startsWith("xml-") //NOI18N
                || subtype.endsWith("+xml") //NOI18N
                || isApplicationXSource(subtype, fileObj);
    }

    return mimeType.endsWith("+xml");                               //NOI18N
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:DefaultMatcher.java

示例9: createMultiObject

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
protected MultiDataObject createMultiObject (FileObject primaryFile) 
throws DataObjectExistsException, IOException {
    String mimeType = primaryFile.getMIMEType ();
    if (LanguagesManager.getDefault ().createDataObjectFor (mimeType))
        return new LanguagesDataObject (primaryFile, this);
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:LanguagesDataLoader.java

示例10: getMimeType

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
 * Uses content analysis for unversioned files.
 *
 * @param file file to examine
 * @return String mime type of the file (or best guess)
 */
public static String getMimeType(File file) {
    FileObject fo = FileUtil.toFileObject(file);
    String foMime;
    if (fo == null) {
        foMime = "content/unknown";
    } else {
        foMime = fo.getMIMEType();
    }
    if(foMime.startsWith("text")) {
        return foMime;
    }
    return Utils.isFileContentText(file) ? "text/plain" : "application/octet-stream";
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:HgUtils.java

示例11: getHeaderField

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public String getHeaderField (String name) {
    if ("content-type".equals(name)) {                  //NOI18N
        try {
            this.connect();
            FileObject fo = FileUtil.toFileObject(f);
            if (fo != null) {
                return fo.getMIMEType();
            }
        } catch (IOException ioe) {
            Exceptions.printStackTrace(ioe);
        }
    }
    return super.getHeaderField(name);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:NbinstURLStreamHandler.java

示例12: getMimeType

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
 * Reads the svn:mime-type property or uses content analysis for unversioned files.
 *
 * @param file file to examine
 * @return String mime type of the file (or best guess)
 */
public static String getMimeType(File file) {
    FileObject fo = FileUtil.toFileObject(file);
    String foMime;
    if (fo == null) {
        foMime = "content/unknown";
    } else {
        foMime = fo.getMIMEType();
    }
    FileStatusCache cache = Subversion.getInstance().getStatusCache();
    if ((cache.getStatus(file).getStatus() & FileInformation.STATUS_VERSIONED) == 0) {
        if(foMime.startsWith("text/")) {
            return foMime;
        }
        return Utils.isFileContentText(file) ? "text/plain" : "application/octet-stream";
    } else {
        PropertiesClient client = new PropertiesClient(file);
        try {
            byte [] mimeProperty = client.getProperties().get("svn:mime-type");
            if (mimeProperty != null) {
                String mimePath = new String(mimeProperty);
                int pos = mimePath.indexOf('/');
                if (pos > 0) {
                    while (pos < mimePath.length()) {
                        try {
                            return MimePath.parse(mimePath).getPath();
                        } catch (IllegalArgumentException ex) {
                            // for paths in the form of text/plain;charset=UTF-8
                            mimePath = mimePath.substring(0, mimePath.length() - 1);
                        }
                    }
                }
            }
            return Utils.isFileContentText(file) ? foMime : "application/octet-stream";
        } catch (IOException e) {
            return foMime;
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:45,代码来源:SvnUtils.java

示例13: getMimeType

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private String getMimeType(FileObject file) {
    FileObject fo = file;
    if(fo != null) {
        return fo.getMIMEType();   
    } else {
        return "content/unknown"; // NOI18N
    }                
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:HistoryDiffView.java

示例14: mayBeXhtml

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public boolean mayBeXhtml() {
    FileObject fo = getSource().getSourceFileObject();
    String mimeType = fo != null ? fo.getMIMEType() : null;
    return getHtmlTagDefaultNamespace() != null || "text/xhtml".equals(mimeType);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:6,代码来源:SyntaxAnalyzerResult.java

示例15: TextPreview

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public TextPreview(Preferences prefs, FileObject previewFile) throws IOException {
    this(prefs, previewFile.getMIMEType(), loadPreviewText(previewFile.getInputStream()));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:4,代码来源:IndentationPanel.java


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