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 convertAttributesToLdif(Entry entry)
          Convert all the Entry's attributes to LDIF.
static java.lang.String convertAttributesToLdif(Entry entry, int length)
          Convert the Entry's attributes to LDIF.
static java.lang.String convertEntryToLdif(Entry entry)
          Convert an Entry to LDIF
static java.lang.String convertEntryToLdif(Entry entry, int length)
          Convert an Entry as LDIF
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, DN dn)
          Convert an Attributes as LDIF.
static java.lang.String convertToLdif(javax.naming.directory.Attributes attrs, DN dn, int length)
          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(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(LdifEntry entry)
          Convert an LdifEntry to LDIF
static java.lang.String convertToLdif(LdifEntry entry, int length)
          Convert an LdifEntry to LDIF
static javax.naming.directory.Attributes createAttributes(java.lang.Object... avas)
          Build a new Attributes instance from a LDIF list of lines.
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 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 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 java.lang.String convertToLdif(javax.naming.directory.Attributes attrs,
                                             int length)
                                      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 java.lang.String convertToLdif(javax.naming.directory.Attributes attrs,
                                             DN dn,
                                             int length)
                                      throws LdapException
Convert an Attributes as LDIF. The DN is written.

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 java.lang.String convertToLdif(javax.naming.directory.Attributes attrs,
                                             DN dn)
                                      throws LdapException
Convert an Attributes as LDIF. The DN is written.

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

convertEntryToLdif

public static java.lang.String convertEntryToLdif(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.

convertAttributesToLdif

public static java.lang.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.

convertAttributesFromLdif

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

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

convertEntryToLdif

public static java.lang.String convertEntryToLdif(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 java.lang.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 java.lang.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 java.lang.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 java.lang.String convertToLdif(EntryAttribute 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 java.lang.String convertToLdif(EntryAttribute 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 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

createAttributes

public static javax.naming.directory.Attributes createAttributes(java.lang.Object... avas)
                                                          throws LdapException,
                                                                 LdapLdifException
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
LdapLdifException


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