Example #1
0
  @Override
  public ResourceKeys findResourceKeys(
      final ApplicationKey applicationKey,
      final String path,
      final String filePattern,
      boolean recurse) {
    ResourceKeys resourceKeys = null;
    final Application application = getActiveApplication(applicationKey);

    if (application != null) {
      Bundle bundle = application.getBundle();

      final Enumeration<URL> entries = bundle.findEntries(path, filePattern, recurse);

      if (entries != null) {
        final List<ResourceKey> resourceKeyList =
            Collections.list(entries)
                .stream()
                .map(resourceUrl -> ResourceKey.from(applicationKey, resourceUrl.getPath()))
                .collect(Collectors.toList());

        resourceKeys = ResourceKeys.from(resourceKeyList);
      }
    }

    if (resourceKeys == null) {
      resourceKeys = ResourceKeys.empty();
    }

    return resourceKeys;
  }
Example #2
0
  @Override
  public ResourceKeys findFolders(final ApplicationKey applicationKey, final String path) {
    ResourceKeys resourceKeys = null;
    final Application application = getActiveApplication(applicationKey);

    if (application != null) {
      Bundle bundle = application.getBundle();

      final Enumeration<String> entryPaths = bundle.getEntryPaths(path);

      if (entryPaths != null) {
        final List<ResourceKey> resourceKeyList =
            Collections.list(entryPaths)
                .stream()
                .filter(entryPath -> entryPath.endsWith("/"))
                .map(entryPath -> ResourceKey.from(applicationKey, entryPath))
                .collect(Collectors.toList());

        resourceKeys = ResourceKeys.from(resourceKeyList);
      }
    }

    if (resourceKeys == null) {
      resourceKeys = ResourceKeys.empty();
    }

    return resourceKeys;
  }
Example #3
0
  private Application getActiveApplication(final ApplicationKey applicationKey) {
    Application activeApplication = null;

    final Application application = applicationService.getApplication(applicationKey);
    if (application != null && application.getBundle().getState() == Bundle.ACTIVE) {
      activeApplication = application;
    }

    return activeApplication;
  }
Example #4
0
  @Override
  public Resource getResource(final ResourceKey resourceKey) {
    URL resourceUrl = null;
    final Application application = getActiveApplication(resourceKey.getApplicationKey());
    if (application != null) {
      String resourcePath = resourceKey.getPath();
      resourceUrl = application.getBundle().getResource(resourcePath);
    }

    return new UrlResource(resourceKey, resourceUrl);
  }