public final class Ldif extends Object
Modifier and Type | Method and Description |
---|---|
static ChangeRecordWriter |
copyTo(ChangeRecordReader input,
ChangeRecordWriter output)
Copies the content of
input to output . |
static EntryWriter |
copyTo(EntryReader input,
EntryWriter output)
Copies the content of
input to output . |
static ChangeRecordReader |
diff(EntryReader source,
EntryReader target)
Compares the content of
source to the content of target
and returns the differences in a change record reader. |
static ChangeRecordReader |
diff(EntryReader source,
EntryReader target,
Options options)
Compares the content of
source to the content of target
and returns the differences in a change record reader. |
static ChangeRecord |
makeChangeRecord(String... ldifLines)
Parses the provided array of LDIF lines as a single LDIF change record.
|
static List<Entry> |
makeEntries(List<String> ldifLines)
Builds a list of entries from the provided lines of LDIF.
|
static List<Entry> |
makeEntries(String... ldifLines)
Builds a list of entries from the provided lines of LDIF.
|
static Entry |
makeEntry(List<String> ldifLines)
Builds an entry from the provided lines of LDIF.
|
static Entry |
makeEntry(String... ldifLines)
Builds an entry from the provided lines of LDIF.
|
static Flowable<ChangeRecord> |
newChangeRecordPublisher(Callable<? extends ChangeRecordReader> factory)
Returns a
Flowable view of a ChangeRecordReader , creating a new reader for each subscriber. |
static ChangeRecordReader |
newChangeRecordReader(Iterable<? extends ChangeRecord> changes)
Returns a change record reader over the provided change record collection.
|
static ChangeRecordReader |
newChangeRecordReader(Iterator<? extends ChangeRecord> changes)
Returns a change record reader over the provided change record iterator.
|
static Flowable<Entry> |
newEntryPublisher(Callable<? extends EntryReader> factory)
Returns a
Flowable view of a EntryReader , creating a new reader for each subscriber. |
static EntryReader |
newEntryReader(Iterable<? extends Entry> entries)
Returns an entry reader over the provided entry collection.
|
static EntryReader |
newEntryReader(Iterator<? extends Entry> entries)
Returns an entry reader over the provided entry iterator.
|
static EntryReader |
patch(EntryReader input,
ChangeRecordReader patch)
Applies the set of changes contained in
patch to the content of
input and returns the result in an entry reader. |
static EntryReader |
patch(EntryReader input,
ChangeRecordReader patch,
RejectedChangeRecordListener listener)
Applies the set of changes contained in
patch to the content of
input and returns the result in an entry reader. |
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 . |
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 . |
static String |
toLdif(ChangeRecord change)
Returns the LDIF representation of
change . |
static String |
toLdif(Entry entry)
Returns the LDIF representation of
entry . |
public static Flowable<ChangeRecord> newChangeRecordPublisher(Callable<? extends ChangeRecordReader> factory)
Flowable
view of a ChangeRecordReader
, creating a new reader for each subscriber.factory
- The factory which will be invoked for each subscriber.Flowable
view of a ChangeRecordReader
.public static Flowable<Entry> newEntryPublisher(Callable<? extends EntryReader> factory)
Flowable
view of a EntryReader
, creating a new reader for each subscriber.factory
- The factory which will be invoked for each subscriber.Flowable
view of a EntryReader
.public static ChangeRecordWriter copyTo(ChangeRecordReader input, ChangeRecordWriter output) throws IOException
input
to output
. This method does
not close input
or output
.input
- The input change record reader.output
- The output change record reader.IOException
- If an unexpected IO error occurred.public static EntryWriter copyTo(EntryReader input, EntryWriter output) throws IOException
input
to output
. This method does
not close input
or output
.input
- The input entry reader.output
- The output entry reader.IOException
- If an unexpected IO error occurred.public static ChangeRecordReader diff(EntryReader source, EntryReader target) throws IOException
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.
source
- The entry reader containing the source entries to be compared.target
- The entry reader containing the target entries to be compared.IOException
- If an unexpected IO error occurred.public static ChangeRecordReader diff(EntryReader source, EntryReader target, Options options) throws IOException
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.
source
- The entry reader containing the source entries to be compared.target
- The entry reader containing the target entries to be compared.options
- Options to control how entries are compared.IOException
- If an unexpected IO error occurred.public static Entry makeEntry(String... ldifLines)
Sample usage:
Entry john = makeEntry( "dn: cn=John Smith,dc=example,dc=com", "objectclass: inetorgperson", "cn: John Smith", "sn: Smith", "givenname: John");
ldifLines
- LDIF lines that contains entry definition.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
.public static Entry makeEntry(List<String> ldifLines)
ldifLines
- LDIF lines that contains entry definition.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(String...)
public static List<Entry> makeEntries(String... ldifLines)
Sample usage:
List<Entry> 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");
ldifLines
- LDIF lines that contains entries definition. Entries are separated by an empty string: ""
.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
.public static List<Entry> makeEntries(List<String> ldifLines)
ldifLines
- LDIF lines that contains entries definition. Entries are separated by an empty string: ""
.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(String...)
public static ChangeRecordReader newChangeRecordReader(Iterable<? extends ChangeRecord> changes)
changes
- The change record collection.public static ChangeRecordReader newChangeRecordReader(Iterator<? extends ChangeRecord> changes)
changes
- The change record collection.public static EntryReader newEntryReader(Iterable<? extends Entry> entries)
entries
- The entry collection.public static EntryReader newEntryReader(Iterator<? extends Entry> entries)
entries
- The entry iterator.public static EntryReader patch(EntryReader input, ChangeRecordReader patch) throws IOException
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.
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.IOException
- If an unexpected IO error occurred.public static EntryReader patch(EntryReader input, ChangeRecordReader patch, RejectedChangeRecordListener listener) throws IOException
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.
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.IOException
- If an unexpected IO error occurred.public static EntryReader search(EntryReader input, SearchRequest search)
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.
input
- The entry reader containing the set of entries to be filtered.search
- The search request defining the filtering criteria.input
containing only those entries
which match the provided search request.public static EntryReader search(EntryReader input, SearchRequest search, Schema schema)
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.
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.input
containing only those entries
which match the provided search request.public static String toLdif(Entry entry)
entry
. All attributes will be included and no wrapping will be
performed. This method can be useful when debugging applications.entry
- The entry to be converted to LDIF.entry
.public static String toLdif(ChangeRecord change)
change
. No wrapping will be performed. This method can be useful when
debugging applications.change
- The change record to be converted to LDIF.change
.public static ChangeRecord makeChangeRecord(String... ldifLines)
This method is tolerant to missing change types.
ldifLines
- The lines of LDIF to be parsed.LocalizedIllegalArgumentException
- If ldifLines
did not contain an LDIF change record,
if it contained multiple change records, if contained
malformed LDIF, or if the change record could not be decoded
using the default schema.NullPointerException
- If ldifLines
was null
.Copyright 2010-2022 ForgeRock AS.