public FixedStepsPathMatcher(List<PatternStep> steps, PathMatcher next) {
   this.steps = steps;
   this.next = next;
   minSegments = steps.size() + next.getMinSegments();
   maxSegments =
       next.getMaxSegments() == Integer.MAX_VALUE
           ? Integer.MAX_VALUE
           : next.getMaxSegments() + steps.size();
 }
  @Test
  public void testMatches() throws Exception {
    Path baseFolder = new Path("tests/res/PathMatcherTest");
    FList<String> wc = new FList<>("test1.txt", "./test3.*");
    PathMatcher matcher = new PathMatcher(wc, baseFolder);

    assertTrue(matcher.matches(baseFolder.combination("test1.txt")));
    assertFalse(matcher.matches(new Path("test3.bin")));
    assertTrue(matcher.matches(baseFolder.combination("test3.bin")));
  }
Exemple #3
0
  public static PathMatcher readRoots() {
    PathMatcher pathMatcher = new PathMatcher();
    String rootString = StringUtil.replace(roots, "\n", ",");
    String[] roots = rootString.split(",");
    for (int i = 0; i < roots.length; i += 2) {
      if (showRoots) System.out.printf("  %-40s %-40s%n", roots[i], roots[i + 1]);
      pathMatcher.put(roots[i], roots[i + 1]);
    }

    return pathMatcher;
  }
 // The name we accept is:
 // /filter/mediatype/k/{set}
 // where k is the media type we want.
 @Override
 public MediaObject createMediaObject(Path path) {
   int matchType = mMatcher.match(path);
   int mediaType = mMatcher.getIntVar(0);
   String setsName = mMatcher.getVar(1);
   DataManager dataManager = mApplication.getDataManager();
   MediaSet[] sets = dataManager.getMediaSetsFromString(setsName);
   switch (matchType) {
     case FILTER_BY_MEDIATYPE:
       return new FilterSet(path, dataManager, sets[0], mediaType);
     default:
       throw new RuntimeException("bad path: " + path);
   }
 }
  FieldMatcher(FieldsMatcher parent, Field field) {
    super(parent.owner, field.paths);
    this.parent = parent;

    // test the initial match
    super.start(parent.element);
  }
Exemple #6
0
  public static String getDataroot(String path, int status) {
    if (pathMatcher == null) pathMatcher = readRoots();

    String ss = getServiceSpecial(path);
    if (ss != null) return "service-" + ss;

    if (path.startsWith("//thredds/")) path = path.substring(1);

    if (!path.startsWith("/thredds/")) return "zervice-root";

    String dataRoot = null;
    String spath = path.substring(9); // remove /thredds/
    String service = findService(spath);
    if (service != null) {
      // if (service.equals("radarServer")) dataRoot = "radarServer";
      // else if (service.equals("casestudies")) dataRoot = "casestudies";
      // else if (service.equals("dqc")) dataRoot = "dqc";
      if (spath.length() > service.length()) {
        spath = spath.substring(service.length() + 1);
        PathMatcher.Match match = pathMatcher.match(spath);
        if (match != null) dataRoot = match.root;
      }
    }

    if (dataRoot == null) {
      if (status >= 400) dataRoot = "zBad";
    }

    if (dataRoot == null) {
      service = getService(path);
      dataRoot = (service != null) ? "zervice-" + service : "unknown";
    }
    return dataRoot;
  }
 protected void endElement(Datatype type) {
   super.endElement(type);
   // double match error is already checked in the corresponding
   // startElement method.
   if (element != null) {
     final String val = element.getText();
     setValue(val, type);
     element = null;
   }
 }
 @Override
 public boolean allowed(
     final MavenProxyRepository mavenProxyRepository,
     final ResourceStoreRequest resourceStoreRequest) {
   final PathMatcher pathMatcher = getPathMatcherFor(mavenProxyRepository);
   if (pathMatcher != null) {
     final boolean allowed = pathMatcher.matches(resourceStoreRequest.getRequestPath());
     if (!allowed) {
       // flag the request as rejected
       resourceStoreRequest
           .getRequestContext()
           .put(Manager.ROUTING_REQUEST_REJECTED_FLAG_KEY, Boolean.TRUE);
     }
     return allowed;
   } else {
     // no pathMatcher for a proxy, it does not publishes it
     return true;
   }
 }
 public boolean isPrefix(String[] segments, int startIndex) {
   int pos = startIndex;
   for (int i = 0; pos < segments.length && i < steps.size(); i++, pos++) {
     PatternStep step = steps.get(i);
     if (!step.matches(segments[pos])) {
       return false;
     }
   }
   if (pos == segments.length) {
     return true;
   }
   return next.isPrefix(segments, pos);
 }
