private static OSD ParseLLSDXmlElement(Node reader) throws OSDException, URISyntaxException
{
if (reader.getNodeType() != Node.ELEMENT_NODE)
throw new OSDException("Expected an element");
String type = reader.getNodeName();
OSD ret;
////System.out.println("Parsing Element..." + type);
if(type.equals("undef"))
{
if (!reader.hasChildNodes())
{
return new OSD();
}
ret = new OSD();
}
else if(type.equals("boolean"))
{
if (!reader.hasChildNodes())
{
return OSD.FromBoolean(false);
}
String s = reader.getFirstChild().getNodeValue().trim();
if (s.equals("true") || s.equals("1"))
ret = OSD.FromBoolean(true);
else
ret = OSD.FromBoolean(false);
}
else if(type.equals("integer"))
{
if (!reader.hasChildNodes())
{
return OSD.FromInteger(0);
}
String s = reader.getFirstChild().getNodeValue().trim();
int[] result = new int[1];
if(Utils.tryParseInt(s, result))
{
ret = OSD.FromInteger(result[0]);
}
else
ret = OSD.FromInteger(0);
}
else if(type.equals("real"))
{
if (!reader.hasChildNodes())
{
return OSD.FromReal(0d);
}
double[] value = new double[]{0d};
String s = reader.getFirstChild().getNodeValue().trim().toLowerCase();
if (s.equals("nan"))
value[0] = Double.NaN;
else
Utils.tryParseDouble(s, value);
ret = OSD.FromReal(value[0]);
}
else if(type.equals("uuid"))
{
if (!reader.hasChildNodes())
{
return OSD.FromUUID(UUID.Zero);
}
UUID[] value = new UUID[]{UUID.Zero};
String s = reader.getFirstChild().getNodeValue().trim();
UUID.TryParse(s, value);
ret = OSD.FromUUID(value[0]);
}
else if(type.equals("date"))
{
if (!reader.hasChildNodes())
{
return OSD.FromDate(Utils.Epoch);
}
Date[] value = new Date[]{Utils.Epoch};
String s = reader.getFirstChild().getNodeValue().trim();
Utils.tryParseDate(s, value);
ret = OSD.FromDate(value[0]);
}
else if(type.equals("string"))
{
if (!reader.hasChildNodes())
{
return OSD.FromString("");
}
String s = reader.getFirstChild().getNodeValue().trim();
ret = OSD.FromString(s);
}
else if(type.equals("binary"))
{
if (!reader.hasChildNodes())
{
return OSD.FromBinary(Utils.EmptyBytes);
}
NamedNodeMap namedNodeMap = reader.getAttributes();
Node attr = namedNodeMap.getNamedItem("encoding");
if (attr != null && !attr.getNodeValue().equals("base64"))
throw new OSDException("Unsupported binary encoding: " + attr.getNodeValue());
try
{
String s = reader.getFirstChild().getNodeValue().trim();
byte[] bytes = Utils.decodeBase64String(s);
ret = OSD.FromBinary(bytes);
}
catch (Exception ex)
{
throw new OSDException("Binary decoding exception: " + ex.getMessage());
}
}
else if(type.equals("uri"))
{