mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

neil_a_wilson
25.53.2007 b1225d4ea6bf876a5f2a1c097b2c908af49354b9
Update the MakeLDIF tool to implement support for the "extends" keyword,
allowing one template to extend another and inherit all of the definitions from
the parent template.
2 files modified
72 ■■■■ changed files
opends/src/server/org/opends/server/messages/ToolMessages.java 18 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/makeldif/TemplateFile.java 54 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/messages/ToolMessages.java
@@ -6935,6 +6935,19 @@
  public static final int MSGID_LDAPMODIFY_DESCRIPTION_FILENAME =
       CATEGORY_MASK_TOOLS | SEVERITY_MASK_INFORMATIONAL | 874;
  /**
   * The message ID for the message that will be used if a template references
   * a parent template that is not yet defined.  This takes three arguments,
   * which are the parent template name, the line number on which it is
   * referenced, and the child template name.
   */
  public static final int MSGID_MAKELDIF_TEMPLATE_INVALID_PARENT_TEMPLATE =
       CATEGORY_MASK_TOOLS | SEVERITY_MASK_MILD_ERROR | 875;
  /**
   * Associates a set of generic messages with the message IDs defined in this
   * class.
@@ -8497,6 +8510,11 @@
                    "Unable to parse the number of entries for template %s " +
                    "as an integer for the subordinate template definition " +
                    "on line %d for branch %s");
    registerMessage(MSGID_MAKELDIF_TEMPLATE_INVALID_PARENT_TEMPLATE,
                    "The parent template %s referenced on line %d for " +
                    "template %s is invalid because the referenced parent " +
                    "template is not defined before the template that " +
                    "extends it");
    registerMessage(MSGID_MAKELDIF_TEMPLATE_SUBORDINATE_TEMPLATE_NO_COLON,
                    "Subordinate template definition on line %d for template " +
                    "%s is missing a colon to separate the template name " +
opends/src/server/org/opends/server/tools/makeldif/TemplateFile.java
@@ -950,7 +950,8 @@
        Template t = parseTemplateDefinition(templateLines, startLineNumber,
                                             templateFileIncludeTags,
                                             templateFileConstants, warnings);
                                             templateFileConstants,
                                             templateFileTemplates, warnings);
        String lowerName = toLowerCase(t.getName());
        if (templateFileTemplates.containsKey(lowerName))
        {
@@ -1112,16 +1113,19 @@
   * Parses the information contained in the provided set of lines as a MakeLDIF
   * template definition.
   *
   * @param  templateLines    The set of lines containing the template
   *                          definition.
   * @param  startLineNumber  The line number in the template file on which the
   *                          first of the template lines appears.
   * @param  tags             The set of defined tags from the template file.
   *                          Note that this does not include the tags that are
   *                          always registered by default.
   * @param  constants        The set of constants defined in the template file.
   * @param  warnings         A list into which any warnings identified may be
   *                          placed.
   * @param  templateLines     The set of lines containing the template
   *                           definition.
   * @param  startLineNumber   The line number in the template file on which the
   *                           first of the template lines appears.
   * @param  tags              The set of defined tags from the template file.
   *                           Note that this does not include the tags that are
   *                           always registered by default.
   * @param  constants         The set of constants defined in the template
   *                           file.
   * @param  definedTemplates  The set of templates already defined in the
   *                           template file.
   * @param  warnings          A list into which any warnings identified may be
   *                           placed.
   *
   * @return  The decoded template definition.
   *
@@ -1135,6 +1139,8 @@
                                           LinkedHashMap<String,Tag> tags,
                                           LinkedHashMap<String,String>
                                                constants,
                                           LinkedHashMap<String,Template>
                                                definedTemplates,
                                           List<String> warnings)
          throws InitializationException, MakeLDIFException
  {
@@ -1146,7 +1152,7 @@
    // "subordinateTemplate: ".  Keep reading until we find something that's
    // not one of those.
    int                arrayLineNumber    = 1;
    String             parentTemplateName = null;
    Template           parentTemplate     = null;
    AttributeType[]    rdnAttributes      = null;
    ArrayList<String>  subTemplateNames   = new ArrayList<String>();
    ArrayList<Integer> entriesPerTemplate = new ArrayList<Integer>();
@@ -1163,7 +1169,15 @@
      }
      else if (lowerLine.startsWith("extends: "))
      {
        parentTemplateName = line.substring(9).trim();
        String parentTemplateName = line.substring(9).trim();
        parentTemplate = definedTemplates.get(parentTemplateName.toLowerCase());
        if (parentTemplate == null)
        {
          int msgID = MSGID_MAKELDIF_TEMPLATE_INVALID_PARENT_TEMPLATE;
          String message = getMessage(msgID, parentTemplateName, lineNumber,
                                      templateName);
          throw new MakeLDIFException(msgID, message);
        }
      }
      else if (lowerLine.startsWith("rdnattr: "))
      {
@@ -1242,9 +1256,21 @@
      numEntriesPerTemplate[i] = entriesPerTemplate.get(i);
    }
    TemplateLine[] parsedLines;
    if (parentTemplate == null)
    {
      parsedLines = new TemplateLine[0];
    }
    else
    {
      TemplateLine[] parentLines = parentTemplate.getTemplateLines();
      parsedLines = new TemplateLine[parentLines.length];
      System.arraycopy(parentLines, 0, parsedLines, 0, parentLines.length);
    }
    Template template = new Template(this, templateName, rdnAttributes,
                                     subordinateTemplateNames,
                                     numEntriesPerTemplate);
                                     numEntriesPerTemplate, parsedLines);
    for ( ; arrayLineNumber < templateLines.length; arrayLineNumber++)
    {