Examples of TextPElement


Examples of org.odftoolkit.odfdom.dom.element.text.TextPElement

   */
  public void setTextContent(String content) {
    if (content != null) {
      Node child = listItemElement.getFirstChild();
      Node positionNode = null;
      TextPElement pElement = null;
      while (child != null) {
        if (child instanceof TextNumberElement) {
          positionNode = child.getNextSibling();
          child = child.getNextSibling();
        } else if ((child instanceof TextPElement) && (pElement == null)) {
          pElement = (TextPElement) child;
          child = child.getNextSibling();
        } else if ((child instanceof TextListElement) && (positionNode == null)) {
          positionNode = child;
          child = child.getNextSibling();
        } else {
          Node tmp = child;
          child = child.getNextSibling();
          listItemElement.removeChild(tmp);
        }
      }
      if (pElement == null) {
        if (positionNode == null) {
          pElement = listItemElement.newTextPElement();
        } else {
          pElement = ((OdfFileDom) listItemElement.getOwnerDocument()).newOdfElement(TextPElement.class);
          listItemElement.insertBefore(pElement, positionNode);
        }
      }
      pElement.setTextContent(content);
      if (paragraphDecorator != null) {
        paragraphDecorator.decorateListItem(this);
      } else {
        // paragraphDecorator is null when the owner List is constructed
        // by List(TextListElement).
        Node previousSibling = listItemElement.getPreviousSibling();
        String pElementStyleName = null;
        while (previousSibling != null) {
          if (previousSibling instanceof TextListItemElement) {
            Node previousChild = previousSibling.getFirstChild();
            while (previousChild != null) {
              if (previousChild instanceof TextPElement) {
                TextPElement previousPElement = (TextPElement) previousChild;
                pElementStyleName = previousPElement.getTextStyleNameAttribute();
                break;
              }
              previousChild = previousChild.getNextSibling();
            }
            break;
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.element.text.TextPElement

        }
        NodeList paras = axisTitle.getElementsByTagNameNS(OdfDocumentNamespace.TEXT.getUri(), "p");
        if (paras.getLength() == 0) {
          axisTitle.newTextPElement().setTextContent(title);
        } else {
          TextPElement para0 = (TextPElement) paras.item(0);
          para0.setTextContent(title);

        }
      }
    }
  }
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.element.text.TextPElement

    if(frameList.getLength() > 0){
      DrawFrameElement frame = (DrawFrameElement)frameList.item(0);
      NodeList textBoxList = frame.getElementsByTagNameNS(OdfDocumentNamespace.DRAW.getUri(), "text-box");
      if(textBoxList.getLength() > 0){
        DrawTextBoxElement textBox = (DrawTextBoxElement)textBoxList.item(0);
        TextPElement newPara = textBox.newTextPElement();
        newPara.setTextContent(text);
      }
    }
  }
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.element.text.TextPElement

  public void decorateListItem(ListItem item) {
    TextListItemElement listItemElement = item.getOdfElement();
    Node child = listItemElement.getFirstChild();
    while (child != null) {
      if (child instanceof TextPElement) {
        TextPElement pElement = (TextPElement) child;
        pElement.setTextStyleNameAttribute(paragraphStyle.getStyleNameAttribute());
      }
      child = child.getNextSibling();
    }
  }
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.element.text.TextPElement

      // http://www.w3.org/TR/xpath#path-abbrev)
      XPath xpath2 = odfContent.getXPath();

      // receiving the first paragraph "//text:p[1]" ''(JDK5
      // functionality)''
      TextPElement para = (TextPElement) xpath2.evaluate("//text:p[1]", odfContent, XPathConstants.NODE);

      // adding an image - expecting the user to know that
      // an image consists always of a 'draw:image' and a 'draw:frame'
      // parent

      // FUTURE USAGE:
      // para.createDrawFrame().createDrawImage("/myweb.org/images/myHoliday.png",
      // "/Pictures/myHoliday.png");
      // Child access methods are still not part of the v0.6.x releases
      // CURRENT USAGE:
      OdfDrawFrame odfFrame = (OdfDrawFrame) OdfXMLFactory.newOdfElement(odfContent,
          DrawFrameElement.ELEMENT_NAME);
      para.appendChild(odfFrame);
      OdfDrawImage odfImage = (OdfDrawImage) OdfXMLFactory.newOdfElement(odfContent, OdfDrawImage.ELEMENT_NAME);
      odfFrame.appendChild(odfImage);
      odfImage.newImage(ResourceUtilities.getURI(TEST_PIC));

      OdfDrawImage odfImage2 = (OdfDrawImage) OdfXMLFactory.newOdfElement(odfContent, OdfDrawImage.ELEMENT_NAME);
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.element.text.TextPElement

      OdfContentDom contentDom = embDoc.getContentDom();
      XPath xpath = contentDom.getXPath();
      // Make sure the embedded document is being loaded

      // Add text element
      TextPElement para = (TextPElement) xpath.evaluate("//text:p[1]", contentDom, XPathConstants.NODE);
      LOG.log(Level.INFO, "First para: {0}", para.getTextContent());
      OdfTextSpan spanElem = new OdfTextSpan(contentDom);
      spanElem.setTextContent(TEST_SPAN_TEXT);
      para.appendChild(spanElem);

      // Add frame and image element
      TextPElement paraLast = (TextPElement) xpath.evaluate("//text:p[last()]", contentDom, XPathConstants.NODE);
      addImageToDocument(contentDom, paraLast);

      // Access/Update automatic styles
      OdfOfficeAutomaticStyles autoStyles = embDoc.getContentDom().getAutomaticStyles();
      OdfStyle autoStyle = autoStyles.getStyle("P1", OdfStyleFamily.Paragraph);
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.element.text.TextPElement

      Assert.assertNotNull(fileEntry);

      // get "Object 1/content.xml"
      OdfContentDom contentDom = embDoc.getContentDom();
      XPath xpath = contentDom.getXPath();
      TextPElement lastPara = (TextPElement) xpath.evaluate("//text:p[last()]", contentDom, XPathConstants.NODE);
      addFrameForEmbeddedDoc(contentDom, lastPara, "Object in Object1");
      List<Document> emb_embDocs = embDoc.getEmbeddedDocuments();
      Assert.assertEquals(embDocsNumber + 1, emb_embDocs.size());

      Document emb_embDoc = rootDocument.getEmbeddedDocument(embDoc.getDocumentPath() + pathOfSecondInnerDoc);
      contentDom = emb_embDoc.getContentDom();
      TextPElement para = (TextPElement) xpath.evaluate("//text:p[1]", contentDom, XPathConstants.NODE);
      OdfTextSpan spanElem = new OdfTextSpan(contentDom);
      spanElem.setTextContent(TEST_SPAN_TEXT);
      para.appendChild(spanElem);

      // embDoc.save(ResourceUtilities.newTestOutputFile("222debug.odt"));
      rootDocument.save(TEST_FILE_EMBEDDED_EMBEDDED);

      Document docWithdoubleEmbeddedDoc = Document.loadDocument(TEST_FILE_EMBEDDED_EMBEDDED);
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.element.text.TextPElement

      Document doc1 = embDocs.get(0);
      Assert.assertNotNull(doc1);

      OdfContentDom contentDom = doc1.getContentDom();
      XPath xpath = contentDom.getXPath();
      TextPElement para = (TextPElement) xpath.evaluate("//text:p[1]", contentDom, XPathConstants.NODE);
      OdfTextSpan spanElem = new OdfTextSpan(contentDom);
      spanElem.setTextContent(TEST_SPAN_TEXT);
      para.appendChild(spanElem);
      // save the embed document to a stand alone document
      doc1.save(TEST_FILE_SAVE_EMBEDDED_OUT);
      // Load test
      Document loadedDoc = Document.loadDocument(TEST_FILE_SAVE_EMBEDDED_OUT);
      OdfContentDom contentDom2 = loadedDoc.getContentDom();
      OdfTextSpan span = (OdfTextSpan) xpath.evaluate("//text:span[last()]", contentDom2, XPathConstants.NODE);
      Assert.assertEquals(span.getTextContent(), TEST_SPAN_TEXT);
      List<Document> embDocs3 = docWithEmbeddedObjects.getEmbeddedDocuments(Document.OdfMediaType.TEXT);

      // Writer Doc
      Document doc3 = embDocs3.get(0);
      Assert.assertNotNull(doc3);
      OdfContentDom contentDom3 = doc3.getContentDom();
      TextPElement para2 = (TextPElement) xpath.evaluate("//text:p[1]", contentDom3, XPathConstants.NODE);
      addImageToDocument(contentDom3, para2);
      TextPElement para3 = (TextPElement) xpath.evaluate("//text:p[last()]", contentDom3, XPathConstants.NODE);
      addFrameForEmbeddedDoc(contentDom3, para3, "NewEmbedded");
      doc3.insertDocument(TextDocument.newTextDocument(), "/NewEmbedded/");
      Document doc4 = doc3.getEmbeddedDocument("NewEmbedded");
      Assert.assertNotNull(doc4);
      OdfContentDom contentDom4 = doc4.getContentDom();
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.element.text.TextPElement

   * Create child element {@odf.element text:p}.
   *
   * @return the element {@odf.element text:p}
   */
  public TextPElement newTextPElement() {
    TextPElement textP = ((OdfFileDom) this.ownerDocument).newOdfElement(TextPElement.class);
    this.appendChild(textP);
    return textP;
  }
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.element.text.TextPElement

    // get root of all content of a text document
    OfficeTextElement officeText = odt.getContentRoot();

    // get first paragraph
    TextPElement firstParagraph =
      OdfElement.findFirstChildNode(TextPElement.class, officeText);

    // XPath alternative to get the first paragraph
    /*
      XPath xpath = XPathFactory.newInstance().newXPath();
      xpath.setNamespaceContext(new OdfNamespace());
      OdfFileDom dom = odt.getContentDom();
      firstParagraph = (TextPElement) xpath.evaluate("//text:p[1]", dom, XPathConstants.NODE);
    */

    // insert a frame
    DrawFrameElement frame = firstParagraph.newDrawFrameElement();

    // insert an image: This is a class from the Document API
    OdfDrawImage image = (OdfDrawImage) frame.newDrawImageElement();
    image.newImage(new URI("./MySampleImage.png"));

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.