Class LDIFReader

    • Field Detail

      • importConfig

        protected final LDIFImportConfig importConfig
        The import configuration that specifies what should be imported.
      • lastEntryBodyLines

        protected List<StringBuilder> lastEntryBodyLines
        The lines that comprise the body of the last entry read.
      • lastEntryHeaderLines

        protected List<StringBuilder> lastEntryHeaderLines
        The lines that comprise the header (DN and any comments) for the last entry read.
      • entriesRead

        protected final AtomicLong entriesRead
        The number of entries that have been read by this LDIF reader, including those that were ignored because they didn't match the criteria, and including those that were rejected because they were invalid in some way.
      • lastEntryLineNumber

        protected long lastEntryLineNumber
        The line number on which the last entry started.
    • Constructor Detail

      • LDIFReader

        public LDIFReader​(LDIFImportConfig importConfig,
                          ServerContext serverContext)
                   throws IOException
        Creates a new LDIF reader that will read information from the specified file.
        Parameters:
        importConfig - The import configuration for this LDIF reader. It must not be null.
        serverContext - The server context
        Throws:
        IOException - If a problem occurs while opening the LDIF file for reading.
    • Method Detail

      • readEntry

        public Entry readEntry()
                        throws IOException,
                               LDIFException
        Reads the next entry from the LDIF source.
        Returns:
        The next entry read from the LDIF source, or null if the end of the LDIF data is reached.
        Throws:
        IOException - If an I/O problem occurs while reading from the file.
        LDIFException - If the information read cannot be parsed as an LDIF entry.
      • createEntry

        protected Entry createEntry​(Dn entryDN,
                                    List<StringBuilder> lines,
                                    boolean checkSchema)
                             throws LDIFException
        Parses the provided LDIF lines as an LDAP entry.
        Parameters:
        entryDN - The parsed entry DN.
        lines - The lines of LDIF.
        checkSchema - Whether attributes should be validated.
        Returns:
        The parsed LDAP entry.
        Throws:
        LDIFException - If the attributes could not be parsed.
      • invokeImportPlugins

        protected final boolean invokeImportPlugins​(Entry entry,
                                                    LinkedList<StringBuilder> lines)
        Invokes the LDIF import plugins.
        Parameters:
        entry - the entry to pass to the LDIF import plugins
        lines - the lines for error reporting purposes
        Returns:
        whether to continue processing this entry
      • readEntryLines

        protected LinkedList<StringBuilder> readEntryLines()
                                                    throws IOException,
                                                           LDIFException
        Reads a set of lines from the next entry in the LDIF source.
        Returns:
        A set of lines from the next entry in the LDIF source.
        Throws:
        IOException - If a problem occurs while reading from the LDIF source.
        LDIFException - If the information read is not valid LDIF.
      • readDN

        protected Dn readDN​(LinkedList<StringBuilder> lines)
                     throws LDIFException
        Reads the DN of the entry from the provided list of lines. The DN must be the first line in the list, unless the first line starts with "version", in which case the DN should be the second line.
        Parameters:
        lines - The set of lines from which the DN should be read.
        Returns:
        The decoded entry DN.
        Throws:
        LDIFException - If DN is not the first element in the list (or the second after the LDIF version), or if a problem occurs while trying to parse it.
      • getServerContext

        protected final ServerContext getServerContext()
        Returns the server context.
        Returns:
        the server context
      • rejectLastEntry

        public void rejectLastEntry​(LocalizableMessage message)
        Rejects the last entry read from the LDIF. This method is intended for use by components that perform their own validation of entries (e.g., backends during import processing) in which the entry appeared valid to the LDIF reader but some other problem was encountered.
        Parameters:
        message - A human-readable message providing the reason that the last entry read was not acceptable.
      • rejectEntry

        public void rejectEntry​(Entry entry,
                                LocalizableMessage message)
        Log the specified entry and messages in the reject writer. The method is intended to be used in a threaded environment, where individual import threads need to log an entry and message to the reject file.
        Parameters:
        entry - The entry to log.
        message - The message to log.
      • close

        public void close()
        Closes this LDIF reader and the underlying file or input stream.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
      • getEntriesRead

        public long getEntriesRead()
        Retrieves the total number of entries read so far by this LDIF reader, including those that have been ignored or rejected.
        Returns:
        The total number of entries read so far by this LDIF reader.
      • getEntriesIgnored

        public long getEntriesIgnored()
        Retrieves the total number of entries that have been ignored so far by this LDIF reader because they did not match the import criteria.
        Returns:
        The total number of entries ignored so far by this LDIF reader.
      • getEntriesRejected

        public long getEntriesRejected()
        Retrieves the total number of entries rejected so far by this LDIF reader. This includes both entries that were rejected because of internal validation failure (e.g., they didn't conform to the defined server schema) or an external validation failure (e.g., the component using this LDIF reader didn't accept the entry because it didn't have a parent).
        Returns:
        The total number of entries rejected so far by this LDIF reader.
      • logToRejectWriter

        protected void logToRejectWriter​(List<StringBuilder> lines,
                                         LocalizableMessage message)
        Log a message to the reject writer if one is configured.
        Parameters:
        lines - The set of rejected lines.
        message - The associated error message.
      • logToSkipWriter

        protected void logToSkipWriter​(List<StringBuilder> lines,
                                       LocalizableMessage message)
        Log a message to the reject writer if one is configured.
        Parameters:
        lines - The set of rejected lines.
        message - The associated error message.