1 2 23 package org.enhydra.tool.codegen; 24 import java.io.File ; 26 import java.util.StringTokenizer ; 27 28 33 public class ValidationUtil { 34 35 38 private ValidationUtil() {} 39 40 49 public static boolean isJavaPackage(String pack) { 50 final String DOT = (new String ()) + '.'; 51 52 boolean valid = true; 53 StringTokenizer tokenizer = null; 54 55 if (pack.trim().length() == 0) { 56 valid = false; 57 } else if (pack.trim().startsWith(DOT) 58 || pack.trim().endsWith(DOT)) { 59 valid = false; 60 } else { 61 tokenizer = new StringTokenizer (pack, DOT); 62 while (tokenizer.hasMoreTokens()) { 63 if (!ValidationUtil.isJavaIdentifier(tokenizer.nextToken())) { 64 valid = false; 65 break; 66 } 67 } 68 } 69 return valid; 70 } 71 72 81 public static boolean isJavaIdentifier(String ident) { 82 boolean valid = true; 83 84 if (ident == null || ident.trim().length() == 0) { 85 valid = false; 86 } else { 87 for (int i = 0; i < ident.length(); i++) { 88 char ch = ident.charAt(i); 89 90 if (i == 0) { 91 if (!Character.isJavaIdentifierStart(ch)) { 92 valid = false; 93 break; 94 } 95 } else if (!Character.isJavaIdentifierPart(ch)) { 96 valid = false; 97 break; 98 } 99 } 100 } 101 return valid; 102 } 103 104 113 public static boolean isDirectory(String path) { 114 boolean valid = false; 115 File file = new File (path); 116 117 if (file != null) { 118 valid = file.isDirectory(); 119 } 120 return valid; 121 } 122 123 132 public static boolean isParentDirectory(String path) { 133 boolean valid = false; 134 File file = new File (path); 135 136 if (file != null && file.getParentFile() != null) { 137 valid = file.getParentFile().isDirectory(); 138 } 139 return valid; 140 } 141 142 } 143 | Popular Tags |