All LDAP Classes
Internal LDAP Classes

com.novell.ldap.util
Class LDIFWriter

java.lang.Object
  extended by com.novell.ldap.util.LDIFWriter
All Implemented Interfaces:
LDAPWriter

public class LDIFWriter
extends java.lang.Object
implements LDAPWriter

LDIFWriter is used to write LDIF content records or LDIF change records to the OutputStream object.

The object of the class is used to generate LDIF content record or LDIF change record lines and write the lines to OUtputStream


Field Summary
private  java.io.BufferedWriter bufWriter
           
private  java.lang.Boolean requestFile
           
private  java.lang.String version
           
 
Constructor Summary
  LDIFWriter(java.io.OutputStream out)
          Constructs an LDIFWriter object.
  LDIFWriter(java.io.OutputStream out, java.lang.String version, boolean request)
          Constructs an LDIFWriter object.
private LDIFWriter(java.io.OutputStream out, java.lang.String version, java.lang.Boolean request)
          Constructs an LDIFWriter object.
 
Method Summary
 void finish()
          Write all remaining data to the output stream
 java.lang.String getVersion()
          Gets the version of the LDIF data associated with the input stream
 boolean isPrintable(byte[] bytes)
          Check if the input byte array object is safe to make a String.
 boolean isRequest()
          Returns true if request data ist associated with the input stream, or false if content data.
private  void writeAddRequest(LDAPEntry entry, LDAPControl[] ctrls)
          Used to generate LDIF content record or LDIF change/add record lines.
private  void writeAttribute(java.lang.String attrName, byte[] attrVal)
          Write attribute name and value into outputStream.
private  void writeAttribute(java.lang.String attrName, java.lang.String attrVal)
          Write attribute name and value into outputStream.
 void writeComments(java.lang.String line)
          Write a comment line into the LDIF OutputStream.
private  void writeControls(LDAPControl[] ctrls)
          Write control line(s).
private  void writeDeleteRequest(java.lang.String dn, LDAPControl[] ctrls)
          Used to generate LDIF change/delete record lines.
private  void writeDN(java.lang.String dn)
          Write the DN to the outputStream.
 void writeEntry(LDAPEntry entry)
          Write an LDAP record into LDIF file as LDAPContent data.
 void writeEntry(LDAPEntry entry, LDAPControl[] controls)
          Write an LDAP record into LDIF file as LDAPContent data.
 void writeError(java.lang.Exception e)
          Writes an exception as a comment in LDIF.
private  void writeLine(java.lang.String line)
          Write a line into the OutputStream.
 void writeMessage(LDAPMessage request)
          Write an LDAP record into LDIF file.
private  void writeModifyDNRequest(java.lang.String dn, java.lang.String newRDN, boolean deleteOldRDN, java.lang.String newSuperior, LDAPControl[] ctrls)
          Used to generate LDIF change/moddn record lines.
private  void writeModifyRequest(java.lang.String dn, LDAPModification[] mods, LDAPControl[] ctrls)
          Used to generate LDIF change/modify record lines.
private  void writeVersionLine()
          Write the version line of LDIF file into the OutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

requestFile

private java.lang.Boolean requestFile

bufWriter

private java.io.BufferedWriter bufWriter

version

private java.lang.String version
Constructor Detail

LDIFWriter

public LDIFWriter(java.io.OutputStream out)
           throws java.io.IOException
Constructs an LDIFWriter object. It allows the setting of the OutputStreamReader object, and assumes the LDIF version is "1". The type of file written is determined by the first message written to the file.

If the first message is one of LDAPAddRequest, LDAPDeleteRequest, LDAPModifyDNRequest, or LDAPModifyRequest the file will be writen as an LDAP request (change) file.

If the first message written to the file is an LDAPSearchResult object an LDIF content file will be written.

You are not allowed to mix request data and content data

Parameters:
out - The OutputStream where the LDIF data will be written.
Throws:
java.io.IOException - for errors writing to the stream.

LDIFWriter

