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, 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(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 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 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. The DN is written.

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. The DN is written.

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

convertEntryToLdif

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

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

convertAttributesToLdif

public static java.lang.String convertAttributesToLdif(Entry entry)
                                                throws javax.naming.NamingException
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:
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

convertEntryToLdif

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

convertAttributesToLdif

public static java.lang.String convertAttributesToLdif(Entry entry,
                                                       int length)
                                                throws javax.naming.NamingException
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:
javax.naming.NamingException - If a naming exception is encountered.

convertToLdif

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

Parameters:
entry - the LdifEntry 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 LdifEntry to LDIF

Parameters:
entry - the LdifEntry 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


Copyright © 2004-2009 The Apache Software Foundation. All Rights Reserved.