Search in sources :

Example 91 with IDOMNode

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();
}
Also used : DOMException(org.w3c.dom.DOMException) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)

Example 92 with IDOMNode

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);
        }
    }
}
Also used : IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)

Example 93 with IDOMNode

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;
}
Also used : IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)

Example 94 with IDOMNode

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;
}
Also used : IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)

Example 95 with IDOMNode

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;
}
Also used : IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) IStructuredFormatter(org.eclipse.wst.sse.core.internal.format.IStructuredFormatter)

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