use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class ElementImpl method setPrefix.
/**
*/
public void setPrefix(String prefix) throws DOMException {
IDOMNode parent = (IDOMNode) getParentNode();
if (parent != null && !parent.isChildEditable()) {
throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, NodeImpl.EMPTY_STRING);
}
int prefixLength = (prefix != null ? prefix.length() : 0);
String localName = getLocalName();
if (prefixLength == 0) {
if (localName == null || localName.length() == 0) {
// invalid local name
return;
}
setTagName(localName);
} else {
int localLength = (localName != null ? localName.length() : 0);
StringBuffer buffer = new StringBuffer(prefixLength + 1 + localLength);
buffer.append(prefix);
buffer.append(':');
if (localName != null)
buffer.append(localName);
setTagName(buffer.toString());
}
boolean changeEndTag = hasEndTag();
notifyStartTagChanged();
if (changeEndTag)
notifyEndTagChanged();
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class TreeContentHelper method setValueForTextContent.
/**
*/
protected void setValueForTextContent(List list, String value) {
// we worry about preserving trimmed text
if (list.size() > 0) {
if (list.get(0) instanceof IDOMNode) {
IDOMNode first = (IDOMNode) list.get(0);
IDOMNode last = (IDOMNode) list.get(list.size() - 1);
int start = first.getStartOffset();
int end = last.getEndOffset();
first.getModel().getStructuredDocument().replaceText(this, start, end - start, value);
}
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class NodeFormatter method getDeepestChildNode.
protected IDOMNode getDeepestChildNode(IDOMNode node) {
IDOMNode result = null;
IDOMNode lastChild = (IDOMNode) node.getLastChild();
if (lastChild == null)
result = node;
else {
result = getDeepestChildNode(lastChild);
if ((result.getNodeType() == Node.TEXT_NODE || result.getNodeType() == Node.COMMENT_NODE) && !isEndTagMissing(node))
result = node;
}
return result;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class NodeFormatter method getSiblingIndent.
/**
* This method will find the indentation for a node sibling to this node.
* It will try to find a sibling node before this node first. If there is
* no sibling node before this node, it will try to find a sibling node
* after this node. If still not found, we will check if this node is
* already indented from its parent. If yes, this node's indentation will
* be used. Otherwise, the parent node's indentation plus one indentation
* will be used. If this node is null or it's a document node or it's a
* first level node (node's parent is a document node) the default empty
* string will be returned as the indentation.
*/
protected String getSiblingIndent(Node node) {
String result = EMPTY_STRING;
if ((node != null) && (node.getNodeType() != Node.DOCUMENT_NODE) && (node.getParentNode() != null) && (node.getParentNode().getNodeType() != Node.DOCUMENT_NODE)) {
// find the text node before the previous non-text sibling
// if that's not found, we will try the text node before the next
// non-text sibling
IDOMNode sibling = (IDOMNode) node.getPreviousSibling();
while ((sibling != null) && (sibling.getNodeType() == Node.TEXT_NODE || sibling.getNodeType() == Node.COMMENT_NODE)) {
if (sibling.getNodeType() == Node.COMMENT_NODE && sibling.getPreviousSibling() != null && sibling.getPreviousSibling().getNodeType() == Node.TEXT_NODE && StringUtils.containsLineDelimiter(sibling.getPreviousSibling().getNodeValue()))
break;
sibling = (IDOMNode) sibling.getPreviousSibling();
}
if (sibling == null) {
sibling = (IDOMNode) node.getNextSibling();
while ((sibling != null) && (sibling.getNodeType() == Node.TEXT_NODE)) sibling = (IDOMNode) sibling.getNextSibling();
}
String singleIndent = getFormatPreferences().getIndent();
String parentLineIndent = getNodeIndent(node.getParentNode());
if (sibling != null) {
String siblingIndent = getNodeIndent(sibling);
if (siblingIndent.length() > 0)
result = siblingIndent;
else {
String nodeIndent = getNodeIndent(node);
if (nodeIndent.length() > parentLineIndent.length())
// this node is indented from its parent, its
// indentation will be used
result = nodeIndent;
else
result = parentLineIndent + singleIndent;
}
} else {
String nodeIndent = getNodeIndent(node);
if (nodeIndent.length() > parentLineIndent.length())
// this node is indented from its parent, its indentation
// will be used
result = nodeIndent;
else
result = parentLineIndent + singleIndent;
}
}
return result;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class NodeFormatter method getFormatter.
protected IStructuredFormatter getFormatter(IDOMNode node) {
// 262135 - NPE during format of empty document
if (node == null)
return null;
short nodeType = ((Node) node).getNodeType();
IStructuredFormatter formatter = null;
switch(nodeType) {
case Node.ELEMENT_NODE:
{
formatter = new ElementNodeFormatter();
break;
}
case Node.TEXT_NODE:
{
formatter = new TextNodeFormatter();
break;
}
case Node.CDATA_SECTION_NODE:
{
formatter = new NoMoveFormatter();
break;
}
case Node.COMMENT_NODE:
{
formatter = new CommentNodeFormatter();
break;
}
case Node.PROCESSING_INSTRUCTION_NODE:
{
formatter = new NodeFormatter();
break;
}
case Node.DOCUMENT_NODE:
{
formatter = new DocumentNodeFormatter();
break;
}
case Node.ENTITY_REFERENCE_NODE:
{
formatter = new NoMoveFormatter();
break;
}
default:
{
formatter = new NodeFormatter();
}
}
// init fomatter
formatter.setFormatPreferences(getFormatPreferences());
formatter.setProgressMonitor(fProgressMonitor);
return formatter;
}
Aggregations