use of org.eclipse.core.runtime.content.IContentDescription in project webtools.sourceediting by eclipse.
the class FormatActionDelegate method format.
protected void format(IProgressMonitor monitor, IFile file) {
if (monitor == null || monitor.isCanceled())
return;
try {
monitor.beginTask("", 100);
IContentDescription contentDescription = file.getContentDescription();
monitor.worked(5);
if (contentDescription != null) {
IContentType contentType = contentDescription.getContentType();
IStructuredFormatProcessor formatProcessor = getFormatProcessor(contentType.getId());
if (formatProcessor != null && (monitor == null || !monitor.isCanceled())) {
String message = NLS.bind(SSEUIMessages.FormatActionDelegate_3, new String[] { file.getFullPath().toString().substring(1) });
monitor.subTask(message);
formatProcessor.setProgressMonitor(monitor);
formatProcessor.formatFile(file);
}
}
monitor.worked(95);
monitor.done();
} catch (MalformedInputExceptionWithDetail e) {
String message = NLS.bind(SSEUIMessages.FormatActionDelegate_5, new String[] { file.getFullPath().toString() });
fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e));
} catch (IOException e) {
String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[] { file.getFullPath().toString() });
fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e));
} catch (CoreException e) {
String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[] { file.getFullPath().toString() });
fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e));
}
}
use of org.eclipse.core.runtime.content.IContentDescription in project webtools.sourceediting by eclipse.
the class TestCodedReader method doCoreTest.
protected Reader doCoreTest(String expectedJavaCharset, String expectedDetectedCharset, IFile file) throws CoreException, IOException {
Reader reader;
// create these first, to test exception being thrown correctly
CodedReaderCreator codedReaderCreator = new CodedReaderCreator();
codedReaderCreator.set(file);
reader = codedReaderCreator.getCodedReader();
String javaCharsetName = file.getCharset();
IContentDescription description = file.getContentDescription();
javaCharsetName = massageCharset(javaCharsetName);
// codedReaderCreator.getEncodingMemento().getJavaCharsetName();
if (expectedJavaCharset.equals("expectPlatformCharset")) {
String platformDefault = NonContentBasedEncodingRules.useDefaultNameRules(null);
assertTrue(javaCharsetName.equals(platformDefault));
} else {
boolean asExpected = javaCharsetName.equals(expectedJavaCharset);
assertTrue(javaCharsetName + " did not equal the expected " + expectedJavaCharset + " (this is a VM dependent test)", asExpected);
}
String javaCharsetNameProperty = (String) description.getProperty(IContentDescription.CHARSET);
String detectedCharsetNameProperty = getDetectedCharsetName(description);
detectedCharsetNameProperty = massageCharset(detectedCharsetNameProperty);
// }
if (!expectedJavaCharset.equals("expectPlatformCharset")) {
boolean expecedResult = expectedJavaCharset.equals(javaCharsetNameProperty);
assertTrue("java based charset name was not as expected", expecedResult);
} else {
String expectedDefault = NonContentBasedEncodingRules.useDefaultNameRules(null);
boolean ExpectedResult = expectedDefault.equals(javaCharsetNameProperty);
assertTrue("java based charset name not as expected when platform default expected", ExpectedResult);
}
if (expectedDetectedCharset != null) {
boolean expectedResult = expectedDetectedCharset.equals(detectedCharsetNameProperty);
assertTrue("detected charset name was not as expected", expectedResult);
}
// test if can read/write file
StringBuffer buffer = readInputStream(reader);
if (DEBUG_TEST_DETAIL) {
System.out.print(buffer);
}
return reader;
}
use of org.eclipse.core.runtime.content.IContentDescription in project webtools.sourceediting by eclipse.
the class TestContentTypeDetection method doGetContentTypeBasedOnFile.
protected IContentDescription doGetContentTypeBasedOnFile(IFile file) throws CoreException {
IContentDescription fileContentDescription = file.getContentDescription();
assertNotNull("file content description was null", fileContentDescription);
return fileContentDescription;
}
use of org.eclipse.core.runtime.content.IContentDescription in project webtools.sourceediting by eclipse.
the class TestContentTypeDetection method doGetContentTypeBasedOnStream.
protected IContentDescription doGetContentTypeBasedOnStream(IFile file) throws CoreException, IOException {
IContentDescription streamContentDescription = null;
InputStream inputStream = null;
try {
inputStream = file.getContents();
streamContentDescription = Platform.getContentTypeManager().getDescriptionFor(inputStream, file.getName(), IContentDescription.ALL);
} finally {
if (inputStream != null) {
inputStream.close();
}
}
assertNotNull("content description was null", streamContentDescription);
return streamContentDescription;
}
use of org.eclipse.core.runtime.content.IContentDescription in project webtools.sourceediting by eclipse.
the class TestSourceValidationFramework method detectContentTypes.
private IContentType[] detectContentTypes(String fileName) {
IContentType[] types = null;
IFile file = ensureFileIsAccessible(PROJECT_NAME + SEPARATOR + fileName, null);
types = Platform.getContentTypeManager().findContentTypesFor(file.getName());
if (types.length == 0) {
IContentDescription d = null;
try {
// optimized description lookup, might not succeed
d = file.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(file.getName());
}
return types;
}
Aggregations