Fixed a bug in the repo XML reader

This commit is contained in:
Ciaran Gultnieks 2010-11-12 08:54:42 +00:00
parent e2c7ca10dc
commit 6477be4c6c

View File

@ -47,7 +47,7 @@ public class RepoXMLHandler extends DefaultHandler {
private DB.App curapp = null; private DB.App curapp = null;
private DB.Apk curapk = null; private DB.Apk curapk = null;
private String curel = null; private String curchars = null;
public RepoXMLHandler(String srv, DB db) { public RepoXMLHandler(String srv, DB db) {
mserver = srv; mserver = srv;
@ -61,7 +61,30 @@ public class RepoXMLHandler extends DefaultHandler {
super.characters(ch, start, length); super.characters(ch, start, length);
String str = new String(ch).substring(start, start + length); String str = new String(ch).substring(start, start + length);
if (curapk != null && curel != null) { if(curchars == null)
curchars = str;
else
curchars += str;
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
super.endElement(uri, localName, qName);
String curel = localName;
String str = curchars;
if (curel == "application" && curapp != null) {
Log.d("FDroid", "Repo: Updating application " + curapp.id);
db.updateApplication(curapp);
getIcon(curapp);
curapp = null;
} else if (curel == "package" && curapk != null && curapp != null) {
Log.d("FDroid", "Repo: Package added (" + curapk.version + ")");
curapp.apks.add(curapk);
curapk = null;
} else if (curapk != null && str!= null) {
if (curel == "version") { if (curel == "version") {
curapk.version = str; curapk.version = str;
} else if (curel == "versioncode") { } else if (curel == "versioncode") {
@ -81,8 +104,9 @@ public class RepoXMLHandler extends DefaultHandler {
} else if (curel == "apkname") { } else if (curel == "apkname") {
curapk.apkName = str; curapk.apkName = str;
} }
} else if (curapp != null && curel != null) { } else if (curapp != null && str != null) {
if (curel == "id") { if (curel == "id") {
Log.d("FDroid","App id is " + str);
curapp.id = str; curapp.id = str;
} else if (curel == "name") { } else if (curel == "name") {
curapp.name = str; curapp.name = str;
@ -110,26 +134,6 @@ public class RepoXMLHandler extends DefaultHandler {
} }
} }
} }
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
super.endElement(uri, localName, qName);
if (localName == "application" && curapp != null) {
Log.d("FDroid", "Repo: Updating application " + curapp.id);
db.updateApplication(curapp);
getIcon(curapp);
curapp = null;
} else if (localName == "package" && curapk != null && curapp != null) {
Log.d("FDroid", "Repo: Package added (" + curapk.version + ")");
curapp.apks.add(curapk);
curapk = null;
} else {
curel = null;
}
} }
@ -146,9 +150,8 @@ public class RepoXMLHandler extends DefaultHandler {
curapk = new DB.Apk(); curapk = new DB.Apk();
curapk.id = curapp.id; curapk.id = curapp.id;
curapk.server = mserver; curapk.server = mserver;
} else {
curel = localName;
} }
curchars = null;
} }
private void getIcon(DB.App app) { private void getIcon(DB.App app) {