@Override
protected Status compute()
{
final Value<?> value = context( Value.class );
final CreateWorkspaceFileOp op = value.nearest( CreateWorkspaceFileOp.class );
final FileName fileName = (FileName) value.content();
if( fileName != null )
{
final String extension = fileName.extension();
if( extension != null )
{
final FileExtensionsService fileExtensionsService = value.service( FileExtensionsService.class );
if( fileExtensionsService != null )
{
final List<String> extensions = fileExtensionsService.extensions();
final int count = extensions.size();
if( count > 0 )
{
boolean match = false;
for( String ext : extensions )
{
if( extension.equalsIgnoreCase( ext ) )
{
match = true;
break;
}
}
if( ! match )
{
final String message;
if( count == 1 )
{
message = invalidFileExtensionOne.format( extensions.get( 0 ) );
}
else if( count == 2 )
{
message = invalidFileExtensionTwo.format( extensions.get( 0 ), extensions.get( 1 ) );
}
else
{
final StringBuilder buf = new StringBuilder();
for( String ext : extensions )
{
if( buf.length() != 0 )
{
buf.append( ", " );
}
buf.append( ext );
}
message = invalidFileExtensionMultiple.format( buf.toString() );
}
return Status.createWarningStatus( message );
}
}
}
}
final IFile fileHandle = op.getFile().target();
if( fileHandle != null && fileHandle.exists() && op.getOverwriteExistingFile().content() == false )
{
final String msg = fileExists.format( fileName );
return Status.factoryForLeaf().severity( Status.Severity.ERROR ).type( PROBLEM_FILE_EXISTS ).message( msg ).create();
}
}