Paragraph.getTextContent for text:s elements within spaces and without count
git-svn-id: https://svn.apache.org/repos/asf/incubator/odf/trunk@1786770 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/simple/src/main/java/org/odftoolkit/simple/text/Paragraph.java b/simple/src/main/java/org/odftoolkit/simple/text/Paragraph.java
index f75ab60..5c4edac 100644
--- a/simple/src/main/java/org/odftoolkit/simple/text/Paragraph.java
+++ b/simple/src/main/java/org/odftoolkit/simple/text/Paragraph.java
@@ -1,4 +1,4 @@
-/*
+/*
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
@@ -24,14 +24,12 @@
import java.util.Date;
import java.util.Iterator;
import java.util.List;
-
import org.odftoolkit.odfdom.dom.OdfContentDom;
import org.odftoolkit.odfdom.dom.OdfDocumentNamespace;
import org.odftoolkit.odfdom.dom.OdfStylesDom;
import org.odftoolkit.odfdom.dom.element.OdfStyleBase;
import org.odftoolkit.odfdom.dom.element.dc.DcCreatorElement;
import org.odftoolkit.odfdom.dom.element.dc.DcDateElement;
-import org.odftoolkit.odfdom.dom.element.draw.DrawControlElement;
import org.odftoolkit.odfdom.dom.element.office.OfficeAnnotationElement;
import org.odftoolkit.odfdom.dom.element.style.StyleTextPropertiesElement;
import org.odftoolkit.odfdom.dom.element.text.TextAElement;
@@ -69,7 +67,7 @@
* manipulate text content, and other child component under the paragraph.
* Headings and body text paragraphs are collectively referred to as paragraph
* elements.
- *
+ *
* @since 0.5
*/
public class Paragraph extends Component implements TextboxContainer,
@@ -98,7 +96,7 @@
/**
* Gets a paragraph instance by an instance of
* <code>TextParagraphElementBase</code>.
- *
+ *
* @param paragraphElement
* the instance of TextParagraphElementBase.
* @return an instance of paragraph.
@@ -121,7 +119,7 @@
* Create an instance of paragraph
* <p>
* The paragrah will be added at the end of this container.
- *
+ *
* @param container
* the paragraph container that contains this paragraph.
*/
@@ -147,7 +145,7 @@
* The white space characters in the content would be collapsed by default.
* For example, tab character would be replaced with <text:tab>, break line
* character would be replaced with <text:line-break>.
- *
+ *
* @param content
* - the text content
* @see #setTextContentNotCollapsed(String content)
@@ -186,7 +184,7 @@
* will be removed.
* <p>
* The other child elements except text content will not be removed.
- *
+ *
*/
public void removeTextContent() {
removeTextContentImpl(getOdfElement());
@@ -218,7 +216,7 @@
* Return the text content of this paragraph.
* <p>
* The other child elements except text content will not be returned.
- *
+ *
* @return - the text content of this paragraph
*/
public String getTextContent() {
@@ -236,11 +234,11 @@
buffer.append(node.getNodeValue());
else if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node instanceof TextSpanElement) {
- buffer.append(((TextSpanElement) node).getTextContent());
+ buffer.append((getTextContent((TextSpanElement) node)));
}
else if (node.getNodeName().equals("text:s")) {
Integer count = ((TextSElement) node).getTextCAttribute();
- for (int j = 0; j < (count != null ? count : 0); j++)
+ for (int j = 0; j < (count != null ? count : 1); j++)
buffer.append(' ');
} else if (node.getNodeName().equals("text:tab"))
buffer.append('\t');
@@ -261,7 +259,7 @@
* then new text content would be set.
* <p>
* The white space characters in the content would not be collapsed.
- *
+ *
* @param content
* - the text content
* @see #setTextContent(String content)
@@ -279,7 +277,7 @@
* The white space characters in the content would be collapsed by default.
* For example, tab character would be replaced with <text:tab>, break line
* character would be replaced with <text:line-break>.
- *
+ *
* @param content
* - the text content
* @see #appendTextContentNotCollapsed(String content)
@@ -297,7 +295,7 @@
* The white space characters in the content would be collapsed by default.
* For example, tab character would be replaced with <text:tab>, break line
* character would be replaced with <text:line-break>.
- *
+ *
* @param content
* - the text content
* @param isStyleInherited
@@ -325,7 +323,7 @@
* would follow the style of the last character.
* <p>
* The white space characters in the content would not be collapsed.
- *
+ *
* @param content
* - the text content
* @see #appendTextContent(String content)
@@ -348,7 +346,7 @@
/**
* Set the style name of this paragraph
- *
+ *
* @param styleName
* - the style name
*/
@@ -358,7 +356,7 @@
/**
* Get the style name of this paragraph
- *
+ *
* @return - the style name
*/
public String getStyleName() {
@@ -374,7 +372,7 @@
/**
* Get the owner document of this paragraph.
- *
+ *
* @return the document who owns this paragraph.
*/
public Document getOwnerDocument() {
@@ -383,7 +381,7 @@
/**
* Remove this paragraph from its container.
- *
+ *
* @since 0.6.5
*/
public void remove(){
@@ -396,12 +394,12 @@
mTextboxContainerImpl=null;
mHyperlinkContainerImpl=null;
}
-
+
/**
* Get the style handler of this paragraph.
* <p>
* The style handler is an instance of ParagraphStyleHandler
- *
+ *
* @return an instance of ParagraphStyleHandler
* @see ParagraphStyleHandler
*/
@@ -419,7 +417,7 @@
* Headings and body text paragraphs are collectively referred to as
* paragraph elements, so the <code>TextParagraphElementBase</code> can be
* <code>TextHElement</code> element or <code>TextPElement</code> element.
- *
+ *
* @return the <code>TextParagraphElementBase</code> of this paragraph.
*/
@Override
@@ -433,7 +431,7 @@
/**
* Creates a comment in the front of this paragraph.
- *
+ *
* @param content
* the content of this comment.
* @param creator
@@ -480,10 +478,10 @@
/**
* Returns the paragraph type, heading or body text paragraph.
- *
+ *
* @return the paragraph type, if this paragraph is heading, returns
* <code>true</code>, otherwise return <code>false</code>.
- *
+ *
* @since 0.6.5
*/
public boolean isHeading() {
@@ -496,10 +494,10 @@
/**
* Returns outline level of this paragraph.
- *
+ *
* @return outline level, if this paragraph is a body text paragraph, 0 will
* be returned.
- *
+ *
* @since 0.6.5
*/
public int getHeadingLevel() {
@@ -511,14 +509,14 @@
/**
* Sets the paragraph type, heading or body text paragraph.
- *
+ *
* @param isHeading
* if <code>true</code>, this paragraph would be formatted as
* heading, otherwise as a body text paragraph.
* @param level
* the heading outline level of this paragraph, if
* <code>isHeading</code> is <code>true</code>.
- *
+ *
* @since 0.6.5
*/
public void applyHeading(boolean isHeading, int level) {
@@ -577,7 +575,7 @@
/**
* Formats the paragraph as heading. Its outline level is 1.
- *
+ *
* @since 0.6.5
*/
public void applyHeading() {
@@ -586,10 +584,10 @@
/**
* Returns the font definition for this paragraph.
- *
+ *
* @return font if there is no style definition for this paragraph,
* <code>null</code> will be returned.
- *
+ *
* @since 0.6.5
*/
public Font getFont() {
@@ -598,10 +596,10 @@
/**
* Sets font style for this paragraph.
- *
+ *
* @param font
* the font definition of this paragraph
- *
+ *
* @since 0.6.5
*/
public void setFont(Font font) {
@@ -616,7 +614,7 @@
* <p>
* Default value will be returned if explicit style definition is found but
* no horizontal alignment is set.
- *
+ *
* @return the horizontal alignment setting.
* @since 0.6.5
*/
@@ -627,7 +625,7 @@
/**
* Set the horizontal alignment setting of this paragraph. If the alignment
* is set as Default, the explicit horizontal alignment setting is removed.
- *
+ *
* @param alignType
* the horizontal alignment setting.
* @since 0.6.5
diff --git a/simple/src/test/java/org/odftoolkit/simple/text/ParagraphTest.java b/simple/src/test/java/org/odftoolkit/simple/text/ParagraphTest.java
index e59c3cc..102729c 100644
--- a/simple/src/test/java/org/odftoolkit/simple/text/ParagraphTest.java
+++ b/simple/src/test/java/org/odftoolkit/simple/text/ParagraphTest.java
@@ -1,4 +1,4 @@
-/*
+/*
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
@@ -15,8 +15,7 @@
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-*/
-
+ */
package org.odftoolkit.simple.text;
import java.io.FileNotFoundException;
@@ -24,7 +23,6 @@
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
-
import org.junit.Assert;
import org.junit.Test;
import org.odftoolkit.odfdom.type.Color;
@@ -38,297 +36,297 @@
public class ParagraphTest {
- private static final String[] PLAIN_TEXT = { "nospace", "one space", "two spaces", "three spaces",
- " three leading spaces", "three trailing spaces ", "one\ttab", "two\t\ttabs", "\tleading tab",
- "trailing tab\t", "mixed \t spaces and tabs", "line" + System.getProperty("line.separator") + "break" };
+ private static final String[] PLAIN_TEXT = {"nospace", "one space", "two spaces", "three spaces",
+ " three leading spaces", "three trailing spaces ", "one\ttab", "two\t\ttabs", "\tleading tab",
+ "trailing tab\t", "mixed \t spaces and tabs", "line" + System.getProperty("line.separator") + "break"};
- private static final String[][] ELEMENT_RESULT = { { "nospace" }, { "one space" }, { "two ", "*s1", "spaces" },
- { "three ", "*s2", "spaces" }, { " ", "*s2", "three leading spaces" }, { "three trailing spaces ", "*s2" },
- { "one", "*t", "tab" }, { "two", "*t", "*t", "tabs" }, { "*t", "leading tab" }, { "trailing tab", "*t" },
- { "mixed ", "*s2", "*t", " ", "*s2", "spaces and tabs" }, { "line", "*n", "break" } };
+ private static final String[][] ELEMENT_RESULT = {{"nospace"}, {"one space"}, {"two ", "*s1", "spaces"},
+ {"three ", "*s2", "spaces"}, {" ", "*s2", "three leading spaces"}, {"three trailing spaces ", "*s2"},
+ {"one", "*t", "tab"}, {"two", "*t", "*t", "tabs"}, {"*t", "leading tab"}, {"trailing tab", "*t"},
+ {"mixed ", "*s2", "*t", " ", "*s2", "spaces and tabs"}, {"line", "*n", "break"}};
- private static final Logger LOGGER = Logger.getLogger(ParagraphTest.class.getName());
+ private static final Logger LOGGER = Logger.getLogger(ParagraphTest.class.getName());
- private static final String TEST_FILE = "CommentBreakHeadingDocument.odt";
+ private static final String TEST_FILE = "CommentBreakHeadingDocument.odt";
- @Test
- public void testAppend() {
- TextDocument doc;
- try {
- doc = TextDocument.newTextDocument();
- int i;
- for (i = 0; i < PLAIN_TEXT.length; i++) {
- Paragraph para = Paragraph.newParagraph(doc);
- para.appendTextContent(PLAIN_TEXT[i]);
- compareResults(para.getOdfElement(), PLAIN_TEXT[i], ELEMENT_RESULT[i]);
- }
- } catch (Exception e) {
- LOGGER.log(Level.SEVERE, e.getMessage(), e);
- Assert.fail(e.getMessage());
- }
- }
+ @Test
+ public void testAppend() {
+ TextDocument doc;
+ try {
+ doc = TextDocument.newTextDocument();
+ int i;
+ for (i = 0; i < PLAIN_TEXT.length; i++) {
+ Paragraph para = Paragraph.newParagraph(doc);
+ para.appendTextContent(PLAIN_TEXT[i]);
+ compareResults(para.getOdfElement(), PLAIN_TEXT[i], ELEMENT_RESULT[i]);
+ }
+ } catch (Exception e) {
+ LOGGER.log(Level.SEVERE, e.getMessage(), e);
+ Assert.fail(e.getMessage());
+ }
+ }
- @Test
- public void testSetTextContent() {
- TextDocument doc;
- try {
- doc = TextDocument.newTextDocument();
- int i;
- for (i = 0; i < PLAIN_TEXT.length; i++) {
- Paragraph para = Paragraph.newParagraph(doc);
- para.setTextContent(PLAIN_TEXT[i]);
- compareResults(para.getOdfElement(), PLAIN_TEXT[i], ELEMENT_RESULT[i]);
+ @Test
+ public void testSetTextContent() {
+ TextDocument doc;
+ try {
+ doc = TextDocument.newTextDocument();
+ int i;
+ for (i = 0; i < PLAIN_TEXT.length; i++) {
+ Paragraph para = Paragraph.newParagraph(doc);
+ para.setTextContent(PLAIN_TEXT[i]);
+ compareResults(para.getOdfElement(), PLAIN_TEXT[i], ELEMENT_RESULT[i]);
- String content = para.getTextContent();
- Assert.assertEquals(PLAIN_TEXT[i], content);
- }
- } catch (Exception e) {
- LOGGER.log(Level.SEVERE, e.getMessage(), e);
- Assert.fail(e.getMessage());
- }
- }
+ String content = para.getTextContent();
+ Assert.assertEquals(PLAIN_TEXT[i], content);
+ }
+ } catch (Exception e) {
+ LOGGER.log(Level.SEVERE, e.getMessage(), e);
+ Assert.fail(e.getMessage());
+ }
+ }
- @Test
- public void testRemoveContent() {
- TextDocument doc;
- try {
- doc = TextDocument.newTextDocument();
- int i;
- for (i = 0; i < PLAIN_TEXT.length; i++) {
- Paragraph para = Paragraph.newParagraph(doc);
- para.setTextContentNotCollapsed(PLAIN_TEXT[i]);
- String content = para.getTextContent();
- Assert.assertEquals(PLAIN_TEXT[i], content);
- para.removeTextContent();
- content = para.getTextContent();
- Assert.assertEquals("", content);
- }
- } catch (Exception e) {
- LOGGER.log(Level.SEVERE, e.getMessage(), e);
- Assert.fail(e.getMessage());
- }
- }
+ @Test
+ public void testRemoveContent() {
+ TextDocument doc;
+ try {
+ doc = TextDocument.newTextDocument();
+ int i;
+ for (i = 0; i < PLAIN_TEXT.length; i++) {
+ Paragraph para = Paragraph.newParagraph(doc);
+ para.setTextContentNotCollapsed(PLAIN_TEXT[i]);
+ String content = para.getTextContent();
+ Assert.assertEquals(PLAIN_TEXT[i], content);
+ para.removeTextContent();
+ content = para.getTextContent();
+ Assert.assertEquals("", content);
+ }
+ } catch (Exception e) {
+ LOGGER.log(Level.SEVERE, e.getMessage(), e);
+ Assert.fail(e.getMessage());
+ }
+ }
- private void compareResults(Element element, String input, String[] output) {
- int i;
- int nSpaces;
- int nSpacesInAttribute;
- Node node = element.getFirstChild();
- for (i = 0; i < output.length; i++) {
- if (output[i].startsWith("*")) {
- Assert.assertEquals(Node.ELEMENT_NODE, node.getNodeType());
- if (output[i].equals("*t")) {
- Assert.assertEquals("tab", node.getLocalName());
- } else if (output[i].equals("*n")) {
- Assert.assertEquals("line-break", node.getLocalName());
- } else {
- nSpaces = Integer.parseInt(output[i].substring(2));
- Assert.assertEquals(node.getLocalName(), "s");
- nSpacesInAttribute = Integer.parseInt(((Element) node).getAttribute("text:c"));
- Assert.assertEquals(nSpaces, nSpacesInAttribute);
- }
- } else {
- Assert.assertEquals(Node.TEXT_NODE, node.getNodeType());
- Assert.assertEquals(output[i], node.getTextContent());
- }
- node = node.getNextSibling();
- }
- Assert.assertEquals(node, null);
- }
+ private void compareResults(Element element, String input, String[] output) {
+ int i;
+ int nSpaces;
+ int nSpacesInAttribute;
+ Node node = element.getFirstChild();
+ for (i = 0; i < output.length; i++) {
+ if (output[i].startsWith("*")) {
+ Assert.assertEquals(Node.ELEMENT_NODE, node.getNodeType());
+ if (output[i].equals("*t")) {
+ Assert.assertEquals("tab", node.getLocalName());
+ } else if (output[i].equals("*n")) {
+ Assert.assertEquals("line-break", node.getLocalName());
+ } else {
+ nSpaces = Integer.parseInt(output[i].substring(2));
+ Assert.assertEquals(node.getLocalName(), "s");
+ nSpacesInAttribute = Integer.parseInt(((Element) node).getAttribute("text:c"));
+ Assert.assertEquals(nSpaces, nSpacesInAttribute);
+ }
+ } else {
+ Assert.assertEquals(Node.TEXT_NODE, node.getNodeType());
+ Assert.assertEquals(output[i], node.getTextContent());
+ }
+ node = node.getNextSibling();
+ }
+ Assert.assertEquals(node, null);
+ }
- @Test
- public void testGetParagraphByIndex() {
- try {
- TextDocument doc = TextDocument.newTextDocument();
- Paragraph paragraph1 = doc.addParagraph("paragraph1");
- Paragraph paragraphE = doc.addParagraph(null);
- Paragraph paragraph2 = doc.addParagraph("p2");
+ @Test
+ public void testGetParagraphByIndex() {
+ try {
+ TextDocument doc = TextDocument.newTextDocument();
+ Paragraph paragraph1 = doc.addParagraph("paragraph1");
+ Paragraph paragraphE = doc.addParagraph(null);
+ Paragraph paragraph2 = doc.addParagraph("p2");
- Paragraph t1 = doc.getParagraphByIndex(1, false);
- Assert.assertEquals(t1, paragraph1);
- t1 = doc.getParagraphByIndex(3, false);
- Assert.assertEquals(t1, paragraph2);
- t1 = doc.getParagraphByIndex(1, true);
- Assert.assertEquals(t1, paragraph2);
- t1 = doc.getParagraphByReverseIndex(0, false);
- Assert.assertEquals(t1, paragraph2);
- t1 = doc.getParagraphByReverseIndex(2, false);
- Assert.assertEquals(t1, paragraph1);
- t1 = doc.getParagraphByReverseIndex(1, true);
- Assert.assertEquals(t1, paragraph1);
- doc.save(ResourceUtilities.newTestOutputFile("testGetParagraphByIndex.odt"));
- } catch (Exception e) {
- LOGGER.log(Level.SEVERE, e.getMessage(), e);
- Assert.fail(e.getMessage());
- }
- }
+ Paragraph t1 = doc.getParagraphByIndex(1, false);
+ Assert.assertEquals(t1, paragraph1);
+ t1 = doc.getParagraphByIndex(3, false);
+ Assert.assertEquals(t1, paragraph2);
+ t1 = doc.getParagraphByIndex(1, true);
+ Assert.assertEquals(t1, paragraph2);
+ t1 = doc.getParagraphByReverseIndex(0, false);
+ Assert.assertEquals(t1, paragraph2);
+ t1 = doc.getParagraphByReverseIndex(2, false);
+ Assert.assertEquals(t1, paragraph1);
+ t1 = doc.getParagraphByReverseIndex(1, true);
+ Assert.assertEquals(t1, paragraph1);
+ doc.save(ResourceUtilities.newTestOutputFile("testGetParagraphByIndex.odt"));
+ } catch (Exception e) {
+ LOGGER.log(Level.SEVERE, e.getMessage(), e);
+ Assert.fail(e.getMessage());
+ }
+ }
- @Test
- public void testSetGetFont() {
- try {
- TextDocument doc = TextDocument.newTextDocument();
- Paragraph paragraph1 = doc.addParagraph("paragraph1");
- Font font1 = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 12, Color.BLACK,
- StyleTypeDefinitions.TextLinePosition.THROUGH);
- paragraph1.setFont(font1);
- Font font11 = paragraph1.getFont();
- LOGGER.info(font11.toString());
- if (!font11.equals(font1)) {
- Assert.fail();
- }
+ @Test
+ public void testSetGetFont() {
+ try {
+ TextDocument doc = TextDocument.newTextDocument();
+ Paragraph paragraph1 = doc.addParagraph("paragraph1");
+ Font font1 = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 12, Color.BLACK,
+ StyleTypeDefinitions.TextLinePosition.THROUGH);
+ paragraph1.setFont(font1);
+ Font font11 = paragraph1.getFont();
+ LOGGER.info(font11.toString());
+ if (!font11.equals(font1)) {
+ Assert.fail();
+ }
- Paragraph paragraph2 = doc.addParagraph("paragraph2");
- Font font2 = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 12, Color.RED,
- StyleTypeDefinitions.TextLinePosition.UNDER);
- paragraph2.setFont(font2);
- Font font22 = paragraph2.getFont();
- LOGGER.info(font22.toString());
- if (!font22.equals(font2)) {
- Assert.fail();
- }
+ Paragraph paragraph2 = doc.addParagraph("paragraph2");
+ Font font2 = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 12, Color.RED,
+ StyleTypeDefinitions.TextLinePosition.UNDER);
+ paragraph2.setFont(font2);
+ Font font22 = paragraph2.getFont();
+ LOGGER.info(font22.toString());
+ if (!font22.equals(font2)) {
+ Assert.fail();
+ }
- Paragraph paragraph3 = doc.addParagraph("paragraph3");
- Font font3 = paragraph3.getFont();
- LOGGER.info(font3.toString());
- font3.setColor(Color.GREEN);
- font3.setFontStyle(StyleTypeDefinitions.FontStyle.BOLD);
- paragraph3.setFont(font3);
- LOGGER.info(font3.toString());
- Font font33 = paragraph3.getFont();
- if (!font33.equals(font3)) {
- Assert.fail();
- }
- doc.save(ResourceUtilities.newTestOutputFile("TestParagraphSetGetFont.odt"));
- } catch (Exception e) {
- LOGGER.log(Level.SEVERE, e.getMessage(), e);
- Assert.fail();
- }
- }
+ Paragraph paragraph3 = doc.addParagraph("paragraph3");
+ Font font3 = paragraph3.getFont();
+ LOGGER.info(font3.toString());
+ font3.setColor(Color.GREEN);
+ font3.setFontStyle(StyleTypeDefinitions.FontStyle.BOLD);
+ paragraph3.setFont(font3);
+ LOGGER.info(font3.toString());
+ Font font33 = paragraph3.getFont();
+ if (!font33.equals(font3)) {
+ Assert.fail();
+ }
+ doc.save(ResourceUtilities.newTestOutputFile("TestParagraphSetGetFont.odt"));
+ } catch (Exception e) {
+ LOGGER.log(Level.SEVERE, e.getMessage(), e);
+ Assert.fail();
+ }
+ }
- @Test
- public void testGetSetHoriAlignment() {
- try {
- TextDocument doc = TextDocument.newTextDocument();
- Paragraph paragraph1 = doc.addParagraph("paragraph1");
+ @Test
+ public void testGetSetHoriAlignment() {
+ try {
+ TextDocument doc = TextDocument.newTextDocument();
+ Paragraph paragraph1 = doc.addParagraph("paragraph1");
- paragraph1.setHorizontalAlignment(HorizontalAlignmentType.DEFAULT);
- HorizontalAlignmentType align = paragraph1.getHorizontalAlignment();
- Assert.assertEquals(HorizontalAlignmentType.DEFAULT, align);
+ paragraph1.setHorizontalAlignment(HorizontalAlignmentType.DEFAULT);
+ HorizontalAlignmentType align = paragraph1.getHorizontalAlignment();
+ Assert.assertEquals(HorizontalAlignmentType.DEFAULT, align);
- paragraph1.setHorizontalAlignment(HorizontalAlignmentType.LEFT);
- align = paragraph1.getHorizontalAlignment();
- Assert.assertEquals(HorizontalAlignmentType.LEFT, align);
+ paragraph1.setHorizontalAlignment(HorizontalAlignmentType.LEFT);
+ align = paragraph1.getHorizontalAlignment();
+ Assert.assertEquals(HorizontalAlignmentType.LEFT, align);
- paragraph1.setHorizontalAlignment(HorizontalAlignmentType.RIGHT);
- align = paragraph1.getHorizontalAlignment();
- Assert.assertEquals(HorizontalAlignmentType.RIGHT, align);
+ paragraph1.setHorizontalAlignment(HorizontalAlignmentType.RIGHT);
+ align = paragraph1.getHorizontalAlignment();
+ Assert.assertEquals(HorizontalAlignmentType.RIGHT, align);
- doc.save(ResourceUtilities.newTestOutputFile("TestParagraphSetGetHoriAlignment.odt"));
- } catch (Exception e) {
- LOGGER.log(Level.SEVERE, e.getMessage(), e);
- Assert.fail();
- }
- }
+ doc.save(ResourceUtilities.newTestOutputFile("TestParagraphSetGetHoriAlignment.odt"));
+ } catch (Exception e) {
+ LOGGER.log(Level.SEVERE, e.getMessage(), e);
+ Assert.fail();
+ }
+ }
- @Test
- public void testGetSetHeading() {
- try {
- TextDocument doc = TextDocument.loadDocument(ResourceUtilities.getAbsolutePath(TEST_FILE));
- // test isHeading() and getHeadingLevel();
- Paragraph headingParagraph = doc.getParagraphByIndex(0, true);
- Assert.assertEquals(true, headingParagraph.isHeading());
- Assert.assertEquals(1, headingParagraph.getHeadingLevel());
- Paragraph textParagraph = doc.getParagraphByIndex(1, true);
- Assert.assertEquals(false, textParagraph.isHeading());
- Assert.assertEquals(0, textParagraph.getHeadingLevel());
+ @Test
+ public void testGetSetHeading() {
+ try {
+ TextDocument doc = TextDocument.loadDocument(ResourceUtilities.getAbsolutePath(TEST_FILE));
+ // test isHeading() and getHeadingLevel();
+ Paragraph headingParagraph = doc.getParagraphByIndex(0, true);
+ Assert.assertEquals(true, headingParagraph.isHeading());
+ Assert.assertEquals(1, headingParagraph.getHeadingLevel());
+ Paragraph textParagraph = doc.getParagraphByIndex(1, true);
+ Assert.assertEquals(false, textParagraph.isHeading());
+ Assert.assertEquals(0, textParagraph.getHeadingLevel());
- // test applyHeading()
- textParagraph.applyHeading();
- Assert.assertEquals(true, textParagraph.isHeading());
- Assert.assertEquals(1, textParagraph.getHeadingLevel());
- textParagraph.applyHeading(true, 3);
- Assert.assertEquals(true, textParagraph.isHeading());
- Assert.assertEquals(3, textParagraph.getHeadingLevel());
+ // test applyHeading()
+ textParagraph.applyHeading();
+ Assert.assertEquals(true, textParagraph.isHeading());
+ Assert.assertEquals(1, textParagraph.getHeadingLevel());
+ textParagraph.applyHeading(true, 3);
+ Assert.assertEquals(true, textParagraph.isHeading());
+ Assert.assertEquals(3, textParagraph.getHeadingLevel());
- doc.save(ResourceUtilities.newTestOutputFile("TestParagraphSetGetHeading.odt"));
- } catch (Exception e) {
- LOGGER.log(Level.SEVERE, e.getMessage(), e);
- Assert.fail();
- }
- }
+ doc.save(ResourceUtilities.newTestOutputFile("TestParagraphSetGetHeading.odt"));
+ } catch (Exception e) {
+ LOGGER.log(Level.SEVERE, e.getMessage(), e);
+ Assert.fail();
+ }
+ }
- @Test
- public void testHyperlink() {
- try {
- TextDocument doc = TextDocument.newTextDocument();
- Paragraph para = doc.addParagraph("abc");
- TextHyperlink link1 = para.applyHyperlink(new URI("http://odftoolkit.org"));
- Assert.assertEquals("http://odftoolkit.org", link1.getURI().toString());
- Assert.assertEquals("abc", link1.getTextContent());
+ @Test
+ public void testHyperlink() {
+ try {
+ TextDocument doc = TextDocument.newTextDocument();
+ Paragraph para = doc.addParagraph("abc");
+ TextHyperlink link1 = para.applyHyperlink(new URI("http://odftoolkit.org"));
+ Assert.assertEquals("http://odftoolkit.org", link1.getURI().toString());
+ Assert.assertEquals("abc", link1.getTextContent());
- String text = para.getTextContent();
- Assert.assertEquals("abc", text);
+ String text = para.getTextContent();
+ Assert.assertEquals("abc", text);
- para.removeTextContent();
- text = para.getTextContent();
- Assert.assertEquals("", text);
- para.setTextContent("no hyperlink there ");
- para.appendHyperlink("link to ibm", new URI("http://www.ibm.com"));
+ para.removeTextContent();
+ text = para.getTextContent();
+ Assert.assertEquals("", text);
+ para.setTextContent("no hyperlink there ");
+ para.appendHyperlink("link to ibm", new URI("http://www.ibm.com"));
- Paragraph heading = doc.addParagraph("Heading1");
- TextHyperlink link2 = heading.applyHyperlink(new URI("mailto:daisy@odftoolkit.org"));
- heading.applyHeading(true, 1);
+ Paragraph heading = doc.addParagraph("Heading1");
+ TextHyperlink link2 = heading.applyHyperlink(new URI("mailto:daisy@odftoolkit.org"));
+ heading.applyHeading(true, 1);
- link2.setTextContent("New Heading1");
- link2.setURI(new URI("mailto:devin@odftoolkit.org"));
- Assert.assertEquals("mailto:devin@odftoolkit.org", link2.getURI().toString());
+ link2.setTextContent("New Heading1");
+ link2.setURI(new URI("mailto:devin@odftoolkit.org"));
+ Assert.assertEquals("mailto:devin@odftoolkit.org", link2.getURI().toString());
- Paragraph para3 = doc.addParagraph("world");
- TextHyperlink link3 = para3.applyHyperlink(new URI("http://odftoolkit.org"));
- link3.setTextContent("new world");
- para3.appendTextContent("_prefix");
- para3.appendTextContent("_nolink", false);
+ Paragraph para3 = doc.addParagraph("world");
+ TextHyperlink link3 = para3.applyHyperlink(new URI("http://odftoolkit.org"));
+ link3.setTextContent("new world");
+ para3.appendTextContent("_prefix");
+ para3.appendTextContent("_nolink", false);
- doc.save(ResourceUtilities.newTestOutputFile("TestParagraphHyperlink.odt"));
+ doc.save(ResourceUtilities.newTestOutputFile("TestParagraphHyperlink.odt"));
- TextDocument textdoc = TextDocument.loadDocument(ResourceUtilities
- .getTestResourceAsStream("TestParagraphHyperlink.odt"));
- Iterator<TextHyperlink> linkList = textdoc.getParagraphByReverseIndex(1, true).getHyperlinkIterator();
- if (linkList.hasNext()) {
- TextHyperlink aLink = linkList.next();
- Assert.assertEquals("New Heading1", aLink.getTextContent());
- Assert.assertEquals("mailto:devin@odftoolkit.org", aLink.getURI().toString());
- }
+ TextDocument textdoc = TextDocument.loadDocument(ResourceUtilities
+ .getTestResourceAsStream("TestParagraphHyperlink.odt"));
+ Iterator<TextHyperlink> linkList = textdoc.getParagraphByReverseIndex(1, true).getHyperlinkIterator();
+ if (linkList.hasNext()) {
+ TextHyperlink aLink = linkList.next();
+ Assert.assertEquals("New Heading1", aLink.getTextContent());
+ Assert.assertEquals("mailto:devin@odftoolkit.org", aLink.getURI().toString());
+ }
- linkList = textdoc.getParagraphByReverseIndex(0, true).getHyperlinkIterator();
- if (linkList.hasNext()) {
- TextHyperlink aLink = linkList.next();
- Assert.assertEquals("new world_prefix", aLink.getTextContent());
- Assert.assertEquals("http://odftoolkit.org", aLink.getURI().toString());
- }
- } catch (Exception e) {
- LOGGER.log(Level.SEVERE, e.getMessage(), e);
- Assert.fail();
- }
- }
-
- @Test
- public void testGetTextContentWithLibreOfficeFile() throws FileNotFoundException, Exception {
- TextDocument document = TextDocument.loadDocument(ResourceUtilities.getAbsolutePath("Bell.odt"));
- Paragraph paragraph = document.getParagraphByIndex(0, true);
+ linkList = textdoc.getParagraphByReverseIndex(0, true).getHyperlinkIterator();
+ if (linkList.hasNext()) {
+ TextHyperlink aLink = linkList.next();
+ Assert.assertEquals("new world_prefix", aLink.getTextContent());
+ Assert.assertEquals("http://odftoolkit.org", aLink.getURI().toString());
+ }
+ } catch (Exception e) {
+ LOGGER.log(Level.SEVERE, e.getMessage(), e);
+ Assert.fail();
+ }
+ }
- Assert.assertEquals(
- "Bell, based in Los Angeles, makes and distributes electronic articles, "
- + "computer and building products.",
- paragraph.getTextContent());
- }
-
- @Test
- public void shouldReturnMultipleLines() throws Exception {
- final String expected = "Hello\tWorld!\twho \t ever read this, is stupid.\n\n\nReally!";
- TextDocument document = TextDocument.newTextDocument();
- Paragraph p = document.addParagraph(expected);
- String textContent = p.getTextContent();
- Assert.assertEquals(expected, textContent.replace("\r", ""));
- }
+ @Test
+ public void testGetTextContentWithLibreOfficeFile() throws FileNotFoundException, Exception {
+ TextDocument document = TextDocument.loadDocument(ResourceUtilities.getAbsolutePath("Bell.odt"));
+ Paragraph paragraph = document.getParagraphByIndex(0, true);
+
+ Assert.assertEquals(
+ "Bell, based in Los Angeles, makes and distributes electronic articles, "
+ + "computer and building products.",
+ paragraph.getTextContent());
+ }
+
+ @Test
+ public void shouldReturnMultipleLines() throws Exception {
+ final String expected = "Hello\tWorld!\twho \t ever read this, is stupid.\n\n\nReally!";
+ TextDocument document = TextDocument.newTextDocument();
+ Paragraph p = document.addParagraph(expected);
+ String textContent = p.getTextContent();
+ Assert.assertEquals(expected, textContent.replace("\r", ""));
+ }
}
diff --git a/simple/src/test/resources/Bell.odt b/simple/src/test/resources/Bell.odt
index d97561c..9aee252 100644
--- a/simple/src/test/resources/Bell.odt
+++ b/simple/src/test/resources/Bell.odt
Binary files differ