private static void moveBoundariesIntoParagraphs(Document rawmaryxml){
  if (rawmaryxml == null) {
    throw new NullPointerException("Received null rawmaryxml");
  }
  TreeWalker paraTW=((DocumentTraversal)rawmaryxml).createTreeWalker(rawmaryxml.getDocumentElement(),NodeFilter.SHOW_ELEMENT,new NameNodeFilter(MaryXML.PARAGRAPH),true);
  TreeWalker tw=((DocumentTraversal)rawmaryxml).createTreeWalker(rawmaryxml.getDocumentElement(),NodeFilter.SHOW_ELEMENT,new NameNodeFilter(MaryXML.PARAGRAPH,MaryXML.BOUNDARY),true);
  Element firstParagraph=(Element)paraTW.nextNode();
  if (firstParagraph == null) {
    throw new NullPointerException("Document does not have a paragraph");
  }
  tw.setCurrentNode(firstParagraph);
  Element boundary=null;
  while ((boundary=(Element)tw.previousNode()) != null) {
    assert boundary.getTagName().equals(MaryXML.BOUNDARY);
    firstParagraph.insertBefore(boundary,firstParagraph.getFirstChild());
    tw.setCurrentNode(firstParagraph);
  }
  tw.setCurrentNode(firstParagraph);
  Element paragraph=firstParagraph;
  Element current=null;
  while ((current=(Element)tw.nextNode()) != null) {
    if (current.getTagName().equals(MaryXML.PARAGRAPH)) {
      paragraph=current;
    }
 else {
      if (!DomUtils.hasAncestor(current,MaryXML.PARAGRAPH)) {
        paragraph.appendChild(current);
      }
    }
  }
}

private static void moveBoundariesIntoParagraphs ( Document rawmaryxml ) { if ( rawmaryxml == null ) { throw new NullPointerException ( "Received null rawmaryxml" ) ; } TreeWalker paraTW = ( ( DocumentTraversal ) rawmaryxml ) . createTreeWalker ( rawmaryxml . getDocumentElement ( ) , NodeFilter . SHOW_ELEMENT , new NameNodeFilter ( MaryXML . PARAGRAPH ) , true ) ; TreeWalker tw = ( ( DocumentTraversal ) rawmaryxml ) . createTreeWalker ( rawmaryxml . getDocumentElement ( ) , NodeFilter . SHOW_ELEMENT , new NameNodeFilter ( MaryXML . PARAGRAPH , MaryXML . BOUNDARY ) , true ) ; Element firstParagraph = ( Element ) paraTW . nextNode ( ) ; if ( firstParagraph == null ) { throw new NullPointerException ( "Document does not have a paragraph" ) ; } tw . setCurrentNode ( firstParagraph ) ; Element boundary = null ; while ( ( boundary = ( Element ) tw . previousNode ( ) ) != null ) { assert boundary . getTagName ( ) . equals ( MaryXML . BOUNDARY ) ; firstParagraph . insertBefore ( boundary , firstParagraph . getFirstChild ( ) ) ; tw . setCurrentNode ( firstParagraph ) ; } tw . setCurrentNode ( firstParagraph ) ; Element paragraph = firstParagraph ; Element current = null ; while ( ( current = ( Element ) tw . nextNode ( ) ) != null ) { if ( current . getTagName ( ) . equals ( MaryXML . PARAGRAPH ) ) { paragraph = current ; } else { if ( ! DomUtils . hasAncestor ( current , MaryXML . PARAGRAPH ) ) { paragraph . appendChild ( current ) ; } } } }
move all the boundary elements outside of paragraphs into paragraphs .
