@PublicAPI(stability=UNCOMMITTED, mayInstantiate=true, mayExtend=false, mayInvoke=true) public class LDIFReader extends Object implements Closeable
Modifier and Type | Field and Description |
---|---|
protected 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.
|
protected LDIFImportConfig |
importConfig
The import configuration that specifies what should be imported.
|
protected List<StringBuilder> |
lastEntryBodyLines
The lines that comprise the body of the last entry read.
|
protected List<StringBuilder> |
lastEntryHeaderLines
The lines that comprise the header (DN and any comments) for the last entry read.
|
protected long |
lastEntryLineNumber
The line number on which the last entry started.
|
protected PluginConfigManager |
pluginConfigManager
The plugin config manager that will be used if we are to invoke plugins on
the entries as they are read.
|
Constructor and Description |
---|
LDIFReader(LDIFImportConfig importConfig)
Creates a new LDIF reader that will read information from the specified
file.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addRDNAttributesIfNecessary(org.forgerock.opendj.ldap.Dn entryDN,
Map<org.forgerock.opendj.ldap.schema.AttributeType,List<Attribute>> userAttributes,
Map<org.forgerock.opendj.ldap.schema.AttributeType,List<Attribute>> operationalAttributes)
Adds any missing RDN attributes to the entry that is being imported.
|
void |
close()
Closes this LDIF reader and the underlying file or input stream.
|
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.
|
long |
getEntriesRead()
Retrieves the total number of entries read so far by this LDIF reader,
including those that have been ignored or rejected.
|
long |
getEntriesRejected()
Retrieves the total number of entries rejected so far by this LDIF reader.
|
long |
getLastEntryLineNumber()
Retrieves the starting line number for the last entry read from the LDIF
source.
|
protected void |
logToRejectWriter(List<StringBuilder> lines,
LocalizableMessage message)
Log a message to the reject writer if one is configured.
|
protected void |
logToSkipWriter(List<StringBuilder> lines,
LocalizableMessage message)
Log a message to the reject writer if one is configured.
|
static org.forgerock.opendj.ldap.AttributeDescription |
parseAttrDescription(String attrDescr)
Parse an AttributeDescription (an attribute type name and its
options).
|
protected void |
readAttribute(List<StringBuilder> lines,
StringBuilder line,
org.forgerock.opendj.ldap.Dn entryDN,
Map<org.forgerock.opendj.ldap.schema.ObjectClass,String> objectClasses,
Map<org.forgerock.opendj.ldap.schema.AttributeType,List<AttributeBuilder>> userAttrBuilders,
Map<org.forgerock.opendj.ldap.schema.AttributeType,List<AttributeBuilder>> operationalAttrBuilders,
boolean checkSchema)
Decodes the provided line as an LDIF attribute and adds it to the
appropriate hash.
|
ChangeRecordEntry |
readChangeRecord(boolean defaultAdd)
Reads the next change record from the LDIF source.
|
protected org.forgerock.opendj.ldap.Dn |
readDN(LinkedList<StringBuilder> lines)
Reads the DN of the entry from the provided list of lines.
|
Entry |
readEntry()
Reads the next entry from the LDIF source.
|
Entry |
readEntry(boolean checkSchema)
Reads the next entry from the LDIF source.
|
protected LinkedList<StringBuilder> |
readEntryLines()
Reads a set of lines from the next entry in the LDIF source.
|
void |
rejectEntry(Entry e,
LocalizableMessage message)
Log the specified entry and messages in the reject writer.
|
void |
rejectLastEntry(LocalizableMessage message)
Rejects the last entry read from the LDIF.
|
protected Map<org.forgerock.opendj.ldap.schema.AttributeType,List<Attribute>> |
toAttributesMap(Map<org.forgerock.opendj.ldap.schema.AttributeType,List<AttributeBuilder>> attrBuilders)
Returns a new Map where the provided Map with AttributeBuilders is converted to another Map
with Attributes.
|
protected final LDIFImportConfig importConfig
protected List<StringBuilder> lastEntryBodyLines
protected List<StringBuilder> lastEntryHeaderLines
protected final AtomicLong entriesRead
protected long lastEntryLineNumber
protected final PluginConfigManager pluginConfigManager
public LDIFReader(LDIFImportConfig importConfig) throws IOException
importConfig
- The import configuration for this LDIF reader. It
must not be null
.IOException
- If a problem occurs while opening the LDIF file for
reading.public Entry readEntry() throws IOException, LDIFException
null
if
the end of the LDIF data is reached.IOException
- If an I/O problem occurs while reading from the file.LDIFException
- If the information read cannot be parsed as an LDIF
entry.public Entry readEntry(boolean checkSchema) throws IOException, LDIFException
checkSchema
- Indicates whether this reader should perform schema
checking on the entry before returning it to the
caller. Note that some basic schema checking (like
refusing multiple values for a single-valued
attribute) may always be performed.null
if
the end of the LDIF data is reached.IOException
- If an I/O problem occurs while reading from the file.LDIFException
- If the information read cannot be parsed as an LDIF
entry.protected Map<org.forgerock.opendj.ldap.schema.AttributeType,List<Attribute>> toAttributesMap(Map<org.forgerock.opendj.ldap.schema.AttributeType,List<AttributeBuilder>> attrBuilders)
attrBuilders
- the provided Map containing AttributeBuilderspublic ChangeRecordEntry readChangeRecord(boolean defaultAdd) throws IOException, LDIFException
defaultAdd
- Indicates whether the change type should default to
"add" if none is explicitly provided.null
if the end of the LDIF data is reached.IOException
- If an I/O problem occurs while reading from the file.LDIFException
- If the information read cannot be parsed as an LDIF
entry.protected LinkedList<StringBuilder> readEntryLines() throws IOException, LDIFException
IOException
- If a problem occurs while reading from the LDIF
source.LDIFException
- If the information read is not valid LDIF.protected org.forgerock.opendj.ldap.Dn readDN(LinkedList<StringBuilder> lines) throws LDIFException
lines
- The set of lines from which the DN should be read.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.protected void readAttribute(List<StringBuilder> lines, StringBuilder line, org.forgerock.opendj.ldap.Dn entryDN, Map<org.forgerock.opendj.ldap.schema.ObjectClass,String> objectClasses, Map<org.forgerock.opendj.ldap.schema.AttributeType,List<AttributeBuilder>> userAttrBuilders, Map<org.forgerock.opendj.ldap.schema.AttributeType,List<AttributeBuilder>> operationalAttrBuilders, boolean checkSchema) throws LDIFException
lines
- The full set of lines that comprise the
entry (used for writing reject information).line
- The line to decode.entryDN
- The DN of the entry being decoded.objectClasses
- The set of objectclasses decoded so far for
the current entry.userAttrBuilders
- The map of user attribute builders decoded
so far for the current entry.operationalAttrBuilders
- The map of operational attribute builders
decoded so far for the current entry.checkSchema
- Indicates whether to perform schema
validation for the attribute.LDIFException
- If a problem occurs while trying to decode the
attribute contained in the provided entry.public long getLastEntryLineNumber()
public void rejectLastEntry(LocalizableMessage message)
message
- A human-readable message providing the reason that the
last entry read was not acceptable.public void rejectEntry(Entry e, LocalizableMessage message)
e
- The entry to log.message
- The message to log.public void close()
close
in interface Closeable
close
in interface AutoCloseable
public static org.forgerock.opendj.ldap.AttributeDescription parseAttrDescription(String attrDescr)
attrDescr
- The attribute description to be parsed.public long getEntriesRead()
public long getEntriesIgnored()
public long getEntriesRejected()
protected void logToRejectWriter(List<StringBuilder> lines, LocalizableMessage message)
lines
- The set of rejected lines.message
- The associated error message.protected void logToSkipWriter(List<StringBuilder> lines, LocalizableMessage message)
lines
- The set of rejected lines.message
- The associated error message.protected void addRDNAttributesIfNecessary(org.forgerock.opendj.ldap.Dn entryDN, Map<org.forgerock.opendj.ldap.schema.AttributeType,List<Attribute>> userAttributes, Map<org.forgerock.opendj.ldap.schema.AttributeType,List<Attribute>> operationalAttributes)
entryDN
- the entry DNuserAttributes
- the user attributesoperationalAttributes
- the operational attributesCopyright © 2010-2017 ForgeRock AS. All Rights Reserved.