/** * Returns the content description of the resource if it is a file and it * has a content description. * * @return the content description or <code>null</code> if resource is not * an <code>IFile</code> or it does not have a description */ private IContentDescription getContentDescription() { try { if (resource instanceof IFile) { return (((IFile) resource).getContentDescription()); } } catch (CoreException exception) { // If we cannot find it return null } return null; }
/** * Caches the BOM of the underlying file. * * @throws CoreException if reading of file's content description fails */ protected void cacheBOM() throws CoreException { fBOM= null; IContentDescription description= fFile.getContentDescription(); if (description != null) fBOM= (byte[])description.getProperty(IContentDescription.BYTE_ORDER_MARK); }
private IContentType getFileContentType() { try { IContentDescription description= fFile.getContentDescription(); if (description != null) { return description.getContentType(); } } catch (CoreException e) { } return null; } }
/** * Sets whether the underlying file has a BOM. * * @throws CoreException if reading of file's content description fails */ protected void setHasBOM() throws CoreException { fHasBOM= false; IContentDescription description= fFile.getContentDescription(); fHasBOM= description != null && description.getProperty(IContentDescription.BYTE_ORDER_MARK) != null; }
private IContentDescription getContentDescription(IResource resource) { if (resource.getType() != IResource.FILE) { return null; } if (cachedContentDescription == null) { try { cachedContentDescription = ((IFile) resource) .getContentDescription(); } catch (CoreException e) { // silently ignore } } return cachedContentDescription; }
private boolean isDSFile(IFile candidate) { try { IContentDescription description = candidate.getContentDescription(); if (description == null) return false; IContentType type = description.getContentType(); return Activator.CONTENT_TYPE_ID.equals(type.getId()); } catch (CoreException e) { return false; } }
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); } }
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); } }
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$ }
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$ }
private static String getEncodingFromContent(IFile file) throws CoreException { IContentDescription description = file.getContentDescription(); if (description != null) { byte[] bom= (byte[])description.getProperty(IContentDescription.BYTE_ORDER_MARK); if (bom == null) return (String)description.getProperty(IContentDescription.CHARSET); if (bom == IContentDescription.BOM_UTF_8) return TextEditorMessages.WorkbenchPreference_encoding_BOM_UTF_8; if (bom == IContentDescription.BOM_UTF_16BE) return TextEditorMessages.WorkbenchPreference_encoding_BOM_UTF_16BE; if (bom == IContentDescription.BOM_UTF_16LE) return TextEditorMessages.WorkbenchPreference_encoding_BOM_UTF_16LE; } return null; }
private static String getEncodingFromContent(IFile file) throws CoreException { IContentDescription description = file.getContentDescription(); if (description != null) { byte[] bom= (byte[])description.getProperty(IContentDescription.BYTE_ORDER_MARK); if (bom == null) return (String)description.getProperty(IContentDescription.CHARSET); if (bom == IContentDescription.BOM_UTF_8) return TextEditorMessages.WorkbenchPreference_encoding_BOM_UTF_8; if (bom == IContentDescription.BOM_UTF_16BE) return TextEditorMessages.WorkbenchPreference_encoding_BOM_UTF_16BE; if (bom == IContentDescription.BOM_UTF_16LE) return TextEditorMessages.WorkbenchPreference_encoding_BOM_UTF_16LE; } return null; }
/** * Returns the content type of for the given file editor input or * <code>null</code> if none could be determined. * * @param input the element * @return the content type or <code>null</code> * @throws CoreException if reading or accessing the underlying store * fails * @since 3.1 */ private IContentType getContentType(IFileEditorInput input) throws CoreException { IContentDescription desc= input.getFile().getContentDescription(); if (desc != null) return desc.getContentType(); return null; }
/** * Returns the content type of for the given file editor input or * <code>null</code> if none could be determined. * * @param input the element * @return the content type or <code>null</code> * @throws CoreException if reading or accessing the underlying store * fails * @since 3.1 */ private IContentType getContentType(IFileEditorInput input) throws CoreException { IContentDescription desc= input.getFile().getContentDescription(); if (desc != null) return desc.getContentType(); return null; }
private String getContentTypeName(Resource resource) { IFile file = getPlatformFile(resource); IContentDescription desc = null; try { desc = file.getContentDescription(); } catch (CoreException e) { } if (desc != null && desc.getContentType() != null) return desc.getContentType().getName(); return null; } private URI findKey(Resource resource) {
@Override public boolean visit(IResourceProxy proxy) throws CoreException { if (proxy.getType() == IResource.FILE && (proxy.getName().endsWith("yaml") || proxy.getName().endsWith("yml"))) { if (!proxy.isDerived()) { IFile file = (IFile) proxy.requestResource(); if (!file.equals(currentFile)) { String currFileType = file.getContentDescription().getContentType().getId(); if (fileContentType == null || fileContentType.equals(currFileType)) { files.add(file); } } } } else if (proxy.getType() == IResource.FOLDER && (proxy.isDerived() || proxy.getName().equalsIgnoreCase("gentargets"))) { return false; } return true; }
/** * Returns the set of content types for the given location. * * @param file the file for which to look up the content types * @return the set of content types for the location */ private IContentType[] findContentTypes(IFile file) { try { IContentDescription contentDescription= file.getContentDescription(); if (contentDescription != null) { IContentType contentType= contentDescription.getContentType(); if (contentType != null) return new IContentType[] {contentType}; } } catch (CoreException x) { // go for the default } return fContentTypeManager.findContentTypesFor(file.getFullPath().lastSegment()); }
protected FileInfo createFileInfo(Object element) throws CoreException { if (JAVA_PROPERTIES_FILE_CONTENT_TYPE == null || !(element instanceof IFileEditorInput)) return null; IFileEditorInput input= (IFileEditorInput)element; IFile file= input.getFile(); if (file == null || !file.isAccessible()) return null; IContentDescription description= file.getContentDescription(); if (description == null || description.getContentType() == null || !description.getContentType().isKindOf(JAVA_PROPERTIES_FILE_CONTENT_TYPE)) return null; return super.createFileInfo(element); }
public static boolean isTwigTemplate(IResource resource) { assert resource != null; if (resource.getType() != IResource.FILE) { return false; } try { return ((IFile) resource).getContentDescription().getContentType().isKindOf( Platform.getContentTypeManager().getContentType(ContentTypeIdForTwig.CONTENT_TYPE_ID_TWIG)); } catch (CoreException e) { Logger.logException(e); } return false; }
public void run() { try { String editorId = null; IEditorDescriptor editor = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(iFile.getLocation().toOSString(), iFile.getContentDescription().getContentType()); if (editor != null) { editorId = editor.getId(); } workbenchWindow.getActivePage().openEditor(new FileEditorInput(iFile), editorId); } catch (PartInitException ex) { } catch (CoreException ex) { } } });