package org.openas2.params;

import java.text.DecimalFormat;
import java.util.Random;
import java.util.UUID;

public class RandomParameters extends ParameterParser {
    public void setParameter(String key, String value) throws InvalidParameterException {
        throw new InvalidParameterException("Set not supported", this, key, value);
    }

    public String getParameter(String key) throws InvalidParameterException {
        if (key == null) {
            throw new InvalidParameterException("Invalid key", this, key, null);
        }
        if ("uuid".equalsIgnoreCase(key))
        {
        	return UUID.randomUUID().toString();
        }
        int wanted = key.length();
        String fmt = "";
        int max = 1;
        
        while (wanted-- > 0) {
        	fmt += "0";
        	max *= 10;
        }

        DecimalFormat randomFormatter = new DecimalFormat(fmt);
        return randomFormatter.format(new Random().nextInt(max));
    }
}
 	  	 

@@ -24,16 +24,65 @@
 ams;%0D%0A%0D%0A
+import org.bouncycastle.util.encoders.Base64;%0D%0A%0D%0A
 import j
@@ -155,16 +155,45 @@
 l.UUID;%0D
+%0Aimport java.nio.ByteBuffer;%0D
 %0A%0D%0Apubli
@@ -670,25 +670,16 @@
 se(key))
-%0D%0A       
  %7B%0D%0A    
@@ -724,32 +724,136 @@
 ();%0D%0A        %7D%0D%0A
+        if (%22shortUUID%22.equalsIgnoreCase(key)) %7B%0D%0A            return getRandomBase62UUID();%0D%0A        %7D%0D%0A
         int want
@@ -1157,16 +1157,1253 @@
 %0A    %7D%0D%0A
+    %0D%0A    private static String getRandomBase62UUID() %7B%0D%0A        UUID uuid = UUID.randomUUID();%0D%0A        ByteBuffer uuidBytes = ByteBuffer.wrap(new byte%5B16%5D);%0D%0A        uuidBytes.putLong(uuid.getMostSignificantBits()); %0D%0A        uuidBytes.putLong(uuid.getLeastSignificantBits());%0D%0A        return base64ToBase62(Base64.toBase64String(uuidBytes.array()));%0D%0A    %7D%0D%0A        %0D%0A    private static String base64ToBase62(String base64String) %7B        %0D%0A        StringBuffer buffer = new StringBuffer(base64String.length() * 2);%0D%0A        for (int i = 0; i %3C base64String.length(); i++) %7B%0D%0A            char c = base64String.charAt(i);%0D%0A            switch (c) %7B%0D%0A                case 'i':%0D%0A                    buffer.append(%22ii%22);%0D%0A                break;%0D%0A                case '+':%0D%0A                    buffer.append(%22ip%22);%0D%0A                break;%0D%0A                case '/':%0D%0A                    buffer.append(%22is%22);%0D%0A                break;   %0D%0A                case '=':%0D%0A                    buffer.append(%22ie%22);%0D%0A                break;%0D%0A                case '%5Cn':%0D%0A                    // Skip%0D%0A                break;%0D%0A                default:%0D%0A                    buffer.append(c);%0D%0A            %7D%0D%0A        %7D%0D%0A        return buffer.toString();%0D%0A    
 %7D%0D%0A %09  %09
@@ -2405,8 +2405,11 @@
  %09  %09 %0D%0A
+%7D%0D%0A

Add short UUID random parameter (#77)