Search in sources :

Example 21 with IContentDescription

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);
}
Also used : IFile(org.eclipse.core.resources.IFile) IContentDescription(org.eclipse.core.runtime.content.IContentDescription)

Example 22 with IContentDescription

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IContentType(org.eclipse.core.runtime.content.IContentType) IContentDescription(org.eclipse.core.runtime.content.IContentDescription) IResource(org.eclipse.core.resources.IResource)

Example 23 with IContentDescription

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;
}
Also used : IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IContentDescription(org.eclipse.core.runtime.content.IContentDescription)

Example 24 with IContentDescription

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);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IContentDescription(org.eclipse.core.runtime.content.IContentDescription)

Example 25 with IContentDescription

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());
}
Also used : IFile(org.eclipse.core.resources.IFile) IContentType(org.eclipse.core.runtime.content.IContentType) IContentDescription(org.eclipse.core.runtime.content.IContentDescription)

Aggregations

IContentDescription (org.eclipse.core.runtime.content.IContentDescription)58 CoreException (org.eclipse.core.runtime.CoreException)27 IOException (java.io.IOException)24 IContentType (org.eclipse.core.runtime.content.IContentType)22 InputStream (java.io.InputStream)19 IFile (org.eclipse.core.resources.IFile)14 QualifiedName (org.eclipse.core.runtime.QualifiedName)13 IContentTypeManager (org.eclipse.core.runtime.content.IContentTypeManager)8 Reader (java.io.Reader)6 IStatus (org.eclipse.core.runtime.IStatus)6 Status (org.eclipse.core.runtime.Status)6 BufferedReader (java.io.BufferedReader)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStreamReader (java.io.InputStreamReader)4 IStructuredFormatProcessor (org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor)4 SequenceInputStream (java.io.SequenceInputStream)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 IResource (org.eclipse.core.resources.IResource)3