| 1555 | |
| 1556 | |
| 1557 | void saveStringODS(OutputStream output, String text) throws IOException { |
| 1558 | // At this point, I should have just used the XML library. But this does |
| 1559 | // save us from having to create the entire document in memory again before |
| 1560 | // writing to the file. So while it's dorky, the outcome is still useful. |
| 1561 | StringBuilder sanitized = new StringBuilder(); |
| 1562 | if (text != null) { |
| 1563 | char[] array = text.toCharArray(); |
| 1564 | for (char c : array) { |
| 1565 | if (c == '&') { |
| 1566 | sanitized.append("&"); |
| 1567 | } else if (c == '\'') { |
| 1568 | sanitized.append("'"); |
| 1569 | } else if (c == '"') { |
| 1570 | sanitized.append("""); |
| 1571 | } else if (c == '<') { |
| 1572 | sanitized.append("<"); |
| 1573 | } else if (c == '>') { |
| 1574 | sanitized.append("&rt;"); |
| 1575 | } else if (c < 32 || c > 127) { |
| 1576 | sanitized.append("&#" + ((int) c) + ";"); |
| 1577 | } else { |
| 1578 | sanitized.append(c); |
| 1579 | } |
| 1580 | } |
| 1581 | } |
| 1582 | |
| 1583 | writeUTF(output, |
| 1584 | " <table:table-cell office:value-type=\"string\">", |
| 1585 | " <text:p>" + sanitized + "</text:p>", |
| 1586 | " </table:table-cell>"); |
| 1587 | } |
| 1588 | |
| 1589 | |
| 1590 | void saveNumberODS(OutputStream output, String text) throws IOException { |