Package org.eclipse.wst.xml.core.internal.provisional.document

Examples of org.eclipse.wst.xml.core.internal.provisional.document.IDOMText


          }
        }
        else if (TEXT.equals(selectionStrategy)) {
          // underline the text between the tags
          if (node.getNodeType() == Node.TEXT_NODE) {
            IDOMText textNode = (IDOMText) node;
            int start = textNode.getStartOffset();
            String value = textNode.getNodeValue();
            int index = 0;
            char curChar = value.charAt(index);
            // here we are finding start offset by skipping over
            // whitespace:
            while ((curChar == '\n') || (curChar == '\t') || (curChar == '\r') || (curChar == ' ')) {
              curChar = value.charAt(index);
              index++;
            }
            if (index > 0) {
              index--;

            }
            start = start + index;
            startEndPositions[0] = start;
            startEndPositions[1] = start + value.trim().length();
          }
          else if (node.getNodeType() == Node.ELEMENT_NODE) {
            IDOMElement element = (IDOMElement) node;
            Node child = element.getFirstChild();
            if (child instanceof IDOMNode) {
              IDOMNode xmlChild = ((IDOMNode) child);
              startEndPositions[0] = xmlChild.getStartOffset();
              startEndPositions[1] = xmlChild.getEndOffset();
            }
          }
        }
        else if (FIRST_NON_WHITESPACE_TEXT.equals(selectionStrategy)) {
          // search through all child nodes and return range of
          // first non-whitespace
          // text node
          if (node.getNodeType() == Node.ELEMENT_NODE) {
            NodeList nodes = node.getChildNodes();
            for (int i = 0; i < nodes.getLength(); i++) {
              Node currentNode = nodes.item(i);
              if (currentNode.getNodeType() == Node.TEXT_NODE) {
                // TODO (Trung) I don't think we should call
                // getNodeValue(), trim(), length()
                // repeatedly.
                // This is inefficient, to improve use local
                // variables to store values.
                IDOMText textNode = (IDOMText) currentNode;
                if (textNode.getNodeValue().trim().length() > 0) {
                  String value = textNode.getNodeValue();
                  int index = 0;
                  int start = textNode.getStartOffset();
                  char curChar = value.charAt(index);
                  // here we are finding start offset by
                  // skipping over whitespace:
                  while ((curChar == '\n') || (curChar == '\t') || (curChar == '\r') || (curChar == ' ')) {
                    curChar = value.charAt(index);
View Full Code Here


   */
  public boolean haveNonWhitespaceTextChild() {
    List children1 = this.getChildren();
    for (int i = 0, size = children1.size(); i < size; i++) {
      if (children1.get(i) instanceof TextEditPart) {
        IDOMText xmltext = (IDOMText) ((TextEditPart) children1.get(i))
            .getIDOMNode();
        if (!xmltext.isElementContentWhitespace()) {
          return true;
        }
      }
    }
    return false;
View Full Code Here

  /**
   */
  protected void formatNode(IDOMNode node, HTMLFormatContraints contraints) {
    if (node == null)
      return;
    IDOMText text = (IDOMText) node;

    String source = getCSSContent(node);
    if (source == null) { // fallback
      source = text.getSource();
    }

    int offset = text.getStartOffset();
    int length = text.getEndOffset() - offset;
    replaceSource(text.getModel(), offset, length, source);
    setWidth(contraints, source);
  }
View Full Code Here

      }
    }
    else if (child.getNodeType() == Node.TEXT_NODE) {
      String tagName = impl.getTagName();
      if (tagName != null && tagName.equalsIgnoreCase(HTML40Namespace.ElementName.EMBED)) {
        IDOMText text = (IDOMText) child;
        if (!text.isElementContentWhitespace())
          return false;
      }
    }
    else if (child.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
      if (impl.isImplicitTag())
View Full Code Here

      return;
    Node parent = node.getParentNode();
    if (parent == null)
      return;

    IDOMText text = (IDOMText) node;
    String source = text.getSource();

    if (!canFormatText(text)) {
      setWidth(contraints, source);
      return;
    }

    int offset = text.getStartOffset();
    int length = text.getEndOffset() - offset;

    // format adjacent text at once
    if (mode == FORMAT_HEAD) {
      Node next = node.getNextSibling();
      while (next != null && next.getNodeType() == Node.TEXT_NODE) {
        IDOMText nextText = (IDOMText) next;
        length += (nextText.getEndOffset() - nextText.getStartOffset());
        String nextSource = nextText.getSource();
        if (nextSource != null && nextSource.length() > 0) {
          if (source == null)
            source = nextSource;
          else
            source += nextSource;
        }
        next = next.getNextSibling();
      }
    }
    else if (mode == FORMAT_TAIL) {
      Node prev = node.getPreviousSibling();
      while (prev != null && prev.getNodeType() == Node.TEXT_NODE) {
        IDOMText prevText = (IDOMText) prev;
        offset = prevText.getStartOffset();
        length += (prevText.getEndOffset() - offset);
        String prevSource = prevText.getSource();
        if (prevSource != null && prevSource.length() > 0) {
          if (source == null)
            source = prevSource;
          else
            source = prevSource + source;
View Full Code Here

      NodeList list = input.getChildNodes();
      CharacterData textNode = null;

      for (int i = 0; i < list.getLength(); i++) {
        if (list.item(i) instanceof IDOMText) {
          IDOMText text = (IDOMText) list.item(i);
          if (!text.isElementContentWhitespace()) {
            // This is a naive assumption that the first text space
            // is the one we want to edit. What to do?
            textNode = text;
            break;
          }
View Full Code Here

  public String getElementValue() {
    if (input != null) {
      NodeList list = input.getChildNodes();
      for (int i = 0; i < list.getLength(); i++) {
        if (list.item(i) instanceof IDOMText) {
          IDOMText text = (IDOMText) list.item(i);
          if (!text.isElementContentWhitespace()) {
            // We don't trim this text because it causes another
            // synchronization to the source page, and the cursor
            // will jump to the start of the text area.
            // Unfortunately formatted text in the source page will
            // look ugly in the text area.
            return text.getData();
          }
        }
      }
    }
    return ""; //$NON-NLS-1$
View Full Code Here

TOP

Related Classes of org.eclipse.wst.xml.core.internal.provisional.document.IDOMText

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.