Class TemplateFile


  • public class TemplateFile
    extends Object
    This class defines a template file, which is a collection of constant definitions, branches, and templates.
    • Constructor Detail

      • TemplateFile

        public TemplateFile​(String resourcePath,
                            Random random)
        Creates a new, empty template file structure.
        Parameters:
        resourcePath - The path to the directory that may contain additional resource files needed during the LDIF generation process.
        random - The random number generator for this template file.
    • Method Detail

      • getTags

        public Map<String,​Tag> getTags()
        Retrieves the set of tags that have been registered. They will be in the form of a mapping between the name of the tag (in all lowercase characters) and the corresponding tag implementation.
        Returns:
        The set of tags that have been registered.
      • getConstants

        public Map<String,​String> getConstants()
        Retrieves the set of constants defined for this template file.
        Returns:
        The set of constants defined for this template file.
      • getBranches

        public Map<DN,​Branch> getBranches()
        Retrieves the set of branches defined in this template file.
        Returns:
        The set of branches defined in this template file.
      • getTemplates

        public Map<String,​Template> getTemplates()
        Retrieves the set of templates defined in this template file.
        Returns:
        The set of templates defined in this template file.
      • getRandom

        public Random getRandom()
        Retrieves the random number generator for this template file.
        Returns:
        The random number generator for this template file.
      • nextFirstAndLastNames

        public void nextFirstAndLastNames()
        Updates the first and last name indexes to choose new values. The algorithm used is designed to ensure that the combination of first and last names will never be repeated. It depends on the number of first names and the number of last names being relatively prime. This method should be called before beginning generation of each template entry.
      • getFirstName

        public String getFirstName()
        Retrieves the first name value that should be used for the current entry.
        Returns:
        The first name value that should be used for the current entry.
      • getLastName

        public String getLastName()
        Retrieves the last name value that should be used for the current entry.
        Returns:
        The last name value that should be used for the current entry.
      • parse

        public void parse​(String filename,
                          List<org.forgerock.i18n.LocalizableMessage> warnings)
                   throws IOException,
                          InitializationException,
                          MakeLDIFException
        Parses the contents of the specified file as a MakeLDIF template file definition.
        Parameters:
        filename - The name of the file containing the template data.
        warnings - A list into which any warnings identified may be placed.
        Throws:
        IOException - If a problem occurs while attempting to read data from the specified file.
        InitializationException - If a problem occurs while initializing any of the MakeLDIF components.
        MakeLDIFException - If any other problem occurs while parsing the template file.
      • parse

        public void parse​(String[] lines,
                          List<org.forgerock.i18n.LocalizableMessage> warnings)
                   throws InitializationException,
                          MakeLDIFException
        Parses the provided data as a MakeLDIF template file definition.
        Parameters:
        lines - The lines that make up the template file.
        warnings - A list into which any warnings identified may be placed.
        Throws:
        InitializationException - If a problem occurs while initializing any of the MakeLDIF components.
        MakeLDIFException - If any other problem occurs while parsing the template file.
      • getFile

        public File getFile​(String path)
        Retrieves a File object based on the provided path. If the given path is absolute, then that absolute path will be used. If it is relative, then it will first be evaluated relative to the current working directory. If that path doesn't exist, then it will be evaluated relative to the resource path. If that path doesn't exist, then it will be evaluated relative to the directory containing the template file.
        Parameters:
        path - The path provided for the file.
        Returns:
        The File object for the specified path, or null if the specified file could not be found.
      • getFileLines

        public String[] getFileLines​(File file)
                              throws IOException
        Retrieves the lines of the specified file as a string array. If the result is already cached, then it will be used. If the result is not cached, then the file data will be cached so that the contents can be re-used if there are multiple references to the same file.
        Parameters:
        file - The file for which to retrieve the contents.
        Returns:
        An array containing the lines of the specified file.
        Throws:
        IOException - If a problem occurs while reading the file.
      • generateLDIF

        public TagResult generateLDIF​(EntryWriter entryWriter)
                               throws IOException,
                                      MakeLDIFException
        Generates the LDIF content and writes it to the provided LDIF writer.
        Parameters:
        entryWriter - The entry writer that should be used to write the entries.
        Returns:
        The result that indicates whether processing should continue.
        Throws:
        IOException - If an error occurs while writing to the LDIF file.
        MakeLDIFException - If some other problem occurs.