Examples of OdfTextSpan


Examples of org.odftoolkit.odfdom.incubator.doc.text.OdfTextSpan

    }
    OdfElement parentElement = getContainerElement();
    int leftLength = getText().length();
    int index = mIndexInContainer;
    delete(index, leftLength, parentElement);
    OdfTextSpan textSpan = new OdfTextSpan((OdfFileDom) parentElement.getOwnerDocument());
    textSpan.addContentWhitespace(newText);
    mIsInserted = false;
    insertOdfElement(textSpan, index, parentElement);
    // optimize the parent element
    optimize(parentElement);
    int offset = newText.length() - leftLength;
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.text.OdfTextSpan

    }
    OdfElement parentElement = getContainerElement();
    int leftLength = getText().length();
    int index = mIndexInContainer;
    delete(index, leftLength, parentElement);
    OdfTextSpan textSpan = new OdfTextSpan((OdfFileDom) parentElement.getOwnerDocument());
    textSpan.addContentWhitespace(getText());
    mIsInserted = false;
    insertOdfElement(textSpan, index, parentElement);
    // optimize the parent element
    optimize(parentElement);
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.text.OdfTextSpan

    if (positionItem instanceof TextSelection) {
      indexOfNew = ((TextSelection) positionItem).getIndex();
      newElement = ((TextSelection) positionItem).getContainerElement();
    }

    OdfTextSpan textSpan = getSpan((OdfFileDom) positionItem.getElement().getOwnerDocument());
    mIsInserted = false;
    insertOdfElement(textSpan, indexOfNew, newElement);
    adjustStyle(newElement, textSpan, null);
    SelectionManager.refreshAfterPasteAtFrontOf(this, positionItem);
  }
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.text.OdfTextSpan

    OdfElement newElement = positionItem.getElement();
    if (positionItem instanceof TextSelection) {
      indexOfNew = ((TextSelection) positionItem).getIndex() + ((TextSelection) positionItem).getText().length();
      newElement = ((TextSelection) positionItem).getContainerElement();
    }
    OdfTextSpan textSpan = getSpan((OdfFileDom) positionItem.getElement().getOwnerDocument());
    mIsInserted = false;
    insertOdfElement(textSpan, indexOfNew, newElement);
    adjustStyle(newElement, textSpan, null);
    SelectionManager.refreshAfterPasteAtEndOf(this, positionItem);
  }
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.text.OdfTextSpan

    if (parentElement != null) {
      OdfElement copyParentNode = (OdfElement) parentElement.cloneNode(true);
      if (ownerDoc != parentElement.getOwnerDocument()) {
        copyParentNode = (OdfElement) ownerDoc.adoptNode(copyParentNode);
      }
      OdfTextSpan textSpan = new OdfTextSpan(ownerDoc);
      int sIndex = mIndexInContainer;
      int eIndex = sIndex + mMatchedText.length();
      // delete the content except the selection string
      // delete from the end to start, so that the postion will not be
      // impact by delete action
      delete(eIndex, TextExtractor.getText(copyParentNode).length() - eIndex, copyParentNode);
      delete(0, sIndex, copyParentNode);
      optimize(copyParentNode);
      Node childNode = copyParentNode.getFirstChild();
      while (childNode != null) {
        textSpan.appendChild(childNode.cloneNode(true));
        childNode = childNode.getNextSibling();
      }
      // apply text style for the textSpan
      if (copyParentNode instanceof OdfStylableElement) {
        applyTextStyleProperties(getTextStylePropertiesDeep((OdfStylableElement) copyParentNode), textSpan);
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.text.OdfTextSpan

      Node node = parentNode.getFirstChild();
      while (node != null) {
        if (node.getNodeType() == Node.TEXT_NODE) {
          if (node.getTextContent().length() > 0) {
            Node nextNode = node.getNextSibling();
            OdfTextSpan span = new OdfTextSpan((OdfFileDom) node.getOwnerDocument());
            span.appendChild(node);
            if (nextNode != null) {
              parentNode.insertBefore(span, nextNode);
            } else {
              parentNode.appendChild(span);
            }
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.text.OdfTextSpan

          int nextLength = value.length() - endLength;

          Node nextNode = node.getNextSibling();
          Node parNode = node.getParentNode();
          // init text:a
          OdfTextSpan textSpan = new OdfTextSpan((OdfFileDom) node.getOwnerDocument());
          Node newNode = null;
          if (nextLength >= 0) {
            textSpan.setTextContent(value.substring(fromIndex, endLength));
            newNode = node.cloneNode(true);
            newNode.setNodeValue(value.substring(endLength, value.length()));
            leftLength = 0;
          } else {
            textSpan.setTextContent(value.substring(fromIndex, value.length()));
            leftLength = endLength - value.length();
          }
          textSpan.setProperties(style.getStyleProperties());

          if (nextNode != null) {
            parNode.insertBefore(textSpan, nextNode);
            if (newNode != null) {
              parNode.insertBefore(newNode, nextNode);
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.text.OdfTextSpan


      // 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);
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.text.OdfTextSpan

      Assert.assertEquals(embDocsNumber + 1, emb_embDocs.size());
     
      OdfDocument emb_embDoc = rootDocument.loadSubDocument(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);
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.text.OdfTextSpan

        OdfDocument doc1 = embDocs.get(eDocPath);
        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
        OdfDocument loadedDoc = OdfDocument.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);
        Map<String, OdfDocument> embDocs3 = docWithEmbeddedObjects.loadSubDocuments(OdfDocument.OdfMediaType.TEXT);
        for(String eDocPath3 : embDocs3.keySet()){
          // Writer Doc
          OdfDocument doc3 = embDocs3.get(eDocPath3);
          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(OdfTextDocument.newTextDocument(), "/NewEmbedded/");
          OdfDocument doc4 = doc3.loadSubDocument("NewEmbedded");
          Assert.assertNotNull(doc4);
          OdfContentDom contentDom4 = doc4.getContentDom();
          para = (TextPElement) xpath.evaluate("//text:p[1]",  contentDom4, XPathConstants.NODE);
          spanElem = new OdfTextSpan(contentDom4);
          spanElem.setTextContent(TEST_SPAN_TEXT);
          para.appendChild(spanElem);
          doc3.save(TEST_FILE_SAVE_EMBEDDED_OUT2);

          OdfDocument testLoad = OdfDocument.loadDocument(TEST_FILE_SAVE_EMBEDDED_OUT2);
          NodeList linkNodes = (NodeList) xpath.evaluate("//*[@xlink:href]", testLoad.getContentDom(), XPathConstants.NODE);
          for (int i = 0; i < linkNodes.getLength(); i++) {
            OdfElement object = (OdfElement) linkNodes.item(i);
            String refObjPath = object.getAttributeNS(OdfDocumentNamespace.XLINK.getUri(), "href");
            Assert.assertTrue(refObjPath.equals("Pictures/"  + TEST_PIC|| refObjPath.equals("./NewEmbedded"));
          }
          Assert.assertNotNull(testLoad.getPackage().getFileEntry("Pictures/" + TEST_PIC));
          OdfDocument embedDocOftestLoad = testLoad.loadSubDocument("NewEmbedded/");
          contentDom4 = embedDocOftestLoad.getContentDom();
          OdfTextSpan span4 = (OdfTextSpan) xpath.evaluate("//text:span[last()]", contentDom4, XPathConstants.NODE);
          Assert.assertNotNull(span4);
          Assert.assertEquals(span4.getTextContent(), TEST_SPAN_TEXT);
        }
      }     
    } catch (Exception ex) {
      Logger.getLogger(DocumentCreationTest.class.getName()).log(Level.SEVERE, null, ex);
      Assert.fail("Failed with " + ex.getClass().getName() + ": '" + ex.getMessage() + "'");
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.