Examples of OdfWhitespaceProcessor


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

    if ((fromindex == 0) && (leftLength == 0)) {
      return;
    }
    int nodeLength = 0;
    Node node = pNode.getFirstChild();
    OdfWhitespaceProcessor textProcessor = new OdfWhitespaceProcessor();

    while (node != null) {
      if ((fromindex == 0) && (leftLength == 0)) {
        return;
      }
      if (node.getNodeType() == Node.TEXT_NODE) {
        nodeLength = node.getNodeValue().length();
      } else if (node.getNodeType() == Node.ELEMENT_NODE) {
        if (node.getLocalName().equals("s")) // text:s
        {
          try {
            nodeLength = Integer.parseInt(((Element) node).getAttributeNS(OdfDocumentNamespace.TEXT.getUri(), "c"));
          } catch (Exception e) {
            nodeLength = 1;
          }

        } else if (node.getLocalName().equals("line-break")) {
          nodeLength = 1;
        } else if (node.getLocalName().equals("tab")) {
          nodeLength = 1;
        } else {
          nodeLength = textProcessor.getText((OdfElement) node).length();
        }

      }
      if (nodeLength <= fromindex) {
        fromindex -= nodeLength;
View Full Code Here

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

   * text content of the container element will be provided
   * @return a String representation of the value of this TextSelection
   */
  @Override
  public String toString() {
    OdfWhitespaceProcessor textProcessor = new OdfWhitespaceProcessor();

    return "[" + mMatchedText + "] started from " + mIndexInContainer + " in paragraph:" + textProcessor.getText(getContainerElement());
  }
View Full Code Here

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

      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
      OdfWhitespaceProcessor textProcessor = new OdfWhitespaceProcessor();
      delete(eIndex, textProcessor.getText(copyParentNode).length() - eIndex, copyParentNode);
      delete(0, sIndex, copyParentNode);
      optimize(copyParentNode);
      Node childNode = copyParentNode.getFirstChild();
      while (childNode != null) {
        textSpan.appendChild(childNode.cloneNode(true));
View Full Code Here

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

   *
   * @param element
   */
  private void optimize(Node pNode) {
    // check if the text:a can be optimized
    OdfWhitespaceProcessor textProcess = new OdfWhitespaceProcessor();
    Node node = pNode.getFirstChild();
    while (node != null) {
      Node nextNode = node.getNextSibling();
      //if ((node.getNodeType() == Node.ELEMENT_NODE) && (node.getPrefix().equals("text"))) {
      if (node instanceof OdfTextSpan) {
        if (textProcess.getText(node).length() == 0) {
          node.getParentNode().removeChild(node);
        } else {
          optimize(node);
        }
      }
View Full Code Here

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

      fromindex = 0;
    }
    if (fromindex == 0 && mIsInserted) {
      return;
    }
    OdfWhitespaceProcessor textProcessor = new OdfWhitespaceProcessor();
    int nodeLength = 0;
    Node node = pNode.getFirstChild();
    while (node != null) {
      if (fromindex <= 0 && mIsInserted) {
        return;
      }
      if (node.getNodeType() == Node.TEXT_NODE) {
        nodeLength = node.getNodeValue().length();
        if ((fromindex != 0) && (nodeLength < fromindex)) {
          fromindex -= nodeLength;
        } else {
          // insert result after node, and insert an new text node
          // after
          // the result node
          String value = node.getNodeValue();
          StringBuffer buffer = new StringBuffer();
          buffer.append(value.substring(0, fromindex));
          // insert the text span in appropriate position
          node.setNodeValue(buffer.toString());
          Node nextNode = node.getNextSibling();
          Node parNode = node.getParentNode();

          Node newNode = node.cloneNode(true);
          newNode.setNodeValue(value.substring(fromindex, value.length()));
          if (nextNode != null) {
            parNode.insertBefore(textSpan, nextNode);
            parNode.insertBefore(newNode, nextNode);
          } else {
            parNode.appendChild(textSpan);
            parNode.appendChild(newNode);
          }
          mIsInserted = true;
          return;
        }
      } else if (node.getNodeType() == Node.ELEMENT_NODE) {
        if (node.getLocalName().equals("s")) // text:s
        {
          try {
            nodeLength = Integer.parseInt(((Element) node).getAttributeNS(OdfDocumentNamespace.TEXT.getUri(), "c"));
          } catch (Exception e) {
            nodeLength = 1;
          }
          fromindex -= nodeLength;

        } else if (node.getLocalName().equals("line-break")) {
          nodeLength = 1;
          fromindex--;
        } else if (node.getLocalName().equals("tab")) {
          nodeLength = 1;
          fromindex--;
        } else {
          nodeLength = textProcessor.getText(node).length();
          insertSpan(textSpan, fromindex, node);
          fromindex -= nodeLength;
        }

      }
View Full Code Here

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

   * @return the text displayed in this cell
   */
  public String getDisplayText() {
    //TODO: This function doesn't work well if a cell contains a list.
    //Refer to testGetSetTextValue();
    OdfWhitespaceProcessor textProcessor = new OdfWhitespaceProcessor();
    return textProcessor.getText(mCellElement);
  }
View Full Code Here

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

    if (content == null) {
      content = "";
    }
    removeContent();

    OdfWhitespaceProcessor textProcessor = new OdfWhitespaceProcessor();
    OdfTextParagraph para = new OdfTextParagraph((OdfFileDom) mCellElement.getOwnerDocument());
    textProcessor.append(para, content);

    mCellElement.appendChild(para);
  }
View Full Code Here

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

    if (content == null) {
      content = "";
    }
    removeContent();

    OdfWhitespaceProcessor textProcessor = new OdfWhitespaceProcessor();
    OdfTextParagraph para = new OdfTextParagraph((OdfFileDom) mCellElement.getOwnerDocument());
    if ((stylename != null) && (stylename.length() > 0)) {
      para.setStyleName(stylename);
    }
    textProcessor.append(para, content);

    mCellElement.appendChild(para);
  }
View Full Code Here

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

   *
   * @param fromCell  another cell whose content will be appended to this cell
   */
  void appendContentFrom(OdfTableCell fromCell) {
    splitRepeatedCells();
    OdfWhitespaceProcessor textProcess = new OdfWhitespaceProcessor();
    TableTableCellElementBase cell = fromCell.getOdfElement();
    Node node = cell.getFirstChild();
    while (node != null) {
      if (node instanceof OdfTextParagraph) {
        if (!textProcess.getText(node).equals("")) {
          mCellElement.appendChild(node.cloneNode(true));
        }
      } else {
        mCellElement.appendChild(node.cloneNode(true));
      }
View Full Code Here

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

    }
    OdfElement container = getContainerElement();
    if (container == null) {
      return false;
    }
    OdfWhitespaceProcessor textProcessor = new OdfWhitespaceProcessor();
    String content = textProcessor.getText(container);
    if (content.indexOf(mMatchedText, mIndexInContainer) == mIndexInContainer) {
      return true;
    } else {
      return false;
    }
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.