Giter Site home page Giter Site logo

Comments (4)

dirmgr avatar dirmgr commented on September 13, 2024

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.

idsecurity avatar idsecurity commented on September 13, 2024

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:

  1. Create new LDIFReader with a LDIFReaderEntryTranslator
  2. Create new LDIFWriter
  3. 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.

dirmgr avatar dirmgr commented on September 13, 2024

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.

idsecurity avatar idsecurity commented on September 13, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.