1 11 package org.eclipse.core.internal.resources; 12 13 import java.util.Arrays ; 14 import org.eclipse.core.runtime.Platform; 15 16 20 public abstract class OS { 21 private static final String INSTALLED_PLATFORM; 22 23 public static final char[] INVALID_RESOURCE_CHARACTERS; 24 public static final String [] INVALID_RESOURCE_NAMES; 25 26 static { 27 INSTALLED_PLATFORM = Platform.getOS(); 30 if (INSTALLED_PLATFORM.equals(Platform.OS_WIN32)) { 31 INVALID_RESOURCE_CHARACTERS = new char[] {'\\', '/', ':', '*', '?', '"', '<', '>', '|'}; 33 INVALID_RESOURCE_NAMES = new String [] {"aux", "clock$", "com1", "com2", "com3", "com4", "com5", "com6", "com7", "com8", "com9", "con", "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9", "nul", "prn"}; Arrays.sort(INVALID_RESOURCE_NAMES); 37 } else { 38 INVALID_RESOURCE_CHARACTERS = new char[] {'/', '\0',}; 41 INVALID_RESOURCE_NAMES = new String [] {}; 42 } 43 } 44 45 49 public static boolean isNameValid(String name) { 50 if (name.equals(".") || name.equals("..")) return false; 53 if (INSTALLED_PLATFORM.equals(Platform.OS_WIN32)) { 54 final int length = name.length(); 56 if (length == 0) 57 return false; 58 final char lastChar = name.charAt(length-1); 59 if (lastChar == '.') 61 return false; 62 if (Character.isWhitespace(lastChar)) 64 return false; 65 int dot = name.indexOf('.'); 66 name = dot == -1 ? name : name.substring(0, dot); 68 } 69 return Arrays.binarySearch(INVALID_RESOURCE_NAMES, name.toLowerCase()) < 0; 70 } 71 } 72 | Popular Tags |