public LDIFWriter(java.io.OutputStream out,
                  java.lang.String version,
                  boolean request)
           throws java.io.IOException
Constructs an LDIFWriter object. It allows the setting of the OutputStreamReader object, the LDIF version, and the type of LDIF file.

Parameters:
out - The OutputStream where the LDIF data will be written.
version - The version to set in the LDIF file, must be "1".
request - If true sets the out file type to request (change) data, else the file type will be content.
Throws:
java.io.IOException

LDIFWriter

private LDIFWriter(java.io.OutputStream out,
                   java.lang.String version,
                   java.lang.Boolean request)
            throws java.io.IOException
Constructs an LDIFWriter object. It allows the setting of the OutputStreamReader object, the LDIF version, and the type of LDIF file.

You are not allowed to mix request data and content data

Parameters:
out - The OutputStream where the LDIF data will be written.
version - The version to set in the LDIF file, must be "1".
request - If true sets the out file type to request (change) data, else the file type will be content.
Throws:
java.io.IOException
Method Detail

writeEntry

public void writeEntry(LDAPEntry entry)
                throws java.io.IOException
Write an LDAP record into LDIF file as LDAPContent data.

You are not allowed to mix request data and content data

Specified by:
writeEntry in interface LDAPWriter
Parameters:
entry - LDAPEntry object
Throws:
java.io.IOException - if an I/O error occurs.
See Also:
LDAPEntry

writeEntry

public void writeEntry(LDAPEntry entry,
                       LDAPControl[] controls)
                throws java.io.IOException
Write an LDAP record into LDIF file as LDAPContent data.

You are not allowed to mix request data and content data

Specified by:
writeEntry in interface LDAPWriter
Parameters:
entry - LDAPEntry object
controls - Controls that were returned with this entry
Throws:
java.io.IOException - if an I/O error occurs.
See Also:
LDAPEntry

writeMessage

public void writeMessage(LDAPMessage request)
                  throws java.io.IOException
Write an LDAP record into LDIF file. A request or change operation may be objects of type LDAPAddRequest, LDAPDeleteRequest, LDAPModifyDNRequest, or LDAPModifyRequest. To write LDIF Content you must use an LDAPSearchResult object.

You are not allowed to mix request data and content data

Specified by:
writeMessage in interface LDAPWriter
Parameters:
request - LDAPMessage object
Throws:
java.io.IOException - if an I/O error occurs.
See Also:
LDAPSearchResults, LDAPAddRequest, LDAPDeleteRequest, LDAPModifyDNRequest, LDAPModifyRequest

writeComments

public void writeComments(java.lang.String line)
                   throws java.io.IOException
Write a comment line into the LDIF OutputStream.

an '#' char is added to the front of each line to indicate that the line is a comment line. If a line contains more than 78 chars, it will be split into multiple lines each of which starts with '#'

Specified by:
writeComments in interface LDAPWriter
Parameters:
line - The comment lines to be written to the OutputStream
Throws:
java.io.IOException - if an I/O error occurs.

writeError

public void writeError(java.lang.Exception e)
                throws java.io.IOException
Writes an exception as a comment in LDIF.

Specified by:
writeError in interface LDAPWriter
Parameters:
e - Exception to be written.
Throws:
java.io.IOException

getVersion

public java.lang.String getVersion()
Gets the version of the LDIF data associated with the input stream

Specified by:
getVersion in interface LDAPWriter
Returns:
the version number

isRequest

public boolean isRequest()
Returns true if request data ist associated with the input stream, or false if content data.

Specified by:
isRequest in interface LDAPWriter
Returns:
true if input stream contains request data.

isPrintable

public boolean isPrintable(byte[] bytes)
Check if the input byte array object is safe to make a String.

Check if the input byte array contains any un-printable value

Parameters:
bytes - The byte array object to be checked.
Returns:
boolean object to incidate that the byte array object is safe or not

writeVersionLine

private void writeVersionLine()
                       throws java.io.IOException
Write the version line of LDIF file into the OutputStream.

Two extra lines will be written to separate version line with the rest of lines in LDIF file

