org.apache.directory.api.ldap.model.ldif
Class LdifUtils

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

public final class LdifUtils
extends Object

Some LDIF helper methods.

Author:
Apache Directory Project

Method Summary
static String convertAttributesToLdif(Entry entry)
          Convert all the Entry's attributes to LDIF.
static String convertAttributesToLdif(Entry entry, int length)
          Convert the Entry's attributes to LDIF.
static String convertToLdif(Attribute attr)
          Converts an EntryAttribute to LDIF
static String convertToLdif(Attribute attr, int length)
          Converts an EntryAttribute as LDIF
static String convertToLdif(Attributes attrs)
          Convert an Attributes as LDIF
static String convertToLdif(Attributes attrs, Dn dn)
          Convert an Attributes as LDIF.
static String convertToLdif(Attributes attrs, Dn dn, int length)
          Convert an Attributes as LDIF.
static String convertToLdif(Attributes attrs, int length)
          Convert an Attributes as LDIF
static String convertToLdif(Entry entry)
          Convert an Entry to LDIF
static String convertToLdif(Entry entry, boolean includeVersionInfo)
          Convert an Entry to LDIF including a version number at the top
static String convertToLdif(Entry entry, int length)
          Convert an Entry as LDIF
static String convertToLdif(LdifEntry entry)
          Convert an LdifEntry to LDIF
static String convertToLdif(LdifEntry entry, int length)
          Convert an LdifEntry to LDIF
static Attributes createJndiAttributes(Object... avas)
          Build a new Attributes instance from a LDIF list of lines.
static Attributes getJndiAttributesFromLdif(String ldif)
          Convert a LDIF String to a JNDI attributes.
static boolean isLDIFSafe(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 String stripLineToNChars(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
 

Method Detail

isLDIFSafe

public static boolean isLDIFSafe(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: The data cannot contain any of the following char values: 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 String convertToLdif(Attributes attrs)
                            throws LdapException
Convert an Attributes as LDIF

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

convertToLdif

public static String convertToLdif(Attributes attrs,
                                   int length)
                            throws LdapException
Convert an Attributes as LDIF

Parameters:
attrs - the Attributes to convert
length - The ldif line length
Returns:
the corresponding LDIF code as a String
Throws:
LdapException - If a naming exception is encountered.

convertToLdif

public static String convertToLdif(Attributes attrs,
                                   Dn dn,
                                   int length)
                            throws LdapException
Convert an Attributes as LDIF. The Dn is written.

Parameters:
attrs - the Attributes to convert
dn - The Dn for this entry
length - The ldif line length
Returns:
the corresponding LDIF code as a String
Throws:
LdapException - If a naming exception is encountered.

convertToLdif

public static String convertToLdif(Attributes attrs,
                                   Dn dn)
                            throws LdapException
Convert an Attributes as LDIF. The Dn is written.

Parameters:
attrs - the Attributes to convert
dn - The Dn for this entry
Returns:
the corresponding LDIF code as a String
Throws:
LdapException - If a naming exception is encountered.

convertToLdif

public static String convertToLdif(Entry entry)
                            throws LdapException
Convert an Entry to LDIF

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

convertToLdif

public static String convertToLdif(Entry entry,
                                   boolean includeVersionInfo)
                            throws LdapException
Convert an Entry to LDIF including a version number at the top

Parameters:
entry - the Entry to convert
includeVersionInfo - flag to tell whether to include version number or not
Returns:
the corresponding LDIF code as a String
Throws:
LdapException - If a naming exception is encountered.

convertAttributesToLdif

public static String convertAttributesToLdif(Entry entry)
                                      throws LdapException
Convert all the Entry's attributes to LDIF. The Dn is not written

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

getJndiAttributesFromLdif

public static Attributes getJndiAttributesFromLdif(String ldif)
                                            throws LdapLdifException
Convert a LDIF String to a JNDI attributes.

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

convertToLdif

public static String convertToLdif(Entry entry,
                                   int length)
                            throws LdapException
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:
LdapException - If a naming exception is encountered.

convertAttributesToLdif

public static String convertAttributesToLdif(Entry entry,
                                             int length)
                                      throws LdapException
Convert the Entry's attributes to LDIF. The Dn is not written.

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

convertToLdif

public static String convertToLdif(LdifEntry entry)
                            throws LdapException
Convert an LdifEntry to LDIF

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

convertToLdif

public static String convertToLdif(LdifEntry entry,
                                   int length)
                            throws LdapException
Convert an LdifEntry to LDIF

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

convertToLdif

public static String convertToLdif(Attribute attr)
                            throws LdapException
Converts an EntryAttribute to LDIF

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

convertToLdif

public static String convertToLdif(Attribute attr,
                                   int length)
                            throws LdapException
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:
LdapException - If a naming exception is encountered.

stripLineToNChars

public static String stripLineToNChars(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

createJndiAttributes

public static Attributes createJndiAttributes(Object... avas)
                                       throws LdapException
Build a new Attributes instance from a LDIF list of lines. The values can be either a complete Ava, or a couple of AttributeType ID and a value (a String or a byte[]). The following sample shows the three cases :
 Attribute attr = AttributeUtils.createAttributes(
     "objectclass: top",
     "cn", "My name",
     "jpegPhoto", new byte[]{0x01, 0x02} );
 

Parameters:
avas - The AttributeType and Values, using a ldif format, or a couple of Attribute ID/Value
Returns:
An Attributes instance
Throws:
LdapException - If the data are invalid


Copyright © 2003-2013 The Apache Software Foundation. All Rights Reserved.