voxforge.org
VoxForge Dev

Changeset 2328

Show
Ignore:
Timestamp:
10/11/07 21:28:09 (11 months ago)
Author:
kmaclean
Message:

fix ticket #262 Validate username

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Trunk/SpeechSubmission/VFSpeechSubmission/java/src/speechrecorder/CapturePlayback.java

    r2327 r2328  
    6565import speechrecorder.License; 
    6666import speechrecorder.Prompts; 
     67import java.util.regex.Matcher; 
     68import java.util.regex.Pattern; 
    6769// !!!!!! 
    6870 
     
    266268     
    267269    public static final String pleaseSelect = "Please Select"; 
     270    public static final String notApplicable = "unknown"; 
    268271     
    269272    JComboBox ageRangeChooser;  
     
    271274    public static final String adult = "Adult";  
    272275    public static final String senior = "Senior";  
    273     String ageRange = adult
     276    String ageRange = notApplicable
    274277     
    275278    JComboBox genderChooser;        
    276279    public static final String male = "Male";     
    277280    public static final String female = "Female"; 
    278     String gender = male; 
     281    String gender = notApplicable; 
    279282     
    280283    JComboBox dialectChooser;      
     
    287290    public static final String southafrican = "South African English";      
    288291    public static final String otherDialect = "Other"; 
    289     String dialect = american
     292    String dialect = notApplicable
    290293     
    291294    JComboBox microphoneChooser;      
     
    296299    public static final String studio = "Studio mic";  
    297300    public static final String otherMic = "Other";  
    298     String microphone = headset;     
     301    String microphone = notApplicable;     
    299302// !!!!!!       
    300303    String fileFieldName; 
     
    481484        //p2.setBorder(sbb); 
    482485        p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); 
    483 //      ###########################################################               
    484486//      ############ User name ####################################              
    485487//      userName is read when user clicks Upload 
     
    488490         usernamePanel.add(new JLabel("Username:")); 
    489491         usernamePanel.add(usernameTextField = new JTextField(20)); 
    490          usernamePanel.add(new JLabel("(leave blank to submit anonymously)"));              
     492         usernamePanel.add(new JLabel("(leave blank to submit anonymously)"));      
     493          
    491494         p2.add(usernamePanel);   
    492495// ############ Gender ####################################              
     
    506509                         gender = (female); 
    507510                     }else if(choice.equals(pleaseSelect)){ 
    508                          gender = ("n/a"); 
     511                         gender = (notApplicable); 
     512                     }else { 
     513                         gender = (notApplicable); 
    509514                     } 
    510515                 } 
     
    529534                         ageRange = (senior); 
    530535                     }else if(choice.equals(pleaseSelect)){ 
    531                          ageRange = ("n/a"); 
     536                         ageRange = (notApplicable); 
     537                     }else { 
     538                         ageRange = (notApplicable); 
    532539                     } 
    533540                 } 
     
    561568                         dialect = (otherDialect); 
    562569                     }else if(choice.equals(pleaseSelect)){ 
    563                          dialect = ("n/a"); 
     570                         dialect = (notApplicable); 
     571                     }else { 
     572                         dialect = (notApplicable); 
    564573                     } 
    565574                 } 
    566575                 }); 
     576        dialectPanel.add(new JLabel("(mother tongue)"));  
    567577        p2.add(dialectPanel); 
    568578 
     
    591601                         microphone = (otherMic); 
    592602                     }else if(choice.equals(pleaseSelect)){ 
    593                          microphone = ("n/a"); 
     603                         microphone = (notApplicable); 
     604                     }else { 
     605                         microphone = (notApplicable); 
    594606                     } 
    595607                 } 
     
    739751         //progBar.setVisible(false); 
    740752         p2.add(progBar);                
    741  
    742753// ############ More Information Button ####################################           
    743754         JPanel moreInfoButtonPanel = new JPanel(); 
     
    754765                 +"This program comes with ABSOLUTELY NO WARRANTY; without even the implied<br> " 
    755766                 +"warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  For<br>"  
    756                  +"details click the \"About\" button:"; 
     767                 +"more details click the \"About\" button:"; 
    757768         DisclaimerInnerPanel.add(new JLabel(DisclaimerText)); 
    758769         aboutB = addButton("About", DisclaimerInnerPanel, true);  
     
    761772         DisclaimerPanel.add(DisclaimerInnerPanel);         
    762773        p2.add(DisclaimerPanel);  
    763 //      #########################################################################    
     774//#########################################################################    
    764775        add(p2); 
    765776    } 
     
    13261337                aboutB.setEnabled(true);  
    13271338                capt8.setEnabled(true); 
    1328                  
    1329  
    13301339            } 
    13311340          }     
     
    15051514                
    15061515               uploadB.setEnabled(false);                
    1507 // !!!!!!                 
    15081516                try { 
    15091517                   usernameTextField.selectAll(); 
     
    15111519                   if (userName.length() == 0 ) { 
    15121520                       userName = "anonymous"; 
     1521                   } else { 
     1522                // !!!!!!          
     1523                // see   java.util.regex.Pattern 
     1524                //         \w   A word character: [a-zA-Z_0-9] 
     1525                //         \W   A non-word character: [^\w] 
     1526                   userName = (usernameTextField.getText().replaceAll("\\W","")).substring(0,25); 
    15131527                   } 
     1528// !!!!!!                   
    15141529                } catch (NullPointerException ex) {  
    15151530               userName = "anonymous"; 
     
    15171532           convertAndUpload.start(); 
    15181533        } 
     1534//      ################### More Information #######################################      
    15191535        else if (obj.equals(moreInfoB)) { 
    15201536             JTextArea textArea = new JTextArea(license); 
     
    15291545                    "More info on Copyright and GPL license", JOptionPane.PLAIN_MESSAGE); 
    15301546        } 
     1547//      ################### About #######################################  
    15311548        else if (obj.equals(aboutB)) { 
    15321549            JTextArea textArea = new JTextArea(VFlicense); 
     
    22222239        out_readme.write("Sample rate format: " + samplingRateFormat + System.getProperty("line.separator")); 
    22232240        out_readme.write("Number of channels: " + numberChannels + System.getProperty("line.separator"));        
    2224         out_readme.write(System.getProperty("line.separator")); 
    2225          
    2226         out_readme.write("License Info:" + System.getProperty("line.separator"));        
    2227         out_readme.write(System.getProperty("line.separator")); 
    2228         out_readme.write("Copyright name: " + copyrightName + System.getProperty("line.separator")); 
    2229         out_readme.write("Accepted that speech be covered by the GPL license: " + gplAccepted + System.getProperty("line.separator")); 
    22302241         
    22312242        out_readme.close();