This is an automated email from the ASF dual-hosted git repository.
delei pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fesod.git
The following commit(s) were added to refs/heads/main by this push:
new f22b56b3 refactor: encapsulate xlsx boolean cell parsing in CellData
(#964)
f22b56b3 is described below
commit f22b56b328e49a89c70cba749992a7e590452568
Author: Nikita Kuprins <[email protected]>
AuthorDate: Sat Jul 25 08:54:18 2026 +0300
refactor: encapsulate xlsx boolean cell parsing in CellData (#964)
* refactor: encapsulate xlsx boolean cell parsing in CellData
Move the 1-only boolean parsing from the shared BooleanUtils.valueOf
into CellData.setBooleanValueFromString, next to its only caller in the
xlsx SAX read path. The behavior (matching Excel's 0/1 markers and POI's
XSSFCell) is unchanged and now pinned by CellDataTest.
Deprecate BooleanUtils.valueOf(String), which is not a general-purpose
string-to-boolean conversion, for future removal.
Closes #953
* refactor: move boolean cell parsing down to ReadCellData
Address review feedback: CellData is the shared abstraction, so the
xlsx-specific 1 -> true parsing belongs on the read-side subclass.
Move setBooleanValueFromString and TRUE_NUMBER to ReadCellData and
rename CellDataTest accordingly. No behavior change.
---
.../org/apache/fesod/common/util/BooleanUtils.java | 5 +++
.../analysis/v07/handlers/CellTagHandler.java | 3 +-
.../fesod/sheet/metadata/data/ReadCellData.java | 18 +++++++++
.../sheet/metadata/data/ReadCellDataTest.java | 47 ++++++++++++++++++++++
4 files changed, 71 insertions(+), 2 deletions(-)
diff --git
a/fesod-common/src/main/java/org/apache/fesod/common/util/BooleanUtils.java
b/fesod-common/src/main/java/org/apache/fesod/common/util/BooleanUtils.java
index f83adce5..f7b5f67e 100644
--- a/fesod-common/src/main/java/org/apache/fesod/common/util/BooleanUtils.java
+++ b/fesod-common/src/main/java/org/apache/fesod/common/util/BooleanUtils.java
@@ -36,7 +36,12 @@ public class BooleanUtils {
*
* @param str
* @return
+ * @deprecated this only targets Excel's {@code 0}/{@code 1} boolean cell
markers and is not a
+ * general-purpose string-to-boolean conversion; it should not be used
outside that scenario and
+ * will be removed in a future release. Use
+ * {@code
org.apache.fesod.sheet.metadata.data.ReadCellData#setBooleanValueFromString(String)}
instead.
*/
+ @Deprecated
public static Boolean valueOf(String str) {
if (TRUE_NUMBER.equals(str)) {
return Boolean.TRUE;
diff --git
a/fesod-sheet/src/main/java/org/apache/fesod/sheet/analysis/v07/handlers/CellTagHandler.java
b/fesod-sheet/src/main/java/org/apache/fesod/sheet/analysis/v07/handlers/CellTagHandler.java
index 2c24b5cb..f98e297e 100644
---
a/fesod-sheet/src/main/java/org/apache/fesod/sheet/analysis/v07/handlers/CellTagHandler.java
+++
b/fesod-sheet/src/main/java/org/apache/fesod/sheet/analysis/v07/handlers/CellTagHandler.java
@@ -27,7 +27,6 @@ package org.apache.fesod.sheet.analysis.v07.handlers;
import java.math.BigDecimal;
import java.util.List;
-import org.apache.fesod.common.util.BooleanUtils;
import org.apache.fesod.common.util.PositionUtils;
import org.apache.fesod.common.util.StringUtils;
import org.apache.fesod.sheet.constant.ExcelXmlConstants;
@@ -121,7 +120,7 @@ public class CellTagHandler extends AbstractXlsxTagHandler {
tempCellData.setType(CellDataTypeEnum.EMPTY);
break;
}
-
tempCellData.setBooleanValue(BooleanUtils.valueOf(tempData.toString()));
+ tempCellData.setBooleanValueFromString(tempData.toString());
break;
case NUMBER:
case EMPTY:
diff --git
a/fesod-sheet/src/main/java/org/apache/fesod/sheet/metadata/data/ReadCellData.java
b/fesod-sheet/src/main/java/org/apache/fesod/sheet/metadata/data/ReadCellData.java
index 40ea6fbc..4656ee3c 100644
---
a/fesod-sheet/src/main/java/org/apache/fesod/sheet/metadata/data/ReadCellData.java
+++
b/fesod-sheet/src/main/java/org/apache/fesod/sheet/metadata/data/ReadCellData.java
@@ -45,6 +45,11 @@ import org.apache.fesod.sheet.enums.CellDataTypeEnum;
@NoArgsConstructor
public class ReadCellData<T> extends CellData<T> {
+ /**
+ * Marker Excel writes for a {@code true} boolean cell value ({@code
<v>1</v>} for {@code t="b"} cells).
+ */
+ private static final String TRUE_NUMBER = "1";
+
/**
* originalNumberValue vs numberValue
* <ol>
@@ -119,6 +124,19 @@ public class ReadCellData<T> extends CellData<T> {
setBooleanValue(booleanValue);
}
+ /**
+ * Sets the boolean value from the raw {@code <v>} text of a boolean
({@code t="b"}) xlsx cell.
+ *
+ * <p>Excel encodes boolean cells using the numeric markers {@code
0}/{@code 1}, so only the exact
+ * string {@code "1"} maps to {@code true}; any other input (including
{@code "true"}) maps to
+ * {@code false}. This mirrors Apache POI's {@code
XSSFCell.getBooleanCellValue()}.
+ *
+ * @param str the raw cell value text
+ */
+ public void setBooleanValueFromString(String str) {
+ setBooleanValue(TRUE_NUMBER.equals(str));
+ }
+
public static ReadCellData<?> newEmptyInstance() {
return newEmptyInstance(null, null);
}
diff --git
a/fesod-sheet/src/test/java/org/apache/fesod/sheet/metadata/data/ReadCellDataTest.java
b/fesod-sheet/src/test/java/org/apache/fesod/sheet/metadata/data/ReadCellDataTest.java
new file mode 100644
index 00000000..a36b3a00
--- /dev/null
+++
b/fesod-sheet/src/test/java/org/apache/fesod/sheet/metadata/data/ReadCellDataTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.fesod.sheet.metadata.data;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class ReadCellDataTest {
+
+ /**
+ * xlsx boolean cells use Excel's {@code 0}/{@code 1} markers, so only
{@code "1"} maps to {@code true}.
+ * This mirrors POI's {@code XSSFCell.getBooleanCellValue()}; {@code
"true"} intentionally maps to
+ * {@code false}.
+ */
+ @Test
+ void setBooleanValueFromStringMatchesExcelMarkers() {
+ Assertions.assertTrue(booleanFrom("1"));
+ Assertions.assertFalse(booleanFrom("0"));
+ Assertions.assertFalse(booleanFrom("true"));
+ Assertions.assertFalse(booleanFrom("TRUE"));
+ Assertions.assertFalse(booleanFrom(""));
+ Assertions.assertFalse(booleanFrom(null));
+ }
+
+ private static Boolean booleanFrom(String str) {
+ ReadCellData<?> cellData = new ReadCellData<>();
+ cellData.setBooleanValueFromString(str);
+ return cellData.getBooleanValue();
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]