joonseolee commented on code in PR #9898:
URL: https://github.com/apache/seatunnel/pull/9898#discussion_r2425014400


##########
seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/reader/WordReadStrategy.java:
##########
@@ -0,0 +1,296 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.file.source.reader;
+
+import org.apache.seatunnel.api.source.Collector;
+import org.apache.seatunnel.api.table.catalog.CatalogTable;
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import 
org.apache.seatunnel.connectors.seatunnel.file.exception.FileConnectorErrorCode;
+import 
org.apache.seatunnel.connectors.seatunnel.file.exception.FileConnectorException;
+
+import org.apache.poi.xwpf.usermodel.IBodyElement;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFHyperlink;
+import org.apache.poi.xwpf.usermodel.XWPFHyperlinkRun;
+import org.apache.poi.xwpf.usermodel.XWPFParagraph;
+import org.apache.poi.xwpf.usermodel.XWPFRun;
+import org.apache.poi.xwpf.usermodel.XWPFTable;
+import org.apache.poi.xwpf.usermodel.XWPFTableCell;
+import org.apache.poi.xwpf.usermodel.XWPFTableRow;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+
+@Slf4j
+public class WordReadStrategy extends AbstractReadStrategy {
+
+    private static final String DEFAULT_TEXT_COLOR = "000000";
+
+    @Override
+    public void read(String path, String tableId, Collector<SeaTunnelRow> 
output)
+            throws IOException, FileConnectorException {
+        try (FileInputStream fis = new FileInputStream(path);
+                XWPFDocument document = new XWPFDocument(fis)) {
+
+            int elementId = 1;
+
+            processDocumentInOrder(document, output, tableId, elementId);
+        } catch (Exception e) {
+            throw new FileConnectorException(
+                    FileConnectorErrorCode.FILE_READ_FAILED,
+                    "Failed to read Word document: " + path,
+                    e);
+        }
+    }
+
+    private void processDocumentInOrder(
+            XWPFDocument document, Collector<SeaTunnelRow> output, String 
tableId, int elementId) {
+
+        for (IBodyElement element : document.getBodyElements()) {
+            if (element instanceof XWPFParagraph) {
+                XWPFParagraph paragraph = (XWPFParagraph) element;
+                if (paragraph.getText() != null && 
!paragraph.getText().trim().isEmpty()) {
+                    SeaTunnelRow row = createParagraphRow(paragraph, 
elementId++, tableId);
+                    output.collect(row);
+                }
+            } else if (element instanceof XWPFTable) {
+                XWPFTable table = (XWPFTable) element;
+                String tableData = extractTableData(table);
+                if (!tableData.trim().isEmpty()) {
+                    SeaTunnelRow row = createTableRow(tableData, elementId++, 
tableId);
+                    output.collect(row);
+                }
+            }
+        }
+    }
+
+    @Override
+    public SeaTunnelRowType getSeaTunnelRowTypeInfo(String path) throws 
FileConnectorException {
+        return new SeaTunnelRowType(
+                new String[] {

Review Comment:
   @Hisoka-X 
   
   I wanted to add those values as well, but I couldn't due to technical issues 
like the ones below.
   
   - heading_level: Not reliably derivable. Style names/IDs vary by template, 
language, and custom styles; there is no stable, standard mapping. Outline 
level may be absent, so consistent extraction isn’t guaranteed.
   - text: Same as text_content
   - page_number: Not available. Pagination is a rendering/layout result (paper 
size, margins, fonts, images, printer settings); Apache POI does not perform 
layout computation.
   - position_index: A hierarchical index (Markdown-style) isn’t feasible 
without a reliable document tree and heading detection; Word’s body is 
effectively flat and heading detection is inconsistent. A simple global ordinal 
is possible.
   - parent_id: Not available. WordprocessingML does not provide an explicit 
AST with parent-child relationships for paragraphs.
   - child_ids: Not available for the same reason as parent_id; there’s no 
stable logical child list per element in Word.



-- 
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]

Reply via email to