本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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
}