1 11 package org.eclipse.core.internal.filebuffers; 12 13 import java.util.HashSet ; 14 import java.util.List ; 15 import java.util.Set ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IPath; 19 import org.eclipse.core.runtime.content.IContentDescription; 20 import org.eclipse.core.runtime.content.IContentType; 21 22 import org.eclipse.core.resources.IFile; 23 24 import org.eclipse.core.filebuffers.FileBuffers; 25 import org.eclipse.core.filebuffers.IAnnotationModelFactory; 26 import org.eclipse.core.filebuffers.IDocumentFactory; 27 import org.eclipse.core.filebuffers.IDocumentSetupParticipant; 28 import org.eclipse.core.filebuffers.LocationKind; 29 30 31 37 public class ResourceExtensionRegistry extends ExtensionsRegistry { 38 39 46 protected IContentType[] findContentTypes(IPath location, LocationKind locationKind) { 47 if (locationKind != LocationKind.LOCATION) { 48 IFile file= FileBuffers.getWorkspaceFileAtLocation(location); 49 if (file != null) 50 return findContentTypes(file); 51 } 52 return fContentTypeManager.findContentTypesFor(location.lastSegment()); 53 } 54 55 61 IDocumentFactory getDocumentFactory(IFile file) { 62 IDocumentFactory factory= getDocumentFactory(findContentTypes(file)); 63 if (factory == null) { 64 factory= getDocumentFactory(file.getFullPath().lastSegment()); 65 } 66 if (factory == null) 67 factory= getDocumentFactory(file.getFileExtension()); 68 if (factory == null) 69 factory= getDocumentFactory(WILDCARD); 70 return factory; 71 } 72 73 79 IAnnotationModelFactory getAnnotationModelFactory(IFile file) { 80 IAnnotationModelFactory factory= getAnnotationModelFactory(findContentTypes(file)); 81 if (factory == null) 82 factory= getAnnotationModelFactory(file.getFullPath().lastSegment()); 83 if (factory == null) 84 factory= getAnnotationModelFactory(file.getFileExtension()); 85 if (factory == null) 86 factory= getAnnotationModelFactory(WILDCARD); 87 return factory; 88 } 89 90 96 private IContentType[] findContentTypes(IFile file) { 97 try { 98 IContentDescription contentDescription= file.getContentDescription(); 99 if (contentDescription != null) { 100 IContentType contentType= contentDescription.getContentType(); 101 if (contentType != null) 102 return new IContentType[] {contentType}; 103 } 104 } catch (CoreException x) { 105 } 107 return fContentTypeManager.findContentTypesFor(file.getFullPath().lastSegment()); 108 } 109 110 116 IDocumentSetupParticipant[] getDocumentSetupParticipants(IFile file) { 117 Set participants= new HashSet (); 118 119 List p= getDocumentSetupParticipants(findContentTypes(file)); 120 if (p != null) 121 participants.addAll(p); 122 123 p= getDocumentSetupParticipants(file.getFullPath().lastSegment()); 124 if (p != null) 125 participants.addAll(p); 126 127 p= getDocumentSetupParticipants(file.getFileExtension()); 128 if (p != null) 129 participants.addAll(p); 130 131 p= getDocumentSetupParticipants(WILDCARD); 132 if (p != null) 133 participants.addAll(p); 134 135 IDocumentSetupParticipant[] result= new IDocumentSetupParticipant[participants.size()]; 136 participants.toArray(result); 137 return result; 138 } 139 140 } 141 | Popular Tags |