/** * Enumerate all imported resources in this module which match the given glob expression. The glob applies to * the whole resource name. * * @param glob the glob to apply * @return the iterator * @throws ModuleLoadException if linking a dependency module fails for some reason */ public Iterator<Resource> globResources(final String glob) throws ModuleLoadException { String safeGlob = PathUtils.canonicalize(PathUtils.relativize(glob)); final int i = safeGlob.lastIndexOf('/'); if (i == -1) { return PathFilters.filtered(PathFilters.match(glob), iterateResources(PathFilters.acceptAll())); } else { return PathFilters.filtered(PathFilters.match(glob.substring(i + 1)), iterateResources(PathFilters.match(glob.substring(0, i)))); } }
/** * Enumerate all imported resources in this module which match the given glob expression. The glob applies to * the whole resource name. * * @param glob the glob to apply * @return the iterator * @throws ModuleLoadException if linking a dependency module fails for some reason */ public Iterator<Resource> globResources(final String glob) throws ModuleLoadException { String safeGlob = PathUtils.canonicalize(PathUtils.relativize(glob)); final int i = safeGlob.lastIndexOf('/'); if (i == -1) { return PathFilters.filtered(PathFilters.match(glob), iterateResources(PathFilters.acceptAll())); } else { return PathFilters.filtered(PathFilters.match(glob.substring(i + 1)), iterateResources(PathFilters.match(glob.substring(0, i)))); } }
filters.add(new FilterSpecification(PathFilters.match(path), include));
filters.add(new FilterSpecification(PathFilters.match(path), include));
filters.add(new FilterSpecification(PathFilters.match(path), include));
filters.add(new FilterSpecification(PathFilters.match(path), include));
filters.add(new FilterSpecification(PathFilters.match(path), include));
filters.add(new FilterSpecification(PathFilters.match(path), include));
filters.add(new FilterSpecification(PathFilters.match(path), include));
filters.add(new FilterSpecification(PathFilters.match(path), include));
builder.addFilter(PathFilters.match(path), include);
builder.addFilter(PathFilters.match(path), include);
builder.addFilter(PathFilters.match(path), include);
builder.addFilter(PathFilters.match(path), include);
builder.addFilter(PathFilters.match(path), include);
builder.addFilter(PathFilters.match(path), include);
builder.addFilter(PathFilters.match(path), include);
private static void parsePath(final XmlPullParser reader, final boolean include, final MultiplePathFilterBuilder builder) throws XmlPullParserException, IOException { String path = null; final Set<String> required = new HashSet<>(Arrays.asList(A_PATH)); final int count = reader.getAttributeCount(); for (int i = 0; i < count; i ++) { final String attribute = reader.getAttributeName(i); required.remove(attribute); switch (attribute) { case A_PATH: path = reader.getAttributeValue(i); break; default: throw unknownAttribute(reader, attribute); } } if (! required.isEmpty()) { throw missingAttributes(reader, required); } final boolean literal = path.indexOf('*') == -1 && path.indexOf('?') == -1; if (literal) { if (path.charAt(path.length() - 1) == '/') { builder.addFilter(PathFilters.isChildOf(path), include); } else { builder.addFilter(PathFilters.is(path), include); } } else { builder.addFilter(PathFilters.match(path), include); } // consume remainder of element parseNoContent(reader); }
/** * Build a PathFilter for a set of filter paths * * @param filterPaths the set of paths to filter on. * Can be null to indicate that no filters should be applied (accept all), * can be empty to indicate that everything should be filtered (reject all). * @param failedMatchValue the value the PathFilter returns when a path does not match. * @return a PathFilter. */ private static PathFilter buildFilters(Set<String> filterPaths, boolean failedMatchValue) { if (filterPaths == null) return PathFilters.acceptAll(); else if (filterPaths.isEmpty()) { return PathFilters.rejectAll(); } else { MultiplePathFilterBuilder builder = PathFilters.multiplePathFilterBuilder(failedMatchValue); for (String importPathGlob : filterPaths) builder.addFilter(PathFilters.match(importPathGlob), !failedMatchValue); return builder.create(); } } }
private static void parsePath(final XmlPullParser reader, final boolean include, final MultiplePathFilterBuilder builder) throws XmlPullParserException, IOException { String path = null; final Set<String> required = new HashSet<>(LIST_A_PATH); final int count = reader.getAttributeCount(); for (int i = 0; i < count; i ++) { validateAttributeNamespace(reader, i); final String attribute = reader.getAttributeName(i); required.remove(attribute); switch (attribute) { case A_PATH: path = reader.getAttributeValue(i); break; default: throw unknownAttribute(reader, i); } } if (! required.isEmpty()) { throw missingAttributes(reader, required); } final boolean literal = path.indexOf('*') == -1 && path.indexOf('?') == -1; if (literal) { if (path.charAt(path.length() - 1) == '/') { builder.addFilter(PathFilters.isChildOf(path), include); } else { builder.addFilter(PathFilters.is(path), include); } } else { builder.addFilter(PathFilters.match(path), include); } // consume remainder of element parseNoContent(reader); }