Search in sources :

Example 61 with IDOMNode

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.

the class MarkupValidator method getStartEndFixInfo.

private Object[] getStartEndFixInfo(IDOMNode xmlNode, String tagName, ITextRegion r) {
    // quick fix info
    // $NON-NLS-1$
    String tagClose = "/>";
    int tagCloseOffset = xmlNode.getFirstStructuredDocumentRegion().getEndOffset();
    if ((r != null) && (r.getType() == DOMRegionContext.XML_TAG_CLOSE)) {
        // $NON-NLS-1$
        tagClose = "/";
        tagCloseOffset--;
    }
    IDOMNode firstChild = (IDOMNode) xmlNode.getFirstChild();
    while ((firstChild != null) && (firstChild.getNodeType() == Node.TEXT_NODE)) {
        firstChild = (IDOMNode) firstChild.getNextSibling();
    }
    int endOffset = xmlNode.getEndOffset();
    int firstChildStartOffset = firstChild == null ? endOffset : firstChild.getStartOffset();
    Object[] additionalFixInfo = { // startTagEndOffset
    tagName, // startTagEndOffset
    tagClose, // startTagEndOffset
    new Integer(tagCloseOffset), // startTagEndOffset
    new Integer(xmlNode.getFirstStructuredDocumentRegion().getEndOffset()), // firstChildStartOffset
    new Integer(firstChildStartOffset), // endOffset
    new Integer(endOffset) };
    return additionalFixInfo;
}
Also used : IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)

Example 62 with IDOMNode

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.

the class DOMModelImpl method getIndexedRegion.

/**
 * getNode method
 *
 * @param offset
 *            int
 */
public IndexedRegion getIndexedRegion(int offset) {
    if (this.document == null)
        return null;
    // search in document children
    IDOMNode parent = null;
    int length = this.document.getEndOffset();
    if (offset * 2 < length) {
        // search from the first
        IDOMNode child = (IDOMNode) this.document.getFirstChild();
        while (child != null) {
            if (child.getEndOffset() <= offset) {
                child = (IDOMNode) child.getNextSibling();
                continue;
            }
            if (child.getStartOffset() > offset) {
                break;
            }
            IStructuredDocumentRegion startStructuredDocumentRegion = child.getStartStructuredDocumentRegion();
            if (startStructuredDocumentRegion != null) {
                if (startStructuredDocumentRegion.getEnd() > offset)
                    return child;
            }
            IStructuredDocumentRegion endStructuredDocumentRegion = child.getEndStructuredDocumentRegion();
            if (endStructuredDocumentRegion != null) {
                if (endStructuredDocumentRegion.getStart() <= offset)
                    return child;
            }
            // dig more
            parent = child;
            child = (IDOMNode) parent.getFirstChild();
        }
    } else {
        // search from the last
        IDOMNode child = (IDOMNode) this.document.getLastChild();
        while (child != null) {
            if (child.getStartOffset() > offset) {
                child = (IDOMNode) child.getPreviousSibling();
                continue;
            }
            if (child.getEndOffset() <= offset) {
                break;
            }
            IStructuredDocumentRegion startStructuredDocumentRegion = child.getStartStructuredDocumentRegion();
            if (startStructuredDocumentRegion != null) {
                if (startStructuredDocumentRegion.getEnd() > offset)
                    return child;
            }
            IStructuredDocumentRegion endStructuredDocumentRegion = child.getEndStructuredDocumentRegion();
            if (endStructuredDocumentRegion != null) {
                if (endStructuredDocumentRegion.getStart() <= offset)
                    return child;
            }
            // dig more
            parent = child;
            child = (IDOMNode) parent.getLastChild();
        }
    }
    return parent;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)

Example 63 with IDOMNode

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.

the class NodeImpl method compareDocumentPosition.

/* (non-Javadoc)
	 * @see org.w3c.dom.Node#compareDocumentPosition(org.w3c.dom.Node)
	 */
