1 11 12 package org.eclipse.core.internal.propertytester; 13 14 import org.eclipse.core.internal.utils.Policy; 15 import org.eclipse.core.resources.IFile; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.core.runtime.content.IContentDescription; 19 import org.eclipse.core.runtime.content.IContentType; 20 21 26 public class FilePropertyTester extends ResourcePropertyTester { 27 28 33 private static final String CONTENT_TYPE_ID = "contentTypeId"; 35 41 public boolean test(Object receiver, String method, Object [] args, Object expectedValue) { 42 if ((receiver instanceof IFile) && method.equals(CONTENT_TYPE_ID)) 43 return testContentType((IFile) receiver, toString(expectedValue)); 44 return false; 45 } 46 47 62 private boolean testContentType(final IFile file, String contentTypeId) { 63 final String expectedValue = contentTypeId.trim(); 64 65 String actualValue = null; 66 try { 67 IContentDescription contentDescription = file.getContentDescription(); 68 if (contentDescription != null) { 69 IContentType contentType = contentDescription.getContentType(); 70 actualValue = contentType.getId(); 71 } 72 } catch (CoreException e) { 73 Policy.log(IStatus.ERROR, "Core exception while retrieving the content description", e); } 75 return expectedValue.equals(actualValue); 76 } 77 78 } 79 | Popular Tags |