[ 
https://issues.apache.org/jira/browse/ODFTOOLKIT-418?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Georg Füchsle closed ODFTOOLKIT-418.
------------------------------------

Sorry for the late reaction. Didn't realize before, that i should close the 
issue when fixed. Thanks

> missing method to find an embedded section
> ------------------------------------------
>
>                 Key: ODFTOOLKIT-418
>                 URL: https://issues.apache.org/jira/browse/ODFTOOLKIT-418
>             Project: ODF Toolkit
>          Issue Type: Improvement
>          Components: simple api
>            Reporter: Georg Füchsle
>            Assignee: Svante Schubert
>            Priority: Minor
>         Attachments: simpleApi-section.zip
>
>
> 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:
> {quote}
>     /**
>      * 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;
>     \} 
> {quote}
> in
> http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/text/SectionTest.java
> we propose the appropriate test:
> {quote}
>     @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();
>       \}
>     \}
> {quote}
> see the attached file.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to