List of usage examples for org.apache.commons.io FilenameUtils wildcardMatch
public static boolean wildcardMatch(String filename, String wildcardMatcher)
From source file:org.simbasecurity.core.service.authorization.AuthorizationServiceImpl.java
private PolicyDecision isURLRuleAllowed(String username, String url, URLOperationType operationType) { AuthorizationRequestContext context = new AuthorizationRequestContext(username); Collection<URLRule> rules = ruleRepository.findURLRules(username); PolicyDecision decision = null;/*from w w w . j ava 2 s . c om*/ for (URLRule rule : rules) { if (FilenameUtils.wildcardMatch(url, rule.getResourceName())) { boolean allowed = rule.getPolicy().applies(context) && rule.isAllowed(operationType); long newTimestamp = rule.getPolicy().getExpirationTimestamp(context); decision = determineDecisionBasedOn(decision, allowed, newTimestamp); } } if (decision == null) { decision = NEVER_ALLOWED; } logAuthorizationDecision(username, URL_RESOURCE_LABEL + url + LOG_DELIM + operationType.name() + LOG_DELIM + decision.toString()); return decision; }
From source file:org.teavm.maven.BuildJavascriptTestMojo.java
private void addCandidate(ClassLoader classLoader, String className) { boolean matches = false; String simpleName = className.replace('.', '/'); for (String wildcard : wildcards) { if (FilenameUtils.wildcardMatch(simpleName, wildcard.replace('.', '/'))) { matches = true;/* w w w.ja v a 2 s.co m*/ break; } } if (!matches) { return; } try { Class<?> candidate = Class.forName(className, true, classLoader); if (tool.getAdapter().acceptClass(candidate)) { tool.getTestClasses().add(candidate.getName()); getLog().info("Test class detected: " + candidate.getName()); } } catch (ClassNotFoundException e) { getLog().info("Could not load class `" + className + "' to search for tests"); } }
From source file:org.walkmod.util.FileResource.java
private boolean matches(String fileName, String filter) { return filter.startsWith(fileName) || FilenameUtils.wildcardMatch(fileName, filter) || fileName.startsWith(filter); }
From source file:org.walkmod.util.FileResource.java
@Override public Iterator<File> iterator() { String fileNormalized = FilenameUtils.normalize(file.getAbsolutePath(), true); if (includes != null) { for (int i = 0; i < includes.length; i++) { if (!includes[i].startsWith(fileNormalized)) { includes[i] = fileNormalized + "/" + includes[i]; }/*from ww w . j ava 2 s . c o m*/ if (includes[i].endsWith("**")) { includes[i] = includes[i].substring(0, includes[i].length() - 3); } } } if (excludes != null) { for (int i = 0; i < excludes.length; i++) { if (!excludes[i].startsWith(fileNormalized)) { excludes[i] = fileNormalized + "/" + excludes[i]; } if (excludes[i].endsWith("**")) { excludes[i] = excludes[i].substring(0, excludes[i].length() - 3); } } } if (file.isDirectory()) { IOFileFilter filter = null; IOFileFilter directoryFilter = TrueFileFilter.INSTANCE; if (excludes != null || includes != null) { directoryFilter = new IOFileFilter() { @Override public boolean accept(File dir, String name) { boolean excludesEval = false; boolean includesEval = false; String aux = FilenameUtils.normalize(name, true); if (excludes != null) { for (int i = 0; i < excludes.length && !excludesEval; i++) { excludesEval = (FilenameUtils.wildcardMatch(aux, excludes[i]) || dir.getAbsolutePath().startsWith(excludes[i])); } } if (includes != null) { for (int i = 0; i < includes.length && !includesEval; i++) { includesEval = matches(aux, includes[i]); } } else { includesEval = true; } return (includesEval && !excludesEval) || (includes == null && excludes == null); } @Override public boolean accept(File file) { boolean excludesEval = false; boolean includesEval = false; String aux = FilenameUtils.normalize(file.getAbsolutePath(), true); if (excludes != null) { for (int i = 0; i < excludes.length && !excludesEval; i++) { excludesEval = (FilenameUtils.wildcardMatch(aux, excludes[i]) || file.getParentFile().getAbsolutePath().startsWith(excludes[i])); } } if (includes != null) { for (int i = 0; i < includes.length && !includesEval; i++) { includesEval = matches(aux, includes[i]); } } else { includesEval = true; } boolean result = (includesEval && !excludesEval) || (includes == null && excludes == null); return result; } }; if (extensions == null) { filter = directoryFilter; } else { String[] suffixes = toSuffixes(extensions); filter = new SuffixFileFilter(suffixes); } } else { if (extensions == null) { filter = TrueFileFilter.INSTANCE; } else { String[] suffixes = toSuffixes(extensions); filter = new SuffixFileFilter(suffixes); } } return FileUtils.listFiles(file, filter, directoryFilter).iterator(); } Collection<File> aux = new LinkedList<File>(); if (extensions == null) { aux.add(file); } return aux.iterator(); }
From source file:org.walkmod.writers.AbstractFileWriter.java
public void write(Object n, VisitorContext vc) throws Exception { File out = null;// www . java 2 s. c om boolean createdEmptyFile = false; if (vc != null) { out = (File) vc.get(AbstractWalker.ORIGINAL_FILE_KEY); } if (out == null) { log.debug("Creating the target source file. This is not the original source file."); out = createOutputDirectory(n); createdEmptyFile = true; } else { log.debug("The system will overwrite the original source file."); } boolean write = true; if (out != null) { log.debug("Analyzing exclude and include rules"); String aux = FilenameUtils.normalize(out.getCanonicalPath(), true); if (excludes != null) { for (int i = 0; i < excludes.length && write; i++) { if (!excludes[i].startsWith(normalizedOutputDirectory)) { excludes[i] = normalizedOutputDirectory + "/" + excludes[i]; if (excludes[i].endsWith("\\*\\*")) { excludes[i] = excludes[i].substring(0, excludes[i].length() - 2); } } write = !(excludes[i].startsWith(aux) || FilenameUtils.wildcardMatch(aux, excludes[i])); } } if (includes != null && write) { write = false; for (int i = 0; i < includes.length && !write; i++) { if (!includes[i].startsWith(normalizedOutputDirectory)) { includes[i] = normalizedOutputDirectory + "/" + includes[i]; if (includes[i].endsWith("\\*\\*")) { includes[i] = includes[i].substring(0, includes[i].length() - 2); } } write = includes[i].startsWith(aux) || FilenameUtils.wildcardMatch(aux, includes[i]); } } if (write) { Writer writer = null; try { vc.put("outFile", out); String content = getContent(n, vc); vc.remove("outFile"); if (content != null && !"".equals(content)) { char endLineChar = getEndLineChar(out); writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(out), getEncoding())); if (vc.get("append") == null) { write(content, writer, endLineChar); } else { if (Boolean.TRUE.equals(vc.get("append"))) { append(content, writer, endLineChar); } else { write(content, writer, endLineChar); } } Summary.getInstance().addFile(out); log.debug(out.getPath() + " written "); } } finally { if (writer != null) { writer.close(); } } } else { if (createdEmptyFile && out != null && out.isFile()) { out.delete(); } log.debug("skipping " + out.getParent()); } } else { log.debug("There is no place where to write."); } }
From source file:org.walkmod.writers.VisitorMessagesWriter.java
public void write(Object n, VisitorContext vc) { File out = null;/*from ww w . j a v a 2s .c om*/ if (vc != null) { out = (File) vc.get(AbstractWalker.ORIGINAL_FILE_KEY); } boolean write = true; if (out != null) { if (excludes != null) { for (int i = 0; i < excludes.length && write; i++) { write = !(FilenameUtils.wildcardMatch(out.getPath(), excludes[i])); } } if (includes != null && write) { write = false; for (int i = 0; i < includes.length && !write; i++) { write = FilenameUtils.wildcardMatch(out.getPath(), includes[i]); } } if (write) { Collection<String> messages = vc.getVisitorMessages(); if (messages != null) { for (String message : messages) { log.info(message); } } Summary.getInstance().addFile(out); } } }
From source file:ru.runa.af.web.system.TaskHandlerClassesInformation.java
private static void searchInJar(String jarName, JarInputStream jarInputStream) throws IOException { boolean matches = false; for (String patternFileName : BotStationResources.getTaskHandlerJarNames()) { if (FilenameUtils.wildcardMatch(jarName, patternFileName)) { matches = true;/*w w w . j a v a2 s . co m*/ break; } } if (!matches) { log.debug("Ignored " + jarName); return; } log.info("Searching in " + jarName); ZipEntry entry; while ((entry = jarInputStream.getNextEntry()) != null) { if (entry.getName().endsWith(".class")) { try { String className = entry.getName(); int lastIndexOfDotSymbol = className.lastIndexOf('.'); className = className.substring(0, lastIndexOfDotSymbol).replace('/', '.'); // If we can't load class - just move to next class. Class<?> someClass = ClassLoaderUtil.loadClass(className); if (TaskHandler.class.isAssignableFrom(someClass) && !Modifier.isAbstract(someClass.getModifiers())) { taskHandlerImplementationClasses.add(someClass.getCanonicalName()); } } catch (Throwable e) { log.warn("Error on loading task handler for " + e.getMessage()); } } } }