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


Java DocumentFragment.insertBefore方法代码示例

本文整理汇总了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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:79,代码来源:RangeImpl.java


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