49 public PackageMap(File file) throws PackageMapParsingException { |
49 public PackageMap(File file) throws PackageMapParsingException { |
50 try { |
50 try { |
51 DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
51 DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
52 Document doc = builder.parse(file); |
52 Document doc = builder.parse(file); |
53 if (!doc.getDocumentElement().getNodeName().equals("PackageMap")) { |
53 if (!doc.getDocumentElement().getNodeName().equals("PackageMap")) { |
54 throw new PackageMapParsingException("Invalid XML format for " + file.getAbsolutePath() + " root element must be PackageMap"); |
54 throw new PackageMapParsingException("Invalid XML format for " + file.getAbsolutePath() + " root element must be PackageMap"); |
55 } |
55 } |
56 if (!doc.getDocumentElement().hasAttribute("root")) { |
56 if (!doc.getDocumentElement().hasAttribute("root")) { |
57 throw new PackageMapParsingException("root attribute under element " + doc.getDocumentElement().getTagName() + " is missing in file: " + file); |
57 throw new PackageMapParsingException("root attribute under element " + doc.getDocumentElement().getTagName() + " is missing in file: " + file); |
58 } |
58 } |
59 if (!doc.getDocumentElement().hasAttribute("layer")) { |
59 if (!doc.getDocumentElement().hasAttribute("layer")) { |
60 throw new PackageMapParsingException("layer attribute under element " + doc.getDocumentElement().getTagName() + " is missing in file: " + file); |
60 throw new PackageMapParsingException("layer attribute under element " + doc.getDocumentElement().getTagName() + " is missing in file: " + file); |
61 } |
61 } |
62 setRoot(doc.getDocumentElement().getAttribute("root")); |
62 setRoot(doc.getDocumentElement().getAttribute("root")); |
63 setLayer(doc.getDocumentElement().getAttribute("layer")); |
63 setLayer(doc.getDocumentElement().getAttribute("layer")); |
64 } catch (ParserConfigurationException e) { |
64 } catch (ParserConfigurationException e) { |
65 throw new PackageMapParsingException("Error from the XML parser configuration: " + e.getMessage(), e); |
65 throw new PackageMapParsingException("Error from the XML parser configuration: " + e.getMessage(), e); |