# HG changeset patch # User Da Risk # Date 1299343481 -3600 # Node ID 2236fe5b2db178d4a8e7e4fde96043ba19efb45c # Parent d051db285d7e7ee96d233e4b2a18ab181afe484a Improve robustness of AvatarMetadata parser. diff -r d051db285d7e -r 2236fe5b2db1 src/com/beem/project/beem/smack/avatar/AvatarMetadataProvider.java --- a/src/com/beem/project/beem/smack/avatar/AvatarMetadataProvider.java Sat Feb 26 16:47:59 2011 +0100 +++ b/src/com/beem/project/beem/smack/avatar/AvatarMetadataProvider.java Sat Mar 05 17:44:41 2011 +0100 @@ -70,16 +70,34 @@ int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { if ("info".equals(parser.getName())) { - int bytes = Integer.parseInt(parser.getAttributeValue(null, "bytes")); - int height = Integer.parseInt(parser.getAttributeValue(null, "height")); - int width = Integer.parseInt(parser.getAttributeValue(null, "width")); String id = parser.getAttributeValue(null, "id"); String type = parser.getAttributeValue(null, "type"); + String sbytes = parser.getAttributeValue(null, "bytes"); + String sheight = parser.getAttributeValue(null, "height"); + String swidth = parser.getAttributeValue(null, "width"); + int bytes = 0; + AvatarMetadataExtension.Info info = null; + try { + if (sbytes != null) + bytes = Integer.parseInt(sbytes); + } catch (NumberFormatException e) { } + if (bytes != 0 && id != null && type != null) + info = new AvatarMetadataExtension.Info(id, type, bytes); + else // invalid info + continue; + String url = parser.getAttributeValue(null, "url"); - AvatarMetadataExtension.Info info = new AvatarMetadataExtension.Info(id, type, bytes); - info.setHeight(height); - info.setWidth(width); info.setUrl(url); + try { + int height = 0; + int width = 0; + if (sheight != null) + height = Integer.parseInt(parser.getAttributeValue(null, "height")); + if (swidth != null) + width = Integer.parseInt(parser.getAttributeValue(null, "width")); + info.setHeight(height); + info.setWidth(width); + } catch (NumberFormatException e) { } metadata.addInfo(info); } } else if (eventType == XmlPullParser.END_TAG) {