textTableOfContent = content
.newOdfElement(TextTableOfContentElement.class);
textTableOfContent.setTextNameAttribute("Table of Contents");
textTableOfContent.setTextProtectedAttribute(true);
TextTableOfContentSourceElement textTableOfContentSource = textTableOfContent
.newTextTableOfContentSourceElement();
textTableOfContentSource.setTextOutlineLevelAttribute(10);
textTableOfContentSource.setTextUseIndexMarksAttribute(true);
textTableOfContentSource.setTextUseIndexSourceStylesAttribute(true);
TextIndexTitleTemplateElement textIndexTitleTemplate = textTableOfContentSource
.newTextIndexTitleTemplateElement();
textIndexTitleTemplate
.setTextStyleNameAttribute("Contents_20_Heading");
textIndexTitleTemplate.setTextContent("Table of Contents");
for (int i = 1; i <= 10; i++) {
TextTableOfContentEntryTemplateElement textTableOfContentEntryTemplate = textTableOfContentSource
.newTextTableOfContentEntryTemplateElement(i,
"Contents_20_" + i);
TextIndexEntryLinkStartElement TextIndexEntryLinkStart = textTableOfContentEntryTemplate
.newTextIndexEntryLinkStartElement();
TextIndexEntryLinkStart
.setTextStyleNameAttribute("Index_20_Link");
textTableOfContentEntryTemplate
.newTextIndexEntryChapterElement();
textTableOfContentEntryTemplate.newTextIndexEntryTextElement();
TextIndexEntryTabStopElement TextIndexEntryTabStop = textTableOfContentEntryTemplate
.newTextIndexEntryTabStopElement("right");
TextIndexEntryTabStop.setStyleLeaderCharAttribute(".");
textTableOfContentEntryTemplate
.newTextIndexEntryPageNumberElement();
textTableOfContentEntryTemplate
.newTextIndexEntryLinkEndElement();
}
if (!tocstyleList.isEmpty()) {
Set<Integer> key = tocstyleList.keySet();
Iterator<Integer> it = key.iterator();
while (it.hasNext()) {
Integer textOutlineLevelValue = it.next();
String textStyleNameValue = tocstyleList
.get(textOutlineLevelValue);
TextIndexSourceStylesElement textIndexSourceStyles = textTableOfContentSource
.newTextIndexSourceStylesElement(textOutlineLevelValue);
textIndexSourceStyles
.newTextIndexSourceStyleElement(textStyleNameValue);
}
}