Comments (4)
For LDIF files that may contain a mix of entries and change records, you should use the LDIFReader.readLDIFRecord()
method rather than LDIFReader.readEntry()
. You can then use something like:
while (true)
{
LDIFRecord r = ldifReader.readLDIFRecord();
if (r == null)
{
// End of the LDIF file.
break;
}
else if (r instanceof Entry)
{
// Treat it as an Entry
}
else
{
// Treat it as an LDIFChangeRecord
}
}
Another option would be to use the LDIFReader.readChangeRecord(boolean)
method with a value of true
for the defaultAdd
argument. This will cause the LDIF reader to always read LDIF records as if they were change records, and will assume that any record without a changetype
element is an add change record. For example, if you're reading an LDIF file with a mix of entries and change records and want to send all of those to an LDAP server, you could use something like:
while (true)
{
LDIFChangeRecord r = ldifReader.readChangeRecord(true);
if (r == null)
{
// End of the LDIF file.
break;
}
r.processChange(ldapConnection);
}
from ldapsdk.
Thanks, one more question.
Just to make sure, I want to "transform" the entries while reading them using different implementations of the LDIFReaderEntryTranslator interface depending on what I want to do.
For example I do this:
- Create new LDIFReader with a LDIFReaderEntryTranslator
- Create new LDIFWriter
- Read using LDIFReader and writing directly to a new LDIF using LDIFWriter
This means if I use readChangeRecord/readLDIFRecord it won't be processed by the LDIFReaderEntryTranslator since those methods don't produce Entry objects?
This is actually not a problem for me, I can apply the same logic that I use in the LDIFReaderEntryTranslator implementation to the LDIFChangeRecord.
from ldapsdk.
Although it's not yet in a release, there is code checked into the repository that includes an equivalent of an LDIFReaderEntryTranslator for LDIF change records. So you could check out and build the LDAP SDK for yourself if you want to try that.
But the translator interface is really only beneficial if you're using multiple threads to read data and decode data from the LDIF file concurrently, since in that case the translator also is invoked concurrently. In most cases, a single-threaded approach is good enough, and you can just apply whatever transformation you want in your code after reading the change record and before writing it out to the new file.
from ldapsdk.
I've found the translator interface to be beneficial since it's so easy to implement it in JavaScript for quick transformation/processing/prototyping using jjs and Nashorn in Java 8. I can just specify a different JavaScript file each time and I don't need to compile anything.
from ldapsdk.
Related Issues (20)
- Is there way to use objectGuid instead of dn in API ? HOT 1
- What is the best option to remove object by objectGuid ? HOT 2
- Is there way to add user to multiple groups using single ldap request ? HOT 5
- How to get group by primaryGroupId ? How to convert primaryGroupId to groupDn? HOT 8
- How to search entry by operational attribute (PrimaryGroupToken)? HOT 2
- search with ALL_OPERATIONAL_ATTRIBUTES doesn't return any operational attributes HOT 2
- Filter.createSubstringFilter with "subInitial" or "subFinal" set to an empty string HOT 1
- Unable to login with AdditionalBindCredentials when certain OperationTypes are part of AuthenticationRequiredOperationTypes (Supressing Anonymous Connections) HOT 3
- Metric to show potentially available connections HOT 3
- Memory 'leak' in GSSAPIBindRequest HOT 5
- transactions support in unboundid ldap HOT 3
- Is there way to encrypt LDAP password ? (at least Base 64) HOT 1
- Is there way to get page number N during pagination request without iterating over previous pages ? HOT 13
- IdleTimeout parameter for pooled connections HOT 6
- KeyStoreKeyManager doesn't expose alternative KeyStore loading mechanisms. HOT 4
- InMemoryDirectoryServer is single threaded and blocks for searches HOT 1
- Simple bind fails if password contains latin character HOT 2
- multihomed ldap server HOT 3
- Unable to read or decode an LDAP message: Invalid value length of 0 for an ASN.1 HOT 2
- Is there a way to get multiple entries by dn using a single ldap call? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ldapsdk.