com.ca.commons.naming
Class LdifUtility

java.lang.Object
  |
  +--com.ca.commons.naming.LdifUtility

public class LdifUtility
extends java.lang.Object

collection of static utility ftns. for writing and reading ldif files. Currently does not handle URLs properly, but will do base64 encoding quite happily given half a chance...


Constructor Summary
LdifUtility()
           
LdifUtility(java.util.Hashtable params, java.lang.String filedir)
          Constructor
 
Method Summary
 java.lang.Object expandValueParams(java.lang.Object value)
          This method expands the strings inside the ldif file that match the list of expandable strings in params list.
 void ldifDecode(java.lang.String parseableLine, DXEntry newEntry)
          Parse an attribute: value line of an ldif file, and place the attribute value pair in an Attributes object.
 java.lang.String ldifEncode(java.lang.Object o, int offset)
          This is used to write a value that is *probably* normal string encoded, but *may* need to be base64 encoded.
 java.lang.String ldifEncode(java.lang.Object o, int offset, boolean forceBase64Encoding)
          This is used to write a value that is *probably* normal string encoded, but *may* need to be base64 encoded.
 DXEntry readLdifEntry(java.io.BufferedReader textReader)
          Reads an entry of ldif text (i.e. att/val pairs until a blank line)
 void setFileDir(java.lang.String filedir)
          Set the ldif filepath - used to find input files
 void setParams(java.util.Hashtable params)
          Set the ldif file parameters
 void writeLdifEntry(java.lang.String dn, java.io.FileWriter saveFile, java.lang.String originalPrefix, java.lang.String replacementPrefix, javax.naming.directory.Attributes atts)
          retrieves a single entry from the directory and writes it out to an ldif file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LdifUtility

public LdifUtility()

LdifUtility

public LdifUtility(java.util.Hashtable params,
                   java.lang.String filedir)
Constructor

Parameters:
params - - hashtable with the list of string that will have to be suvstituted in the ldif file
filedir - - ldif file directory, used to find the input files specified in the ldif stream
Method Detail

setFileDir

public void setFileDir(java.lang.String filedir)
Set the ldif filepath - used to find input files

Parameters:
filedir - file path

setParams

public void setParams(java.util.Hashtable params)
Set the ldif file parameters

Parameters:
params - list of parameters

ldifEncode

public java.lang.String ldifEncode(java.lang.Object o,
                                   int offset,
                                   boolean forceBase64Encoding)
This is used to write a value that is *probably* normal string encoded, but *may* need to be base64 encoded. It also takes a boolean parameter that forces base64 encoding. Otherwise, it checks the string against the requirements of draft-good-ldap-ldif-04 (initial character sane, subsequent characters not null, CR or LF), and returns the appropriate string, with appropriate ': ' or ':: ' prefix.

Parameters:
o - the object to be ldif encoded
Returns:
the ldif encoding (possibly base64) with appropriate colons.

ldifEncode

public java.lang.String ldifEncode(java.lang.Object o,
                                   int offset)
This is used to write a value that is *probably* normal string encoded, but *may* need to be base64 encoded. It checks the string against the requirements of draft-good-ldap-ldif-04 (initial character sane, subsequent characters not null, CR or LF), and returns the appropriate string, with appropriate ': ' or ':: ' prefix.

Parameters:
o - the object to be ldif encoded
Returns:
the ldif encoding (possibly base64) with appropriate colons.

writeLdifEntry

public void writeLdifEntry(java.lang.String dn,
                           java.io.FileWriter saveFile,
                           java.lang.String originalPrefix,
                           java.lang.String replacementPrefix,
                           javax.naming.directory.Attributes atts)
                    throws javax.naming.NamingException,
                           java.io.IOException
retrieves a single entry from the directory and writes it out to an ldif file. Note that ldif header 'version 1' must be written elsewhere...

Parameters:
dn - the ldap escaped dn of the entry being written
saveFile - the file to write the entry to
originalPrefix - an optional portion of the dn to update
replacementPrefix - an optional replacement for a portion of the dn
atts - the attributes of teh entry
javax.naming.NamingException
java.io.IOException

ldifDecode

public void ldifDecode(java.lang.String parseableLine,
                       DXEntry newEntry)
Parse an attribute: value line of an ldif file, and place the attribute value pair in an Attributes object.

Parameters:
parseableLine - a complete ldif text line (unwrapped) to parse
newEntry - the partially created entry, which is modified by this method.

readLdifEntry

public DXEntry readLdifEntry(java.io.BufferedReader textReader)
                      throws java.io.IOException
Reads an entry of ldif text (i.e. att/val pairs until a blank line)

Returns:
the read entry, as a DXAttributes object
Throws:
java.io.InterruptedIOException - if the user hits cancel on the progress bar
java.io.IOException

expandValueParams

public java.lang.Object expandValueParams(java.lang.Object value)
This method expands the strings inside the ldif file that match the list of expandable strings in params list.

Parameters:
value - value to be expanded
Returns:
expanded object