Exemple #10
0
 // it compares the link if it is equal to .html then it will be added to the list.
 private void find(Path file) {
   Path name = file.getFileName();
   if (name != null && matcher.matches(name)) {
     numMatches++;
     int i = -1;
     String shortPath = file.toString();
     i = shortPath.indexOf("-lewis");
     shortPath = shortPath.substring(i + 7, shortPath.length());
     URI newLink = new File(file.toString()).toURI();
     //  System.out.println("Antes  :" +newLink.toString() );
     newLink = newLink.normalize();
     linksMatches.add(newLink.toString().substring(6));
   }
 }
 public boolean matches(String[] segments, int startIndex) {
   int remaining = segments.length - startIndex;
   if (remaining < minSegments || remaining > maxSegments) {
     return false;
   }
   int pos = startIndex;
   for (int i = 0; i < steps.size(); i++, pos++) {
     PatternStep step = steps.get(i);
     if (!step.matches(segments[pos])) {
       return false;
     }
   }
   return next.matches(segments, pos);
 }
  protected void startElement(final org.dom4j.Element elt) {
    if (element != null) {
      // this situation is an error because a matched element
      // cannot contain any child element.
      // But what I don't know is how to treat this situation.

      // 1. to make the document invalid?
      // 2. cancel the match?

      // the current implementation choose the 2nd.
      element = null;
    }
    super.startElement(elt);
  }
 @Override
 public MediaObject createMediaObject(Path path) {
   switch (mMatcher.match(path)) {
     case SECURE_ALBUM:
       {
         DataManager dataManager = mApplication.getDataManager();
         MediaItem unlock = (MediaItem) dataManager.getMediaObject("/secure/unlock");
         return new SecureAlbum(path, mApplication, unlock);
       }
     case SECURE_UNLOCK:
       return new UnlockImage(path, mApplication);
     default:
       throw new RuntimeException("bad path: " + path);
   }
 }
Exemple #14
0
  @Override
  public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
    if (_pathMatcher.matches(file.getFileName())) storeFile(file.toFile());

    return super.visitFile(file, attrs);
  }
 @Override
 public void describeTo(Description description) {
   super.describeTo(description);
   description.appendText("a regular file");
 }
 void find(Path file) {
   Path name = file.getFileName();
   if (name != null && pathMatcher.matches(name)) {
     System.out.println(name);
   }
 }
 public FilterSource(GalleryApp application) {
   super("filter");
   mApplication = application;
   mMatcher = new PathMatcher();
   mMatcher.add("/filter/mediatype/*/*", FILTER_BY_MEDIATYPE);
 }
 public static boolean isSecurePath(String path) {
   return (SECURE_ALBUM == mMatcher.match(Path.fromString(path)));
 }
 static {
   mMatcher.add("/secure/all/*", SECURE_ALBUM);
   mMatcher.add("/secure/unlock", SECURE_UNLOCK);
 }
Exemple #20
0
  public void testWildcardMatch() {
    String path = "org/andromda/some/file/Test.java";
    assertTrue(PathMatcher.wildcardMatch(path, "**/*.java"));
    assertFalse(PathMatcher.wildcardMatch(path, "*.java"));
    assertTrue(PathMatcher.wildcardMatch(path, "*/*/*/*/*.java"));
    assertFalse(PathMatcher.wildcardMatch(path, "*/*/*.java"));
    assertTrue(PathMatcher.wildcardMatch(path, "**/*Test.java"));
    assertTrue(PathMatcher.wildcardMatch(path, "**/*Tes*.java"));
    assertFalse(PathMatcher.wildcardMatch(path, "**/*TestFile*.java"));
    assertFalse(PathMatcher.wildcardMatch(path, "**/.java"));
    assertTrue(PathMatcher.wildcardMatch(path, "org/andromda/**/*"));

    path = "Test.java";
    assertTrue(PathMatcher.wildcardMatch(path, "*.java"));
    assertTrue(PathMatcher.wildcardMatch(path, "**/*.java"));
    assertTrue(PathMatcher.wildcardMatch(path, "**/*"));

    assertTrue(PathMatcher.wildcardMatch(path, "*.java"));
    assertTrue(PathMatcher.wildcardMatch(path, "**.java"));
    assertTrue(PathMatcher.wildcardMatch(path, "**/*"));
    assertFalse(PathMatcher.wildcardMatch(path, "***/*.java"));

    path = "org/Test.java";
    assertFalse(PathMatcher.wildcardMatch(path, "*.java"));
    assertTrue(PathMatcher.wildcardMatch(path, "**/*"));
  }