org.apache.directory.shared.ldap.ldif
Class LdifUtils

java.lang.Object
  extended by org.apache.directory.shared.ldap.ldif.LdifUtils

public class LdifUtils
extends java.lang.Object

Some LDIF useful methods

Version:
$Rev$, $Date$
Author:
Apache Directory Project

Constructor Summary
LdifUtils()
           
 
Method Summary
static javax.naming.directory.Attributes convertAttributesFromLdif(java.lang.String ldif)
          Convert a LDIF String to an attributes.
static java.lang.String convertToLdif(javax.naming.directory.Attributes attrs)
          Convert an Attributes as LDIF
static java.lang.String convertToLdif(javax.naming.directory.Attributes attrs, int length)
          Convert an Attributes as LDIF
static java.lang.String convertToLdif(javax.naming.directory.Attributes attrs, LdapDN dn)
          Convert an Attributes as LDIF
static java.lang.String convertToLdif(javax.naming.directory.Attributes attrs, LdapDN dn, int length)
          Convert an Attributes as LDIF
static java.lang.String convertToLdif(Entry attrs)
          Convert an Entry as LDIF
static java.lang.String convertToLdif(EntryAttribute attr)
          Converts an EntryAttribute to LDIF
static java.lang.String convertToLdif(EntryAttribute attr, int length)
          Converts an EntryAttribute as LDIF
static java.lang.String convertToLdif(Entry entry, int length)
          Convert an Entry as LDIF
static java.lang.String convertToLdif(LdifEntry entry)
          Convert an Entry to LDIF
static java.lang.String convertToLdif(LdifEntry entry, int length)
          Convert an Entry to LDIF
static boolean isLDIFSafe(java.lang.String str)
          Checks if the input String contains only safe values, that is, the data does not need to be encoded for use with LDIF.
static LdifEntry reverseAdd(LdapDN dn)
          Compute a reverse LDIF of an AddRequest.
static LdifEntry reverseDel(LdapDN dn, Entry deletedEntry)
          Compute a reverse LDIF of a DeleteRequest.
static LdifEntry reverseModify(LdapDN dn, java.util.List<Modification> forwardModifications, Entry modifiedEntry)
          Compute the reversed LDIF for a modify request.
static LdifEntry reverseModifyDn(LdapDN newSuperiorDn, LdapDN modifiedDn)
          Compute a reverse LDIF for a forward change which if in LDIF format would represent a moddn operation.
static java.util.List<LdifEntry> reverseModifyRdn(javax.naming.directory.Attributes t0, LdapDN t1_parentDn, LdapDN t0_dn, Rdn t1_rdn)
          Compute a reverse LDIF for a forward change which if in LDIF format would represent a modrdn operation.
static java.util.List<LdifEntry> reverseRename(javax.naming.directory.Attributes t0, LdapDN t0_dn, Rdn t1_rdn)
          Revert a DN to it's previous version by removing the first RDN and adding the given RDN
static java.lang.String stripLineToNChars(java.lang.String str, int nbChars)
          Strips the String every n specified characters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LdifUtils

public LdifUtils()
Method Detail

isLDIFSafe

public static boolean isLDIFSafe(java.lang.String str)
Checks if the input String contains only safe values, that is, the data does not need to be encoded for use with LDIF. The rules for checking safety are based on the rules for LDIF (LDAP Data Interchange Format) per RFC 2849. The data does not need to be encoded if all the following are true: The data cannot start with the following char values: 00 (NUL) 10 (LF) 13 (CR) 32 (SPACE) 58 (:) 60 (<) Any character with value greater than 127 The data cannot contain any of the following char values: 00 (NUL) 10 (LF) 13 (CR) Any character with value greater than 127 The data cannot end with a space.

Parameters:
str - the String to be checked
Returns:
true if encoding not required for LDIF

convertToLdif

public static java.lang.String convertToLdif(javax.naming.directory.Attributes attrs)
                                      throws javax.naming.NamingException
Convert an Attributes as LDIF

Parameters:
attrs - the Attributes to convert
Returns:
the corresponding LDIF code as a String
Throws:
javax.naming.NamingException - If a naming exception is encountered.

convertToLdif

public static java.lang.String convertToLdif(javax.naming.directory.Attributes attrs,
                                             int length)
                                      throws javax.naming.NamingException
Convert an Attributes as LDIF

Parameters:
attrs - the Attributes to convert
Returns:
the corresponding LDIF code as a String
Throws:
javax.naming.NamingException - If a naming exception is encountered.

convertToLdif

public static java.lang.String convertToLdif(javax.naming.directory.Attributes attrs,
                                             LdapDN dn,
                                             int length)
                                      throws javax.naming.NamingException
Convert an Attributes as LDIF

Parameters:
attrs - the Attributes to convert
Returns:
the corresponding LDIF code as a String
Throws:
javax.naming.NamingException - If a naming exception is encountered.

convertToLdif

public static java.lang.String convertToLdif(javax.naming.directory.Attributes attrs,
                                             LdapDN dn)
                                      throws javax.naming.NamingException
Convert an Attributes as LDIF

Parameters:
attrs - the Attributes to convert
Returns:
the corresponding LDIF code as a String
Throws:
javax.naming.NamingException - If a naming exception is encountered.

convertToLdif

public static java.lang.String convertToLdif(Entry attrs)
                                      throws javax.naming.NamingException
Convert an Entry as LDIF

Parameters:
attrs - the Entry to convert
Returns:
the corresponding LDIF code as a String
Throws:
javax.naming.NamingException - If a naming exception is encountered.

