1 11 package org.eclipse.core.filebuffers; 12 13 14 import java.io.File ; 15 import java.net.URI ; 16 17 import org.eclipse.core.filesystem.EFS; 18 import org.eclipse.core.filesystem.IFileStore; 19 import org.eclipse.core.internal.filebuffers.FileBuffersPlugin; 20 21 import org.eclipse.core.runtime.CoreException; 22 import org.eclipse.core.runtime.IPath; 23 24 import org.eclipse.core.resources.IFile; 25 import org.eclipse.core.resources.IWorkspaceRoot; 26 import org.eclipse.core.resources.ResourcesPlugin; 27 28 29 41 public final class FileBuffers { 42 43 47 private static final IWorkspaceRoot WORKSPACE_ROOT= ResourcesPlugin.getWorkspace().getRoot(); 48 49 52 private FileBuffers() { 53 } 54 55 61 public final static String PLUGIN_ID= FileBuffersPlugin.PLUGIN_ID; 62 63 76 public static ITextFileBufferManager getTextFileBufferManager() { 77 FileBuffersPlugin plugin= FileBuffersPlugin.getDefault(); 78 return plugin != null ? plugin.getFileBufferManager() : null; 79 } 80 81 88 public static IFile getWorkspaceFileAtLocation(IPath location) { 89 return getWorkspaceFileAtLocation(location, false); 90 } 91 92 101 public static IFile getWorkspaceFileAtLocation(IPath location, boolean isNormalized) { 102 IPath normalized; 103 if (isNormalized) 104 normalized= location; 105 else 106 normalized= normalizeLocation(location); 107 108 if (normalized.segmentCount() >= 2) { 109 IFile file= WORKSPACE_ROOT.getFile(normalized); 111 if (file != null && file.exists()) 112 return file; 113 } 114 return null; 115 } 116 117 140 public static IPath normalizeLocation(IPath pathOrLocation) { 141 if (WORKSPACE_ROOT.exists(pathOrLocation)) 143 return pathOrLocation.makeAbsolute(); 144 145 IFile file= WORKSPACE_ROOT.getFileForLocation(pathOrLocation); 146 if (file != null && file.exists()) 149 return file.getFullPath(); 150 151 return pathOrLocation.makeAbsolute(); 153 } 154 155 166 public static IFileStore getFileStoreAtLocation(IPath location) { 167 if (location == null) 168 return null; 169 170 IFile file= getWorkspaceFileAtLocation(location); 171 try { 172 if (file != null) { 173 URI uri= file.getLocationURI(); 174 if (uri == null) 175 return null; 176 return EFS.getStore(uri); 177 } 178 } catch (CoreException e) { 179 } 181 return EFS.getLocalFileSystem().getStore(location); 182 } 183 184 195 public static File getSystemFileAtLocation(IPath location) { 196 IFileStore store= getFileStoreAtLocation(location); 197 if (store != null) { 198 try { 199 return store.toLocalFile(EFS.NONE, null); 200 } catch (CoreException e) { 201 return null; 202 } 203 } 204 return null; 205 } 206 } 207 | Popular Tags |