Sapphire Developer Guide > Services

FileExtensionsService

FileExtensionsService produces the list of file extensions that are allowed for a path value property.

Although custom implementations are supported, in most cases the supplied implementation that is configured via @FileExtensions annotation should be sufficient. In many cases, specifying file extensions is as simple as listing them with a comma in between.

Example

@Type( base = Path.class )
@AbsolutePath
@MustExist
@ValidFileSystemResourceType( FileSystemResourceType.FILE )
@FileExtensions( expr = "jar,zip" )

ValueProperty PROP_FILE_PATH = new ValueProperty( TYPE, "FilePath" );

Value<Path> getFilePath();
void setFilePath( String value );
void setFilePath( Path value );

File extensions can also be specified via an expression that takes into account values of other properties.

Examples

@FileExtensions( expr = "${ Extension }" )
@FileExtensions( expr = "${ LossyFormat ? 'jpeg,jpg' : 'png,gif' }" )

If declarative approach is not sufficient, a custom FileExtensionsService implementation can be supplied.

Example

public class CustomFileExtensionsService extends FileExtensionsService
{
    @Override
    protected void initFileExtensionsService()
    {
        // Optionally register listeners to invoke refresh method when the list of extensions
        // may need to be updated.
    }

    @Override
    protected FileExtensionsServiceData compute()
    {
        // Compute the list of extensions.

        List<String> extensions = new ArrayList<String>();

        ...

        return new FileExtensionsServiceData( extensions );
    }

    @Override
    public void dispose()
    {
        super.dispose();

        // Remove any listeners that were added during initialization.
    }
}
@Type( base = Path.class )
@AbsolutePath
@MustExist
@ValidFileSystemResourceType( FileSystemResourceType.FILE )
@Service( impl = CustomFileExtensionsService.class )

ValueProperty PROP_FILE_PATH = new ValueProperty( TYPE, "FilePath" );

Value<Path> getFilePath();
void setFilePath( String value );
void setFilePath( Path value );