Пример #1
0
  @Override
  public List<String> getWebPaths(Resource<?> r) {
    List<String> results = new ArrayList<String>();

    if (r != null) {
      WebResourceFacet web = project.getFacet(WebResourceFacet.class);
      List<DirectoryResource> webRootDirectories = web.getWebRootDirectories();
      for (DirectoryResource d : webRootDirectories) {
        if (r.getFullyQualifiedName().startsWith(d.getFullyQualifiedName())) {
          String path = r.getFullyQualifiedName().substring(d.getFullyQualifiedName().length());

          for (String p : getWebPaths(path)) {
            if (!results.contains(p)) results.add(p);
          }
          break;
        }
      }
    }
    return results;
  }
Пример #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 : getFacesServletMappings()) {
        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;
  }