|
20 | 20 |
|
21 | 21 | import org.apache.hadoop.classification.InterfaceAudience; |
22 | 22 | import org.apache.hadoop.conf.Configuration; |
23 | | -import org.w3c.dom.DOMException; |
24 | | -import org.w3c.dom.Document; |
25 | | -import org.w3c.dom.Element; |
26 | | -import org.w3c.dom.Node; |
27 | | -import org.w3c.dom.NodeList; |
28 | | -import org.w3c.dom.Text; |
29 | | -import org.xml.sax.SAXException; |
30 | 23 |
|
31 | | -import javax.xml.parsers.DocumentBuilder; |
32 | | -import javax.xml.parsers.DocumentBuilderFactory; |
33 | | -import javax.xml.parsers.ParserConfigurationException; |
34 | 24 | import java.io.IOException; |
35 | 25 | import java.io.InputStream; |
36 | 26 | import java.util.Map; |
@@ -98,62 +88,6 @@ public static Configuration resolve(Configuration conf) { |
98 | 88 | * @throws IOException thrown if the configuration could not be read. |
99 | 89 | */ |
100 | 90 | public static void load(Configuration conf, InputStream is) throws IOException { |
101 | | - try { |
102 | | - DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); |
103 | | - // ignore all comments inside the xml file |
104 | | - docBuilderFactory.setIgnoringComments(true); |
105 | | - DocumentBuilder builder = docBuilderFactory.newDocumentBuilder(); |
106 | | - Document doc = builder.parse(is); |
107 | | - parseDocument(conf, doc); |
108 | | - } catch (SAXException e) { |
109 | | - throw new IOException(e); |
110 | | - } catch (ParserConfigurationException e) { |
111 | | - throw new IOException(e); |
112 | | - } |
113 | | - } |
114 | | - |
115 | | - // Canibalized from FileSystemAccess <code>Configuration.loadResource()</code>. |
116 | | - private static void parseDocument(Configuration conf, Document doc) throws IOException { |
117 | | - try { |
118 | | - Element root = doc.getDocumentElement(); |
119 | | - if (!"configuration".equals(root.getTagName())) { |
120 | | - throw new IOException("bad conf file: top-level element not <configuration>"); |
121 | | - } |
122 | | - NodeList props = root.getChildNodes(); |
123 | | - for (int i = 0; i < props.getLength(); i++) { |
124 | | - Node propNode = props.item(i); |
125 | | - if (!(propNode instanceof Element)) { |
126 | | - continue; |
127 | | - } |
128 | | - Element prop = (Element) propNode; |
129 | | - if (!"property".equals(prop.getTagName())) { |
130 | | - throw new IOException("bad conf file: element not <property>"); |
131 | | - } |
132 | | - NodeList fields = prop.getChildNodes(); |
133 | | - String attr = null; |
134 | | - String value = null; |
135 | | - for (int j = 0; j < fields.getLength(); j++) { |
136 | | - Node fieldNode = fields.item(j); |
137 | | - if (!(fieldNode instanceof Element)) { |
138 | | - continue; |
139 | | - } |
140 | | - Element field = (Element) fieldNode; |
141 | | - if ("name".equals(field.getTagName()) && field.hasChildNodes()) { |
142 | | - attr = ((Text) field.getFirstChild()).getData().trim(); |
143 | | - } |
144 | | - if ("value".equals(field.getTagName()) && field.hasChildNodes()) { |
145 | | - value = ((Text) field.getFirstChild()).getData(); |
146 | | - } |
147 | | - } |
148 | | - |
149 | | - if (attr != null && value != null) { |
150 | | - conf.set(attr, value); |
151 | | - } |
152 | | - } |
153 | | - |
154 | | - } catch (DOMException e) { |
155 | | - throw new IOException(e); |
156 | | - } |
| 91 | + conf.addResource(is); |
157 | 92 | } |
158 | | - |
159 | 93 | } |
0 commit comments