01: package de.latlon.deejump.plugin.manager;
02:
03: import java.io.IOException;
04: import java.net.URL;
05: import java.util.ArrayList;
06: import java.util.List;
07:
08: import javax.xml.parsers.DocumentBuilder;
09: import javax.xml.parsers.DocumentBuilderFactory;
10: import javax.xml.parsers.ParserConfigurationException;
11:
12: import org.w3c.dom.Document;
13: import org.w3c.dom.Element;
14: import org.w3c.dom.NodeList;
15: import org.xml.sax.SAXException;
16:
17: public class CatalogParser {
18:
19: private URL catalog;
20:
21: public CatalogParser(URL catalog) {
22: this .catalog = catalog;
23: }
24:
25: public List getExtensionList() {
26:
27: List tmpRemoteExtensions = new ArrayList(50);
28:
29: // System.out.println("found remote ext: " );
30:
31: try {
32: DocumentBuilder docBuilder;
33: docBuilder = DocumentBuilderFactory.newInstance()
34: .newDocumentBuilder();
35:
36: Document doc = docBuilder.parse(catalog.openStream());
37: NodeList extNodes = doc.getDocumentElement()
38: .getElementsByTagName("Extension");
39: for (int i = 0; i < extNodes.getLength(); i++) {
40: Element ext = (Element) extNodes.item(i);
41:
42: String name = ext.getAttribute("name");
43: String title = ext.getAttribute("title");
44: String author = ext.getAttribute("author");
45: String version = ext.getAttribute("version");
46: String jumpVersion = ext.getAttribute("jumpVersion");
47: String category = ext.getAttribute("category");
48:
49: String descrip = ext
50: .getElementsByTagName("Description").item(0)
51: .getFirstChild().getNodeValue();
52:
53: NodeList resources = ((Element) ext
54: .getElementsByTagName("ResourceList").item(0))
55: .getElementsByTagName("Resource");
56:
57: List resourcesList = new ArrayList(resources
58: .getLength());
59: for (int j = 0; j < resources.getLength(); j++) {
60: Element resource = (Element) resources.item(j);
61: resourcesList.add(resource.getAttribute("value"));
62: }
63:
64: ExtensionWrapper catExtension = new ExtensionWrapper(
65: name, title, author, version, jumpVersion,
66: category, descrip, resourcesList);
67:
68: tmpRemoteExtensions.add(catExtension);
69: // System.out.println( catExtension );
70:
71: }
72:
73: // DOMPrinter.printNode(System.out, doc);
74:
75: } catch (ParserConfigurationException e) {
76: e.printStackTrace();
77: } catch (IOException e) {
78: e.printStackTrace();
79: } catch (SAXException e) {
80: e.printStackTrace();
81: }
82: return tmpRemoteExtensions;
83: }
84:
85: }
|