Package org.odftoolkit.simple.text

Examples of org.odftoolkit.simple.text.Paragraph


  @Before
  public void setUp() {
    try {
      doc = (TextDocument) Document.loadDocument(ResourceUtilities.getAbsolutePath(TEXT_FILE));
      sourcedoc=TextDocument.newTextDocument();
      Paragraph para = sourcedoc.addParagraph("helloImage");
      Image image = Image.newImage(para, ResourceUtilities.getURI("image_list_item.png"));
      image.setName("this image 1");
      image.setHyperlink(new URI("http://odftoolkit.org"));
     
      Paragraph para2 = sourcedoc.addParagraph("helloImage2");
      image2 = Image.newImage(para2, ResourceUtilities.getURI("testA.jpg"));
      image2.setName("this image 2");
      image2.setHyperlink(new URI("http://odftoolkit.org"));
     
     
View Full Code Here


    try {
      ImageSelection nextImageSelection=null;
      while (search.hasNext()) {
        TextSelection item= (TextSelection) search.nextSelection();
        nextImageSelection=new ImageSelection(item);
        Paragraph paragraph=sourcedoc.getParagraphByIndex(0, true);
        TextParagraphElementBase textParaEleBase = paragraph.getOdfElement();
        NodeList nodeImages = textParaEleBase.getElementsByTagName("draw:image");
        Node nodeImage = nodeImages.item(0);
        DrawImageElement im = (DrawImageElement)nodeImage;
        Image ima = Image.getInstanceof(im);
        Image image = nextImageSelection.replaceWithImage(ima);
View Full Code Here

          Assert.assertEquals(cell.getCellStyleName(), oddTableStyle);
          paraStyle = oddParaStyle;
        }
        Iterator<Paragraph> paraIterator = cell.getParagraphIterator();
        while (paraIterator.hasNext()) {
          Paragraph t = paraIterator.next();
          if (paraStyle != null && paraStyle != "") {
            Assert.assertEquals(t.getOdfElement().getStyleName(),
                paraStyle);
          }
        }
        cellIndex++;
      }
View Full Code Here

   */
  @Test
  public void testReplacewithImage() throws Exception {
    // create source image
    TextDocument sourcedoc = TextDocument.newTextDocument();
    Paragraph para = sourcedoc.addParagraph("helloImage");
    Image image = Image.newImage(para, ResourceUtilities.getURI("image_list_item.png"));
    image.setName("this image 1");
    image.setHyperlink(new URI("http://odftoolkit.org"));
    Paragraph para2 = sourcedoc.addParagraph("helloImage2");
    Image image2 = Image.newImage(para2, ResourceUtilities.getURI("testA.jpg"));
    image2.setName("this image 2");
    image2.setHyperlink(new URI("http://odftoolkit.org"));
    search = null;
    // 6 Simple, at the middle of original Paragraph, split original
    // Paragraph, insert before the second Paragraph.
    doc = (TextDocument) Document.loadDocument(ResourceUtilities.getAbsolutePath(TEXT_FILE));
    search = new TextNavigation("SIMPLE", doc);
    int i = 0;
    TextSelection item = null;
    while (search.hasNext()) {
      item = (TextSelection) search.nextSelection();
      Paragraph paragraph = sourcedoc.getParagraphByIndex(0, true);
      TextParagraphElementBase textParaEleBase = paragraph.getOdfElement();
      NodeList nodeImages = textParaEleBase.getElementsByTagName("draw:image");
      Node nodeImage = nodeImages.item(0);
      DrawImageElement im = (DrawImageElement) nodeImage;
      Image ima = Image.getInstanceof(im);
      image = item.replaceWith(ima);
View Full Code Here

    search = new TextNavigation("SIMPLE", doc);
    int i = 0;
    TextSelection item = null;
    while (search.hasNext()) {
      item = (TextSelection) search.nextSelection();
      Paragraph paragraph = sourcedoc.getParagraphByIndex(0, true);
      item.replaceWith(paragraph);
      i++;
    }
    search = new TextNavigation("Hello1 from SIMPLE source document!", doc);
    int j = 0;
    while (search.hasNext()) {
      search.nextSelection();
      j++;
    }
    Assert.assertTrue(i == j);
   
    // 2 Task1, #1 at the start of original Paragraph, #2 replace original
    // Paragraph
    search = new TextNavigation("Task1", doc);
    i = 0;
    while (search.hasNext()) {
      item = (TextSelection) search.nextSelection();
     
      Paragraph paragraph = sourcedoc.getParagraphByIndex(1, true);
      item.replaceWith(paragraph);
      i++;
    }
    search = new TextNavigation("Hello2 from source document!", doc);
    j = 0;
    while (search.hasNext()) {
      search.nextSelection();
      j++;
    }
    Assert.assertTrue(i == j);
   
    // 1 Container, #1 at the end of original Paragraph,
    search = new TextNavigation("Container", doc);
    i = 0;
    while (search.hasNext()) {
      item = (TextSelection) search.nextSelection();
      Paragraph paragraph = sourcedoc.getParagraphByIndex(2, true);
      item.replaceWith(paragraph);
      i++;
    }
    search = new TextNavigation("Hello3 from source document!", doc);
    j = 0;
    while (search.hasNext()) {
      search.nextSelection();
      j++;
    }
    Assert.assertTrue(i == j);
    try {
      doc.save(ResourceUtilities.newTestOutputFile("TextSelectionReplacewithParagraphResult.odt"));
    } catch (Exception e) {
      Logger.getLogger(TextSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
      Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'");
    }
    doc = (TextDocument) Document.loadDocument(ResourceUtilities
        .getAbsolutePath(TEST_FILE));
    search = new TextNavigation("<<target>>", doc);
    i = 0;
    try {
      while (search.hasNext()) {
        i++;
        item = (TextSelection) search.nextSelection();
        Paragraph paragraph = sourcedoc.getParagraphByIndex(1, true);
        paragraph = item.replaceWith(paragraph);
        Assert.assertNotNull(paragraph);
        Assert.assertEquals(
            TextExtractor.getText(paragraph.getOdfElement()),
            "Hello2 from source document!");
      }
      doc.save(ResourceUtilities
          .newTestOutputFile("TextSelectionReplacewithPararaphResult-BasicCases.odt"));
      verifyReplaceWithParagraphByBasicCases("TextSelectionReplacewithPararaphResult-BasicCases.odt");
View Full Code Here

      Assert.assertNotNull(breakBefore);
      description = search.nextSelection().getElement();
      replacement = description.getNextSibling();
      Assert.assertEquals("prefix", TextExtractor
          .getText((TextParagraphElementBase) replacement));
      Paragraph para = Paragraph
          .getInstanceof((TextParagraphElementBase) replacement);
      breakBefore = para.getStyleHandler()
          .getParagraphPropertiesForRead().getBreakBefore();
      Assert.assertNotNull(breakBefore);
      replacement = replacement.getNextSibling();
      Assert.assertTrue(replacement instanceof TableTableElement);
      table = Table.getInstance((TableTableElement) replacement);
      breakBefore = table.getStyleHandler().getTablePropertiesForRead()
          .getBreakBefore();
      Assert.assertNull(breakBefore);
      replacement = replacement.getNextSibling();
      Assert.assertEquals("suffix", TextExtractor
          .getText((TextParagraphElementBase) replacement));
      para = Paragraph
          .getInstanceof((TextParagraphElementBase) replacement);
      breakBefore = para.getStyleHandler()
          .getParagraphPropertiesForRead().getBreakBefore();
      Assert.assertNull(breakBefore);
      description = search.nextSelection().getElement();
      replacement = description.getNextSibling();
      Assert.assertTrue(replacement instanceof TableTableElement);
View Full Code Here

      OdfElement description = search.nextSelection().getElement();
      TextParagraphElementBase replacement = (TextParagraphElementBase) description
          .getNextSibling();
      Assert.assertEquals("Hello2 from source document!",
          TextExtractor.getText(replacement));
      Paragraph para = Paragraph.getInstanceof(replacement);
      String breakBefore = para.getStyleHandler()
          .getParagraphPropertiesForRead().getBreakBefore();
      Assert.assertNotNull(breakBefore);
      description = search.nextSelection().getElement();
      replacement = (TextParagraphElementBase) description
          .getNextSibling();
      Assert.assertEquals("prefix", TextExtractor.getText(replacement));
      para = Paragraph.getInstanceof(replacement);
      breakBefore = para.getStyleHandler()
          .getParagraphPropertiesForRead().getBreakBefore();
      Assert.assertNotNull(breakBefore);
      replacement = (TextParagraphElementBase) replacement
          .getNextSibling();
      Assert.assertEquals("Hello2 from source document!",
          TextExtractor.getText(replacement));
      para = Paragraph.getInstanceof(replacement);
      breakBefore = para.getStyleHandler()
          .getParagraphPropertiesForRead().getBreakBefore();
      Assert.assertNull(breakBefore);
      replacement = (TextParagraphElementBase) replacement
          .getNextSibling();
      Assert.assertEquals("suffix", TextExtractor.getText(replacement));
      para = Paragraph.getInstanceof(replacement);
      breakBefore = para.getStyleHandler()
          .getParagraphPropertiesForRead().getBreakBefore();
      Assert.assertNull(breakBefore);
      description = search.nextSelection().getElement();
      replacement = (TextParagraphElementBase) description
          .getNextSibling();
      Assert.assertEquals("Hello2 from source document!",
          TextExtractor.getText(replacement));
      para = Paragraph.getInstanceof(replacement);
      String masterStyle = para.getStyleHandler()
          .getStyleElementForRead()
          .getAttribute("style:master-page-name");
      Assert.assertNotNull(masterStyle);
    } catch (Exception e) {
      Logger.getLogger(TextSelectionTest.class.getName()).log(
View Full Code Here

  @Test
  public void testHorizontalAlignmentType() {
    try {
     
      TextDocument doc = TextDocument.newTextDocument();
      Paragraph paragraph1 = doc.addParagraph("paragraph text");

      paragraph1.setHorizontalAlignment(HorizontalAlignmentType.DEFAULT);
      HorizontalAlignmentType align = paragraph1.getHorizontalAlignment();
      Assert.assertEquals(HorizontalAlignmentType.DEFAULT, align);
     
      HorizontalAlignmentType filled = HorizontalAlignmentType.enumValueOf("filled");
      String start = filled.getAlignmentString();
      Assert.assertEquals("start", start);
View Full Code Here

  @Test
  public void testAnchorType() throws Exception{
      String content = "XXXXX This is a text box XXXXX";
    try {
      TextDocument textDoc = TextDocument.newTextDocument();
      Paragraph p = textDoc.addParagraph("paragraph");
      FrameRectangle frameR = new FrameRectangle(4.21, 1.32, 4.41, 3.92, SupportedLinearMeasure.CM);
     
      Textbox box = p.addTextbox(frameR);
      box.setName("tbox name");
      box.setTextContent(content);
     
      FrameStyleHandler frameStyleHandler = new FrameStyleHandler(box);
      frameStyleHandler.setBackgroundColor(Color.BLUE);
View Full Code Here

  @Test
  public void testVerticalRelative() throws Exception{
      String content = "This is a text box";
    try {
      TextDocument textDoc = TextDocument.newTextDocument();
      Paragraph p = textDoc.addParagraph("paragraph");
      FrameRectangle frameR = new FrameRectangle(4.21, 1.32, 4.41, 3.92, SupportedLinearMeasure.IN);
     
      Textbox box = p.addTextbox(frameR);
      box.setName("tbox name");
      box.setTextContent(content);
     
      FrameStyleHandler frameStyleHandler = new FrameStyleHandler(box);
      frameStyleHandler.setBackgroundColor(Color.YELLOW);
View Full Code Here

TOP

Related Classes of org.odftoolkit.simple.text.Paragraph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.