1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.captcha.modules.jcaptcha.service.sound;
35
36 import fr.paris.lutece.portal.service.util.AppPathService;
37
38 import java.io.File;
39
40 import java.util.ArrayList;
41 import java.util.List;
42
43
44
45
46
47
48 public class LuteceBackgroundSoundMixerConfigurator
49 {
50 private static final String STRING_SLASH = "/";
51 private static final String WAV_EXTENSION = ".wav";
52 private static final String JCAPTCHA_SOUND_DIRECTORY = "jcaptcha.sound.directory";
53 private float _attenuationValue;
54 private File [ ] _backgroundSoundFiles = new File [ 0];
55
56
57
58
59
60
61
62
63 public LuteceBackgroundSoundMixerConfigurator( int attenuationValue, String... backGroundFileNames )
64 {
65 _attenuationValue = attenuationValue / 100f;
66
67 String soundFolder = AppPathService.getPath( JCAPTCHA_SOUND_DIRECTORY );
68 List<File> tempFileList = new ArrayList<File>( );
69 File soundFile;
70
71 for ( int i = 0; i < backGroundFileNames.length; i++ )
72 {
73 soundFile = new File( soundFolder + STRING_SLASH + backGroundFileNames [i] + WAV_EXTENSION );
74
75 if ( soundFile.exists( ) )
76 {
77 tempFileList.add( soundFile );
78 }
79 }
80
81 _backgroundSoundFiles = (File [ ]) tempFileList.toArray( _backgroundSoundFiles );
82 }
83
84
85
86
87
88 public float getAttenuationValue( )
89 {
90 return _attenuationValue;
91 }
92
93
94
95
96
97 public File getRandomBackgroundFile( )
98 {
99 int randomFileInt = (int) Math.rint( _backgroundSoundFiles.length * Math.random( ) );
100
101 if ( randomFileInt >= _backgroundSoundFiles.length )
102 {
103 randomFileInt = _backgroundSoundFiles.length - 1;
104 }
105
106 return _backgroundSoundFiles [randomFileInt];
107 }
108 }