title: POI docx paragraph outline parsing
body: <p>I have a very simple issue that is driving me crazy. Basically I want to extract, via POI/DOCX4J libraries, docx paragraph structure and document outline. I did the same task with a normal doc document using the POI paragraph.getLvl() method. Is there a way to get the same result with a docx? How can I re-construct the entire TOC structure of the docx?</p>
  <hr />
  <h3>Solution:</h3>
  <p>I resolved in this way:</p>
  <pre><code>    Map headingMap = new HashMap();
      headingMap.put(&quot;heading 1&quot;, 1);
      headingMap.put(&quot;heading 2&quot;, 2);
      headingMap.put(&quot;heading 3&quot;, 3);
      headingMap.put(&quot;heading 4&quot;, 4);
      headingMap.put(&quot;heading 5&quot;, 5);
      headingMap.put(&quot;heading 6&quot;, 6);
      headingMap.put(&quot;heading 7&quot;, 7);
      headingMap.put(&quot;heading 8&quot;, 8);
      headingMap.put(&quot;heading 9&quot;, 9);
      
      Iterator&lt;XWPFParagraph&gt; iterator = docx.getParagraphsIterator();
      Styles styles = getStyle(completePath);
  
      while(iterator.hasNext()){
          XWPFParagraph p = iterator.next();
  
          if( p != null &amp;&amp; p.getStyleID() != null){
              for (Style s : styles.getStyle()){
                  if (p.getStyleID().equals(s.getStyleId()) &amp;&amp; headingMap.containsKey(s.getName().getVal())){
                      StringBuffer text = new StringBuffer();
                      for(XWPFRun run : p.getRuns()) {
                          text.append(run.toString());
                      }
                  }
              }
          }
      }
  </code></pre>