addSection() public method

Adds the given Resources to the TableOfContents at the location specified by the pathElements. Example: Calling this method with a Resource and new String[] {"chapter1", "paragraph1"} will result in the following:
  • a TOCReference with the title "chapter1" at the root level.
    If this TOCReference did not yet exist it will have been created and does not point to any resource
  • A TOCReference that has the title "paragraph1". This TOCReference will be the child of TOCReference "chapter1" and will point to the given Resource
public addSection ( Resource resource, String pathElements ) : TOCReference
resource Resource
pathElements String
return TOCReference
 public void testAddResource1()
 {
     Resource resource = new Resource("foo");
     TableOfContents toc = new TableOfContents();
     TOCReference tocReference = toc.addSection(resource, "apple/pear", "/");
     Assert.IsNotNull(tocReference);
     Assert.IsNotNull(tocReference.getResource());
     Assert.AreEqual(2, toc.size());
     Assert.AreEqual("pear", tocReference.getTitle());
 }
        public void testAddResourceWithIndexes()
        {
            Resource resource = new Resource("foo");
            TableOfContents toc = new TableOfContents();
            TOCReference tocReference = toc.addSection(resource, new int[] { 0, 0 }, "Section ", ".");

            // check newly created TOCReference
            Assert.IsNotNull(tocReference);
            Assert.IsNotNull(tocReference.getResource());
            Assert.AreEqual("Section 1.1", tocReference.getTitle());

            // check table of contents
            Assert.AreEqual(1, toc.getTocReferences().Count);
            Assert.AreEqual(1, toc.getTocReferences()[0].getChildren().Count);
            Assert.AreEqual(2, toc.size());
            Assert.AreEqual("Section 1", toc.getTocReferences()[0].getTitle());
            Assert.AreEqual("Section 1.1", toc.getTocReferences()[0].getChildren()[0].getTitle());
            Assert.AreEqual(1, toc.getTocReferences()[0].getChildren().Count);
        }