// Map result = Collections.EMPTY_MAP;
ParameterMap parameterMap = new ParameterMap();
String encodedName = null;
CharBuffer buffer = new CharBuffer(50);
int pos = 0;
int len = queryString.length();
int state = LOOKUP;
while (true)
{
char c;
if (pos < len)
{
c = queryString.charAt(pos++);
}
else if (pos == len)
{
c = '&';
pos++;
}
else
{
break;
}
//
switch(state)
{
case LOOKUP:
if (c == '&')
{
// Do nothing
}
else if (c == '=')
{
state = INVALID_CHUNK;
}
else
{
state = PARAM_NAME;
buffer.append(c);
}
break;
case PARAM_NAME:
if (c == '&')
{
String tmp = buffer.asString();
//
try
{
parameterDecoder.encode(tmp, buffer);
append(parameterMap, buffer.asString(false), "");
}
catch (EncodingException e)
{
log.debug("Could not decode parameter name " + tmp, e);
}
//
buffer.reset();
state = LOOKUP;
}
else if (c == '=')
{
encodedName = buffer.asString();
buffer.reset();
state = PARAM_VALUE;
}
else
{
buffer.append(c);
}
break;
case PARAM_VALUE:
if (c == '&')
{
//
try
{
// Save value
String encodedValue = buffer.asString();
// Decode parameter name
parameterDecoder.encode(encodedName, buffer);
String name = buffer.asString(false);
// Now decode parameter value
try
{
buffer.reset();
parameterDecoder.encode(encodedValue, buffer);
String value = buffer.asString();
append(parameterMap, name, value);
}
catch (EncodingException e)
{
log.debug("Could not decode parameter value " + encodedValue, e);
}
}
catch (EncodingException e)
{
log.debug("Could not decode parameter name " + encodedName, e);
}
//
buffer.reset();
state = LOOKUP;
}
else
{
buffer.append(c);
}
break;
case INVALID_CHUNK:
if (c == '&')
{