convertAttributesFromLdif

public static javax.naming.directory.Attributes convertAttributesFromLdif(java.lang.String ldif)
                                                                   throws javax.naming.NamingException
Convert a LDIF String to an attributes.

Parameters:
ldif - The LDIF string containing an attribute value
Returns:
An Attributes instance
Throws:
javax.naming.NamingException - If the LDIF String cannot be converted to an Attributes

convertToLdif

public static java.lang.String convertToLdif(Entry entry,
                                             int length)
                                      throws javax.naming.NamingException
Convert an Entry as LDIF

Parameters:
entry - the Entry to convert
length - the expected line length
Returns:
the corresponding LDIF code as a String
Throws:
javax.naming.NamingException - If a naming exception is encountered.

convertToLdif

public static java.lang.String convertToLdif(LdifEntry entry)
                                      throws javax.naming.NamingException
Convert an Entry to LDIF

Parameters:
entry - the entry to convert
Returns:
the corresponding LDIF as a String
Throws:
javax.naming.NamingException - If a naming exception is encountered.

convertToLdif

public static java.lang.String convertToLdif(LdifEntry entry,
                                             int length)
                                      throws javax.naming.NamingException
Convert an Entry to LDIF

Parameters:
entry - the entry to convert
length - The maximum line's length
Returns:
the corresponding LDIF as a String
Throws:
javax.naming.NamingException - If a naming exception is encountered.

convertToLdif

public static java.lang.String convertToLdif(EntryAttribute attr)
                                      throws javax.naming.NamingException
Converts an EntryAttribute to LDIF

Parameters:
attr - the >EntryAttribute to convert
Returns:
the corresponding LDIF code as a String
Throws:
javax.naming.NamingException - If a naming exception is encountered.

convertToLdif

public static java.lang.String convertToLdif(EntryAttribute attr,
                                             int length)
                                      throws javax.naming.NamingException
Converts an EntryAttribute as LDIF

Parameters:
attr - the EntryAttribute to convert
length - the expected line length
Returns:
the corresponding LDIF code as a String
Throws:
javax.naming.NamingException - If a naming exception is encountered.

stripLineToNChars

public static java.lang.String stripLineToNChars(java.lang.String str,
                                                 int nbChars)
Strips the String every n specified characters

Parameters:
str - the string to strip
nbChars - the number of characters
Returns:
the stripped String

reverseAdd

public static LdifEntry reverseAdd(LdapDN dn)
Compute a reverse LDIF of an AddRequest. It's simply a delete request of the added entry

Parameters:
dn - the dn of the added entry
Returns:
a reverse LDIF

reverseDel

public static LdifEntry reverseDel(LdapDN dn,
                                   Entry deletedEntry)
                            throws javax.naming.NamingException
Compute a reverse LDIF of a DeleteRequest. We have to get the previous entry in order to restore it.

Parameters:
dn - The deleted entry DN
deletedEntry - The entry which has been deleted
Returns:
A reverse LDIF
Throws:
javax.naming.NamingException

reverseModifyDn

public static LdifEntry reverseModifyDn(LdapDN newSuperiorDn,
                                        LdapDN modifiedDn)
                                 throws javax.naming.NamingException
Compute a reverse LDIF for a forward change which if in LDIF format would represent a moddn operation. Hence there is no newRdn in the picture here.

Parameters:
newSuperiorDn - the new parent dn to be (must not be null)
modifiedDn - the dn of the entry being moved (must not be null)
Returns:
a reverse LDIF
Throws:
javax.naming.NamingException - if something went wrong

reverseRename

public static java.util.List<LdifEntry> reverseRename(javax.naming.directory.Attributes t0,
                                                      LdapDN t0_dn,
                                                      Rdn t1_rdn)
                                               throws javax.naming.NamingException
Revert a DN to it's previous version by removing the first RDN and adding the given RDN

Parameters:
t0 - The initial Attributes
t0_dn - The initial DN
t1_rdn - The new RDN
Returns:
A new LDIF entry with a reverted DN
Throws:
javax.naming.NamingException - If the name reverting failed

reverseModifyRdn

public static java.util.List<LdifEntry> reverseModifyRdn(javax.naming.directory.Attributes t0,
                                                         LdapDN t1_parentDn,
                                                         LdapDN t0_dn,
                                                         Rdn t1_rdn)
                                                  throws javax.naming.NamingException
Compute a reverse LDIF for a forward change which if in LDIF format would represent a modrdn operation.

Parameters:
t0 - the entry the way it was before changes were made
t1_parentDn - the new superior dn if this is a move, otherwise null
t0_dn - the dn of the entry being modified
t1_rdn - the new rdn to use
Returns:
A reverse LDIF, with potentially more than one reverse operation
Throws:
javax.naming.NamingException - If something went wrong

reverseModify

public static LdifEntry reverseModify(LdapDN dn,
                                      java.util.List<Modification> forwardModifications,
                                      Entry modifiedEntry)
                               throws javax.naming.NamingException
Compute the reversed LDIF for a modify request. We will deal with the three kind of modifications : - add - remove - replace As the modifications should be issued in a reversed order ( ie, for the initials modifications {A, B, C}, the reversed modifications will be ordered like {C, B, A}), we will change the modifications order.

Parameters:
dn - the dn of the modified entry
forwardModifications - the modification items for the forward change
modifiedEntry - The modified entry. Necessary for the destructive modifications
Returns:
A reversed LDIF
Throws:
javax.naming.NamingException - If something went wrong


Copyright © 2003-2011 Apache Software Foundation. All Rights Reserved.