[
https://issues.apache.org/jira/browse/HADOOP-19802?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18060203#comment-18060203
]
ASF GitHub Bot commented on HADOOP-19802:
-----------------------------------------
manika137 commented on code in PR #8229:
URL: https://github.com/apache/hadoop/pull/8229#discussion_r2839023221
##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/contracts/services/ContainerListXmlParser.java:
##########
@@ -0,0 +1,203 @@
+/**
+ * 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 org.apache.hadoop.fs.azurebfs.contracts.services;
+
+import java.util.Stack;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants;
+import org.apache.hadoop.fs.azurebfs.utils.DateTimeUtils;
+
+import static
org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.EMPTY_STRING;
+
+/**
+ * SAX parser for Azure Blob Storage "List Containers" REST API response.
+ *
+ * <p>
+ * Parses the XML response returned by:
+ * https://learn.microsoft.com/en-us/rest/api/storageservices/list-containers2
+ * </p>
+ *
+ * <p>
+ * This parser is streaming (SAX-based) to avoid loading the full XML into
memory.
+ * </p>
+ */
+public class ContainerListXmlParser extends DefaultHandler {
+
+ /** Parsed response object */
+ private final ContainerListResponseData responseData;
+
+ /** Stack of active XML elements */
+ private final Stack<String> elements = new Stack<>();
+
+ /** Buffer for character data */
+ private StringBuilder bld = new StringBuilder();
+
+ /** Currently parsed container entry */
+ private ContainerListEntrySchema currentContainer;
+
+ /**
+ * Constructs a parser for List Containers response.
+ *
+ * @param responseData response object to populate
+ */
+ public ContainerListXmlParser(
+ final ContainerListResponseData responseData) {
+ this.responseData = responseData;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @param uri namespace URI
+ * @param localName local element name
+ * @param qName qualified name
+ * @param attributes element attributes
+ */
+ @Override
+ public void startElement(
+ final String uri,
+ final String localName,
+ final String qName,
+ final Attributes attributes) {
+ elements.push(localName);
+ if (AbfsHttpConstants.XML_TAG_CONTAINER.equals(localName)) {
+ currentContainer = new ContainerListEntrySchema();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Initializes container parsing when a container element is encountered.
+ */
+ @Override
+ public void endElement(
+ final String uri,
+ final String localName,
+ final String qName) throws SAXException {
+
+ final String currentNode = elements.pop();
+
+ if (!currentNode.equals(localName)) {
+ throw new SAXException(AbfsHttpConstants.XML_TAG_INVALID_XML);
+ }
+
+ String parentNode = EMPTY_STRING;
+ if (!elements.isEmpty()) {
+ parentNode = elements.peek();
+ }
+
+ String value = bld.toString().trim();
+ if (value.isEmpty()) {
+ value = null;
+ }
+
+ if (currentContainer != null) {
+ if (AbfsHttpConstants.XML_TAG_NAME.equals(currentNode)
+ && AbfsHttpConstants.XML_TAG_CONTAINER.equals(parentNode)) {
+ currentContainer.setName(value);
+ }
+ if (AbfsHttpConstants.XML_TAG_VERSION.equals(currentNode)) {
+ currentContainer.setVersion(value);
+ }
+ if (AbfsHttpConstants.XML_TAG_DELETED.equals(currentNode)) {
+ currentContainer.setDeleted(Boolean.parseBoolean(value));
+ }
+ if (AbfsHttpConstants.XML_TAG_PROPERTIES.equals(parentNode)) {
Review Comment:
And use switch case for more readability
> ABFS: Remove SDK dependency in hadoop-azure
> -------------------------------------------
>
> Key: HADOOP-19802
> URL: https://issues.apache.org/jira/browse/HADOOP-19802
> Project: Hadoop Common
> Issue Type: Sub-task
> Affects Versions: 3.4.2
> Reporter: Anmol Asrani
> Assignee: Anmol Asrani
> Priority: Major
> Labels: pull-request-available
>
> Remove use of SDK from hadoop-azure
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]