587
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
package com.nokia.helium.sysdef;
|
|
18 |
import java.io.File;
|
|
19 |
import java.io.IOException;
|
|
20 |
|
|
21 |
import javax.xml.parsers.DocumentBuilder;
|
|
22 |
import javax.xml.parsers.DocumentBuilderFactory;
|
|
23 |
import javax.xml.parsers.ParserConfigurationException;
|
|
24 |
|
|
25 |
import org.w3c.dom.Document;
|
|
26 |
import org.xml.sax.SAXException;
|
|
27 |
|
|
28 |
/**
|
|
29 |
* This class implement the logic to parse package_map.xml files.
|
|
30 |
*
|
|
31 |
* Example of package_map.xml file:
|
|
32 |
* <code>
|
|
33 |
* <?xml version="1.0"?>
|
|
34 |
* <PackageMap root="sf" layer="app" />
|
|
35 |
* </code>
|
|
36 |
*
|
|
37 |
*/
|
|
38 |
public class PackageMap {
|
|
39 |
|
|
40 |
private String root;
|
|
41 |
private String layer;
|
|
42 |
|
|
43 |
/**
|
|
44 |
* Create a PackageMapParser by loading data from an XML file.
|
|
45 |
*
|
|
46 |
* @param file the file to parse
|
|
47 |
* @throws PackageMapParsingException in case of error
|
|
48 |
*/
|
|
49 |
public PackageMap(File file) throws PackageMapParsingException {
|
588
|
50 |
try {
|
|
51 |
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
|
52 |
Document doc = builder.parse(file);
|
|
53 |
if (!doc.getDocumentElement().getNodeName().equals("PackageMap")) {
|
628
|
54 |
throw new PackageMapParsingException("Invalid XML format for " + file.getAbsolutePath() + " root element must be PackageMap");
|
588
|
55 |
}
|
|
56 |
if (!doc.getDocumentElement().hasAttribute("root")) {
|
628
|
57 |
throw new PackageMapParsingException("root attribute under element " + doc.getDocumentElement().getTagName() + " is missing in file: " + file);
|
588
|
58 |
}
|
|
59 |
if (!doc.getDocumentElement().hasAttribute("layer")) {
|
628
|
60 |
throw new PackageMapParsingException("layer attribute under element " + doc.getDocumentElement().getTagName() + " is missing in file: " + file);
|
588
|
61 |
}
|
|
62 |
setRoot(doc.getDocumentElement().getAttribute("root"));
|
|
63 |
setLayer(doc.getDocumentElement().getAttribute("layer"));
|
587
|
64 |
} catch (ParserConfigurationException e) {
|
|
65 |
throw new PackageMapParsingException("Error from the XML parser configuration: " + e.getMessage(), e);
|
|
66 |
} catch (SAXException e) {
|
|
67 |
throw new PackageMapParsingException("Error parsing the file: " + file + ": " + e.getMessage(), e);
|
|
68 |
} catch (IOException e) {
|
|
69 |
throw new PackageMapParsingException(e.getMessage(), e);
|
|
70 |
}
|
|
71 |
}
|
|
72 |
|
|
73 |
public void setRoot(String root) {
|
|
74 |
this.root = root;
|
|
75 |
}
|
|
76 |
|
|
77 |
public String getRoot() {
|
|
78 |
return root;
|
|
79 |
}
|
|
80 |
|
|
81 |
public void setLayer(String layer) {
|
|
82 |
this.layer = layer;
|
|
83 |
}
|
|
84 |
|
|
85 |
public String getLayer() {
|
|
86 |
return layer;
|
|
87 |
}
|
|
88 |
}
|