當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。