本文整理汇总了Java中org.w3c.dom.DocumentFragment.insertBefore方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentFragment.insertBefore方法的具体用法?Java DocumentFragment.insertBefore怎么用?Java DocumentFragment.insertBefore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.DocumentFragment
的用法示例。
在下文中一共展示了DocumentFragment.insertBefore方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: traverseCommonStartContainer
import org.w3c.dom.DocumentFragment; //导入方法依赖的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;
}