Java 类org.eclipse.core.runtime.content.IContentDescription 实例源码
项目:SecureBPMN
文件:ActivitiMultiPageEditor.java
private boolean isBPM2FileType(final IFileEditorInput editorInput) {
boolean isBPMN2File = false;
IFile file = editorInput.getFile();
try {
IContentDescription desc = file.getContentDescription();
if (desc != null) {
IContentType type = desc.getContentType();
if (ActivitiBPMNDiagramConstants.BPMN2_CONTENTTYPE_ID.equals(type.getId())) {
isBPMN2File = true;
}
}
} catch (CoreException e) {
e.printStackTrace();
return isBPMN2File;
}
return isBPMN2File;
}
项目:filesync4eclipse
文件:SyncWizard.java
/**
* @param file must be not null
* @return true if the file has "text" content description.
*/
public static boolean hasTextContentType(IFile file) {
try {
IContentDescription contentDescr = file.getContentDescription();
if (contentDescr == null) {
return false;
}
IContentType contentType = contentDescr.getContentType();
if (contentType == null) {
return false;
}
return contentType.isKindOf(TEXT_TYPE);
//
} catch (CoreException e) {
FileSyncPlugin.log(
"Could not get content type for: " + file, e, IStatus.WARNING);
}
return false;
}
项目:eclipse-wtp-json
文件:JSONSyntaxValidator.java
private boolean shouldValidate(IResource file, boolean checkExtension) {
if (file == null || !file.exists() || file.getType() != IResource.FILE)
return false;
if (checkExtension) {
String extension = file.getFileExtension();
if (extension != null
&& "json".endsWith(extension.toLowerCase(Locale.US))) //$NON-NLS-1$
return true;
}
IContentDescription contentDescription = null;
try {
contentDescription = ((IFile) file).getContentDescription();
if (contentDescription != null) {
IContentType contentType = contentDescription.getContentType();
return contentDescription != null
&& contentType.isKindOf(getJSONContentType());
}
} catch (CoreException e) {
Logger.logException(e);
}
return false;
}
项目:eclipse-wtp-json
文件:ContentDescriberForJSON.java
private void handleDetectedSpecialCase(IContentDescription description,
Object detectedCharset, Object javaCharset) {
// since equal, we don't need to add, but if our detected version is
// different than javaCharset, then we should add it. This will
// happen, for example, if there's differences in case, or differences
// due to override properties
if (detectedCharset != null) {
// Once we detected a charset, we should set the property even
// though it's the same as javaCharset
// because there are clients that rely on this property to
// determine if the charset is actually detected in file or not.
description.setProperty(
IContentDescriptionExtended.DETECTED_CHARSET,
detectedCharset);
}
}
项目:eclipse-wtp-json
文件:ContentDescriberForJSON.java
/**
* @param description
* @return
*/
private boolean isRelevent(IContentDescription description) {
boolean result = false;
if (description == null)
result = false;
else if (description.isRequested(IContentDescription.BYTE_ORDER_MARK))
result = true;
else if (description.isRequested(IContentDescription.CHARSET))
result = true;
else if (description
.isRequested(IContentDescriptionExtended.APPROPRIATE_DEFAULT))
result = true;
else if (description
.isRequested(IContentDescriptionExtended.DETECTED_CHARSET))
result = true;
else if (description
.isRequested(IContentDescriptionExtended.UNSUPPORTED_CHARSET))
result = true;
// else if
// (description.isRequested(IContentDescriptionExtended.ENCODING_MEMENTO))
// result = true;
return result;
}
项目:OpenSPIFe
文件:ProfileUtil.java
public static boolean isProfileContentType (IResource resource) {
if ((resource instanceof IFile) && resource.exists()) {
try {
IContentDescription cd = ((IFile)resource).getContentDescription();
if (cd != null) {
IContentType type = cd.getContentType();
if ((type != null) && type.isKindOf(PROFILE_CONTENT_TYPE)) {
return true;
}
}
} catch (CoreException e) {
LogUtil.error(e);
}
}
return false;
}
项目:Eclipse-Postfix-Code-Completion
文件:PropertiesFileDocumentProvider.java
/**
* Checks whether the passed file editor input defines a Java properties file.
*
* @param element the file editor input
* @return <code>true</code> if element defines a Java properties file, <code>false</code>
* otherwise
* @throws CoreException
*
* @since 3.7
*/
public static boolean isJavaPropertiesFile(Object element) throws CoreException {
if (JAVA_PROPERTIES_FILE_CONTENT_TYPE == null || !(element instanceof IFileEditorInput))
return false;
IFileEditorInput input= (IFileEditorInput)element;
IFile file= input.getFile();
if (file == null || !file.isAccessible())
return false;
IContentDescription description= file.getContentDescription();
if (description == null || description.getContentType() == null || !description.getContentType().isKindOf(JAVA_PROPERTIES_FILE_CONTENT_TYPE))
return false;
return true;
}
项目:Eclipse-Postfix-Code-Completion
文件:EditorUtility.java
private static boolean isClassFile(IFile file) {
IContentDescription contentDescription;
try {
contentDescription= file.getContentDescription();
} catch (CoreException e) {
contentDescription= null;
}
if (contentDescription == null)
return false;
IContentType contentType= contentDescription.getContentType();
if (contentType == null)
return false;
return "org.eclipse.jdt.core.javaClass".equals(contentType.getId()); //$NON-NLS-1$
}
项目:mybatipse
文件:ConfigRegistry.java
@Override
public boolean visit(IResourceProxy proxy) throws CoreException
{
if (proxy.isDerived())
return false;
if (proxy.getType() == IResource.FILE && proxy.getName().endsWith(".xml"))
{
IFile file = (IFile)proxy.requestResource();
IContentDescription contentDesc = file.getContentDescription();
if (contentDesc != null)
{
IContentType contentType = contentDesc.getContentType();
if (contentType != null && (contentType.isKindOf(configContentType)
|| contentType.isKindOf(springConfigContentType)))
{
configFiles.put(file, contentType);
}
}
}
return true;
}
项目:Eclipse-Postfix-Code-Completion-Juno38
文件:PropertiesFileDocumentProvider.java
/**
* Checks whether the passed file editor input defines a Java properties file.
*
* @param element the file editor input
* @return <code>true</code> if element defines a Java properties file, <code>false</code>
* otherwise
* @throws CoreException
*
* @since 3.7
*/
public static boolean isJavaPropertiesFile(Object element) throws CoreException {
if (JAVA_PROPERTIES_FILE_CONTENT_TYPE == null || !(element instanceof IFileEditorInput))
return false;
IFileEditorInput input= (IFileEditorInput)element;
IFile file= input.getFile();
if (file == null || !file.isAccessible())
return false;
IContentDescription description= file.getContentDescription();
if (description == null || description.getContentType() == null || !description.getContentType().isKindOf(JAVA_PROPERTIES_FILE_CONTENT_TYPE))
return false;
return true;
}
项目:Eclipse-Postfix-Code-Completion-Juno38
文件:EditorUtility.java
private static boolean isClassFile(IFile file) {
IContentDescription contentDescription;
try {
contentDescription= file.getContentDescription();
} catch (CoreException e) {
contentDescription= null;
}
if (contentDescription == null)
return false;
IContentType contentType= contentDescription.getContentType();
if (contentType == null)
return false;
return "org.eclipse.jdt.core.javaClass".equals(contentType.getId()); //$NON-NLS-1$
}
项目:eclipse-avro
文件:PlatformContentHandlerImpl.java
/**
* Returns the given property's Eclipse value converted to EMF's corresponding basic value.
* @param qualifiedName the name of the property for which this value applies.
* @param value the value to convert.
* @return the given property's Eclipse value converted to EMF's corresponding basic value.
*/
protected Object getDescriptionValue(QualifiedName qualifiedName, Object value)
{
if (value == null)
{
return null;
}
else if (IContentDescription.BYTE_ORDER_MARK.equals(qualifiedName))
{
for (ByteOrderMark byteOrderMarker : ContentHandler.ByteOrderMark.values())
{
if (value == byteOrderMarker.bytes())
{
return byteOrderMarker;
}
}
return null;
}
else
{
return value;
}
}
项目:eclipse-avro
文件:ContentHandlerImpl.java
/**
* Returns the given property's basic EMF value converted to the corresponding Eclipse value.
* @param qualifiedName the name of the property for which this value applies.
* @param value the value to convert.
* @return the given property's basic EMF value converted to the corresponding Eclipse value.
*/
protected Object getDescriptionValue(QualifiedName qualifiedName, Object value)
{
if (value == null)
{
return null;
}
else if (IContentDescription.BYTE_ORDER_MARK.equals(qualifiedName))
{
return ((ContentHandler.ByteOrderMark)value).bytes();
}
else
{
return value;
}
}
项目:clickwatch
文件:PlatformContentHandlerImpl.java
/**
* Returns the given property's Eclipse value converted to EMF's corresponding basic value.
* @param qualifiedName the name of the property for which this value applies.
* @param value the value to convert.
* @return the given property's Eclipse value converted to EMF's corresponding basic value.
*/
protected Object getDescriptionValue(QualifiedName qualifiedName, Object value)
{
if (value == null)
{
return null;
}
else if (IContentDescription.BYTE_ORDER_MARK.equals(qualifiedName))
{
for (ByteOrderMark byteOrderMarker : ContentHandler.ByteOrderMark.values())
{
if (value == byteOrderMarker.bytes())
{
return byteOrderMarker;
}
}
return null;
}
else
{
return value;
}
}
项目:clickwatch
文件:ContentHandlerImpl.java
/**
* Returns the given property's basic EMF value converted to the corresponding Eclipse value.
* @param qualifiedName the name of the property for which this value applies.
* @param value the value to convert.
* @return the given property's basic EMF value converted to the corresponding Eclipse value.
*/
protected Object getDescriptionValue(QualifiedName qualifiedName, Object value)
{
if (value == null)
{
return null;
}
else if (IContentDescription.BYTE_ORDER_MARK.equals(qualifiedName))
{
return ((ContentHandler.ByteOrderMark)value).bytes();
}
else
{
return value;
}
}
项目:mule-tooling-incubator
文件:StudioGradleEnabledContentDescriber.java
@Override
public int describe(InputStream contents, IContentDescription description) throws IOException {
try {
GradleScriptASTParser parser = new GradleScriptASTParser(contents);
PluginsSyntaxDescriberVisitor pluginsVisitor = new PluginsSyntaxDescriberVisitor();
ApplySyntaxDescriberVisitor visitor = new ApplySyntaxDescriberVisitor();
parser.walkScript(pluginsVisitor);
if (pluginsVisitor.isFoundPlugin()) {
return IContentDescriber.VALID;
}
parser.walkScript(visitor);
if (visitor.isFoundplugin()) {
return IContentDescriber.VALID;
}
} catch (MultipleCompilationErrorsException ex) {
return IContentDescriber.INDETERMINATE;
}
return IContentDescriber.INVALID;
}
项目:subclipse
文件:SVNUIPlugin.java
public static IContentDescription getContentDescription(String name, InputStream stream) throws IOException {
// tries to obtain a description for this file contents
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
try {
return contentTypeManager.getDescriptionFor(stream, name, IContentDescription.ALL);
} finally {
if (stream != null)
try {
stream.close();
} catch (IOException e) {
// Ignore exceptions on close
}
}
}
项目:che
文件:TextSearchVisitor.java
private boolean hasBinaryContent(CharSequence seq, IFile file) throws CoreException {
IContentDescription desc = file.getContentDescription();
if (desc != null) {
IContentType contentType = desc.getContentType();
if (contentType != null
&& contentType.isKindOf(
Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT))) {
return false;
}
}
// avoid calling seq.length() at it runs through the complete file,
// thus it would do so for all binary files.
try {
int limit = FileCharSequenceProvider.BUFFER_SIZE;
for (int i = 0; i < limit; i++) {
if (seq.charAt(i) == '\0') {
return true;
}
}
} catch (IndexOutOfBoundsException e) {
} catch (FileCharSequenceException ex) {
if (ex.getCause() instanceof CharConversionException) return true;
throw ex;
}
return false;
}
项目:che
文件:FileCharSequenceProvider.java
private InputStream getInputStream(String charset) throws CoreException, IOException {
boolean ok = false;
InputStream contents = fFile.getContents();
try {
if (CHARSET_UTF_8.equals(charset)) {
/*
* This is a workaround for a corresponding bug in Java readers and writer,
* see http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
* we remove the BOM before passing the stream to the reader
*/
IContentDescription description = fFile.getContentDescription();
if ((description != null)
&& (description.getProperty(IContentDescription.BYTE_ORDER_MARK) != null)) {
int bomLength = IContentDescription.BOM_UTF_8.length;
byte[] bomStore = new byte[bomLength];
int bytesRead = 0;
do {
int bytes = contents.read(bomStore, bytesRead, bomLength - bytesRead);
if (bytes == -1) throw new IOException();
bytesRead += bytes;
} while (bytesRead < bomLength);
if (!Arrays.equals(bomStore, IContentDescription.BOM_UTF_8)) {
// discard file reader, we were wrong, no BOM -> new stream
contents.close();
contents = fFile.getContents();
}
}
}
ok = true;
} finally {
if (!ok && contents != null)
try {
contents.close();
} catch (IOException ex) {
// ignore
}
}
return contents;
}
项目:che
文件:JavaProject.java
private boolean hasUTF8BOM(byte[] bytes) {
if (bytes.length > IContentDescription.BOM_UTF_8.length) {
for (int i = 0, length = IContentDescription.BOM_UTF_8.length; i < length; i++) {
if (IContentDescription.BOM_UTF_8[i] != bytes[i]) return false;
}
return true;
}
return false;
}
项目:gwt-eclipse-plugin
文件:UiBinderXmlContentDescriber.java
@Override
public int describe(InputStream input, IContentDescription description)
throws IOException {
if (super.describe(input, description) == INVALID) {
return INVALID;
}
if (rootElementContentDescriber.describe(input, description) == VALID) {
// The root element is a UiBinder element
return VALID;
}
return describe(ContentDescriberUtilities.resolveFileFromInputStream(input));
}
项目:gwt-eclipse-plugin
文件:UiBinderXmlContentDescriber.java
@Override
public int describe(Reader input, IContentDescription description)
throws IOException {
if (super.describe(input, description) == INVALID) {
return INVALID;
}
if (rootElementContentDescriber.describe(input, description) == VALID) {
// The root element is a UiBinder element
return VALID;
}
return describe(ContentDescriberUtilities.resolveFileFromReader(input));
}
项目:gwt-eclipse-plugin
文件:CssResourceContentDescriber.java
public int describe(InputStream contents, IContentDescription description)
throws IOException {
if (regularCssContentDescriber.describe(contents, description) == INVALID) {
return INVALID;
}
return describe(ContentDescriberUtilities.resolveFileFromInputStream(contents));
}
项目:gwt-eclipse-plugin
文件:CssResourceContentDescriber.java
public int describe(Reader contents, IContentDescription description)
throws IOException {
if (regularCssContentDescriber.describe(contents, description) == INVALID) {
return INVALID;
}
return describe(ContentDescriberUtilities.resolveFileFromReader(contents));
}
项目:gwt-eclipse-plugin
文件:GssResourceContentDescriber.java
@Override
public int describe(InputStream contents, IContentDescription description) throws IOException {
// if (regularCssContentDescriber.describe(contents, description) == INVALID) {
// return INVALID;
// }
return describe(ContentDescriberUtilities.resolveFileFromInputStream(contents));
}
项目:gwt-eclipse-plugin
文件:GssResourceContentDescriber.java
@Override
public int describe(Reader contents, IContentDescription description) throws IOException {
// if (regularCssContentDescriber.describe(contents, description) == INVALID) {
// return INVALID;
// }
return describe(ContentDescriberUtilities.resolveFileFromReader(contents));
}
项目:KaiZen-OpenAPI-Editor
文件:TextContentDescriber.java
@Override
public int describe(InputStream contents, IContentDescription description) throws IOException {
String content = CharStreams.toString(new InputStreamReader(contents));
if (content.trim().isEmpty()) {
return INDETERMINATE;
}
return isSupported(content) ? VALID : INVALID;
}
项目:eclipse-wtp-json
文件:ContentDescriberForJSON.java
public int describe(InputStream contents, IContentDescription description)
throws IOException {
int result = IContentDescriber.INDETERMINATE;
if (description == null) {
result = computeValidity(contents);
} else {
calculateSupportedOptions(contents, description);
result = computeValidity(contents);
}
return result;
}
项目:eclipse-wtp-json
文件:ContentDescriberForJSON.java
public int describe(Reader contents, IContentDescription description)
throws IOException {
int result = IContentDescriber.INDETERMINATE;
if (description == null) {
result = computeValidity(contents);
} else {
calculateSupportedOptions(contents, description);
result = computeValidity(contents);
}
return result;
}
项目:eclipse-wtp-json
文件:ContentDescriberForJSON.java
private void calculateSupportedOptions(InputStream contents,
IContentDescription description) throws IOException {
if (isRelevent(description)) {
IResourceCharsetDetector detector = getDetector();
detector.set(contents);
handleCalculations(description, detector);
}
}
项目:eclipse-wtp-json
文件:ContentDescriberForJSON.java
/**
* @param contents
* @param description
* @throws IOException
*/
private void calculateSupportedOptions(Reader contents,
IContentDescription description) throws IOException {
if (isRelevent(description)) {
IResourceCharsetDetector detector = getDetector();
detector.set(contents);
handleCalculations(description, detector);
}
}
项目:APICloud-Studio
文件:SVNUIPlugin.java
public static IContentDescription getContentDescription(String name, InputStream stream) throws IOException {
// tries to obtain a description for this file contents
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
try {
return contentTypeManager.getDescriptionFor(stream, name, IContentDescription.ALL);
} finally {
if (stream != null)
try {
stream.close();
} catch (IOException e) {
// Ignore exceptions on close
}
}
}
项目:strutsclipse
文件:ProjectUtil.java
@Override
public boolean test(IProject project, IResource resource)
throws CoreException {
boolean check = false;
if (contentType != null) {
IFile file = project.getFile(resource.getProjectRelativePath());
IContentDescription descrp = file.getContentDescription();
check = descrp.getContentType().isKindOf(contentType);
} else if (fileName != null
&& resource.getName().toLowerCase(Locale.ROOT)
.contains(fileName)) {
check = true;
}
return check;
}
项目:Eclipse-Postfix-Code-Completion
文件:JavaProject.java
private boolean hasUTF8BOM(byte[] bytes) {
if (bytes.length > IContentDescription.BOM_UTF_8.length) {
for (int i = 0, length = IContentDescription.BOM_UTF_8.length; i < length; i++) {
if (IContentDescription.BOM_UTF_8[i] != bytes[i])
return false;
}
return true;
}
return false;
}
项目:eclipse-wtp-freemarker
文件:FMDocumentLoader.java
@Override
public Reader getCodedReader() throws CoreException, IOException {
Reader reader = super.getCodedReader();
try {
char tBuff[] = new char[CodedIO.MAX_BUF_SIZE];
reader.read(tBuff, 0, tBuff.length);
reader.reset();
return reader;
} catch (Exception e) {
}
InputStream is = getResettableStream();
EncodingMemento encodingMemento = getEncodingMemento();
String charsetName = encodingMemento.getJavaCharsetName();
if (charsetName == null) {
charsetName = encodingMemento.getDetectedCharsetName();
}
if (!encodingMemento.isValid() && !forceDefault()) {
throw new UnsupportedCharsetExceptionWithDetail(encodingMemento);
}
if (fEncodingRule == EncodingRule.FORCE_DEFAULT) {
charsetName = encodingMemento.getAppropriateDefault();
}
// [228366] For files that have a unicode BOM, and a charset name of UTF-16, the charset decoder needs "UTF-16LE"
if(CHARSET_UTF_16.equals(charsetName) && encodingMemento.getUnicodeBOM() == IContentDescription.BOM_UTF_16LE)
charsetName = CHARSET_UTF_16LE;
reader = new BufferedReader(new InputStreamReader(is, charsetName), CodedIO.MAX_BUF_SIZE);
return reader;
}
项目:eclipse-wtp-webresources
文件:WebResourcesValidator.java
/**
* Check file extension to validate
*/
private boolean canHandle(IFile file) {
boolean result = false;
if (file != null) {
try {
IContentDescription contentDescription = file
.getContentDescription();
if (contentDescription != null) {
IContentType fileContentType = contentDescription
.getContentType();
if (fileContentType.isKindOf(fHTMLContentType)) {
result = true;
} else {
IContentType[] otherTypes = getOtherSupportedContentTypes();
for (int i = 0; i < otherTypes.length; i++) {
result = result
|| fileContentType.isKindOf(otherTypes[i]);
}
}
} else if (fHTMLContentType != null) {
result = fHTMLContentType.isAssociatedWith(file.getName());
}
} catch (CoreException e) {
// should be rare, but will ignore to avoid logging "encoding
// exceptions" and the like here.
}
}
return result;
}
项目:Eclipse-Postfix-Code-Completion-Juno38
文件:JavaProject.java
private boolean hasUTF8BOM(byte[] bytes) {
if (bytes.length > IContentDescription.BOM_UTF_8.length) {
for (int i = 0, length = IContentDescription.BOM_UTF_8.length; i < length; i++) {
if (IContentDescription.BOM_UTF_8[i] != bytes[i])
return false;
}
return true;
}
return false;
}
项目:tool
文件:GRAsppartifact2model.java
@Override
protected final boolean theSelectionIsValid(final IFile theSelection) {
try {
final IContentDescription contentDescription = theSelection.getContentDescription();
return contentDescription != null && contentDescription.getContentType() != null
//&& org.ijis.gra.mpd.Activator.CONTENT_TYPE.equals(contentDescription.getContentType().getId())
&&"catalog.xml".equals(theSelection.getName())
&& theSelection.getParent() != theSelection.getProject();
} catch (final CoreException e) {
// no-op
}
return false;
}
项目:data-mapper
文件:DozerConfigContentTypeDescriber.java
/**
* {@inheritDoc}
*
* @see org.eclipse.core.runtime.content.ITextContentDescriber#describe(java.io.Reader,
* org.eclipse.core.runtime.content.IContentDescription)
*/
@Override
public int describe(final Reader contents,
final IContentDescription description) throws IOException {
final char[] buf = new char[200];
contents.read(buf);
final String text = String.valueOf(buf).replaceAll("\\s", "");
final int ndx = text.indexOf(ROOT_ELEMENT);
return ndx > 0 && text.indexOf(XMLNS) > ndx ? ITextContentDescriber.VALID
: ITextContentDescriber.INVALID;
}
项目:eclipse-avro
文件:PlatformResourceURIHandlerImpl.java
public static IContentDescription getContentDescription(String platformResourcePath, Map<?, ?> options) throws IOException
{
IFile file = workspaceRoot.getFile(new Path(platformResourcePath));
try
{
return file.getContentDescription();
}
catch (CoreException exception)
{
throw new Resource.IOWrappedException(exception);
}
}