use of org.eclipse.core.runtime.content.IContentDescription in project webtools.sourceediting by eclipse.
the class TestContentTypeDetectionForJSP method doTest.
protected void doTest(String expectedContentType, String filePath, Class expectedException, String expectedJSPContentType) throws CoreException, IOException {
super.doTest(expectedContentType, filePath, expectedException);
IFile file = (IFile) getTestProject().findMember(filePath);
assertNotNull("Error in test case: file not found: " + filePath, file);
IContentDescription streamContentDescription = doGetContentTypeBasedOnStream(file);
IContentDescription fileContentDescription = doGetContentTypeBasedOnFile(file);
String streamJSPContentType = (String) streamContentDescription.getProperty(IContentDescriptionForJSP.CONTENT_TYPE_ATTRIBUTE);
checkResults(expectedJSPContentType, streamJSPContentType);
String fileJSPContentType = (String) fileContentDescription.getProperty(IContentDescriptionForJSP.CONTENT_TYPE_ATTRIBUTE);
checkResults(expectedJSPContentType, fileJSPContentType);
}
use of org.eclipse.core.runtime.content.IContentDescription in project webtools.sourceediting by eclipse.
the class DebugTextEditor method getEditorInputContentTypes.
IContentType[] getEditorInputContentTypes(IEditorInput input) {
IContentType[] types = null;
IResource resource = null;
if (input.getAdapter(IFile.class) != null) {
resource = input.getAdapter(IFile.class);
} else if (input.getAdapter(IFile.class) != null) {
resource = input.getAdapter(IResource.class);
}
if (resource.getType() == IResource.FILE && resource.isAccessible()) {
IContentDescription d = null;
try {
// optimized description lookup, might not succeed
d = ((IFile) resource).getContentDescription();
if (d != null) {
types = new IContentType[] { d.getContentType() };
}
} catch (CoreException e) {
// should not be possible given the accessible and file type
// check above
}
}
if (types == null) {
types = Platform.getContentTypeManager().findContentTypesFor(input.getName());
}
return types;
}
use of org.eclipse.core.runtime.content.IContentDescription in project webtools.sourceediting by eclipse.
the class WorkspaceFileHyperlink method getEditorLabel.
private String getEditorLabel() throws CoreException {
final IContentDescription description = fFile.getContentDescription();
final IEditorDescriptor defaultEditor = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(fFile.getName(), description != null ? description.getContentType() : null);
return defaultEditor != null ? defaultEditor.getLabel() : null;
}
use of org.eclipse.core.runtime.content.IContentDescription in project webtools.sourceediting by eclipse.
the class TestContentDescription method doTest.
protected void doTest(String expectedJavaCharset, String filePath, Class expectedException) throws CoreException, IOException {
if (expectedJavaCharset != null && expectedJavaCharset.indexOf("UTF-32") > -1) {
// won't try 32 bit right now
return;
}
expectedJavaCharset = massageCharset(expectedJavaCharset);
IFile file = (IFile) fTestProject.findMember(filePath);
assertNotNull("Error in test case: file not found: " + filePath, file);
IContentDescription fileContentDescription = file.getContentDescription();
// IContentDescription streamContentDescription = Platform.getContentTypeManager().getDescriptionFor(file.getContents(), file.getName(), IContentDescription.ALL);
// assertEquals("comparing file and stream contentDescription", fileContentDescription, streamContentDescription);
assertNotNull("Null content description", fileContentDescription);
String foundCharset = fileContentDescription.getCharset();
foundCharset = massageCharset(foundCharset);
if (expectedJavaCharset == null || expectedJavaCharset.equals("expectPlatformCharset")) {
String platformDefault = NonContentBasedEncodingRules.useDefaultNameRules(null);
assertTrue(foundCharset.equals(platformDefault));
} else {
boolean asExpected = foundCharset.equals(expectedJavaCharset);
assertTrue(foundCharset + " did not equal the expected " + expectedJavaCharset + " (this is a VM dependent test)", asExpected);
}
}
use of org.eclipse.core.runtime.content.IContentDescription in project webtools.sourceediting by eclipse.
the class TestContentTypeDetection method doTest.
protected void doTest(String expectedContentType, String filePath, Class expectedException) throws CoreException, IOException {
IFile file = (IFile) fTestProject.findMember(filePath);
assertNotNull("Error in test case: file not found: " + filePath, file);
IContentDescription streamContentDescription = doGetContentTypeBasedOnStream(file);
IContentDescription fileContentDescription = doGetContentTypeBasedOnFile(file);
IContentType fileContentType = fileContentDescription.getContentType();
assertNotNull("file content type was null", fileContentType);
IContentType streamContentType = streamContentDescription.getContentType();
assertNotNull("stream content type was null", streamContentType);
assertEquals("comparing content type based on file and stream: ", fileContentType, streamContentType);
// if equal, above, as expected, then only need to check one.
assertEquals("compareing with expected content type id", expectedContentType, fileContentType.getId());
}
Aggregations