1 22 package org.enhydra.kelp.common; 23 import java.io.File ; 24 import java.util.StringTokenizer ; 25 public class ValidationUtil { 27 28 31 private ValidationUtil() {} 32 33 42 public static boolean isJavaPackage(String pack) { 43 boolean valid = true; 44 StringTokenizer tokenizer = null; 45 46 if (pack == null) { 47 pack = new String (); 48 } 49 pack = pack.trim(); 50 if (pack.length() == 0) { 51 valid = false; 52 } else if (pack.charAt(0) == '.') { 53 valid = false; 54 } else if (pack.charAt(pack.length() - 1) == '.') { 55 valid = false; 56 } else { 57 final String DELIM = "."; tokenizer = new StringTokenizer (pack, DELIM); 60 while (tokenizer.hasMoreTokens()) { 61 if (!ValidationUtil.isJavaIdentifier(tokenizer.nextToken())) { 62 valid = false; 63 break; 64 } 65 } 66 } 67 return valid; 68 } 69 70 79 public static boolean isJavaIdentifier(String ident) { 80 boolean valid = true; 81 82 for (int i = 0; i < ident.length(); i++) { 83 char ch = ident.charAt(i); 84 85 if (i == 0) { 86 if (!Character.isJavaIdentifierStart(ch)) { 87 valid = false; 88 break; 89 } 90 } else if (!Character.isJavaIdentifierPart(ch)) { 91 valid = false; 92 break; 93 } 94 } 95 return valid; 96 } 97 98 107 public static boolean isDirectory(String path) { 108 File file = new File (path); 109 110 return ValidationUtil.isDirectory(file); 111 } 112 113 public static boolean isDirectory(File file) { 114 boolean valid = false; 115 116 if (file != null) { 117 valid = file.isDirectory(); 118 } 119 return valid; 120 } 121 122 131 public static boolean isParentDirectory(String path) { 132 boolean valid = false; 133 File file = new File (path); 134 135 if (file != null && file.getParentFile() != null) { 136 valid = file.getParentFile().isDirectory(); 137 } 138 return valid; 139 } 140 141 } 142 | Popular Tags |