1
package org.herac.tuxguitar.gui.items.xml;
4
import java.io.IOException;
5
import java.util.ArrayList;
8
import javax.xml.parsers.DocumentBuilder;
9
import javax.xml.parsers.DocumentBuilderFactory;
10
import javax.xml.parsers.ParserConfigurationException;
12
import org.w3c.dom.Document;
13
import org.w3c.dom.NamedNodeMap;
14
import org.w3c.dom.Node;
15
import org.w3c.dom.NodeList;
16
import org.xml.sax.SAXException;
18
public class ToolBarsReader {
19
private static final String ITEM_LIST_TAG = "toolbars";
20
private static final String ITEM_TAG = "toolbar";
21
private static final String NAME_ATTRIBUTE = "name";
23
public List loadToolBars(File file){
24
List items = new ArrayList();
27
Document doc = getDocument(file);
28
loadToolBars(items,doc.getFirstChild());
29
} catch (ParserConfigurationException e) {
31
} catch (SAXException e) {
33
} catch (IOException e) {
35
} catch (Exception e) {
45
private static Document getDocument(File file) throws ParserConfigurationException, SAXException, IOException {
46
Document document = null;
47
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
49
DocumentBuilder builder = factory.newDocumentBuilder();
50
document = builder.parse(file);
56
private static void loadToolBars(List items,Node node){
57
NodeList listNode = node.getChildNodes();
58
for (int i = 0; i < listNode.getLength(); i++) {
59
Node child = listNode.item(i);
60
String nameNode = child.getNodeName();
62
if (nameNode.equals(ITEM_TAG)) {
63
NamedNodeMap params = child.getAttributes();
65
String name = params.getNamedItem(NAME_ATTRIBUTE).getNodeValue();
66
if (name == null || name.trim().length() == 0){
67
System.err.println("Invalid ToolBar name.");