------------------------------------------------------------
revno: 5104
committer: Bob Jolliffe [email protected]
branch nick: dhis2
timestamp: Thu 2011-11-03 14:36:56 +0000
message:
  Minor modification to uid code generator to ensure codes don't start with a 
number.  This is to make them compatible with xml:id spec.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/CodeGenerator.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to 
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/CodeGenerator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/CodeGenerator.java	2011-10-23 20:18:55 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/CodeGenerator.java	2011-11-03 14:36:56 +0000
@@ -34,8 +34,10 @@
  */
 public class CodeGenerator
 {
-    public static final String allowedChars = "0123456789" + "abcdefghijklmnopqrstuvwxyz"
+    public static final String letters = "abcdefghijklmnopqrstuvwxyz"
         + "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+    
+    public static final String allowedChars = "0123456789" + letters;
 
     public static final int NUMBER_OF_CODEPOINTS = allowedChars.length();
     public static final int CODESIZE = 11;
@@ -51,7 +53,11 @@
         SecureRandom sr = new SecureRandom();
 
         char[] randomChars = new char[CODESIZE];
-        for ( int i = 0; i < CODESIZE; ++i )
+        
+        // first char should be a letter
+        randomChars[0] = letters.charAt( sr.nextInt( letters.length() ) );
+        
+        for ( int i = 1; i < CODESIZE; ++i )
         {
             randomChars[i] = allowedChars.charAt( sr.nextInt( NUMBER_OF_CODEPOINTS ) );
         }

_______________________________________________
Mailing list: https://launchpad.net/~dhis2-devs
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~dhis2-devs
More help   : https://help.launchpad.net/ListHelp

Reply via email to