Пример #1
0
 @Test
 public void testCreateTopLevelPackage() throws Exception {
   initializeJavaProject();
   DirectoryResource root = getProject().getProjectRoot();
   Resource<?> srcMainJavaDirectory = root.getChild("/src/main/java");
   assertNotNull(srcMainJavaDirectory.reify(DirectoryResource.class));
   Resource<?> testDirectory = srcMainJavaDirectory.getChild("com/test");
   assertNotNull(testDirectory.reify(DirectoryResource.class));
 }
Пример #2
0
  @Override
  public Resource<?> getResourceForWebPath(String path) {
    if (path != null) {
      WebResourceFacet web = project.getFacet(WebResourceFacet.class);
      List<DirectoryResource> webRootDirectories = web.getWebRootDirectories();

      boolean matches = false;
      for (String mapping : getEffectiveFacesServletMappings()) {
        Matcher matcher = ServletUtil.mappingToRegex(mapping).matcher(path);
        if (matcher.matches()) {
          path = matcher.group(1);
          matches = true;
          break;
        }
      }

      while (path.startsWith("/")) {
        path = path.substring(1);
      }

      if (!matches) {
        return null;
      }

      List<String> strings = Arrays.asList(path.split("/"));
      for (DirectoryResource d : webRootDirectories) {
        Queue<String> queue = new LinkedList<String>();
        queue.addAll(strings);

        Resource<?> temp = d;
        while (queue.size() > 1) {
          Resource<?> child = temp.getChild(queue.remove());
          if ((child != null) && child.exists()) {
            temp = child;
          } else {
            break;
          }

          if (queue.isEmpty()) {
            return child;
          }
        }

        if (temp != null) {
          String name = queue.remove();
          for (String suffix : getFacesSuffixes()) {
            Resource<?> child = null;
            if (name.endsWith(suffix)) {
              child = temp.getChild(name);
            } else {
              child = temp.getChild(name + suffix);
            }
            if ((child != null) && child.exists()) {
              return child;
            }
          }
        }
      }
    }
    return null;
  }