private void generateDynamicAbstractNumIfNeeded() {
   if (hasDynamicAbstractNum) {
     return;
   }
   IBufferedRegion region = getCurrentElement();
   DefaultStyle defaultStyle = DocxContextHelper.getDefaultStyle(sharedContext);
   if (defaultStyle.getAbstractNumIdForUnordererList() == null) {
     region.append(
         formatter.getFunctionDirective(
             DocxContextHelper.STYLES_GENERATOR_KEY,
             IDocxStylesGenerator.generateAbstractNumBullet,
             DocxContextHelper.DEFAULT_STYLE_KEY));
   }
   region.append(generateScriptsForDynamicOrderedNumbers());
   hasDynamicAbstractNum = true;
 }
  private String generateScriptsForDynamicNumbers() {

    StringBuilder script = new StringBuilder();
    // Start if
    String startIf = formatter.getStartIfDirective(DocxContextHelper.NUMBERING_REGISTRY_KEY);
    script.append(startIf);

    String listInfos =
        formatter.formatAsSimpleField(
            false, DocxContextHelper.NUMBERING_REGISTRY_KEY, NumberingRegistry.numbersMethod);
    String itemListInfos = formatter.formatAsSimpleField(false, ITEM_INFO);

    // 1) Start loop
    String startLoop = formatter.getStartLoopDirective(itemListInfos, listInfos);
    script.append(startLoop);

    String numId = formatter.formatAsSimpleField(true, ITEM_INFO, "numId");
    String abstractNumId = formatter.formatAsSimpleField(true, ITEM_INFO, "abstractNumId");

    // <w:num w:numId="1">
    // <w:abstractNumId w:val="1" />
    // </w:num>
    script.append("<w:num w:numId=\"");
    script.append(numId);
    script.append("\">");
    script.append("<w:abstractNumId w:val=\"");
    script.append(abstractNumId);
    script.append("\"/>");
    script.append("</w:num>");

    // 3) end loop
    script.append(formatter.getEndLoopDirective(itemListInfos));

    script.append(formatter.getEndIfDirective(DocxContextHelper.NUMBERING_REGISTRY_KEY));

    return script.toString();
  }
  private String generateScriptsForDynamicOrderedNumbers() {

    StringBuilder script = new StringBuilder();
    // Start if
    String startIf = formatter.getStartIfDirective(DocxContextHelper.NUMBERING_REGISTRY_KEY);
    script.append(startIf);

    String listInfos =
        formatter.formatAsSimpleField(
            false, DocxContextHelper.NUMBERING_REGISTRY_KEY, NumberingRegistry.numbersMethod);
    String itemListInfos = formatter.formatAsSimpleField(false, ITEM_INFO);

    // 1) Start loop
    String startLoop = formatter.getStartLoopDirective(itemListInfos, listInfos);
    script.append(startLoop);

    String abstractNumId = formatter.formatAsSimpleField(false, ITEM_INFO, "abstractNumId");

    String abstractNumOrdered = formatter.formatAsSimpleField(false, ITEM_INFO, "ordered");
    String startIfOrderedList = formatter.getStartIfDirective(abstractNumOrdered);
    script.append(startIfOrderedList);

    script.append(
        formatter.getFunctionDirective(
            DocxContextHelper.STYLES_GENERATOR_KEY,
            IDocxStylesGenerator.generateAbstractNumDecimal,
            DocxContextHelper.DEFAULT_STYLE_KEY,
            abstractNumId));

    script.append(formatter.getEndIfDirective(abstractNumOrdered));

    // 3) end loop
    script.append(formatter.getEndLoopDirective(itemListInfos));

    script.append(formatter.getEndIfDirective(DocxContextHelper.NUMBERING_REGISTRY_KEY));

    return script.toString();
  }