Class LdifParser
- java.lang.Object
-
- org.springframework.ldap.ldif.parser.LdifParser
-
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean
,Parser
public class LdifParser extends java.lang.Object implements Parser, org.springframework.beans.factory.InitializingBean
TheLdifParser
is the main class of theorg.springframework.ldap.ldif
package. This class reads lines from a resource and assembles them into anLdapAttributes
object. TheLdifParser
does ignores changetype LDIF entries as their usefulness in the context of an application has yet to be determined.Design
LdifParser
provides the main interface for operation but requires three supporting classes to enable operation:SeparatorPolicy
- establishes the mechanism by which lines are assembled into attributes.AttributeValidationPolicy
- ensures that attributes are correctly structured prior to parsing.Specification
- provides a mechanism by which object structure can be validated after assembly.
Usage
getRecord()
reads the next available record from the resource. Lines are read and passed to theSeparatorPolicy
for interpretation. The parser continues to read lines and appends them to the buffer until it encounters the start of a new attribute or an end of record delimiter. When the new attribute or end of record is encountered, the buffer is passed to theAttributeValidationPolicy
which ensures the buffer conforms to a valid attribute definition as defined in RFC2849 and returns anLdapAttribute
object which is then added to the record, anLdapAttributes
object. Upon encountering the end of record, the record is validated by theSpecification
policy and, if valid, returned to the requester.NOTE: By default, objects are not validated. If validation is required, an appropriate specification object must be set.
The parser requires the resource to be
open()
prior to an invocation ofgetRecord()
.hasMoreRecords()
can be used to loop over the resource until all records have been retrieved. Likewise, thereset()
method will reset the resource.Objects implementing the
Attributes
interface are required to support a case sensitivity setting which controls whether or not the attribute IDs of the object are case sensitive. ThecaseInsensitive
setting of theLdifParser
is passed to the constructor of anyAttributes
created. The default value for this setting is true so that case insensitive objects are created.
-
-
Constructor Summary
Constructors Constructor Description LdifParser()
Default constructor.LdifParser(boolean caseInsensitive)
Creates a LdifParser with the indicated case sensitivity setting.LdifParser(java.io.File file)
Convenience constructor: accepts a File object.LdifParser(org.springframework.core.io.Resource resource)
Convenience constructor for resource specification.LdifParser(org.springframework.core.io.Resource resource, boolean caseInsensitive)
Creates an LdifParser for the specified resource with the provided case sensitivity setting.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPropertiesSet()
void
close()
Closes the resource after parsing.LdapAttributes
getRecord()
Parses the next record from the resource.boolean
hasMoreRecords()
True if the resource contains more records; false otherwise.boolean
isReady()
Indicates whether or not the parser is ready to to return results.void
open()
Opens the resource: the resource must be opened prior to parsing.void
reset()
Resets the line read parser.void
setAttributeValidationPolicy(AttributeValidationPolicy avPolicy)
Policy object enforcing the rules for acceptable attributes.void
setCaseInsensitive(boolean caseInsensitive)
Sets the control parameter for specifying case sensitivity on creation of theAttributes
object.void
setRecordSpecification(Specification<LdapAttributes> specification)
Policy object for enforcing rules to acceptable LDAP objects.void
setResource(org.springframework.core.io.Resource resource)
Sets the resource to parse.void
setSeparatorPolicy(SeparatorPolicy separatorPolicy)
Set the separator policy.
-
-
-
Constructor Detail
-
LdifParser
public LdifParser()
Default constructor.
-
LdifParser
public LdifParser(boolean caseInsensitive)
Creates a LdifParser with the indicated case sensitivity setting.- Parameters:
caseInsensitive
- Case sensitivity setting for LdapAttributes objects returned by the parser.
-
LdifParser
public LdifParser(org.springframework.core.io.Resource resource, boolean caseInsensitive)
Creates an LdifParser for the specified resource with the provided case sensitivity setting.- Parameters:
resource
- The resource to parse.caseInsensitive
- Case sensitivity setting for LdapAttributes objects returned by the parser.
-
LdifParser
public LdifParser(org.springframework.core.io.Resource resource)
Convenience constructor for resource specification.- Parameters:
resource
- The resource to parse.
-
LdifParser
public LdifParser(java.io.File file)
Convenience constructor: accepts a File object.- Parameters:
file
- The file to parse.
-
-
Method Detail
-
setSeparatorPolicy
public void setSeparatorPolicy(SeparatorPolicy separatorPolicy)
Set the separator policy. The default separator policy should suffice for most needs.- Parameters:
separatorPolicy
- Separator policy.
-
setAttributeValidationPolicy
public void setAttributeValidationPolicy(AttributeValidationPolicy avPolicy)
Policy object enforcing the rules for acceptable attributes.- Parameters:
avPolicy
- Attribute validation policy.
-
setRecordSpecification
public void setRecordSpecification(Specification<LdapAttributes> specification)
Policy object for enforcing rules to acceptable LDAP objects. This policy may be used to enforce schema restrictions.- Parameters:
specification
-
-
setResource
public void setResource(org.springframework.core.io.Resource resource)
Description copied from interface:Parser
Sets the resource to parse.- Specified by:
setResource
in interfaceParser
- Parameters:
resource
- The resource to parse.
-
setCaseInsensitive
public void setCaseInsensitive(boolean caseInsensitive)
Description copied from interface:Parser
Sets the control parameter for specifying case sensitivity on creation of theAttributes
object.- Specified by:
setCaseInsensitive
in interfaceParser
- Parameters:
caseInsensitive
- The resource to parse.
-
open
public void open() throws java.io.IOException
Description copied from interface:Parser
Opens the resource: the resource must be opened prior to parsing.
-
isReady
public boolean isReady() throws java.io.IOException
Description copied from interface:Parser
Indicates whether or not the parser is ready to to return results.
-
close
public void close() throws java.io.IOException
Description copied from interface:Parser
Closes the resource after parsing.
-
reset
public void reset() throws java.io.IOException
Description copied from interface:Parser
Resets the line read parser.
-
hasMoreRecords
public boolean hasMoreRecords() throws java.io.IOException
Description copied from interface:Parser
True if the resource contains more records; false otherwise.- Specified by:
hasMoreRecords
in interfaceParser
- Returns:
- boolean indicating whether or not the end of record has been reached.
- Throws:
java.io.IOException
- if a problem is encountered while trying to validate the resource is ready.
-
getRecord
public LdapAttributes getRecord() throws java.io.IOException
Description copied from interface:Parser
Parses the next record from the resource.
-
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
java.lang.Exception
-
-