DOCX4J を使用してコンテンツを解析し、テンプレートに挿入しようとしています。このテンプレートの一部として、2 つのマーカーの間のすべてをコピーし、そのすべてのコンテンツを X 回繰り返す必要があるループがあります。
関連するコードは次のとおりです。
public List<Object> getBetweenLoop(String name){
String startTag = this.tag_start + name + "_LOOP" + this.tag_end;
String endTag = this.tag_start + name + this.tag_end;
P begin_loop = this.getTagParagraph(startTag);
P end_loop = this.getTagParagraph(endTag);
ContentAccessor parent = (ContentAccessor) this.getCommonParent(begin_loop, end_loop);
List<Object> loop = new ArrayList<Object>();
boolean save = false;
//Cycle through the content for the parent and copy all the objects that
//are between and including the start and end-tags
for(Object item : parent.getContent()){
if(item.equals(begin_loop) || item.equals(end_loop))
save = (save) ? false : true;
if(save || item.equals(end_loop)){
loop.add(XmlUtils.deepCopy(item));
}
if(item.equals(end_loop)){
//Here I want to insert everything copied X times after the current item and then exit the for loop.
//This is the part I'm not sure how to do since I don't see any methods "Insert Child", etc.
}
}
return loop;
}
getTagParagraph は、送信されたタグの段落を表すオブジェクトを正常に返します。これは美しく機能します。
getCommonParent は、提供された 2 つのタグ間の共有の親を返します。これは美しく機能します。
私の問題は、コメントされているように、新しくコピーされたアイテムを適切な場所に挿入する方法です。