String bsn = bundleElement.getAttribute("bsn");
List<Comment> comments = new LinkedList<Comment>();
for (Element commentElement: XmlUtils.findElements("comments/comment", bundleElement)) {
comments.add(new Comment(Rating.fromInt(new Integer(commentElement.getAttribute("rating"))), commentElement.getAttribute("comment"), dateFormat.parse(commentElement.getAttribute("date"))));
}
Bundle bundle = new Bundle(bundleElement.getAttribute("bsn"), new Float(bundleElement.getAttribute("uaa-ranking")).floatValue(), comments);
for (Element versionElement: XmlUtils.findElements("versions/version", bundleElement)) {
if (bsn != null && bsn.length() > 0 && versionElement != null) {
String signedBy = "";
String pgpKey = versionElement.getAttribute("pgp-key-id");
if (pgpKey != null && pgpKey.length() > 0) {
Element pgpSigned = XmlUtils.findFirstElement("/roobot/pgp-keys/pgp-key[@id='" + pgpKey + "']/pgp-key-description", roobotXml.getDocumentElement());
if (pgpSigned != null) {
signedBy = pgpSigned.getAttribute("text");
}
}
Map<String, String> commands = new HashMap<String, String>();
for (Element shell : XmlUtils.findElements("shell-commands/shell-command", versionElement)) {
commands.put(shell.getAttribute("command"), shell.getAttribute("help"));
}
StringBuilder versionBuilder = new StringBuilder();
versionBuilder.append(versionElement.getAttribute("major")).append(".").append(versionElement.getAttribute("minor"));
String versionMicro = versionElement.getAttribute("micro");
if (versionMicro != null && versionMicro.length() > 0) {
versionBuilder.append(".").append(versionMicro);
}
String versionQualifier = versionElement.getAttribute("qualifier");
if (versionQualifier != null && versionQualifier.length() > 0) {
versionBuilder.append(".").append(versionQualifier);
}
String rooVersion = versionElement.getAttribute("roo-version");
if (rooVersion.equals("*") || rooVersion.length() == 0) {
rooVersion = getVersionForCompatibility();
} else {
String[] split = rooVersion.split("\\.");
if (split.length > 2) {
//only interested in major.minor
rooVersion = split[0] + "." + split[1];
}
}
BundleVersion version = new BundleVersion(versionElement.getAttribute("url"), versionElement.getAttribute("obr-url"), versionBuilder.toString(), versionElement.getAttribute("name"), new Long(versionElement.getAttribute("size")).longValue(), versionElement.getAttribute("description"), pgpKey, signedBy, rooVersion, commands);
// For security reasons we ONLY accept httppgp:// add-on versions
if (!version.getUri().startsWith("httppgp://")) {
continue;
}
bundle.addVersion(version);
}
bundleCache.put(bsn, bundle);
}
}
success = true;