public short compareDocumentPosition(Node other) throws DOMException {
    if (!(other instanceof IDOMNode))
        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, DOMMessages.NOT_SUPPORTED_ERR);
    int nodeStart = this.getStartOffset();
    int otherStart = ((IDOMNode) other).getStartOffset();
    if (otherStart > nodeStart) {
        return DOCUMENT_POSITION_FOLLOWING;
    } else if (otherStart < nodeStart) {
        return DOCUMENT_POSITION_PRECEDING;
    }
    return DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;
}
Also used : DOMException(org.w3c.dom.DOMException) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)

Example 64 with IDOMNode

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.

the class NodeImpl method getTextContent.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.w3c.dom.Node#getTextContent()
	 */
public String getTextContent() throws DOMException {
    switch(getNodeType()) {
        case Node.DOCUMENT_NODE:
        case Node.DOCUMENT_TYPE_NODE:
        case Node.NOTATION_NODE:
            return null;
        case Node.TEXT_NODE:
        case Node.CDATA_SECTION_NODE:
        case Node.COMMENT_NODE:
        case Node.PROCESSING_INSTRUCTION_NODE:
            return getNodeValue();
    }
    if (hasChildNodes()) {
        final StringBuffer builder = new StringBuffer();
        Node child = getFirstChild();
        while (child != null) {
            short nodeType = child.getNodeType();
            if (nodeType == Node.COMMENT_NODE || nodeType == Node.PROCESSING_INSTRUCTION_NODE) {
                child = child.getNextSibling();
                continue;
            }
            String text = ((IDOMNode) child).getTextContent();
            if (text != null) {
                builder.append(text);
            }
            child = child.getNextSibling();
        }
        return builder.toString();
    }
    return EMPTY_STRING;
}
Also used : IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node)

Example 65 with IDOMNode

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.

the class StreamingMarkupValidator method getStartEndFixInfo.

private Object[] getStartEndFixInfo(String tagName, Token token) {
    Object[] additionalInfo = null;
    if (model != null) {
        IDOMNode xmlNode = (IDOMNode) model.getIndexedRegion(token.offset);
        if (xmlNode != null) {
            // quick fix info
            // $NON-NLS-1$
            String tagClose = "/>";
            int tagCloseOffset = xmlNode.getFirstStructuredDocumentRegion().getEndOffset();
            ITextRegion last = xmlNode.getFirstStructuredDocumentRegion().getLastRegion();
            if ((last != null) && (last.getType() == DOMRegionContext.XML_TAG_CLOSE)) {
                // $NON-NLS-1$
                tagClose = "/";
                tagCloseOffset--;
            }
            IDOMNode firstChild = (IDOMNode) xmlNode.getFirstChild();
            while ((firstChild != null) && (firstChild.getNodeType() == Node.TEXT_NODE)) {
                firstChild = (IDOMNode) firstChild.getNextSibling();
            }
            int endOffset = xmlNode.getEndOffset();
            int firstChildStartOffset = firstChild == null ? endOffset : firstChild.getStartOffset();
            additionalInfo = new Object[] { // startTagEndOffset
            tagName, // startTagEndOffset
            tagClose, // startTagEndOffset
            new Integer(tagCloseOffset), // startTagEndOffset
            new Integer(xmlNode.getFirstStructuredDocumentRegion().getEndOffset()), // firstChildStartOffset
            new Integer(firstChildStartOffset), // endOffset
            new Integer(endOffset) };
        }
    }
    return additionalInfo != null ? additionalInfo : new Object[] {};
}
Also used : IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Aggregations

IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)250 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)91 Node (org.w3c.dom.Node)63 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)57 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)44 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)43 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)38 List (java.util.List)35 ArrayList (java.util.ArrayList)34 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)30 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)30 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)27 Element (org.w3c.dom.Element)27 NodeList (org.w3c.dom.NodeList)23 BadLocationException (org.eclipse.jface.text.BadLocationException)22 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)22 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)20 IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)19 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)18 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)18