Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line breaks issue and naming fixes #62

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 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.5.2</version>
<version>1.5.3</version>

<name>Simple ODS library</name>
<description>A library for load/save ODS files in java.</description>
Expand Down Expand Up @@ -71,6 +71,7 @@
Bundle-SymbolicName: com.github.miachm.sods
Automatic-Module-Name: com.github.miachm.sods
-jpms-module-info: com.github.miachm.sods
-sources: true
]]></bnd>
</configuration>
<extensions>true</extensions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Internal class for generate ODS files.
*/
class OdsWritter {
class OdsWriter {
private final static String office = "urn:oasis:names:tc:opendocument:xmlns:office:1.0";
private final static String table_namespace = "urn:oasis:names:tc:opendocument:xmlns:table:1.0";
private final static String text_namespace = "urn:oasis:names:tc:opendocument:xmlns:text:1.0";
Expand All @@ -27,14 +27,14 @@ class OdsWritter {
private Map<TableStyle, String> tableStyleStringMap = new HashMap<>();
private final String MIMETYPE= "application/vnd.oasis.opendocument.spreadsheet";

private OdsWritter(OutputStream o, SpreadSheet spread) {
private OdsWriter(OutputStream o, SpreadSheet spread) {
this.spread = spread;
this.out = new Compressor(o);
spread.trimSheets();
}

public static void save(OutputStream out,SpreadSheet spread) throws IOException {
new OdsWritter(out,spread).save();
new OdsWriter(out,spread).save();
}

private void save() throws IOException {
Expand Down Expand Up @@ -266,36 +266,43 @@ private void writeValue(XMLStreamWriter out, Cell cell) throws XMLStreamExceptio
Object v = cell.getValue();
if (v != null) {
OfficeValueType valueType = OfficeValueType.ofJavaType(v.getClass());
valueType.write(v, out);

out.writeStartElement("text:p");
String text = v.toString();
if (text.contains(System.lineSeparator())) {
valueType.write("", out);

for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == ' ') {
out.writeStartElement("text:s");
int cnt = 0;
while (i+cnt < text.length() && text.charAt(i + cnt) == ' ') {
cnt++;
out.writeStartElement("text:p");

for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == ' ') {
out.writeStartElement("text:s");
int cnt = 0;
while (i+cnt < text.length() && text.charAt(i + cnt) == ' ') {
cnt++;
}
if (cnt > 1)
out.writeAttribute("text:c", "" + cnt);
i += cnt - 1 ;
out.writeEndElement();
}
if (cnt > 1)
out.writeAttribute("text:c", "" + cnt);
i += cnt - 1 ;
out.writeEndElement();
}
else if (text.charAt(i) == '\t') {
out.writeEmptyElement("text:tab");
}
else if (text.charAt(i) == '\n') {
out.writeEndElement();
out.writeStartElement("text:p");
else if (text.charAt(i) == '\t') {
out.writeEmptyElement("text:tab");
}
else if (text.charAt(i) == '\n') {
out.writeEndElement();
out.writeStartElement("text:p");
}
else
out.writeCharacters("" + text.charAt(i));
}
else
out.writeCharacters("" + text.charAt(i));
}

out.writeEndElement();
out.writeEndElement();

} else {
valueType.write(v, out);
}
}

OfficeAnnotation annotation = cell.getAnnotation();
if (annotation != null) {
out.writeStartElement("office:annotation");
Expand Down
2 changes: 1 addition & 1 deletion src/com/github/miachm/sods/SpreadSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void save(File out) throws IOException {
* @throws IOException In case of an io error.
*/
public void save(OutputStream out) throws IOException {
OdsWritter.save(out,this);
OdsWriter.save(out,this);
}

/**
Expand Down