/** * Verifies if fileName is valid name for content type. Takes base content * type into consideration. * * @param fileName * @return true if extension is valid for this content type */ boolean extensionValidForContentType(String fileName) { boolean valid = false; IContentType type = Platform.getContentTypeManager().getContentType( ContentTypeID_XML); // there is currently an extension if (fileName.lastIndexOf('.') != -1) { // check what content types are associated with current extension IContentType[] types = Platform.getContentTypeManager() .findContentTypesFor(fileName); int i = 0; while ((i < types.length) && !valid) { valid = types[i].isKindOf(type); ++i; } } else { valid = true; // no extension so valid } return valid; }
@Override public IGrammar getGrammarFor(IContentType[] contentTypes) { if (contentTypes == null) { return null; } // Find grammar by content type for (IContentType contentType : contentTypes) { String scopeName = getScopeNameForContentType(contentType.getId()); if (scopeName != null) { IGrammar grammar = getGrammarForScope(scopeName); if (grammar != null) { return grammar; } } } return null; }
private IDEResourcesManager() { this.registryListenerIntialized = false; this.resourceParticipants = new ArrayList<>(); this.listeners = new ArrayList<ITypeScriptElementChangedListener>(); updateUseJsAsJsx(Platform.getContentTypeManager().getContentType(JSX_CONTENT_TYPE_ID)); Platform.getContentTypeManager().addContentTypeChangeListener(new IContentTypeChangeListener() { @Override public void contentTypeChanged(ContentTypeChangeEvent event) { IContentType contentType = event.getContentType(); if (contentType != null && JSX_CONTENT_TYPE_ID.equals(contentType.getId())) { updateUseJsAsJsx(contentType); } } }); }
/** * {@inheritDoc} * * @see org.eclipse.mylyn.docs.intent.mapping.content.IFileTypeRegistry#getFileType(java.lang.String) */ public IFileType getFileType(String typeID) { final IFileType res; final IFileType delegateFileType = registry.getFileType(typeID); if (delegateFileType == null) { final IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); final IContentType contentType = contentTypeManager.getContentType(typeID); if (contentType != null) { res = new FileType(contentType.getId()); } else { res = null; } } else { res = delegateFileType; } return res; }
/** * {@inheritDoc} * * @throws IOException * @see org.eclipse.mylyn.docs.intent.mapping.content.IFileTypeRegistry#getFileTypeFor(java.io.InputStream, * java.lang.String) */ public IFileType getFileTypeFor(InputStream contents, String name) throws IOException { final IFileType res; final IFileType delegateFileType = registry.getFileTypeFor(contents, name); if (delegateFileType == null) { final IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(contents, name); if (contentType != null) { res = new FileType(contentType.getId()); } else { res = null; } } else { res = delegateFileType; } return res; }
/** * Returns a sharable document factory for the given content types. * * @param contentTypes the content types used to find the factory * @return the sharable document factory or <code>null</code> * @deprecated As of 3.5 */ protected org.eclipse.core.filebuffers.IDocumentFactory doGetDocumentFactory( IContentType[] contentTypes) { Set set = null; int i = 0; while (i < contentTypes.length && set == null) { set = (Set) fFactoryDescriptors.get(new ContentTypeAdapter(contentTypes[i++])); } if (set != null) { IConfigurationElement entry = selectConfigurationElement(set); return (org.eclipse.core.filebuffers.IDocumentFactory) getExtension(entry, fFactories, org.eclipse.core.filebuffers.IDocumentFactory.class); } return null; }
/** * Returns the set of setup participants for the given content types. * * @param contentTypes the contentTypes to be used for lookup * @return the sharable set of document setup participants */ private List doGetDocumentSetupParticipants(IContentType[] contentTypes) { Set resultSet = new HashSet(); int i = 0; while (i < contentTypes.length) { Set set = (Set) fSetupParticipantDescriptors.get(new ContentTypeAdapter(contentTypes[i++])); if (set != null) resultSet.addAll(set); } List participants = new ArrayList(); Iterator e = resultSet.iterator(); while (e.hasNext()) { IConfigurationElement entry = (IConfigurationElement) e.next(); Object participant = getExtension(entry, fSetupParticipants, IDocumentSetupParticipant.class); if (participant != null) participants.add(participant); } return participants.isEmpty() ? null : participants; }
/** * Returns the set of direct base content types for the given set of content types. Returns <code> * null</code> if non of the given content types has a direct base content type. * * @param contentTypes the content types * @return the set of direct base content types */ private IContentType[] computeBaseContentTypes(IContentType[] contentTypes) { List baseTypes = new ArrayList(); for (int i = 0; i < contentTypes.length; i++) { IContentType baseType = contentTypes[i].getBaseType(); if (baseType != null) baseTypes.add(baseType); } IContentType[] result = null; int size = baseTypes.size(); if (size > 0) { result = new IContentType[size]; baseTypes.toArray(result); } return result; }
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; }
/** * @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; }
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; }
@Override public String getContentType() { try { IContentType contentType = ((TextFileDocumentProvider) getDocumentProvider()) .getContentType(getEditorInput()); if (contentType != null) { IContentType baseType = contentType.getBaseType(); if (baseType != null && IXMLConstants.CONTENT_TYPE_XML.equals(baseType.getId())) { return contentType.getId(); } } } catch (Exception e) { } return IXMLConstants.CONTENT_TYPE_XML; }
/** * Determines if a given content type is associated with the filename. * * @param filename * @param types * @return */ private boolean hasType(String contentTypeId, Set<IContentType> types) { if (CollectionsUtil.isEmpty(types)) { // FIXME this means if no content type binding is specified then we assume the build participant is valid // for all types! return true; } for (IContentType type : types) { if (type == null) { continue; } if (type.getId().equals(contentTypeId)) { return true; } } return false; }
/** * Returns true if the given file can be evaluated for template-variables.<br> * There is no good way of detecting what is binary and what is not, so we decide what is supported by checking if * the content type is a sub-type of text. * * @param file * @return true if the file can be processed; false, otherwise. */ private static boolean isSupportedFile(IFile file) { IContentTypeManager manager = Platform.getContentTypeManager(); if (manager == null) { return false; } IContentType contentType = manager.findContentTypeFor(file.getName()); if (contentType == null) { return false; } IContentType text = manager.getContentType("org.eclipse.core.runtime.text"); //$NON-NLS-1$ return contentType.isKindOf(text); }
/** * Determines if a given content type is associated with the filename. * * @param filename * @param types * @return */ private boolean hasType(String filename, Set<IContentType> types) { if (types == null || types.isEmpty()) { return false; } for (IContentType type : types) { if (type == null) { continue; } if (type.isAssociatedWith(filename)) { return true; } } return false; }
public String getContentType() { try { IContentType contentType = ((TextFileDocumentProvider) getDocumentProvider()) .getContentType(getEditorInput()); if (contentType != null) { return contentType.getId(); } } catch (Exception e) { IdeLog.logError(CommonEditorPlugin.getDefault(), e); } return null; }
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; }
@Override public IReconciler getReconciler(ISourceViewer sourceViewer) { if (!EditorsUI.getPreferenceStore().getBoolean(SpellingService.PREFERENCE_SPELLING_ENABLED)) return null; IReconcilingStrategy strategy= new SpellingReconcileStrategy(sourceViewer, EditorsUI.getSpellingService()) { @Override protected IContentType getContentType() { return PROPERTIES_CONTENT_TYPE; } }; MonoReconciler reconciler= new MonoReconciler(strategy, false); reconciler.setDelay(500); return reconciler; }
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$ }
@Override public IReconciler getReconciler(ISourceViewer sourceViewer) { if (!EditorsUI.getPreferenceStore().getBoolean(SpellingService.PREFERENCE_SPELLING_ENABLED)) return null; IReconcilingStrategy strategy = new SpellingReconcileStrategy(sourceViewer, EditorsUI.getSpellingService()) { @Override protected IContentType getContentType() { return EditorConfigTextTools.EDITORCONFIG_CONTENT_TYPE; } }; MonoReconciler reconciler = new MonoReconciler(strategy, false); reconciler.setDelay(500); return reconciler; }
/** * Scans the project and returns the MyBatis config file if found.<br> * If there are multiple files in the project, only the first one is returned. * * @param project * @return MyBatis config file or <code>null</code> if none found. */ private Map<IFile, IContentType> search(IJavaProject project) { final Map<IFile, IContentType> configFiles = new ConcurrentHashMap<IFile, IContentType>(); try { project.getResource().accept(new ConfigVisitor(configFiles), IContainer.NONE); for (IPackageFragmentRoot root : project.getPackageFragmentRoots()) { if (root.getKind() != IPackageFragmentRoot.K_SOURCE) continue; root.getResource().accept(new ConfigVisitor(configFiles), IContainer.NONE); } } catch (CoreException e) { Activator.log(Status.ERROR, "Searching MyBatis Config xml failed.", e); } return configFiles; }
@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; }
/** * Gets list of content types this validator is interested in * * @return All HTML-related content types */ private IContentType[] getOtherSupportedContentTypes() { if (fOtherSupportedContentTypes == null) { List contentTypes = new ArrayList(3); if (fAdditionalContentTypesIDs != null) { for (int i = 0; i < fAdditionalContentTypesIDs.length; i++) { IContentType type = Platform.getContentTypeManager() .getContentType(fAdditionalContentTypesIDs[i]); if (type != null) { contentTypes.add(type); } } } fOtherSupportedContentTypes = (IContentType[]) contentTypes .toArray(new IContentType[contentTypes.size()]); } return fOtherSupportedContentTypes; }
/** * {@inheritDoc} * * @see EditorPart#init(IEditorSite, IEditorInput) */ @Override public void init(final IEditorSite site, final IEditorInput input) throws PartInitException { final IContentType contentType = Platform.getContentTypeManager().getContentType(DozerConfigContentTypeDescriber.ID); if (!contentType.isAssociatedWith(input.getName())) throw new PartInitException("The Fuse Transformation editor can only be opened with a" + " Dozer configuration file."); setSite(site); setInput(input); setPartName(input.getName()); configFile = ((FileEditorInput) getEditorInput()).getFile(); final IJavaProject javaProject = JavaCore.create(configFile.getProject()); try { loader = (URLClassLoader) JavaUtil.getProjectClassLoader(javaProject, getClass().getClassLoader()); config = DozerMapperConfiguration.loadConfig(new File(configFile.getLocationURI()), loader); } catch (final Exception e) { throw new PartInitException("Unable to load transformation configuration file", e); } }
private boolean isEnable( ) { IEditorPart editor = UIUtil.getActiveEditor( true ); if ( editor != null ) { IContentType[] contentTypes = Platform.getContentTypeManager( ) .findContentTypesFor( editor.getEditorInput( ).getName( ) ); for ( IContentType type : contentTypes ) { if ( type.getId( ) .equals( "org.eclipse.birt.report.designer.ui.editors.reportdesign" ) //$NON-NLS-1$ || type.getId( ) .equals( "org.eclipse.birt.report.designer.ui.editors.reporttemplate" ) ) //$NON-NLS-1$ return true; } } return false; }
/** * Verifies if fileName is valid name for content type. Takes base content * type into consideration. * * @param fileName * @return true if extension is valid for this content type */ private boolean extensionValidForContentType(String fileName) { boolean valid = false; IContentType type = getContentType(); // there is currently an extension if (fileName.lastIndexOf('.') != -1) { // check what content types are associated with current extension IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName); int i = 0; while (i < types.length && !valid) { valid = types[i].isKindOf(type); ++i; } } else valid = true; // no extension so valid return valid; }
private void setupContentTypes(final TreeItem parent, final IContentType baseType) { final IContentTypeManager manager = Platform.getContentTypeManager(); final IContentType[] contentTypes = manager.getAllContentTypes(); for (final IContentType type : contentTypes) { if (equals(type.getBaseType(), baseType) && type.isKindOf(textType)) { TreeItem item = null; if (parent == null) { item = new TreeItem(contentTypesTree, SWT.NONE); } else { item = new TreeItem(parent, SWT.NONE); } item.setText(type.getName()); item.setData(type.getId()); setupContentTypes(item, type); } } }
/** * Get list of valid extensions for XML Content type * * @return List */ List<String> getValidExtensions() { if (fValidExtensions == null) { IContentType type = Platform.getContentTypeManager() .getContentType(ContentTypeID_XML); fValidExtensions = new ArrayList<String>(Arrays.asList(type .getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); } return fValidExtensions; }
private IGrammar findGrammar(ContentTypeInfo info) { IGrammar grammar; IContentType[] contentTypes = info.getContentTypes(); // Discover the well grammar from the contentTypes grammar = TMEclipseRegistryPlugin.getGrammarRegistryManager().getGrammarFor(contentTypes); if (grammar == null) { // Discover the well grammar from the filetype String fileName = info.getFileName(); if (fileName != null) { String fileType = new Path(fileName).getFileExtension(); grammar = TMEclipseRegistryPlugin.getGrammarRegistryManager().getGrammarForFileType(fileType); } } return grammar; }
@Override public String getColumnText(Object element, int columnIndex) { String contentTypeId = (String) element; switch (columnIndex) { case 0: IContentType contentType = Platform.getContentTypeManager().getContentType(contentTypeId); if (contentType == null) { return contentTypeId; } return contentType.getName() + " (" + contentType.getId() + ")"; default: return ""; //$NON-NLS-1$ } }
private IContentType[] findContentTypes(IDocument document) { if (this.document != null && this.document.equals(document)) { return contentTypes; } try { ContentTypeInfo info = ContentTypeHelper.findContentTypes(document); this.contentTypes = info.getContentTypes(); this.document = document; } catch (CoreException e) { e.printStackTrace(); } return contentTypes; }
/** * Returns the {@link ScriptKindName} from the given file object and null * otherwise. * * @param fileObject * @return the {@link ScriptKindName} from the given file object and null * otherwise. */ public ScriptKindName getScriptKind(Object fileObject) { String ext = getExtension(fileObject); if (ext != null) { ext = ext.toLowerCase(); if (FileUtils.TS_EXTENSION.equals(ext)) { return ScriptKindName.TS; } else if (FileUtils.TSX_EXTENSION.equals(ext)) { return ScriptKindName.TSX; } else if (FileUtils.JSX_EXTENSION.equals(ext)) { return ScriptKindName.JSX; } else if (FileUtils.JS_EXTENSION.equals(ext)) { return useJsAsJsx ? ScriptKindName.JSX : ScriptKindName.JS; } } if (fileObject instanceof IFile) { try { IContentType contentType = ((IFile) fileObject).getContentDescription().getContentType(); if (contentType != null) { String contentTypeId = contentType.getId(); if (TS_CONTENT_TYPE_ID.equals(contentTypeId)) { return ScriptKindName.TS; } else if (TSX_CONTENT_TYPE_ID.equals(contentTypeId)) { return ScriptKindName.TSX; } else if (JSX_CONTENT_TYPE_ID.equals(contentTypeId)) { return ScriptKindName.JSX; } else if (JS_CONTENT_TYPE_ID.equals(contentTypeId)) { return useJsAsJsx ? ScriptKindName.JSX : ScriptKindName.JS; } } } catch (Exception e) { return null; } } return null; }
@Test public void getContentType() { final IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); final IContentType contentType = contentTypeManager.getContentType("org.eclipse.emf.ecore.xmi"); final IFileType expected = MappingUtils.getFileTypeRegistry().getFileType(contentType.getId()); assertEquals(expected, delegate.getFileType()); }
@Test public void getContentType() { final IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); final IContentType contentType = contentTypeManager.getContentType(IContentTypeManager.CT_TEXT); final IFileType expected = MappingUtils.getFileTypeRegistry().getFileType(contentType.getId()); assertEquals(expected, delegate.getFileType()); }
/** * {@inheritDoc} * * @see org.eclipse.mylyn.docs.intent.mapping.content.IFileTypeRegistry#isKindOf(java.lang.String, * java.lang.String) */ public boolean isKindOf(String typeID, String superTypeID) { final boolean res; if (registry.isKindOf(typeID, superTypeID)) { res = true; } else { final IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); final IContentType contentType = contentTypeManager.getContentType(typeID); final IContentType superContentType = contentTypeManager.getContentType(superTypeID); res = contentType != null && contentType.isKindOf(superContentType); } return res; }
@Override public IEditorDescriptor overrideDefaultEditor(IEditorInput editorInput, IContentType contentType, IEditorDescriptor editorDescriptor) { // Override with default text editor only if no association is found yet if (editorDescriptor == null && editorInput != null && editorInput instanceof IURIEditorInput && isOverrideEnabled() && TextFileDetector.isTextFile((IURIEditorInput) editorInput)) { return getTextEditorDescriptor(); } return editorDescriptor; }
@Override public IEditorDescriptor overrideDefaultEditor(String fileName, IContentType contentType, IEditorDescriptor editorDescriptor) { // Override with default text editor only if no association is found yet if (editorDescriptor == null && fileName != null && isOverrideEnabled() && TextFileDetector.isTextFile(fileName)) { return getTextEditorDescriptor(); } return editorDescriptor; }
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; }