@Override
  public void init(final SapphireAction action, final ActionHandlerDef def) {
    super.init(action, def);

    setId(ID);
    setLabel(Resources.label);
    addImage(IMG_FILE);

    final Property property = property();

    this.type = null;

    final String paramType = def.getParam(PARAM_TYPE);

    if (paramType != null) {
      if (paramType.equalsIgnoreCase("file")) {
        this.type = FileSystemResourceType.FILE;
      } else if (paramType.equalsIgnoreCase("folder")) {
        this.type = FileSystemResourceType.FOLDER;
      }
    } else {
      final ValidFileSystemResourceType validFileSystemResourceTypeAnnotation =
          property.definition().getAnnotation(ValidFileSystemResourceType.class);

      if (validFileSystemResourceTypeAnnotation != null) {
        this.type = validFileSystemResourceTypeAnnotation.value();
      }
    }

    final String staticFileExtensions = def.getParam(PARAM_EXTENSIONS);

    if (staticFileExtensions == null) {
      this.fileExtensionService = property.service(FileExtensionsService.class);

      if (this.fileExtensionService == null) {
        this.staticFileExtensionsList = Collections.emptyList();
      }
    } else {
      this.staticFileExtensionsList = new ArrayList<String>();

      for (String extension : staticFileExtensions.split(",")) {
        extension = extension.trim();

        if (extension.length() > 0) {
          this.staticFileExtensionsList.add(extension);
        }
      }
    }

    final String paramLeadingSlash = def.getParam(PARAM_LEADING_SLASH);

    if (paramLeadingSlash != null) {
      this.includeLeadingSlash = Boolean.parseBoolean(paramLeadingSlash);
    } else {
      this.includeLeadingSlash = false;
    }
  }
  @Override
  protected void facts(final SortedSet<String> facts) {
    final ValidFileSystemResourceType a =
        context(PropertyDef.class).getAnnotation(ValidFileSystemResourceType.class);
    final FileSystemResourceType type = a.value();

    if (type == FileSystemResourceType.FILE) {
      facts.add(Resources.statementForFile);
    } else if (type == FileSystemResourceType.FOLDER) {
      facts.add(Resources.statementForFolder);
    } else {
      throw new IllegalStateException();
    }
  }
Пример #3
0
  @Override
  protected void initValidationService() {
    final Property property = context(Property.class);

    this.resourceMustExist = property.definition().hasAnnotation(MustExist.class);

    final ValidFileSystemResourceType validResourceTypeAnnotation =
        property.definition().getAnnotation(ValidFileSystemResourceType.class);
    this.validResourceType =
        (validResourceTypeAnnotation != null ? validResourceTypeAnnotation.value() : null);

    this.fileExtensionsService = property.service(FileExtensionsService.class);

    if (this.fileExtensionsService != null) {
      this.fileExtensionsService.attach(
          new Listener() {
            @Override
            public void handle(final Event event) {
              refresh();
            }
          });
    }
  }