* This converts all the extensions into objects using information from their config.xml and returns an array.
*
* @return A list of extensions that are loaded or an empty list of no extension is loaded successfully.
*/
public ArrayList loadExtensions() {
KXmlParser parser = new KXmlParser();
ArrayList extList = new ArrayList();
File[] extensions = mDirectory.listFiles(new FileFilter() {
public boolean accept(File file) {
return file.isDirectory();
}
});
int i;
try {
for (i = 0; i < extensions.length; i++) {
File ext = extensions[i];
KindleLauncher.LOG.info("Loading: " + ext.getAbsolutePath());
File config = new File(ext, "config.xml");
Extension extObj = new Extension();
parser.setInput(new InputStreamReader(new FileInputStream(config)));
parser.nextTag();
parser.require(XmlPullParser.START_TAG, null, "extension");
while (parser.nextTag() != XmlPullParser.END_TAG) {
parser.require(XmlPullParser.START_TAG, null, null);
String name = parser.getName();
if (name.equals("information"))
parseInformation(parser, extObj);
else if (name.equals("menus"))
parseMenus(parser, extObj, ext);
else //skip
while (parser.next() != XmlPullParser.END_TAG || !parser.getName().equals(name))
; // this one line does magic to skip all unrelated events
parser.require(XmlPullParser.END_TAG, null, name);
}
parser.require(XmlPullParser.END_TAG, null, "extension");
parser.next();
parser.require(XmlPullParser.END_DOCUMENT, null, null);
extList.add(extObj);
KindleLauncher.LOG.info(LOADED_EXTENSION, new String[]{extObj.getName(), extObj.getVersion(), extObj.getAuthor(), extObj.getId()}, "");
}
} catch (IOException e) {
KindleLauncher.LOG.error("Error reading extension config. " + e.getMessage());