private void insertTextNode ( final Characters paramText ) throws TTException , XMLStreamException { assert paramText != null ; /* * Add node if it's either not found among right siblings (and the * cursor on the shreddered file is on a right sibling) or if it's not * found in the structure and it is a new last right sibling. */ mDelete = EDelete . NODELETE ; mRemovedNode = false ; switch ( mInsert ) { case ATTOP : // Insert occurs at the top of a subtree (no end tag has been parsed // immediately before). // Move to parent. mWtx . moveTo ( mWtx . getNode ( ) . getParentKey ( ) ) ; // Insert as first child. addNewText ( EAdd . ASFIRSTCHILD , paramText ) ; // Move to next node if no end tag follows (thus cursor isn't moved // to parent in processEndTag()). if ( mReader . peek ( ) . getEventType ( ) != XMLStreamConstants . END_ELEMENT ) { if ( mWtx . moveTo ( ( ( ITreeStructData ) mWtx . getNode ( ) ) . getRightSiblingKey ( ) ) ) { mMovedToRightSibling = true ; } else { mMovedToRightSibling = false ; } } else if ( ( ( ITreeStructData ) mWtx . getNode ( ) ) . hasRightSibling ( ) ) { mMovedToRightSibling = false ; mInserted = true ; mKeyMatches = - 1 ; mDelete = EDelete . ATBOTTOM ; deleteNode ( ) ; } mInsert = EInsert . INTERMEDIATE ; break ; case INTERMEDIATE : // Inserts have been made before. EAdd addNode = EAdd . ASFIRSTCHILD ; if ( mInsertedEndTag ) { /* * An end tag has been read while inserting, so move back to * left sibling if there is one and insert as right sibling. */ if ( mMovedToRightSibling ) { mWtx . moveTo ( ( ( ITreeStructData ) mWtx . getNode ( ) ) . getLeftSiblingKey ( ) ) ; } addNode = EAdd . ASRIGHTSIBLING ; mInsertedEndTag = false ; } // Insert element as right sibling. addNewText ( addNode , paramText ) ; // Move to next node if no end tag follows (thus cursor isn't moved // to parent in processEndTag()). if ( mReader . peek ( ) . getEventType ( ) != XMLStreamConstants . END_ELEMENT ) { if ( mWtx . moveTo ( ( ( ITreeStructData ) mWtx . getNode ( ) ) . getRightSiblingKey ( ) ) ) { mMovedToRightSibling = true ; } else { mMovedToRightSibling = false ; } } break ; case ATMIDDLEBOTTOM : // Insert occurs in the middle or end of a subtree. // Move one sibling back. if ( mMovedToRightSibling ) { mWtx . moveTo ( ( ( ITreeStructData ) mWtx . getNode ( ) ) . getLeftSiblingKey ( ) ) ; } // Insert element as right sibling. addNewText ( EAdd . ASRIGHTSIBLING , paramText ) ; // Move to next node. mWtx . moveTo ( ( ( ITreeStructData ) mWtx . getNode ( ) ) . getRightSiblingKey ( ) ) ; mInsert = EInsert . INTERMEDIATE ; break ; default : throw new AssertionError ( "Enum value not known!" ) ; } mInserted = true ; }
Insert a text node .