adoroszlai commented on code in PR #6916:
URL: https://github.com/apache/ozone/pull/6916#discussion_r1670045074


##########
hadoop-hdds/common/src/main/java/com/google/protobuf/XmlToMarkdown.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package com.google.protobuf;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * Represents a property in the XML file.
+ */
+class Property {
+  private final String name;
+  private final String value;
+  private final String tag;
+  private final String description;
+
+  Property(String name, String value, String tag, String description) {
+    this.name = name;
+    this.value = value;
+    this.tag = tag;
+    this.description = description;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public String getValue() {
+    return value;
+  }
+
+  public String getTag() {
+    return tag;
+  }
+
+  public String getDescription() {
+    return description;
+  }
+}
+
+/**
+ * Utility class for converting XML properties from ozone-default.xml and
+ * ozone-default-generated.xml into Markdown format. The converted content
+ * is saved to Configurations.md.
+ */
+public final class XmlToMarkdown {
+
+  private XmlToMarkdown() {
+    // Prevent instantiation
+  }
+
+  public static void main(String[] args) {
+    try {
+      // List of XML files to process
+      String[] xmlFiles = {
+          "hadoop-hdds/common/src/main/resources/ozone-default.xml",
+          "hadoop-hdds/config/target/test-classes/ozone-default-generated.xml"
+      };
+
+      List<Property> properties = new ArrayList<>();
+
+      // Load and parse each XML file
+      for (String xmlFile : xmlFiles) {
+        File inputFile = new File(xmlFile);
+        if (!inputFile.exists()) {
+          System.out.println("File not found: " + xmlFile);
+          continue;
+        }
+
+        DocumentBuilderFactory dbFactory = 
DocumentBuilderFactory.newInstance();
+        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+        Document doc = dBuilder.parse(inputFile);
+        doc.getDocumentElement().normalize();
+
+        // Get all properties
+        NodeList nList = doc.getElementsByTagName("property");
+
+        // Process each property
+        for (int temp = 0; temp < nList.getLength(); temp++) {
+          Node nNode = nList.item(temp);
+          if (nNode.getNodeType() == Node.ELEMENT_NODE) {
+            Element eElement = (Element) nNode;
+            String name = getTextContent(eElement, "name");
+            String value = getTextContent(eElement, "value");
+            String tag = getTextContent(eElement, "tag");
+            String description = getTextContent(eElement, 
"description").replaceAll("\\s+", " ").trim();
+
+            properties.add(new Property(name, value, tag, description));
+          }
+        }
+      }
+
+      // Sort properties by name
+      properties.sort(Comparator.comparing(Property::getName));

Review Comment:
   Various `ozone-default-generated.xml` files may have some overlap (the cause 
of that is not yet clear).  Keep only unique items (either by collecting in a 
map, or by using `Stream.distinct()`).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to