本文整理汇总了Java中mf.org.w3c.dom.Node.getPreviousSibling方法的典型用法代码示例。如果您正苦于以下问题:Java Node.getPreviousSibling方法的具体用法?Java Node.getPreviousSibling怎么用?Java Node.getPreviousSibling使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mf.org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.getPreviousSibling方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLastElementChild
import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
/**
* @see <a href="http://www.w3.org/TR/2008/REC-ElementTraversal-20081222/#attribute-lastElementChild">
* Element Traversal Specification</a>
*/
public final Element getLastElementChild() {
Node n = getLastChild();
while (n != null) {
switch (n.getNodeType()) {
case Node.ELEMENT_NODE:
return (Element) n;
case Node.ENTITY_REFERENCE_NODE:
final Element e = getLastElementChild(n);
if (e != null) {
return e;
}
break;
}
n = n.getPreviousSibling();
}
return null;
}
示例2: getPreviousLogicalSibling
import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
private Node getPreviousLogicalSibling(Node n) {
Node prev = n.getPreviousSibling();
// If "n" has no previous sibling and its parent is an entity reference node we
// need to continue the search through the previous siblings of the entity
// reference as these are logically siblings of the given node.
if (prev == null) {
Node parent = n.getParentNode();
while (parent != null && parent.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
prev = parent.getPreviousSibling();
if (prev != null) {
break;
}
parent = parent.getParentNode();
}
}
return prev;
}
示例3: getLastChildElement
import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
/** Finds and returns the last child element node.
* Overload previous method for non-Xerces node impl.
*/
public static Element getLastChildElement(Node parent) {
// search for node
Node child = parent.getLastChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
return (Element)child;
}
child = child.getPreviousSibling();
}
// not found
return null;
}
示例4: getLastVisibleChildElement
import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
/** Finds and returns the last visible child element node. */
public static Element getLastVisibleChildElement(Node parent) {
// search for node
Node child = parent.getLastChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE &&
!isHidden(child)) {
return (Element)child;
}
child = child.getPreviousSibling();
}
// not found
return null;
}
示例5: getLastChildElementNS
import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
/** Finds and returns the last child node with the given qualified name. */
public static Element getLastChildElementNS(Node parent,
String uri, String localpart) {
// search for node
Node child = parent.getLastChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
String childURI = child.getNamespaceURI();
if (childURI != null && childURI.equals(uri) &&
child.getLocalName().equals(localpart)) {
return (Element)child;
}
}
child = child.getPreviousSibling();
}
// not found
return null;
}
示例6: getWholeTextBackward
import mf.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: previousNode
import mf.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;
}
示例8: getPreviousSibling
import mf.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 || isSameNode(node, root)) return null;
Node newNode = node.getPreviousSibling();
if (newNode == null) {
newNode = node.getParentNode();
if (newNode == null || isSameNode(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);
}
}
示例9: synchronizeData
import mf.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
}
示例10: traverseCommonStartContainer
import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
/**
* Visits the nodes selected by this range when we know
* a-priori that the start and end containers are not the
* same, but the start container is an ancestor of the
* end container. This method is invoked by the generic
* <code>traverse</code> method.
*
* @param endAncestor
* The ancestor of the end container that is a direct child
* of the start container.
*
* @param how Specifies what type of traversal is being
* requested (extract, clone, or delete).
* Legal values for this argument are:
*
* <ol>
* <li><code>EXTRACT_CONTENTS</code> - will produce
* a document fragment containing the range's content.
* Partially selected nodes are copied, but fully
* selected nodes are moved.
*
* <li><code>CLONE_CONTENTS</code> - will leave the
* context tree of the range undisturbed, but sill
* produced cloned content in a document fragment
*
* <li><code>DELETE_CONTENTS</code> - will delete from
* the context tree of the range, all fully selected
* nodes.
* </ol>
*
* @return Returns a document fragment containing any
* copied or extracted nodes. If the <code>how</code>
* parameter was <code>DELETE_CONTENTS</code>, the
* return value is null.
*/
private DocumentFragment
traverseCommonStartContainer( Node endAncestor, int how )
{
DocumentFragment frag = null;
if ( how!=DELETE_CONTENTS)
frag = fDocument.createDocumentFragment();
Node n = traverseRightBoundary( endAncestor, how );
if ( frag!=null )
frag.appendChild( n );
int endIdx = indexOf( endAncestor, fStartContainer );
int cnt = endIdx - fStartOffset;
if ( cnt <=0 )
{
// Collapse to just before the endAncestor, which
// is partially selected.
if ( how != CLONE_CONTENTS )
{
setEndBefore( endAncestor );
collapse( false );
}
return frag;
}
n = endAncestor.getPreviousSibling();
while( cnt > 0 )
{
Node sibling = n.getPreviousSibling();
Node xferNode = traverseFullySelected( n, how );
if ( frag!=null )
frag.insertBefore( xferNode, frag.getFirstChild() );
--cnt;
n = sibling;
}
// Collapse to just before the endAncestor, which
// is partially selected.
if ( how != CLONE_CONTENTS )
{
setEndBefore( endAncestor );
collapse( false );
}
return frag;
}