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;
}
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;
}
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;
}
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;
}
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[] {};
}
Aggregations