Search in sources :

Example 21 with IContentTypeManager

use of org.eclipse.core.runtime.content.IContentTypeManager in project webtools.sourceediting by eclipse.

the class FormatProcessorsExtensionReader method getFormatProcessor.

public IStructuredFormatProcessor getFormatProcessor(String contentTypeId) {
    if (contentTypeId == null)
        return null;
    IStructuredFormatProcessor formatProcessor = null;
    if (map.containsKey(contentTypeId)) {
        formatProcessor = (IStructuredFormatProcessor) map.get(contentTypeId);
    } else {
        IContentTypeManager manager = Platform.getContentTypeManager();
        IContentType queryContentType = manager.getContentType(contentTypeId);
        boolean found = false;
        for (Iterator iter = map.keySet().iterator(); iter.hasNext(); ) {
            String elementContentTypeId = (String) iter.next();
            IContentType elementContentType = manager.getContentType(elementContentTypeId);
            if (queryContentType.isKindOf(elementContentType)) {
                formatProcessor = (IStructuredFormatProcessor) map.get(elementContentTypeId);
                map.put(contentTypeId, formatProcessor);
                found = true;
                break;
            }
        }
        if (!found)
            map.put(contentTypeId, null);
    }
    return formatProcessor;
}
Also used : IStructuredFormatProcessor(org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor) IContentTypeManager(org.eclipse.core.runtime.content.IContentTypeManager) Iterator(java.util.Iterator) IContentType(org.eclipse.core.runtime.content.IContentType)

Example 22 with IContentTypeManager

use of org.eclipse.core.runtime.content.IContentTypeManager in project webtools.sourceediting by eclipse.

the class TestContentTypes method testCreation.

public void testCreation() {
    IContentTypeManager registry = Platform.getContentTypeManager();
    assertTrue("content type identifer registry must exist", registry != null);
    IContentType[] allTypes = registry.getAllContentTypes();
    for (int i = 0; i < allTypes.length; i++) {
        IContentType contentType = allTypes[i];
        IContentType parentType = contentType.getBaseType();
        if (DEBUG) {
            System.out.print(contentType);
            if (parentType != null) {
                System.out.println(" (extends " + parentType + ")");
            } else {
                System.out.println();
            }
            System.out.println("   " + contentType.getName());
        }
        String[] filespecs = contentType.getFileSpecs(IContentType.FILE_EXTENSION_SPEC | IContentType.FILE_NAME_SPEC);
        if (DEBUG) {
            for (int j = 0; j < filespecs.length; j++) {
                String filespec = filespecs[j];
                System.out.println("        " + filespec);
            }
        }
    }
}
Also used : IContentTypeManager(org.eclipse.core.runtime.content.IContentTypeManager) IContentType(org.eclipse.core.runtime.content.IContentType)

Example 23 with IContentTypeManager

use of org.eclipse.core.runtime.content.IContentTypeManager in project webtools.sourceediting by eclipse.

the class WorkspaceTaskScanner method init.

