Пример #1
0
 // Canibalized from Hadoop <code>Configuration.loadResource()</code>.
 private void parseDocument(Document doc) throws IOException {
   Element root = doc.getDocumentElement();
   if (!"configuration".equals(root.getTagName())) {
     throw new IOException("bad conf file: top-level element not <configuration>");
   }
   processNodes(root);
 }
Пример #2
0
  // Canibalized from Hadoop <code>Configuration.loadResource()</code>.
  private void processNodes(Element root) throws IOException {
    try {
      NodeList props = root.getChildNodes();
      for (int i = 0; i < props.getLength(); i++) {
        Node propNode = props.item(i);
        if (!(propNode instanceof Element)) {
          continue;
        }
        Element prop = (Element) propNode;
        if (prop.getTagName().equals("configuration")) {
          processNodes(prop);
          continue;
        }
        if (!"property".equals(prop.getTagName())) {
          throw new IOException("bad conf file: element not <property>");
        }
        NodeList fields = prop.getChildNodes();
        String attr = null;
        String value = null;
        for (int j = 0; j < fields.getLength(); j++) {
          Node fieldNode = fields.item(j);
          if (!(fieldNode instanceof Element)) {
            continue;
          }
          Element field = (Element) fieldNode;
          if ("name".equals(field.getTagName()) && field.hasChildNodes()) {
            attr = ((Text) field.getFirstChild()).getData().trim();
          }
          if ("value".equals(field.getTagName()) && field.hasChildNodes()) {
            value = ((Text) field.getFirstChild()).getData();
          }
        }
        if (attr != null && value != null) {
          set(attr, value);
        }
      }

    } catch (DOMException e) {
      throw new IOException(e);
    }
  }