本文整理了Java中org.openide.filesystems.FileUtil.getMIMEType()
方法的一些代码示例,展示了FileUtil.getMIMEType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.getMIMEType()
方法的具体详情如下:
包路径:org.openide.filesystems.FileUtil
类名称:FileUtil
方法名:getMIMEType
[英]Obtain MIME type for a well-known extension. If there is a case-sensitive match, that is used, else will fall back to a case-insensitive match.
[中]获取已知扩展的MIME类型。如果使用了区分大小写的匹配,else将返回到不区分大小写的匹配。
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
/** Get the MIME type of this file.
* The MIME type identifies the type of the file's contents and should be used in the same way as in the <B>Java
* Activation Framework</B> or in the {@link java.awt.datatransfer} package.
* <P>
* The default implementation calls {@link FileUtil#getMIMEType}.
* (As a fallback return value, <code>content/unknown</code> is used.)
* @return the MIME type textual representation, e.g. <code>"text/plain"</code>; never <code>null</code>
*/
public String getMIMEType() {
String mimeType = FileUtil.getMIMEType(this);
return mimeType == null ? "content/unknown" : mimeType; //NOI18N
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
@SuppressWarnings("deprecation")
private static String getMIMEType(String extension) {
return FileUtil.getMIMEType(extension);
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
/** Resolves MIME type from the list of acceptable ones. By default
* calls {@link FileUtil#getMIMEType(org.openide.filesystems.FileObject, java.lang.String[])},
* but subclasses may override this method to be more effective.
*
* @param withinMIMETypes
* A hint to the underlaying infrastructure to
* limit the search to given array of MIME types.
* @return the MIME type for the FileObject, or <code>null</code> if
* the FileObject is unrecognized. It may return {@code content/unknown} instead of {@code null}.
* It is possible for the resulting MIME type to not be a member of given <code>withinMIMETypes</code>
* list.
* @since 7.50
*/
public String getMIMEType(String... withinMIMETypes) {
return FileUtil.getMIMEType(this, withinMIMETypes);
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-clientproject
/**
* Check whether the given file is a CSS file.
* @param file file to be checked
* @return {@code true} if the given file is a CSS file, {@code false} otherwise
*/
public static boolean isCssFile(FileObject file) {
return CSS_MIME_TYPE.equals(FileUtil.getMIMEType(file, CSS_MIME_TYPE));
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-project
public static boolean isPhpOrHtmlFile(FileObject file) {
assert file != null;
String mimeType = FileUtil.getMIMEType(file, FileUtils.PHP_MIME_TYPE, HTML_MIME_TYPE);
return FileUtils.PHP_MIME_TYPE.equals(mimeType) || HTML_MIME_TYPE.equals(mimeType);
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-clientproject
/**
* Check whether the given file is an (X)HTML file.
* @param file file to be checked
* @return {@code true} if the given file is an (X)HTML file, {@code false} otherwise
*/
public static boolean isHtmlFile(FileObject file) {
String mimeType = FileUtil.getMIMEType(file, HTML_MIME_TYPE, XHTML_MIME_TYPE);
return HTML_MIME_TYPE.equals(mimeType) || XHTML_MIME_TYPE.equals(mimeType);
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-utils
/**
* tries to detect mime type of file checking cnd known types first
* @param file file object to check
* @return one of mime types or "content/unknown"
*/
public static String getBinaryFileMIMEType(FileObject fo) {
Parameters.notNull("file object", fo); // NOI18N
// try fast check
String mime = FileUtil.getMIMEType(fo, BINARY_MIME_TYPES);
if (mime == null) {
// now full check
mime = FileUtil.getMIMEType(fo);
}
return mime;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-utils
/**
* tries to detect mime type of file checking cnd known types first
* @param file file object to check
* @return one of mime types or "content/unknown"
*/
public static String getSourceFileMIMEType(FileObject fo) {
Parameters.notNull("file object", fo); // NOI18N
// try fast check
String mime = FileUtil.getMIMEType(fo, SOURCE_MIME_TYPES);
if (mime == null || mime.equals("content/unknown")) { // NOI18N
// now full check
mime = FileUtil.getMIMEType(fo);
}
return mime;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-api-phpmodule
/**
* Returns <code>true</code> if the file is a PHP file.
* @param file file to check
* @return <code>true</code> if the file is a PHP file
* @see #PHP_MIME_TYPE
*/
public static boolean isPhpFile(FileObject file) {
Parameters.notNull("file", file); // NOI18N
return PHP_MIME_TYPE.equals(FileUtil.getMIMEType(file, PHP_MIME_TYPE));
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-groovy-support
private static boolean isGroovyFile(FileObject fileObj) {
return "groovy".equals(fileObj.getExt()) || "text/x-groovy".equals(FileUtil.getMIMEType(fileObj)); //NOI18N
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor
@Override
public boolean accept(FileObject file) {
if (file.equals(currentFile) || isNbProjectMetadata(file)) {
return false; //do not include self in the cc result
}
if (file.isFolder()) {
return true;
}
String mimeType = FileUtil.getMIMEType(file);
return mimeType != null && mimeType.startsWith("text/");
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-modelimpl
private boolean isCOrCpp(FileObject fo) {
String mime = fo.getMIMEType();
if (mime == null) {
mime = FileUtil.getMIMEType(fo);
if (TraceFlags.TRACE_EXTERNAL_CHANGES) {
CsmEvent.LOG.log(Level.INFO, "External updates: MIME resolved: {0}", mime);
}
}
return MIMENames.isFortranOrHeaderOrCppOrC(mime);
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-modelimpl
private boolean isCOrCpp(FileObject fo) {
String mime = fo.getMIMEType();
if (mime == null) {
mime = FileUtil.getMIMEType(fo);
if (TraceFlags.TRACE_EXTERNAL_CHANGES) {
LOG.log(Level.INFO, "External updates: MIME resolved: {0}", mime);
}
}
return MIMENames.isFortranOrHeaderOrCppOrC(mime);
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-gsf
public List<FileObject> getFileObjects() {
List<FileObject> result = new ArrayList<FileObject>();
// Filter uninteresting files from the lookup
LanguageRegistry registry = LanguageRegistry.getInstance();
for( FileObject fileObject : super.getFileObjects() ) {
if (!registry.isSupported(FileUtil.getMIMEType(fileObject))) {
continue;
}
result.add(fileObject);
}
if (result.size() == 1)
return result;
return Collections.emptyList();
}
代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide
/** Resolves MIME type. Registered resolvers are invoked and used to achieve this goal.
* Resolvers must subclass MIMEResolver. If resolvers don`t recognize MIME type then
* MIME type is obtained for a well-known extension.
* @param fo whose MIME type should be recognized
* @return the MIME type for the FileObject, or <code>null</code> if the FileObject is unrecognized
*/
public static String getMIMEType (FileObject fo) {
String retVal = MIMESupport.findMIMEType(fo, null);
if (retVal == null) retVal = getMIMEType (fo.getExt ());
return retVal;
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide
/** Resolves MIME type. Registered resolvers are invoked and used to achieve this goal.
* Resolvers must subclass MIMEResolver. If resolvers don`t recognize MIME type then
* MIME type is obtained for a well-known extension.
* @param fo whose MIME type should be recognized
* @return the MIME type for the FileObject, or <code>null</code> if the FileObject is unrecognized
*/
public static String getMIMEType (FileObject fo) {
String retVal = MIMESupport.findMIMEType(fo, null);
if (retVal == null) retVal = getMIMEType (fo.getExt ());
return retVal;
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide
/** Finds mime type by calling getMIMEType, but
* instead of returning null it fallbacks to default type
* either text/plain or content/unknown (even for folders)
*/
static String getMIMETypeOrDefault (FileObject fo) {
String def = getMIMEType (fo.getExt ());
String t = MIMESupport.findMIMEType(fo, def);
if (t == null) {
// #42965: never allowed
t = "content/unknown"; // NOI18N
}
return t;
}
代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide
/** Finds mime type by calling getMIMEType, but
* instead of returning null it fallbacks to default type
* either text/plain or content/unknown (even for folders)
*/
static String getMIMETypeOrDefault (FileObject fo) {
String def = getMIMEType (fo.getExt ());
String t = MIMESupport.findMIMEType(fo, def);
if (t == null) {
// #42965: never allowed
t = "content/unknown"; // NOI18N
}
return t;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-utils
@Override
protected boolean mimeAccept(FileObject fo) {
if (fo != null) {
if (fo.isValid()) {
return MIMENames.SHELL_MIME_TYPE.equals(FileUtil.getMIMEType(fo, MIMENames.SHELL_MIME_TYPE));
} else {
return MIMEExtensions.isRegistered(MIMENames.SHELL_MIME_TYPE, FileUtil.getExtension(fo.getNameExt()));
}
}
return false;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-navigation
private static FileObject findToggleFile(DataObject dob) {
FileObject res = null;
// check whether current file is C++ Source file
FileObject fo = dob.getPrimaryFile();
if (fo != null) {
String mimeType = FileUtil.getMIMEType(fo, MIMENames.HEADER_MIME_TYPE, MIMENames.CPLUSPLUS_MIME_TYPE, MIMENames.C_MIME_TYPE);
if (MIMENames.isCppOrC(mimeType)) {
// it was Source file, find Header
res = findBrother(dob, MIMEExtensions.get(MIMENames.HEADER_MIME_TYPE).getValues());
} else if (MIMENames.HEADER_MIME_TYPE.equals(mimeType)) {
// check whether current file is Header file
// try to find C++ Source file
res = findBrother(dob, MIMEExtensions.get(MIMENames.CPLUSPLUS_MIME_TYPE).getValues());
if (res == null) {
// try to find C Source file
res = findBrother(dob, MIMEExtensions.get(MIMENames.C_MIME_TYPE).getValues());
}
}
}
return res;
}
内容来源于网络,如有侵权,请联系作者删除!