Throws:
java.io.IOException - if an I/O error occurs.

writeLine

private void writeLine(java.lang.String line)
                throws java.io.IOException
Write a line into the OutputStream.

If the line contains more than 80 chars, it will be splited into multiple lines each of which starts with a space ( ASCII ' ') except the first one.

Parameters:
line - The line to be written to the OutputStream
Throws:
java.io.IOException - if an I/O error occurs.

writeAddRequest

private void writeAddRequest(LDAPEntry entry,
                             LDAPControl[] ctrls)
                      throws java.io.IOException
Used to generate LDIF content record or LDIF change/add record lines.

Turn LDAPEntry object and LDAPControl[] object into LDIF record lines

Parameters:
entry - LDAPREntry object
ctrls - LDAPControl object
Throws:
java.io.IOException

writeModifyRequest

private void writeModifyRequest(java.lang.String dn,
                                LDAPModification[] mods,
                                LDAPControl[] ctrls)
                         throws java.io.IOException
Used to generate LDIF change/modify record lines.

Turn entry DN, LDAPModification[] object, and LDAPControl[] object into LDIF LDIF record fields and then turn record fields into LDIF change/modify record lines

Parameters:
dn - String object representing entry DN
mods - LDAPModification array object
ctrls - LDAPControl array object
Throws:
java.io.IOException
See Also:
LDAPModification, LDAPControl

writeModifyDNRequest

private void writeModifyDNRequest(java.lang.String dn,
                                  java.lang.String newRDN,
                                  boolean deleteOldRDN,
                                  java.lang.String newSuperior,
                                  LDAPControl[] ctrls)
                           throws java.io.IOException
Used to generate LDIF change/moddn record lines.

Turn entry DN and moddn information into LDIF change/modify record lines

Parameters:
dn - String object representing entry DN
newRDN - The NewRDN for the ModDN request
deleteOldRDN - the deleteOldRDN flag
newSuperior - the new Superior DN for a move, or null if rename
ctrls - LDAPControl array object
Throws:
java.io.IOException

writeDeleteRequest

private void writeDeleteRequest(java.lang.String dn,
                                LDAPControl[] ctrls)
                         throws java.io.IOException
Used to generate LDIF change/delete record lines.

Turn entry DN, controls and change type into LDIF change/delete record fields and then turn record fields into LDIF moddn record lines

Parameters:
dn - String object representing entry DN
ctrls - LDAPControl array object
Throws:
java.io.IOException
See Also:
LDAPControl

writeDN

private void writeDN(java.lang.String dn)
              throws java.io.IOException
Write the DN to the outputStream. If the DN characters are unsafe, the DN is encoded.

Parameters:
dn - the DN to write
Throws:
java.io.IOException

writeControls

private void writeControls(LDAPControl[] ctrls)
                    throws java.io.IOException
Write control line(s).

Parameters:
ctrls - LDAPControl array object
Throws:
java.io.IOException

writeAttribute

private void writeAttribute(java.lang.String attrName,
                            java.lang.String attrVal)
                     throws java.io.IOException
Write attribute name and value into outputStream.

Check if attrVal starts with NUL, LF, CR, ' ', ':', or '<' or contains any NUL, LF, or CR, and then write it out

Throws:
java.io.IOException

writeAttribute

private void writeAttribute(java.lang.String attrName,
                            byte[] attrVal)
                     throws java.io.IOException
Write attribute name and value into outputStream.

Check if attribute value contains NON-SAFE-INIT-CHAR or NON-SAFE-CHAR. if it does, it needs to be base64 encoded and then write it out

Throws:
java.io.IOException

finish

public void finish()
            throws java.io.IOException
Write all remaining data to the output stream

Specified by:
finish in interface LDAPWriter
Throws:
java.io.IOException

All LDAP Classes
Internal LDAP Classes

Copyright ? 2002 Novell, Inc. All Rights Reserved.
Novell, Inc.
1800 South Novell Place
Provo, Ut 84606
Phone: (801) 861-5000