public static void writeXml()

in bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/utils/XmlUtils.java [60:97]


    public static void writeXml(String fileName, Map<String, Object> configMap) {
        try {
            Document document = db.newDocument();
            // don't display standalone="no"
            document.setXmlStandalone(true);

            Element configuration = document.createElement("configuration");

            for (Map.Entry<String, Object> entry : configMap.entrySet()) {
                log.info("{} {}", entry.getKey(), entry.getValue());
                Element property = document.createElement("property");

                Element name = document.createElement("name");
                Element value = document.createElement("value");
                name.setTextContent(entry.getKey());
                value.setTextContent(String.valueOf(entry.getValue()));

                property.appendChild(name);
                property.appendChild(value);
                configuration.appendChild(property);
            }

            document.appendChild(configuration);

            TransformerFactory tff = TransformerFactory.newInstance();
            tff.setAttribute("indent-number", "2");
            Transformer tf = tff.newTransformer();

            tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
            tf.setOutputProperty(OutputKeys.INDENT, "yes");

            tf.transform(new DOMSource(document), new StreamResult(new File(fileName)));
            log.info("writeXml {} success", fileName);
        } catch (TransformerException e) {
            log.error("writeXml error", e);
            throw new StackException(e);
        }
    }