public class LdifReader extends Object implements Iterable<LdifEntry>, Closeable
<ldif-file> ::= "version:" <fill> <number> <seps> <dn-spec> <sep>
<ldif-content-change>
<ldif-content-change> ::=
<number> <oid> <options-e> <value-spec> <sep>
<attrval-specs-e> <ldif-attrval-record-e> |
<alpha> <chars-e> <options-e> <value-spec> <sep>
<attrval-specs-e> <ldif-attrval-record-e> |
"control:" <fill> <number> <oid> <spaces-e>
<criticality> <value-spec-e> <sep> <controls-e>
"changetype:" <fill> <changerecord-type> <ldif-change-record-e> |
"changetype:" <fill> <changerecord-type> <ldif-change-record-e>
<ldif-attrval-record-e> ::= <seps> <dn-spec> <sep> <attributeType>
<options-e> <value-spec> <sep> <attrval-specs-e>
<ldif-attrval-record-e> | e
<ldif-change-record-e> ::= <seps> <dn-spec> <sep> <controls-e>
"changetype:" <fill> <changerecord-type> <ldif-change-record-e> | e
<dn-spec> ::= "dn:" <fill> <safe-string> | "dn::" <fill> <base64-string>
<controls-e> ::= "control:" <fill> <number> <oid> <spaces-e> <criticality>
<value-spec-e> <sep> <controls-e> | e
<criticality> ::= "true" | "false" | e
<oid> ::= '.' <number> <oid> | e
<attrval-specs-e> ::= <number> <oid> <options-e> <value-spec>
<sep> <attrval-specs-e> |
<alpha> <chars-e> <options-e> <value-spec> <sep> <attrval-specs-e> | e
<value-spec-e> ::= <value-spec> | e
<value-spec> ::= ':' <fill> <safe-string-e> |
"::" <fill> <base64-chars> |
":<" <fill> <url>
<attributeType> ::= <number> <oid> | <alpha> <chars-e>
<options-e> ::= ';' <char> <chars-e> <options-e> |e
<chars-e> ::= <char> <chars-e> | e
<changerecord-type> ::= "add" <sep> <attributeType>
<options-e> <value-spec> <sep> <attrval-specs-e> |
"delete" <sep> |
"modify" <sep> <mod-type> <fill> <attributeType>
<options-e> <sep> <attrval-specs-e> <sep> '-' <sep> <mod-specs-e> |
"moddn" <sep> <newrdn> <sep> "deleteoldrdn:"
<fill> <0-1> <sep> <newsuperior-e> <sep> |
"modrdn" <sep> <newrdn> <sep> "deleteoldrdn:"
<fill> <0-1> <sep> <newsuperior-e> <sep>
<newrdn> ::= ':' <fill> <safe-string> | "::" <fill> <base64-chars>
<newsuperior-e> ::= "newsuperior" <newrdn> | e
<mod-specs-e> ::= <mod-type> <fill> <attributeType> <options-e>
<sep> <attrval-specs-e> <sep> '-' <sep> <mod-specs-e> | e
<mod-type> ::= "add:" | "delete:" | "replace:"
<url> ::= <a Uniform Resource Locator, as defined in [6]>
LEXICAL
-------
<fill> ::= ' ' <fill> | e
<char> ::= <alpha> | <digit> | '-'
<number> ::= <digit> <digits>
<0-1> ::= '0' | '1'
<digits> ::= <digit> <digits> | e
<digit> ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
<seps> ::= <sep> <seps-e>
<seps-e> ::= <sep> <seps-e> | e
<sep> ::= 0x0D 0x0A | 0x0A
<spaces> ::= ' ' <spaces-e>
<spaces-e> ::= ' ' <spaces-e> | e
<safe-string-e> ::= <safe-string> | e
<safe-string> ::= <safe-init-char> <safe-chars>
<safe-init-char> ::= [0x01-0x09] | 0x0B | 0x0C | [0x0E-0x1F] | [0x21-0x39] | 0x3B | [0x3D-0x7F]
<safe-chars> ::= <safe-char> <safe-chars> | e
<safe-char> ::= [0x01-0x09] | 0x0B | 0x0C | [0x0E-0x7F]
<base64-string> ::= <base64-char> <base64-chars>
<base64-chars> ::= <base64-char> <base64-chars> | e
<base64-char> ::= 0x2B | 0x2F | [0x30-0x39] | 0x3D | [0x41-9x5A] | [0x61-0x7A]
<alpha> ::= [0x41-0x5A] | [0x61-0x7A]
COMMENTS
--------
- The ldap-oid VN is not correct in the RFC-2849. It has been changed from 1*DIGIT 0*1("." 1*DIGIT) to
DIGIT+ ("." DIGIT+)*
- The mod-spec lacks a sep between *attrval-spec and "-".
- The BASE64-UTF8-STRING should be BASE64-CHAR BASE64-STRING
- The ValueSpec rule must accept multilines values. In this case, we have a LF followed by a
single space before the continued value.
The relaxed mode is used when a SchemaManager is injected.| Modifier and Type | Field and Description |
|---|---|
protected static int |
ATTRVAL_SPEC
State values for the modify operation : ATTRVAL_SPEC
|
protected static int |
ATTRVAL_SPEC_OR_SEP
State values for the modify operation : ATTRVAL_SPEC_OR_SEP
|
protected static int |
CHANGE
Type of element read : CHANGE
|
protected boolean |
containsChanges
A flag set if the ldif contains changes
|
protected boolean |
containsEntries
A flag set if the ldif contains entries
|
protected static int |
DEFAULT_VERSION
The ldif file version default value
|
protected int |
entryLen
total length of an LDIF entry including the comments
|
protected long |
entryOffset
the parsed entry's starting position
|
protected Exception |
error
An Exception to handle error message, has Iterator.next() can't throw
exceptions
|
private InputStream |
is
The internal inputStream
|
protected static int |
LDIF_ENTRY
Type of element read : ENTRY
|
protected int |
lineNumber
the numer of the current line being parsed by the reader
|
protected List<String> |
lines
A list of read lines
|
private static org.slf4j.Logger |
LOG
A logger
|
protected static int |
MOD_SPEC
State values for the modify operation : MOD_SPEC
|
protected long |
offset
the current offset of the reader
|
private int |
oidCounter
A counter used to create facked OIDs
|
protected int |
position
The current position
|
protected LdifEntry |
prefetched
Iterator prefetched entry
|
protected Reader |
reader
The ldif Reader
|
protected SchemaManager |
schemaManager
The SchemaManager instance, if any
|
protected static long |
SIZE_LIMIT_DEFAULT
The default size limit : 1Mo
|
protected long |
sizeLimit
Size limit for file contained values
|
protected static int |
UNKNOWN
Type of element read : UNKNOWN
|
protected boolean |
validateDn
flag to turn on/off of the DN validation.
|
protected int |
version
The ldif version
|
| Constructor and Description |
|---|
LdifReader()
Constructors
|
LdifReader(File file)
A constructor which takes a File.
|
LdifReader(File file,
SchemaManager schemaManager)
A constructor which takes a File and a SchemaManager.
|
LdifReader(InputStream in)
A constructor which takes an InputStream.
|
LdifReader(Reader in)
A constructor which takes a Reader.
|
LdifReader(SchemaManager schemaManager)
Creates a Schema aware reader
|
LdifReader(String ldifFileName)
A constructor which takes a file name.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
boolean |
containsEntries() |
protected LdifEntry |
createLdifEntry(SchemaManager schemaManager)
Creates a schema aware LdifEntry
|
LdifEntry |
fetch()
Gets the current entry, but don't move forward.
|
Exception |
getError() |
protected String |
getLine()
gets a line from the underlying data store
|
int |
getLineNumber() |
long |
getSizeLimit() |
private Object |
getValue(String attributeName,
byte[] value) |
int |
getVersion() |
boolean |
hasError() |
boolean |
hasNext()
Tests to see if another LDIF is on the input channel.
|
private boolean |
hasNextInternal()
Tests to see if another LDIF is on the input channel.
|
void |
init()
Initialize the LdifReader
|
private void |
initReader(BufferedReader reader)
Store the reader and initialize the LdifReader
|
boolean |
isValidateDn() |
Iterator<LdifEntry> |
iterator() |
LdifEntry |
next()
Gets the next LDIF on the channel.
|
private LdifEntry |
nextInternal()
Gets the next LDIF on the channel.
|
void |
parseAttributeValue(LdifEntry entry,
String line,
String lowerLine)
Parse an AttributeType/AttributeValue
|
static Attribute |
parseAttributeValue(String line)
Parse an AttributeType/AttributeValue
|
private void |
parseChange(LdifEntry entry,
Iterator<String> iter,
ChangeType operation)
Parse a change operation.
|
protected ChangeType |
parseChangeType(String line)
Parse the changeType
|
private Control |
parseControl(String line)
Parse a control.
|
protected String |
parseDn(String line)
Parse the Dn of an entry
|
protected LdifEntry |
parseEntry()
Parse a ldif file.
|
private void |
parseFill(char[] document) |
List<LdifEntry> |
parseLdif(BufferedReader reader)
The main entry point of the LdifParser.
|
List<LdifEntry> |
parseLdif(String ldif)
A method which parses a ldif string and returns a list of entries.
|
List<LdifEntry> |
parseLdifFile(String fileName)
Parse a ldif file (using the default encoding).
|
List<LdifEntry> |
parseLdifFile(String fileName,
String encoding)
Parse a ldif file, decoding it using the given charset encoding
|
private void |
parseModify(LdifEntry entry,
Iterator<String> iter)
Parse a modify change type.
|
private void |
parseModRdn(LdifEntry entry,
Iterator<String> iter)
Parse a ModRDN operation
|
private String |
parseNumber(char[] document)
Parse a number following the rules :
<number> ::= <digit> <digits> <digits> ::= <digit> <digits> | e <digit>
::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
Check that the number is in the interval
|
protected static Object |
parseSimpleValue(String line,
int pos)
Parse the value part.
|
protected Object |
parseValue(String attributeName,
String line,
int pos)
Parse the value part.
|
protected int |
parseVersion()
Parse the version from the ldif input.
|
protected void |
readLines()
Reads an entry in a ldif buffer, and returns the resulting lines, without
comments, and unfolded.
|
void |
remove()
Always throws UnsupportedOperationException!
|
private void |
removeInternal()
Always throws UnsupportedOperationException!
|
void |
setSchemaManager(SchemaManager schemaManager) |
void |
setSizeLimit(long sizeLimit)
Set the maximum file size that can be accepted for an attribute value
|
void |
setValidateDn(boolean validateDn)
Turns on/off the DN validation
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorprivate static final org.slf4j.Logger LOG
protected int position
protected static final int DEFAULT_VERSION
protected int version
protected static final int LDIF_ENTRY
protected static final int CHANGE
protected static final int UNKNOWN
protected long sizeLimit
protected static final long SIZE_LIMIT_DEFAULT
protected static final int MOD_SPEC
protected static final int ATTRVAL_SPEC
protected static final int ATTRVAL_SPEC_OR_SEP
protected LdifEntry prefetched
protected Reader reader
private InputStream is
protected boolean containsEntries
protected boolean containsChanges
protected SchemaManager schemaManager
protected Exception error
protected int entryLen
protected long entryOffset
protected long offset
protected int lineNumber
protected boolean validateDn
private int oidCounter
public LdifReader()
public LdifReader(SchemaManager schemaManager)
schemaManager - The SchemaManagerpublic LdifReader(String ldifFileName) throws LdapLdifException
ldifFileName - A file name containing ldif formated inputLdapLdifException - If the file cannot be processed or if the format is incorrectpublic LdifReader(Reader in) throws LdapException
in - A Reader containing ldif formated inputLdapException - If the file cannot be processed or if the format is incorrectpublic LdifReader(InputStream in) throws LdapException
in - An InputStream containing ldif formated inputLdapException - If the file cannot be processed or if the format is incorrectpublic LdifReader(File file) throws LdapLdifException
file - A File containing ldif formated inputLdapLdifException - If the file cannot be processed or if the format is incorrectpublic LdifReader(File file, SchemaManager schemaManager) throws LdapLdifException
file - A File containing ldif formated inputschemaManager - The SchemaManager instance to useLdapLdifException - If the file cannot be processed or if the format is incorrectprivate void initReader(BufferedReader reader) throws LdapException
reader - The reader to useLdapException - If the initialization failedpublic void init()
throws LdapException
LdapException - If the initialization failedpublic int getVersion()
public long getSizeLimit()
public void setSizeLimit(long sizeLimit)
sizeLimit - The size in bytesprivate void parseFill(char[] document)
private String parseNumber(char[] document)
document - The document containing the number to parseprotected ChangeType parseChangeType(String line)
line - The line which contains the changeTypeprotected String parseDn(String line) throws LdapLdifException
line - The line to parseLdapLdifException - If the Dn is invalidprotected static Object parseSimpleValue(String line, int pos)
line - The line which contains the valuepos - The starting position in the lineprotected Object parseValue(String attributeName, String line, int pos) throws LdapLdifException
attributeName - The attribute nameline - The line which contains the valuepos - The starting position in the lineLdapLdifException - If something went wrongprivate Control parseControl(String line) throws LdapLdifException
<control> ::= "control:" <fill> <ldap-oid> <critical-e> <value-spec-e> <sep> <critical-e> ::= <spaces> <boolean> | e <boolean> ::= "true" | "false" <value-spec-e> ::= <value-spec> | e <value-spec> ::= ":" <fill> <SAFE-STRING-e> | "::" <fill> <BASE64-STRING> | ":<" <fill> <url>It can be read as :
"control:" <fill> <ldap-oid> [ " "+ ( "true" | "false") ] [ ":" <fill> <SAFE-STRING-e> | "::" <fill> <BASE64-STRING> | ":<" <fill> <url> ]
line - The line containing the controlLdapLdifException - If the control has no OID or if the OID is incorrect,
of if the criticality is not set when it's mandatory.public static Attribute parseAttributeValue(String line)
line - The line to parsepublic void parseAttributeValue(LdifEntry entry, String line, String lowerLine) throws LdapException
entry - The entry where to store the valueline - The line to parselowerLine - The same line, lowercasedLdapException - If anything goes wrongprivate void parseModRdn(LdifEntry entry, Iterator<String> iter) throws LdapLdifException
entry - The entry to updateiter - The lines iteratorLdapLdifException - If anything goes wrongprivate void parseModify(LdifEntry entry, Iterator<String> iter) throws LdapLdifException
<changerecord> ::= "changetype:" FILL "modify" SEP <mod-spec> <mod-specs-e>
<mod-spec> ::= "add:" <mod-val> | "delete:" <mod-val-del> | "replace:" <mod-val>
| "increment:" <mod-val>
<mod-specs-e> ::= <mod-spec>
<mod-specs-e> | e
<mod-val> ::= FILL ATTRIBUTE-DESCRIPTION SEP ATTRVAL-SPEC <attrval-specs-e> "-" SEP
<mod-val-del> ::= FILL ATTRIBUTE-DESCRIPTION SEP <attrval-specs-e> "-" SEP
<attrval-specs-e> ::= ATTRVAL-SPEC <attrval-specs> | e
entry - The entry to feediter - The linesLdapLdifException - If the modify operation is invalidprivate void parseChange(LdifEntry entry, Iterator<String> iter, ChangeType operation) throws LdapException
<changerecord> ::= "changetype:" FILL "add" SEP <attrval-spec> <attrval-specs-e> |
"changetype:" FILL "delete" |
"changetype:" FILL "modrdn" SEP <newrdn> SEP <deleteoldrdn> SEP |
// To be checked
"changetype:" FILL "moddn" SEP <newrdn> SEP <deleteoldrdn> SEP <newsuperior> SEP |
"changetype:" FILL "modify" SEP <mod-spec> <mod-specs-e>
<newrdn> ::= "newrdn:" FILL Rdn | "newrdn::" FILL BASE64-Rdn
<deleteoldrdn> ::= "deleteoldrdn:" FILL "0" | "deleteoldrdn:" FILL "1"
<newsuperior> ::= "newsuperior:" FILL Dn | "newsuperior::" FILL BASE64-Dn
<mod-specs-e> ::= <mod-spec> <mod-specs-e> | e
<mod-spec> ::= "add:" <mod-val> | "delete:" <mod-val> | "replace:" <mod-val>
<mod-val> ::= FILL ATTRIBUTE-DESCRIPTION SEP ATTRVAL-SPEC <attrval-specs-e> "-" SEP
<attrval-specs-e> ::= ATTRVAL-SPEC <attrval-specs> | e
entry - The entry to feediter - The lines iteratoroperation - The change operation (add, modify, delete, moddn or modrdn)LdapException - If the change operation is invalidprotected LdifEntry parseEntry() throws LdapException
<ldif-file> ::= <ldif-attrval-record> <ldif-attrval-records> |
<ldif-change-record> <ldif-change-records>
<ldif-attrval-record> ::= <dn-spec> <sep> <attrval-spec> <attrval-specs>
<ldif-change-record> ::= <dn-spec> <sep> <controls-e> <changerecord>
<dn-spec> ::= "dn:" <fill> <distinguishedName> | "dn::" <fill> <base64-distinguishedName>
<changerecord> ::= "changetype:" <fill> <change-op>
LdapException - If the ldif file does not contain a valid entryprotected int parseVersion()
throws LdapLdifException
LdapLdifException - If the version is incorrect or if the input is incorrectprotected String getLine() throws IOException
IOException - on read failureprotected void readLines()
throws LdapLdifException
LdapLdifException - If something went wrongpublic List<LdifEntry> parseLdifFile(String fileName) throws LdapLdifException
fileName - The ldif fileLdapLdifException - If the parsing failspublic List<LdifEntry> parseLdifFile(String fileName, String encoding) throws LdapLdifException
fileName - The ldif fileencoding - The charset encoding to useLdapLdifException - If the parsing failspublic List<LdifEntry> parseLdif(String ldif) throws LdapLdifException
ldif - The ldif stringLdapLdifException - If something went wrongprivate LdifEntry nextInternal()
public LdifEntry next()
public LdifEntry fetch()
private boolean hasNextInternal()
public boolean hasNext()
private void removeInternal()
Iterator.remove()public void remove()
Iterator.remove()public boolean hasError()
public Exception getError()
public List<LdifEntry> parseLdif(BufferedReader reader) throws LdapException
reader - The buffer being processedLdapException - If something went wrongpublic boolean containsEntries()
public int getLineNumber()
protected LdifEntry createLdifEntry(SchemaManager schemaManager)
schemaManager - The SchemaManagerpublic boolean isValidateDn()
public void setValidateDn(boolean validateDn)
validateDn - the boolean flagpublic void setSchemaManager(SchemaManager schemaManager)
schemaManager - the schemaManager to setpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionCopyright © 2003–2022 The Apache Software Foundation. All rights reserved.