private boolean init(IResource resource) {
    IProject project = getProject(resource);
    IPreferencesService preferencesService = Platform.getPreferencesService();
    IScopeContext[] lookupOrder = new IScopeContext[] { new ProjectScope(project), new InstanceScope(), new DefaultScope() };
    boolean proceed = preferencesService.getBoolean(TaskTagPreferenceKeys.TASK_TAG_NODE, TaskTagPreferenceKeys.TASK_TAG_ENABLE, false, lookupOrder);
    if (Logger.DEBUG_TASKSPREFS) {
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.println(getClass().getName() + " scan of " + resource.getFullPath() + ":" + proceed);
    }
    if (proceed) {
        String[] tags = StringUtils.unpack(preferencesService.getString(TaskTagPreferenceKeys.TASK_TAG_NODE, TaskTagPreferenceKeys.TASK_TAG_TAGS, null, lookupOrder));
        String[] priorities = StringUtils.unpack(preferencesService.getString(TaskTagPreferenceKeys.TASK_TAG_NODE, TaskTagPreferenceKeys.TASK_TAG_PRIORITIES, null, lookupOrder));
        String[] currentIgnoreContentTypeIDs = StringUtils.unpack(preferencesService.getString(TaskTagPreferenceKeys.TASK_TAG_NODE, TaskTagPreferenceKeys.TASK_TAG_CONTENTTYPES_IGNORED, null, lookupOrder));
        if (Logger.DEBUG_TASKSPREFS) {
            // $NON-NLS-1$
            System.out.print(getClass().getName() + " tags: ");
            for (int i = 0; i < tags.length; i++) {
                if (i > 0) {
                    // $NON-NLS-1$
                    System.out.print(",");
                }
                System.out.print(tags[i]);
            }
            System.out.println();
            // $NON-NLS-1$
            System.out.print(getClass().getName() + " priorities: ");
            for (int i = 0; i < priorities.length; i++) {
                if (i > 0) {
                    // $NON-NLS-1$
                    System.out.print(",");
                }
                System.out.print(priorities[i]);
            }
            System.out.println();
            // $NON-NLS-1$
            System.out.print(getClass().getName() + " ignored content types: ");
            for (int i = 0; i < currentIgnoreContentTypeIDs.length; i++) {
                if (i > 0) {
                    // $NON-NLS-1$
                    System.out.print(",");
                }
                System.out.print(currentIgnoreContentTypeIDs[i]);
            }
            System.out.println();
        }
        fCurrentIgnoreContentTypes = new IContentType[currentIgnoreContentTypeIDs.length];
        IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
        for (int i = 0; i < currentIgnoreContentTypeIDs.length; i++) {
            fCurrentIgnoreContentTypes[i] = contentTypeManager.getContentType(currentIgnoreContentTypeIDs[i]);
        }
        int max = Math.min(tags.length, priorities.length);
        fCurrentTaskTags = new TaskTag[max];
        for (int i = 0; i < max; i++) {
            int priority = TaskTag.PRIORITY_NORMAL;
            try {
                priority = Integer.parseInt(priorities[i]);
            } catch (NumberFormatException e) {
            // default to normal priority
            }
            fCurrentTaskTags[i] = new TaskTag(tags[i], priority);
        }
    }
    return proceed;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) TaskTag(org.eclipse.wst.sse.core.internal.provisional.tasks.TaskTag) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) IProject(org.eclipse.core.resources.IProject) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) IContentTypeManager(org.eclipse.core.runtime.content.IContentTypeManager)

Example 24 with IContentTypeManager

use of org.eclipse.core.runtime.content.IContentTypeManager in project webtools.sourceediting by eclipse.

the class CodedStreamCreator method checkForEncodingInContents.

private EncodingMemento checkForEncodingInContents() throws CoreException, IOException {
    EncodingMemento result = null;
    // if encoding memento already set, and no need to get again.
    if (fEncodingMemento != null) {
        result = fEncodingMemento;
    } else {
        if (fClientSuppliedReader) {
            fReader.reset();
            IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
            try {
                IContentDescription contentDescription = contentTypeManager.getDescriptionFor(fReader, fFilename, IContentDescription.ALL);
                if (contentDescription != null) {
                    fEncodingMemento = createMemento(contentDescription);
                } else {
                    // $NON-NLS-1$
                    fEncodingMemento = CodedIO.createEncodingMemento("UTF-8");
                }
            } catch (NullPointerException e) {
                // TODO: work around for 5/14 bug in base, should be
                // removed when move up to 5/21
                // just created a simple default one
                // $NON-NLS-1$
                fEncodingMemento = CodedIO.createEncodingMemento("UTF-8");
            }
            result = fEncodingMemento;
        } else {
            // $NON-NLS-1$
            throw new IllegalStateException("unexpected state: encodingMemento was null but no input stream supplied");
        }
    }
    // }
    return result;
}
Also used : IContentTypeManager(org.eclipse.core.runtime.content.IContentTypeManager) IContentDescription(org.eclipse.core.runtime.content.IContentDescription)

Example 25 with IContentTypeManager

use of org.eclipse.core.runtime.content.IContentTypeManager in project webtools.sourceediting by eclipse.

the class TestContentTypeHandlers method testCSSExists.

public void testCSSExists() {
    String id = ContentTypeIdForCSS.ContentTypeID_CSS;
    IContentTypeManager registry = getContentTypeRegistry();
    IContentType identifier = registry.getContentType(id);
    assertTrue("content type identifier " + id + " does not have CSS type ", identifier != null);
}
Also used : IContentTypeManager(org.eclipse.core.runtime.content.IContentTypeManager) IContentType(org.eclipse.core.runtime.content.IContentType)

Aggregations

IContentTypeManager (org.eclipse.core.runtime.content.IContentTypeManager)33 IContentType (org.eclipse.core.runtime.content.IContentType)27 IContentDescription (org.eclipse.core.runtime.content.IContentDescription)8 CoreException (org.eclipse.core.runtime.CoreException)5 InputStream (java.io.InputStream)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)3 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 BufferedInputStream (java.io.BufferedInputStream)1 Iterator (java.util.Iterator)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IFileInfo (org.eclipse.core.filesystem.IFileInfo)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 ProjectScope (org.eclipse.core.resources.ProjectScope)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1