285 public PathMatcher getPathMatcher(String syntaxAndInput) { 286 int pos = syntaxAndInput.indexOf(':'); 287 if (pos <= 0 || pos == syntaxAndInput.length()) 288 throw new IllegalArgumentException(); 289 String syntax = syntaxAndInput.substring(0, pos); 290 String input = syntaxAndInput.substring(pos+1); 291 292 String expr; 293 if (syntax.equals(GLOB_SYNTAX)) { 294 expr = Globs.toUnixRegexPattern(input); 295 } else { 296 if (syntax.equals(REGEX_SYNTAX)) { 297 expr = input; 298 } else { 299 throw new UnsupportedOperationException("Syntax '" + syntax + 300 "' not recognized"); 301 } 302 } 303 304 // return matcher 305 final Pattern pattern = Pattern.compile(expr); 306 return new PathMatcher() { 307 @Override 308 public boolean matches(Path path) { 309 return pattern.matcher(path.toString()).matches(); 310 } 311 }; 312 } 313 private static final String GLOB_SYNTAX = "glob"; 314 private static final String REGEX_SYNTAX = "regex"; 315 316 317 318 @Override 319 public final UserPrincipalLookupService getUserPrincipalLookupService() { 320 return LookupService.instance; 321 } 322 323 private static class LookupService { 324 static final UserPrincipalLookupService instance = 325 new UserPrincipalLookupService() { 326 @Override 327 public UserPrincipal lookupPrincipalByName(String name) 328 throws IOException 329 { 330 return UnixUserPrincipals.lookupUser(name); 331 } 332 333 @Override 334 public GroupPrincipal lookupPrincipalByGroupName(String group) 335 throws IOException 336 { 337 return UnixUserPrincipals.lookupGroup(group); 338 } 339 }; 340 } 341 342 } | 285 public PathMatcher getPathMatcher(String syntaxAndInput) { 286 int pos = syntaxAndInput.indexOf(':'); 287 if (pos <= 0 || pos == syntaxAndInput.length()) 288 throw new IllegalArgumentException(); 289 String syntax = syntaxAndInput.substring(0, pos); 290 String input = syntaxAndInput.substring(pos+1); 291 292 String expr; 293 if (syntax.equals(GLOB_SYNTAX)) { 294 expr = Globs.toUnixRegexPattern(input); 295 } else { 296 if (syntax.equals(REGEX_SYNTAX)) { 297 expr = input; 298 } else { 299 throw new UnsupportedOperationException("Syntax '" + syntax + 300 "' not recognized"); 301 } 302 } 303 304 // return matcher 305 final Pattern pattern = compilePathMatchPattern(expr); 306 307 return new PathMatcher() { 308 @Override 309 public boolean matches(Path path) { 310 return pattern.matcher(path.toString()).matches(); 311 } 312 }; 313 } 314 315 private static final String GLOB_SYNTAX = "glob"; 316 private static final String REGEX_SYNTAX = "regex"; 317 318 @Override 319 public final UserPrincipalLookupService getUserPrincipalLookupService() { 320 return LookupService.instance; 321 } 322 323 private static class LookupService { 324 static final UserPrincipalLookupService instance = 325 new UserPrincipalLookupService() { 326 @Override 327 public UserPrincipal lookupPrincipalByName(String name) 328 throws IOException 329 { 330 return UnixUserPrincipals.lookupUser(name); 331 } 332 333 @Override 334 public GroupPrincipal lookupPrincipalByGroupName(String group) 335 throws IOException 336 { 337 return UnixUserPrincipals.lookupGroup(group); 338 } 339 }; 340 } 341 342 // Override if the platform has different path match requrement, such as 343 // case insensitive or Unicode canonical equal on MacOSX 344 Pattern compilePathMatchPattern(String expr) { 345 return Pattern.compile(expr); 346 } 347 348 // Override if the platform uses different Unicode normalization form 349 // for native file path. For example on MacOSX, the native path is stored 350 // in Unicode NFD form. 351 char[] normalizeNativePath(char[] path) { 352 return path; 353 } 354 355 // Override if the native file path use non-NFC form. For example on MacOSX, 356 // the native path is stored in Unicode NFD form, the path need to be 357 // normalized back to NFC before passed back to Java level. 358 String normalizeJavaPath(String path) { 359 return path; 360 } 361 } |