当前位置: 首页>>代码示例>>Java>>正文


Java Node.getPreviousSibling方法代码示例

本文整理汇总了Java中org.w3c.dom.Node.getPreviousSibling方法的典型用法代码示例。如果您正苦于以下问题:Java Node.getPreviousSibling方法的具体用法?Java Node.getPreviousSibling怎么用?Java Node.getPreviousSibling使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.w3c.dom.Node的用法示例。


在下文中一共展示了Node.getPreviousSibling方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findArtifactInfo

import org.w3c.dom.Node; //导入方法依赖的package包/类
private ArtifactInfoHolder findArtifactInfo(Node previous) {
    ArtifactInfoHolder holder = new ArtifactInfoHolder();
    while (previous != null) {
        if (previous instanceof org.w3c.dom.Element) {
            org.w3c.dom.Element el = (org.w3c.dom.Element)previous;
            NodeList lst = el.getChildNodes();
            if (lst.getLength() > 0) {
                if ("artifactId".equals(el.getNodeName())) { //NOI18N
                    holder.setArtifactId(getNodeValue(lst.item(0).getNodeValue(), owner.getLookup().lookup(NbMavenProject.class)));
                }
                if ("groupId".equals(el.getNodeName())) { //NOI18N
                    holder.setGroupId(getNodeValue(lst.item(0).getNodeValue(), owner.getLookup().lookup(NbMavenProject.class)));
                }
                if ("version".equals(el.getNodeName())) { //NOI18N
                    holder.setVersion(getNodeValue(lst.item(0).getNodeValue(), owner.getLookup().lookup(NbMavenProject.class)));
                }
            }
        }
        previous = previous.getPreviousSibling();
    }
    return holder;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:MavenProjectGrammar.java

示例2: getLastChildElement

import org.w3c.dom.Node; //导入方法依赖的package包/类
/** Finds and returns the last child node with the given name. */
public static Element getLastChildElement(Node parent, String elemNames[]) {

    // search for node
    Node child = parent.getLastChild();
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            for (int i = 0; i < elemNames.length; i++) {
                if (child.getNodeName().equals(elemNames[i])) {
                    return (Element)child;
                }
            }
        }
        child = child.getPreviousSibling();
    }

    // not found
    return null;

}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:DOMUtil.java

示例3: selectPreviousSiblings

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Given an element E, select which previous siblings we want to merge.
 * We want to include any whitespace up to the closing of the previous element.
 * We also want to include up preceding comment nodes and their preceding whitespace.
 * <p/>
 * This may returns either {@code end} or a previous sibling. Never returns null.
 */
