List of usage examples for org.apache.commons.io IOCase SENSITIVE
IOCase SENSITIVE
To view the source code for org.apache.commons.io IOCase SENSITIVE.
Click Source Link
From source file:com.matteoveroni.model.copy.FilenameUtils.java
/** * Checks a filename to see if it matches the specified wildcard matcher * allowing control over case-sensitivity. * <p>/*from w w w.j a va 2s . c o m*/ * The wildcard matcher uses the characters '?' and '*' to represent a * single or multiple (zero or more) wildcard characters. * N.B. the sequence "*?" does not work properly at present in match strings. * * @param filename the filename to match on * @param wildcardMatcher the wildcard string to match against * @param caseSensitivity what case sensitivity rule to use, null means case-sensitive * @return true if the filename matches the wilcard string * @since 1.3 */ public static boolean wildcardMatch(String filename, String wildcardMatcher, IOCase caseSensitivity) { if (filename == null && wildcardMatcher == null) { return true; } if (filename == null || wildcardMatcher == null) { return false; } if (caseSensitivity == null) { caseSensitivity = IOCase.SENSITIVE; } String[] wcs = splitOnTokens(wildcardMatcher); boolean anyChars = false; int textIdx = 0; int wcsIdx = 0; Stack<int[]> backtrack = new Stack<int[]>(); // loop around a backtrack stack, to handle complex * matching do { if (backtrack.size() > 0) { int[] array = backtrack.pop(); wcsIdx = array[0]; textIdx = array[1]; anyChars = true; } // loop whilst tokens and text left to process while (wcsIdx < wcs.length) { if (wcs[wcsIdx].equals("?")) { // ? so move to next text char textIdx++; if (textIdx > filename.length()) { break; } anyChars = false; } else if (wcs[wcsIdx].equals("*")) { // set any chars status anyChars = true; if (wcsIdx == wcs.length - 1) { textIdx = filename.length(); } } else { // matching text token if (anyChars) { // any chars then try to locate text token textIdx = caseSensitivity.checkIndexOf(filename, textIdx, wcs[wcsIdx]); if (textIdx == -1) { // token not found break; } int repeat = caseSensitivity.checkIndexOf(filename, textIdx + 1, wcs[wcsIdx]); if (repeat >= 0) { backtrack.push(new int[] { wcsIdx, repeat }); } } else { // matching from current position if (!caseSensitivity.checkRegionMatches(filename, textIdx, wcs[wcsIdx])) { // couldnt match token break; } } // matched text token, move text index to end of matched token textIdx += wcs[wcsIdx].length(); anyChars = false; } wcsIdx++; } // full match if (wcsIdx == wcs.length && textIdx == filename.length()) { return true; } } while (backtrack.size() > 0); return false; }
From source file:nl.mpi.oai.harvester.cycle.XMLOverviewTest.java
@Test /**/*from w w w.j ava2 s. com*/ * Test rotating overview files */ public void testOverviewRotate() { // get the overview from a test XML overview file final XMLOverview xmlOverview = new XMLOverview(TestHelper.getFile("/OverviewNormalMode.xml")); /* Instead of rotating the overview file itself, test by rotating a copy of this file. Therefore, try to save a copy of the overview in a temporary folder first. */ try { // create a new temporary file final File newFile = temporaryFolder.newFile("CopyOfNormalModeFile.xml"); // save the overview in the temporary file, creating a copy xmlOverview.save(newFile); } catch (IOException e) { fail(); e.printStackTrace(); } /* Now rotate the copy. This will create a file with a date and timestamp, and a new file containing the overview. */ boolean done = xmlOverview.rotateAndSave(); if (!done) { fail(); } // create a filter for finding the overview XML files String[] allowedExtensions = new String[] { "xml" }; IOFileFilter filter = new SuffixFileFilter(allowedExtensions, IOCase.SENSITIVE); // create an iterator based on the filter Iterator iterator = FileUtils.iterateFiles(temporaryFolder.getRoot(), filter, null); // iterate over the temporary files File file1 = (File) iterator.next(); File file2 = (File) iterator.next(); if (iterator.hasNext()) { // there should only be two files in the temporary folder fail(); } // determine which file is the rotated file and which is the new file File rotatedFile, newFile; int atIndex = file1.getPath().lastIndexOf(" at "); if (atIndex < 0) { // did not find it in this file atIndex = file2.getPath().lastIndexOf(" at "); if (atIndex < 0) { // did not find it in this file either rotatedFile = null; newFile = null; fail(); } else { rotatedFile = file2; newFile = file1; } } else { rotatedFile = file1; newFile = file2; } // determine the index of the first character in the timestamp int first = atIndex + 4; // determine the index of the last character in the timestamp int last = rotatedFile.getPath().lastIndexOf("xml") - 1; // get the timestamp from the rotated file String timeStamp = rotatedFile.getPath().substring(first, last); // the timestamp should be before now DateTime rotatedAt = new DateTime(timeStamp); assertTrue(rotatedAt.isBeforeNow()); // the path of the files up to the timestamp should be equal String partOfRotated = rotatedFile.getPath().substring(0, atIndex); String partOfNew = newFile.getPath().substring(0, atIndex); assertTrue(partOfRotated.equals(partOfNew)); // both files should have equal content try { assertTrue(FileUtils.contentEquals(rotatedFile, newFile)); } catch (IOException e) { fail(); e.printStackTrace(); } }
From source file:org.apache.atlas.authorize.simple.SimpleAtlasAuthorizer.java
private boolean isMatch(String resource, List<String> policyValues) { if (isDebugEnabled) { LOG.debug("==> SimpleAtlasAuthorizer isMatch"); }//from ww w . ja v a 2 s.co m boolean isMatchAny = resourceMatchHelper(policyValues); boolean isMatch = false; boolean allValuesRequested = isAllValuesRequested(resource); if (allValuesRequested || isMatchAny) { isMatch = isMatchAny; } else { for (String policyValue : policyValues) { if (policyValue.contains("*")) { isMatch = optIgnoreCase ? FilenameUtils.wildcardMatch(resource, policyValue, IOCase.INSENSITIVE) : FilenameUtils.wildcardMatch(resource, policyValue, IOCase.SENSITIVE); } else { isMatch = optIgnoreCase ? StringUtils.equalsIgnoreCase(resource, policyValue) : StringUtils.equals(resource, policyValue); } if (isMatch) { break; } } } if (!isMatch) { if (isDebugEnabled) { StringBuilder sb = new StringBuilder(); sb.append("["); for (String policyValue : policyValues) { sb.append(policyValue); sb.append(" "); } sb.append("]"); LOG.debug("AtlasDefaultResourceMatcher.isMatch returns FALSE, (resource={}, policyValues={})", resource, sb.toString()); } } if (isDebugEnabled) { LOG.debug("<== SimpleAtlasAuthorizer isMatch({}): {}", resource, isMatch); } return isMatch; }
From source file:org.apache.atlas.authorize.SimpleAtlasAuthorizer.java
private boolean isMatch(String resource, List<String> policyValues) { if (isDebugEnabled) { LOG.debug("<== SimpleAtlasAuthorizer isMatch"); }// w ww . ja va 2s. c o m boolean isMatchAny = resourceMatchHelper(policyValues); boolean isMatch = false; boolean allValuesRequested = isAllValuesRequested(resource); if (allValuesRequested || isMatchAny) { isMatch = isMatchAny; } else { for (String policyValue : policyValues) { if (policyValue.contains("*")) { isMatch = optIgnoreCase ? FilenameUtils.wildcardMatch(resource, policyValue, IOCase.INSENSITIVE) : FilenameUtils.wildcardMatch(resource, policyValue, IOCase.SENSITIVE); } else { isMatch = optIgnoreCase ? StringUtils.equalsIgnoreCase(resource, policyValue) : StringUtils.equals(resource, policyValue); } if (isMatch) { break; } } } if (isMatch == false) { if (isDebugEnabled) { StringBuilder sb = new StringBuilder(); sb.append("["); for (String policyValue : policyValues) { sb.append(policyValue); sb.append(" "); } sb.append("]"); LOG.debug("AtlasDefaultResourceMatcher.isMatch returns FALSE, (resource=" + resource + ", policyValues=" + sb.toString() + ")"); } } if (isDebugEnabled) { LOG.debug("==> SimpleAtlasAuthorizer isMatch(" + resource + "): " + isMatch); } return isMatch; }
From source file:org.apache.ranger.biz.RangerBizUtil.java
/** * returns true if first and second path are same * * @param pathToCheckFragment// w w w . ja va 2s. c om * @param wildCardPathFragment * @return */ private boolean matchPath(String pathToCheckFragment, String wildCardPathFragment) { if (pathToCheckFragment == null || wildCardPathFragment == null) { return false; } if (pathToCheckFragment.contains("*") || pathToCheckFragment.contains("?")) { pathToCheckFragment = replaceMetaChars(pathToCheckFragment); if (wildCardPathFragment.contains("*") || wildCardPathFragment.contains("?")) { return FilenameUtils.wildcardMatch(pathToCheckFragment, wildCardPathFragment, IOCase.SENSITIVE); } else { return false; } } else { if (wildCardPathFragment.contains("*") || wildCardPathFragment.contains("?")) { return FilenameUtils.wildcardMatch(pathToCheckFragment, wildCardPathFragment, IOCase.SENSITIVE); } else { return pathToCheckFragment.trim().equals(wildCardPathFragment.trim()); } } }
From source file:org.apache.ranger.plugin.resourcematcher.RangerAbstractResourceMatcher.java
@Override boolean isMatch(String resourceValue, Map<String, Object> evalContext) { return FilenameUtils.wildcardMatch(resourceValue, getExpandedValue(evalContext), IOCase.SENSITIVE); }
From source file:org.apache.ranger.plugin.resourcematcher.RangerPathResourceMatcher.java
@Override boolean isMatch(String resourceValue, Map<String, Object> evalContext) { return RangerPathResourceMatcher.isRecursiveWildCardMatch(resourceValue, getExpandedValue(evalContext), levelSeparatorChar, IOCase.SENSITIVE); }
From source file:org.apache.torque.generator.file.Fileset.java
static boolean matchesPattern(File file, String pattern) { String filePath = file.getPath(); List<String> fileParts = splitAndNormalize(filePath); List<String> patternParts = splitAndNormalize(pattern); if (fileParts.size() != patternParts.size()) { return false; }//from ww w . j ava 2 s . c o m Iterator<String> patternPartIt = patternParts.iterator(); for (String filePart : fileParts) { String patternPart = patternPartIt.next(); if (!FilenameUtils.wildcardMatch(filePart, patternPart, IOCase.SENSITIVE)) { return false; } } return true; }
From source file:org.apache.torque.generator.file.WildcardFilter.java
/** * Returns whether a file matches the criteria of this filter. * If the file is a directory and <code>acceptDir</code> is false, * the file is rejected./*w w w . j a v a2 s .c o m*/ * If the file is regular file and <code>acceptFile</code> is false, * the file is rejected. * If the filename does not match the wildcard filter, the file is * rejected. * If none of the above applies, the file is accepted. * * @return false if the file is rejected, true if it is accepted. */ public boolean accept(File file) { if (!acceptDir && file.isDirectory()) { return false; } if (!acceptFile && file.isFile()) { return false; } if (FilenameUtils.wildcardMatch(file.getName(), expression, IOCase.SENSITIVE)) { return true; } return false; }
From source file:org.mule.el.function.WildcardExpressionLanguageFuntion.java
protected boolean isMatch(String wildcardPattern, String text, boolean caseSensitive) { return FilenameUtils.wildcardMatch(text, wildcardPattern, caseSensitive ? IOCase.SENSITIVE : IOCase.INSENSITIVE); }