Uploaded image for project: 'ODF Toolkit'
  1. ODF Toolkit
  2. ODFTOOLKIT-418

missing method to find an embedded section

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 0.6.2-incubating
    • simple api
    • None

    Description

      To handle embedded Sections we miss a method that retrieves an embedded section by name.

      In
      http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/text/Section.java
      we suggest the following code:

      /**

      • recurisve function. looks for an TextSectionElement inside the father Element 'ele' with the name sectionName
      • @param ele
      • @param sectionName
      • @return null or the wanted TextSectionElement
        */
        private static TextSectionElement findChildSectionByName(OdfElement ele, String sectionName)
        {
        if (ele instanceof TextSectionElement)
        {
        // is ele the wanted Element?
        String name = ((TextSectionElement) ele).getTextNameAttribute();
        if (name != null)
        {
        if (name.equals(sectionName))
        {
        return (TextSectionElement) ele;
        }
        }
        }

      // this Element is not the wanted one? then examine all children
      Node chdNode = ele.getFirstChild();
      while (chdNode != null)
      {
      if (chdNode instanceof OdfElement)
      {
      TextSectionElement result = findChildSectionByName((OdfElement) chdNode, sectionName);
      if (result != null)
      {
      return result;
      }
      }
      chdNode = chdNode.getNextSibling();
      }
      return null;
      }

      in
      http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/text/SectionTest.java
      we propose the appropriate test:

      @Test
      public void testGetEmbeddedSectionByName()
      {
      try
      {
      TextDocument doc = TextDocument.loadDocument(ResourceUtilities.getTestResourceAsStream("Sections.odt"));
      Section sectOut = doc.getSectionByName("InnerSection");
      Section sectEmbedded = sectOut.getEmbeddedSectionByName("EmbedSection");
      Assert.assertEquals(true, sectEmbedded != null);
      }
      catch (Exception e)
      {
      e.printStackTrace();
      Assert.fail();
      }
      }

      see the attached file.

      Attachments

        1. simpleApi-section.zip
          8 kB
          Georg Füchsle

        Activity

          People

            svanteschubert Svante Schubert
            giofyxle Georg Füchsle
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: