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;
}
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);
}
}
}
}
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;
}
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;
}
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);
}
Aggregations