Class LdifReader
java.lang.Object
org.apache.directory.api.ldap.model.ldif.LdifReader
- All Implemented Interfaces:
Closeable, AutoCloseable, Iterable<LdifEntry>
- Direct Known Subclasses:
LdifAttributesReader
<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.- Author:
- Apache Directory Project
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intState values for the modify operation : ATTRVAL_SPECprotected static final intState values for the modify operation : ATTRVAL_SPEC_OR_SEPprotected static final intType of element read : CHANGEprotected booleanA flag set if the ldif contains changesprotected booleanA flag set if the ldif contains entriesprotected static final intThe ldif file version default valueprotected inttotal length of an LDIF entry including the commentsprotected longthe parsed entry's starting positionprotected ExceptionAn Exception to handle error message, has Iterator.next() can't throw exceptionsprotected static final intType of element read : ENTRYprotected intthe numer of the current line being parsed by the readerA list of read linesprotected static final intState values for the modify operation : MOD_SPECprotected longthe current offset of the readerprotected intThe current positionprotected LdifEntryIterator prefetched entryprotected ReaderThe ldif Readerprotected SchemaManagerThe SchemaManager instance, if anyprotected static final longThe default size limit : 1Moprotected longSize limit for file contained valuesprotected static final intType of element read : UNKNOWNprotected booleanflag to turn on/off of the DN validation.protected intThe ldif version -
Constructor Summary
ConstructorsConstructorDescriptionConstructorsLdifReader(File file) A constructor which takes a File.LdifReader(File file, SchemaManager schemaManager) A constructor which takes a File and a SchemaManager.A constructor which takes an InputStream.LdifReader(Reader in) A constructor which takes a Reader.LdifReader(String ldifFileName) A constructor which takes a file name.LdifReader(SchemaManager schemaManager) Creates a Schema aware reader -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()booleanprotected LdifEntrycreateLdifEntry(SchemaManager schemaManager) Creates a schema aware LdifEntryfetch()Gets the current entry, but don't move forward.getError()protected StringgetLine()gets a line from the underlying data storeintlongintbooleanhasError()booleanhasNext()Tests to see if another LDIF is on the input channel.voidinit()Initialize the LdifReaderbooleaniterator()next()Gets the next LDIF on the channel.static AttributeparseAttributeValue(String line) Parse an AttributeType/AttributeValuevoidparseAttributeValue(LdifEntry entry, String line, String lowerLine) Parse an AttributeType/AttributeValueprotected ChangeTypeparseChangeType(String line) Parse the changeTypeprotected StringParse the Dn of an entryprotected LdifEntryParse a ldif file.parseLdif(BufferedReader reader) The main entry point of the LdifParser.A method which parses a ldif string and returns a list of entries.parseLdifFile(String fileName) Parse a ldif file (using the default encoding).parseLdifFile(String fileName, String encoding) Parse a ldif file, decoding it using the given charset encodingprotected static ObjectparseSimpleValue(String line, int pos) Parse the value part.protected ObjectparseValue(String attributeName, String line, int pos) Parse the value part.protected intParse the version from the ldif input.protected voidReads an entry in a ldif buffer, and returns the resulting lines, without comments, and unfolded.voidremove()Always throws UnsupportedOperationException!voidsetSchemaManager(SchemaManager schemaManager) voidsetSizeLimit(long sizeLimit) Set the maximum file size that can be accepted for an attribute valuevoidsetValidateDn(boolean validateDn) Turns on/off the DN validationMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
lines
-
position
protected int positionThe current position -
DEFAULT_VERSION
protected static final int DEFAULT_VERSIONThe ldif file version default value- See Also:
-
version
protected int versionThe ldif version -
LDIF_ENTRY
protected static final int LDIF_ENTRYType of element read : ENTRY- See Also:
-
CHANGE
protected static final int CHANGEType of element read : CHANGE- See Also:
-
UNKNOWN
protected static final int UNKNOWNType of element read : UNKNOWN- See Also:
-
sizeLimit
protected long sizeLimitSize limit for file contained values -
SIZE_LIMIT_DEFAULT
protected static final long SIZE_LIMIT_DEFAULTThe default size limit : 1Mo- See Also:
-
MOD_SPEC
protected static final int MOD_SPECState values for the modify operation : MOD_SPEC- See Also:
-
ATTRVAL_SPEC
protected static final int ATTRVAL_SPECState values for the modify operation : ATTRVAL_SPEC- See Also:
-
ATTRVAL_SPEC_OR_SEP
protected static final int ATTRVAL_SPEC_OR_SEPState values for the modify operation : ATTRVAL_SPEC_OR_SEP- See Also:
-
prefetched
Iterator prefetched entry -
reader
The ldif Reader -
containsEntries
protected boolean containsEntriesA flag set if the ldif contains entries -
containsChanges
protected boolean containsChangesA flag set if the ldif contains changes -
schemaManager
The SchemaManager instance, if any -
error
An Exception to handle error message, has Iterator.next() can't throw exceptions -
entryLen
protected int entryLentotal length of an LDIF entry including the comments -
entryOffset
protected long entryOffsetthe parsed entry's starting position -
offset
protected long offsetthe current offset of the reader -
lineNumber
protected int lineNumberthe numer of the current line being parsed by the reader -
validateDn
protected boolean validateDnflag to turn on/off of the DN validation. By default DNs are validated after parsing
-
-
Constructor Details
-
LdifReader
public LdifReader()Constructors -
LdifReader
Creates a Schema aware reader- Parameters:
schemaManager- The SchemaManager
-
LdifReader
A constructor which takes a file name. Default charset is used.- Parameters:
ldifFileName- A file name containing ldif formated input- Throws:
LdapLdifException- If the file cannot be processed or if the format is incorrect
-
LdifReader
A constructor which takes a Reader.- Parameters:
in- A Reader containing ldif formated input- Throws:
LdapException- If the file cannot be processed or if the format is incorrect
-
LdifReader
A constructor which takes an InputStream. Default charset is used.- Parameters:
in- An InputStream containing ldif formated input- Throws:
LdapException- If the file cannot be processed or if the format is incorrect
-
LdifReader
A constructor which takes a File. Default charset is used.- Parameters:
file- A File containing ldif formated input- Throws:
LdapLdifException- If the file cannot be processed or if the format is incorrect
-
LdifReader
A constructor which takes a File and a SchemaManager. Default charset is used.- Parameters:
file- A File containing ldif formated inputschemaManager- The SchemaManager instance to use- Throws:
LdapLdifException- If the file cannot be processed or if the format is incorrect
-
-
Method Details
-
init
Initialize the LdifReader- Throws:
LdapException- If the initialization failed
-
getVersion
public int getVersion()- Returns:
- The ldif file version
-
getSizeLimit
public long getSizeLimit()- Returns:
- The maximum size of a file which is used into an attribute value.
-
setSizeLimit
public void setSizeLimit(long sizeLimit) Set the maximum file size that can be accepted for an attribute value- Parameters:
sizeLimit- The size in bytes
-
parseChangeType
Parse the changeType- Parameters:
line- The line which contains the changeType- Returns:
- The operation.
-
parseDn
Parse the Dn of an entry- Parameters:
line- The line to parse- Returns:
- A Dn
- Throws:
LdapLdifException- If the Dn is invalid
-
parseSimpleValue
-
parseValue
Parse the value part.- Parameters:
attributeName- The attribute nameline- The line which contains the valuepos- The starting position in the line- Returns:
- A String or a byte[], depending of the kind of value we get
- Throws:
LdapLdifException- If something went wrong
-
parseAttributeValue
-
parseAttributeValue
public void parseAttributeValue(LdifEntry entry, String line, String lowerLine) throws LdapException Parse an AttributeType/AttributeValue- Parameters:
entry- The entry where to store the valueline- The line to parselowerLine- The same line, lowercased- Throws:
LdapException- If anything goes wrong
-
parseEntry
Parse a ldif file. The following rules are processed :<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>- Returns:
- the parsed ldifEntry
- Throws:
LdapException- If the ldif file does not contain a valid entry
-
parseVersion
Parse the version from the ldif input.- Returns:
- A number representing the version (default to 1)
- Throws:
LdapLdifException- If the version is incorrect or if the input is incorrect
-
getLine
gets a line from the underlying data store- Returns:
- a line of characters or null if EOF reached
- Throws:
IOException- on read failure
-
readLines
Reads an entry in a ldif buffer, and returns the resulting lines, without comments, and unfolded. The lines represent *one* entry.- Throws:
LdapLdifException- If something went wrong
-
parseLdifFile
Parse a ldif file (using the default encoding).- Parameters:
fileName- The ldif file- Returns:
- A list of entries
- Throws:
LdapLdifException- If the parsing fails
-
parseLdifFile
Parse a ldif file, decoding it using the given charset encoding- Parameters:
fileName- The ldif fileencoding- The charset encoding to use- Returns:
- A list of entries
- Throws:
LdapLdifException- If the parsing fails
-
parseLdif
A method which parses a ldif string and returns a list of entries.- Parameters:
ldif- The ldif string- Returns:
- A list of entries, or an empty List
- Throws:
LdapLdifException- If something went wrong
-
next
-
fetch
Gets the current entry, but don't move forward.- Returns:
- the pre-fetched entry
-
hasNext
public boolean hasNext()Tests to see if another LDIF is on the input channel.- Returns:
- true if another LDIF is available false otherwise.
-
remove
public void remove()Always throws UnsupportedOperationException!- See Also:
-
iterator
-
hasError
public boolean hasError()- Returns:
- True if an error occurred during parsing
-
getError
- Returns:
- The exception that occurs during an entry parsing
-
parseLdif
The main entry point of the LdifParser. It reads a buffer and returns a List of entries.- Parameters:
reader- The buffer being processed- Returns:
- A list of entries
- Throws:
LdapException- If something went wrong
-
containsEntries
public boolean containsEntries()- Returns:
- True if the ldif file contains entries, fals if it contains changes
-
getLineNumber
public int getLineNumber()- Returns:
- the current line that is being processed by the reader
-
createLdifEntry
Creates a schema aware LdifEntry- Parameters:
schemaManager- The SchemaManager- Returns:
- an LdifEntry that is schema aware
-
isValidateDn
public boolean isValidateDn()- Returns:
- true if the DN validation is turned on
-
setValidateDn
public void setValidateDn(boolean validateDn) Turns on/off the DN validation- Parameters:
validateDn- the boolean flag
-
setSchemaManager
- Parameters:
schemaManager- the schemaManager to set
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-