@NonNull
private Node selectPreviousSiblings(Node end) {

    Node start = end;
    Node prev = start.getPreviousSibling();
    while (prev != null) {
        short t = prev.getNodeType();
        if (t == Node.TEXT_NODE) {
            String text = prev.getNodeValue();
            if (text == null || text.trim().length() != 0) {
                // Not whitespace, we don't want it.
                break;
            }
        } else if (t == Node.COMMENT_NODE) {
            // It's a comment. We'll take it.
        } else {
            // Not a comment node nor a whitespace text. We don't want it.
            break;
        }
        start = prev;
        prev = start.getPreviousSibling();
    }

    return start;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:33,代码来源:ManifestMerger.java

示例4: hasSameTypeBefore

import org.w3c.dom.Node; //导入方法依赖的package包/类
public static boolean hasSameTypeBefore(Element element) {
    Node sibling = element.getPreviousSibling();
    while (sibling != null) {
        if (sibling.getNodeType() == Node.ELEMENT_NODE) {
            if (isSameType(element, (Element)sibling)) {
                return true;
            }
        }
        sibling = sibling.getPreviousSibling();
    }
    return false;
}
 
开发者ID:i49,项目名称:cascade,代码行数:13,代码来源:Elements.java

示例5: getPreviousText

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Returns the combined text of previous nodes of the given element
 */
private static String getPreviousText(Node node) {
    StringBuilder builder = new StringBuilder();
    while (node != null) {
        node = node.getPreviousSibling();
        if (node instanceof Text) {
            Text textNode = (Text) node;
            builder.append(textNode.getWholeText());
        } else {
            break;
        }
    }
    return builder.toString();
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:17,代码来源:ChoosePipelineStep.java

示例6: getWholeTextBackward

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Concatenates the text of all logically-adjacent text nodes to the left of
 * the node
 * @param node
 * @param buffer
 * @param parent
 * @return true - if execution was stopped because the type of node
 *         other than EntityRef, Text, CDATA is encountered, otherwise
 *         return false
 */
private boolean getWholeTextBackward(Node node, StringBuffer buffer, Node parent){

    // boolean to indicate whether node is a child of an entity reference
    boolean inEntRef = false;
    if (parent!=null) {
            inEntRef = parent.getNodeType()==Node.ENTITY_REFERENCE_NODE;
    }

    while (node != null) {
        short type = node.getNodeType();
        if (type == Node.ENTITY_REFERENCE_NODE) {
            if (getWholeTextBackward(node.getLastChild(), buffer, node)){
                return true;
            }
        }
        else if (type == Node.TEXT_NODE ||
                 type == Node.CDATA_SECTION_NODE) {
            ((TextImpl)node).insertTextContent(buffer);
        }
        else {
            return true;
        }

        node = node.getPreviousSibling();
    }

    // if the parent node is an entity reference node, must
    // check nodes to the left of the parent entity reference node for logically adjacent
    // text nodes
    if (inEntRef) {
            getWholeTextBackward(parent.getPreviousSibling(), buffer, parent.getParentNode());
        return true;
    }

    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:47,代码来源:TextImpl.java

示例7: getRelativePositionOfElement

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Get relative position of this among all siblings.
 * @return 1..n
 */
private int getRelativePositionOfElement() {
    int count = 1;
    Node n = node.getPreviousSibling();
    while (n != null) {
        if (n.getNodeType() == Node.ELEMENT_NODE) {
            count++;
        }
        n = n.getPreviousSibling();
    }
    return count;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:16,代码来源:DOMNodePointer.java

示例8: previousNode

import org.w3c.dom.Node; //导入方法依赖的package包/类
/** The method previousNode(Node) returns the previous node
 *  from the actual DOM tree.
 */
Node previousNode(Node node) {

    Node result;

    // if we're at the root, return null.
    if (node == fRoot) return null;

    // get sibling
    result = node.getPreviousSibling();
    if (result == null) {
        //if 1st sibling, return parent
        result = node.getParentNode();
        return result;
    }

    // if sibling has children, keep getting last child of child.
    if (result.hasChildNodes()
        && !(!fEntityReferenceExpansion
            && result != null
            && result.getNodeType() == Node.ENTITY_REFERENCE_NODE))

    {
        while (result.hasChildNodes()) {
            result = result.getLastChild();
        }
    }

    return result;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:NodeIteratorImpl.java

示例9: getRelativePositionOfPI

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Get the relative position of this among same-target processing instruction siblings.
 * @return 1..n
 */
private int getRelativePositionOfPI() {
    int count = 1;
    String target = ((ProcessingInstruction) node).getTarget();
    Node n = node.getPreviousSibling();
    while (n != null) {
        if (n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE
            && ((ProcessingInstruction) n).getTarget().equals(target)) {
            count++;
        }
        n = n.getPreviousSibling();
    }
    return count;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:18,代码来源:DOMNodePointer.java

示例10: getLeadingComments

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Returns all leading comments in the source xml before the node to be adopted.
 * @param nodeToBeAdopted node that will be added as a child to this node.
 */
static List<Node> getLeadingComments(Node nodeToBeAdopted) {
    ImmutableList.Builder<Node> nodesToAdopt = new ImmutableList.Builder<Node>();
    Node previousSibling = nodeToBeAdopted.getPreviousSibling();
    while (previousSibling != null
            && (previousSibling.getNodeType() == Node.COMMENT_NODE
            || previousSibling.getNodeType() == Node.TEXT_NODE)) {
        // we really only care about comments.
        if (previousSibling.getNodeType() == Node.COMMENT_NODE) {
            nodesToAdopt.add(previousSibling);
        }
        previousSibling = previousSibling.getPreviousSibling();
    }
    return nodesToAdopt.build().reverse();
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:19,代码来源:XmlElement.java

示例11: hasSiblingBefore

import org.w3c.dom.Node; //导入方法依赖的package包/类
public static boolean hasSiblingBefore(Element element) {
    Node sibling = element.getPreviousSibling();
    while (sibling != null) {
        if (sibling.getNodeType() == Node.ELEMENT_NODE) {
            return true;
        }
        sibling = sibling.getPreviousSibling();
    }
    return false;
}
 
开发者ID:i49,项目名称:cascade,代码行数:11,代码来源:Elements.java

示例12: insertBeforeBookmark

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Inserts some text into a Word document immediately in front of the
 * location of a bookmark.
 *
 * This case is slightly more straightforward than inserting after the
 * bookmark. For example, it is possible only to insert a new node in front
 * of an existing node. When inserting after the bookmark, then end node had
 * to be located whereas, in this case, the node is already known, it is the
 * CTBookmark itself. The only information that must be discovered is
 * whether there is a run immediately in front of the boookmarkStart tag and
 * whether that run is styled. If there is and if it is, then this style
 * must be cloned and applied the text which will be inserted into the
 * paragraph.
 *
 * @param run An instance of the XWPFRun class that encapsulates the text
 * that is to be inserted into the document following the bookmark.
 */
private void insertBeforeBookmark(XWPFRun run) {
    Node insertBeforeNode = null;
    Node childNode = null;
    Node styleNode = null;

    // Get the dom node from the bookmarkStart tag and look for another
    // node immediately preceding it.
    insertBeforeNode = this._ctBookmark.getDomNode();
    childNode = insertBeforeNode.getPreviousSibling();

    // If a node is found, try to get the styling from it.
    if (childNode != null) {
        styleNode = this.getStyleNode(childNode);

        // If that previous node was styled, then apply this style to the
        // text which will be inserted.
        if (styleNode != null) {
            run.getCTR().getDomNode().insertBefore(
                    styleNode.cloneNode(true), run.getCTR().getDomNode().getFirstChild());
        }
    }

    // Insert the text into the paragraph immediately in front of the
    // bookmarkStart tag.
    this._para.getCTP().getDomNode().insertBefore(
            run.getCTR().getDomNode(), insertBeforeNode);
}
 
开发者ID:dragon-yuan,项目名称:Ins_fb_pictureSpider_WEB,代码行数:45,代码来源:BookMark.java

示例13: getPreviousSibling

import org.w3c.dom.Node; //导入方法依赖的package包/类
/** Internal function.
 *  Return the previousSibling Node, from the input node
 *  after applying filter, whatToshow.
     *  NEVER TRAVERSES ABOVE THE SPECIFIED ROOT NODE.
 *  The current node is not consulted or set.
 */
Node getPreviousSibling(Node node, Node root) {

    if (node == null || node == root) return null;

    Node newNode = node.getPreviousSibling();
    if (newNode == null) {

        newNode = node.getParentNode();
        if (newNode == null || newNode == root)  return null;

        int parentAccept = acceptNode(newNode);

        if (parentAccept==NodeFilter.FILTER_SKIP) {
            return getPreviousSibling(newNode, root);
        }

        return null;
    }

    int accept = acceptNode(newNode);

    if (accept == NodeFilter.FILTER_ACCEPT)
        return newNode;
    else
    if (accept == NodeFilter.FILTER_SKIP) {
        Node fChild =  getLastChild(newNode);
        if (fChild == null) {
            return getPreviousSibling(newNode, root);
        }
        return fChild;
    }
    else
    //if (accept == NodeFilter.REJECT_NODE)
    {
        return getPreviousSibling(newNode, root);
    }

}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:45,代码来源:TreeWalkerImpl.java

示例14: newlineBeforeElementOpen

import org.w3c.dom.Node; //导入方法依赖的package包/类
private boolean newlineBeforeElementOpen(Element element, int depth) {
    if (hasBlankLineAbove()) {
        return false;
    }

    if (mPrefs.removeEmptyLines || depth <= 0) {
        return false;
    }

    if (isMarkupElement(element)) {
        return false;
    }

    // See if this element should be separated from the previous element.
    // This is the case if we are not compressing whitespace (checked above),
    // or if we are not immediately following a comment (in which case the
    // newline would have been added above it), or if we are not in a formatting
    // style where
    if (mStyle == XmlFormatStyle.LAYOUT) {
        // In layouts we always separate elements
        return true;
    }

    if (mStyle == XmlFormatStyle.MANIFEST || mStyle == XmlFormatStyle.RESOURCE
            || mStyle == XmlFormatStyle.FILE) {
        Node curr = element.getPreviousSibling();

        // <style> elements are traditionally separated unless it follows a comment
        if (TAG_STYLE.equals(element.getTagName())) {
            if (curr == null
                    || curr.getNodeType() == Node.ELEMENT_NODE
                    || (curr.getNodeType() == Node.TEXT_NODE
                    && curr.getNodeValue().trim().isEmpty()
                    && (curr.getPreviousSibling() == null
                    || curr.getPreviousSibling().getNodeType()
                    == Node.ELEMENT_NODE))) {
                return true;
            }
        }

        // In all other styles, we separate elements if they have a different tag than
        // the previous one (but we don't insert a newline inside tags)
        while (curr != null) {
            short nodeType = curr.getNodeType();
            if (nodeType == Node.ELEMENT_NODE) {
                Element sibling = (Element) curr;
                if (!element.getTagName().equals(sibling.getTagName())) {
                    return true;
                }
                break;
            } else if (nodeType == Node.TEXT_NODE) {
                String text = curr.getNodeValue();
                if (!text.trim().isEmpty()) {
                    break;
                }
                // If there is just whitespace, continue looking for a previous sibling
            } else {
                // Any other previous node type, such as a comment, means we don't
                // continue looking: this element should not be separated
                break;
            }
            curr = curr.getPreviousSibling();
        }
        if (curr == null && depth <= 1) {
            // Insert new line inside tag if it's the first element inside the root tag
            return true;
        }

        return false;
    }

    return false;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:74,代码来源:XmlPrettyPrinter.java

示例15: synchronizeData

import org.w3c.dom.Node; //导入方法依赖的package包/类
/** Synchronizes the node's data. */
protected void synchronizeData() {

    // no need to sync in the future
    needsSyncData(false);

    // fluff up enough nodes to fill identifiers hash
    if (fIdElement != null) {

        // REVISIT: There has to be a more efficient way of
        //          doing this. But keep in mind that the
        //          tree can have been altered and re-ordered
        //          before all of the element nodes with ID
        //          attributes have been registered. For now
        //          this is reasonable and safe. -Ac

        IntVector path = new IntVector();
        for (int i = 0; i < fIdCount; i++) {

            // ignore if it's already been registered
            int elementNodeIndex = fIdElement[i];
            String idName      = fIdName[i];
            if (idName == null) {
                continue;
            }

            // find path from this element to the root
            path.removeAllElements();
            int index = elementNodeIndex;
            do {
                path.addElement(index);
                int pchunk = index >> CHUNK_SHIFT;
                int pindex = index & CHUNK_MASK;
                index = getChunkIndex(fNodeParent, pchunk, pindex);
            } while (index != -1);

            // Traverse path (backwards), fluffing the elements
            // along the way. When this loop finishes, "place"
            // will contain the reference to the element node
            // we're interested in. -Ac
            Node place = this;
            for (int j = path.size() - 2; j >= 0; j--) {
                index = path.elementAt(j);
                Node child = place.getLastChild();
                while (child != null) {
                    if (child instanceof DeferredNode) {
                        int nodeIndex =
                            ((DeferredNode)child).getNodeIndex();
                        if (nodeIndex == index) {
                            place = child;
                            break;
                        }
                    }
                    child = child.getPreviousSibling();
                }
            }

            // register the element
            Element element = (Element)place;
            putIdentifier0(idName, element);
            fIdName[i] = null;

            // see if there are more IDs on this element
            while (i + 1 < fIdCount &&
                fIdElement[i + 1] == elementNodeIndex) {
                idName = fIdName[++i];
                if (idName == null) {
                    continue;
                }
                putIdentifier0(idName, element);
            }
        }

    } // if identifiers

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:77,代码来源:DeferredDocumentImpl.java


注:本文中的org.w3c.dom.Node.getPreviousSibling方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。