Class LDIF

java.lang.Object
org.forgerock.opendj.ldif.LDIF

public final class LDIF extends Object
This class contains common utility methods for creating and manipulating readers and writers.
  • Method Details

    • copyTo

      Copies the content of input to output. This method does not close input or output.
      Parameters:
      input - The input change record reader.
      output - The output change record reader.
      Returns:
      The output change record reader.
      Throws:
      IOException - If an unexpected IO error occurred.
    • copyTo

      public static EntryWriter copyTo(EntryReader input, EntryWriter output) throws IOException
      Copies the content of input to output. This method does not close input or output.
      Parameters:
      input - The input entry reader.
      output - The output entry reader.
      Returns:
      The output entry reader.
      Throws:
      IOException - If an unexpected IO error occurred.
    • diff

      public static ChangeRecordReader diff(EntryReader source, EntryReader target) throws IOException
      Compares the content of source to the content of target and returns the differences in a change record reader. Closing the returned reader will cause source and target to be closed as well.

      NOTE: this method reads the content of source and target into memory before calculating the differences, and is therefore not suited for use in cases where a very large number of entries are to be compared.

      Parameters:
      source - The entry reader containing the source entries to be compared.
      target - The entry reader containing the target entries to be compared.
      Returns:
      A change record reader containing the differences.
      Throws:
      IOException - If an unexpected IO error occurred.
    • makeEntry

      public static Entry makeEntry(String... ldifLines)
      Builds an entry from the provided lines of LDIF.

      Sample usage:

       Entry john = makeEntry(
         "dn: cn=John Smith,dc=example,dc=com",
         "objectclass: inetorgperson",
         "cn: John Smith",
         "sn: Smith",
         "givenname: John");
       
      Parameters:
      ldifLines - LDIF lines that contains entry definition.
      Returns:
      an entry
      Throws:
      org.forgerock.i18n.LocalizedIllegalArgumentException - If ldifLines did not contain an LDIF entry, or contained multiple entries, or contained malformed LDIF, or if the entry could not be decoded using the default schema.
      NullPointerException - If ldifLines was null.
    • makeEntry

      public static Entry makeEntry(List<String> ldifLines)
      Builds an entry from the provided lines of LDIF.
      Parameters:
      ldifLines - LDIF lines that contains entry definition.
      Returns:
      an entry
      Throws:
      org.forgerock.i18n.LocalizedIllegalArgumentException - If ldifLines did not contain an LDIF entry, or contained multiple entries, or contained malformed LDIF, or if the entry could not be decoded using the default schema.
      NullPointerException - If ldifLines was null.
      See Also:
    • makeEntries

      public static List<Entry> makeEntries(String... ldifLines)
      Builds a list of entries from the provided lines of LDIF.

      Sample usage:

       List smiths = TestCaseUtils.makeEntries(
         "dn: cn=John Smith,dc=example,dc=com",
         "objectclass: inetorgperson",
         "cn: John Smith",
         "sn: Smith",
         "givenname: John",
         "",
         "dn: cn=Jane Smith,dc=example,dc=com",
         "objectclass: inetorgperson",
         "cn: Jane Smith",
         "sn: Smith",
         "givenname: Jane");
       
      Parameters:
      ldifLines - LDIF lines that contains entries definition. Entries are separated by an empty string: "".
      Returns:
      a non empty list of entries
      Throws:
      org.forgerock.i18n.LocalizedIllegalArgumentException - If ldifLines did not contain LDIF entries, or contained malformed LDIF, or if the entries could not be decoded using the default schema.
      NullPointerException - If ldifLines was null.
    • makeEntries

      public static List<Entry> makeEntries(List<String> ldifLines)
      Builds a list of entries from the provided lines of LDIF.
      Parameters:
      ldifLines - LDIF lines that contains entries definition. Entries are separated by an empty string: "".
      Returns:
      a non empty list of entries
      Throws:
      org.forgerock.i18n.LocalizedIllegalArgumentException - If ldifLines did not contain LDIF entries, or contained malformed LDIF, or if the entries could not be decoded using the default schema.
      NullPointerException - If ldifLines was null.
      See Also:
    • newEntryCollectionReader

      Returns an entry reader over the provided entry collection.
      Parameters:
      entries - The entry collection.
      Returns:
      An entry reader over the provided entry collection.
    • newEntryIteratorReader

      Returns an entry reader over the provided entry iterator.
      Parameters:
      entries - The entry iterator.
      Returns:
      An entry reader over the provided entry iterator.
    • patch

      public static EntryReader patch(EntryReader input, ChangeRecordReader patch) throws IOException
      Applies the set of changes contained in patch to the content of input and returns the result in an entry reader. This method ignores missing entries, and overwrites existing entries. Closing the returned reader will cause input and patch to be closed as well.

      NOTE: this method reads the content of input into memory before applying the changes, and is therefore not suited for use in cases where a very large number of entries are to be patched.

      NOTE: this method will not perform modifications required in order to maintain referential integrity. In particular, if an entry references another entry using a DN valued attribute and the referenced entry is deleted, then the DN reference will not be removed. The same applies to renamed entries and their references.

      Parameters:
      input - The entry reader containing the set of entries to be patched.
      patch - The change record reader containing the set of changes to be applied.
      Returns:
      An entry reader containing the patched entries.
      Throws:
      IOException - If an unexpected IO error occurred.
    • patch

      Applies the set of changes contained in patch to the content of input and returns the result in an entry reader. Closing the returned reader will cause input and patch to be closed as well.

      NOTE: this method reads the content of input into memory before applying the changes, and is therefore not suited for use in cases where a very large number of entries are to be patched.

      NOTE: this method will not perform modifications required in order to maintain referential integrity. In particular, if an entry references another entry using a DN valued attribute and the referenced entry is deleted, then the DN reference will not be removed. The same applies to renamed entries and their references.

      Parameters:
      input - The entry reader containing the set of entries to be patched.
      patch - The change record reader containing the set of changes to be applied.
      listener - The rejected change listener.
      Returns:
      An entry reader containing the patched entries.
      Throws:
      IOException - If an unexpected IO error occurred.
    • search

      public static EntryReader search(EntryReader input, SearchRequest search)
      Returns a filtered view of input containing only those entries which match the search base DN, scope, and filtered defined in search. In addition, returned entries will be filtered according to any attribute filtering criteria defined in the search request.

      The filter and attribute descriptions will be decoded using the default schema.

      Parameters:
      input - The entry reader containing the set of entries to be filtered.
      search - The search request defining the filtering criteria.
      Returns:
      A filtered view of input containing only those entries which match the provided search request.
    • search

      public static EntryReader search(EntryReader input, SearchRequest search, Schema schema)
      Returns a filtered view of input containing only those entries which match the search base DN, scope, and filtered defined in search. In addition, returned entries will be filtered according to any attribute filtering criteria defined in the search request.

      The filter and attribute descriptions will be decoded using the provided schema.

      Parameters:
      input - The entry reader containing the set of entries to be filtered.
      search - The search request defining the filtering criteria.
      schema - The schema which should be used to decode the search filter and attribute descriptions.
      Returns:
      A filtered view of input containing only those entries which match the provided search request.
    • toLDIF

      public static String toLDIF(Entry entry)
      Returns the LDIF representation of entry. All attributes will be included and no wrapping will be performed. This method can be useful when debugging applications.
      Parameters:
      entry - The entry to be converted to LDIF.
      Returns:
      The LDIF representation of entry.
    • toLDIF

      public static String toLDIF(ChangeRecord change)
      Returns the LDIF representation of change. No wrapping will be performed. This method can be useful when debugging applications.
      Parameters:
      change - The change record to be converted to LDIF.
      Returns:
      The LDIF representation of change.