Skip to content

Commit

Permalink
Fix bug with CData elements #79
Browse files Browse the repository at this point in the history
  • Loading branch information
miachm committed Sep 22, 2023
1 parent 32ccdca commit 189ecf0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.github.miachm.sods</groupId>
<artifactId>SODS</artifactId>
<packaging>jar</packaging>
<version>1.6.0</version>
<version>1.6.3</version>

<name>Simple ODS library</name>
<description>A library for load/save ODS files in java.</description>
Expand Down
6 changes: 6 additions & 0 deletions resources/features/bugs/cellContent.feature
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ Feature: Bugs related to invalid cell value content in SODS
When the client creates a Range with 1,1,1,1
Then the formula of the range is "SUM(Operations!C:C)"

Scenario: Data tags returns a null value
When load a spreadsheet from the resource "emptyCell"
When get the first sheet
Then the cell values are:
| Test 1 |
| A |
1 change: 0 additions & 1 deletion src/com/github/miachm/sods/OdsReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,6 @@ private void readCellText(XmlReaderInstance cellReader, Range range) {
} else {
s.append("\n");
}

// Add content of any contained text:span tags
XmlReaderInstance spanElement = textElement.nextElement("text:s",
XmlReaderInstance.CHARACTERS);
Expand Down
11 changes: 8 additions & 3 deletions src/com/github/miachm/sods/XmlReaderInstanceEventImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javax.xml.stream.XMLStreamReader;
import java.util.HashMap;
import java.util.Map;
import javax.xml.stream.XMLStreamConstants;

class XmlReaderInstanceEventImpl implements XmlReaderInstance {
private XMLStreamReader reader;
Expand All @@ -24,7 +25,7 @@ class XmlReaderInstanceEventImpl implements XmlReaderInstance {
String value = reader.getAttributeValue(i);
atributes.put(name, value);
}
else if (reader.isCharacters()) {
else if (isCharacters(reader)) {
characters = reader.getText();
end = true;
}
Expand Down Expand Up @@ -58,7 +59,7 @@ else if (reader.isEndElement()) {
return null;
}
}
else if (reader.isCharacters()) {
else if (isCharacters(reader)) {
if (contains(names, CHARACTERS))
return new XmlReaderInstanceEventImpl(reader, CHARACTERS);
}
Expand All @@ -85,7 +86,11 @@ public String getContent()
public String getTag() {
return tag;
}


private boolean isCharacters(XMLStreamReader reader) {
return reader.isCharacters() || reader.getEventType() == XMLStreamConstants.CDATA;
}

private String qNameToString(QName qName)
{
return qName.getPrefix() + ":" + qName.getLocalPart();
Expand Down
2 changes: 1 addition & 1 deletion tests/steps/SpreadsheetCucumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void the_cell_values_are(DataTable dataTable) throws Throwable {
Object[][] items = World.sheet.getDataRange().getValues();

for (int i = 0; i < table.size(); i++) {
for (int j = 0; j < table.size(); j++) {
for (int j = 0; j < table.get(i).size(); j++) {
String value = table.get(i).get(j);
if (value.equals(""))
value = null;
Expand Down

0 comments on commit 189ecf0

Please sign in to comment.