Class LdifUtils
- java.lang.Object
-
- org.apache.directory.api.ldap.model.ldif.LdifUtils
-
public final class LdifUtils extends Object
Some LDIF helper methods.- Author:
- Apache Directory Project
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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(Attributes attrs)
Convert an Attributes as LDIFstatic String
convertToLdif(Attributes attrs, int length)
Convert an Attributes as LDIFstatic 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(Attribute attr)
Converts an EntryAttribute to LDIFstatic String
convertToLdif(Attribute attr, int length)
Converts an EntryAttribute as LDIFstatic String
convertToLdif(Entry entry)
Convert an Entry to LDIFstatic String
convertToLdif(Entry entry, boolean includeVersionInfo)
Convert an Entry to LDIF including a version number at the topstatic String
convertToLdif(Entry entry, int length)
Convert an Entry as LDIFstatic String
convertToLdif(LdifEntry entry)
Convert an LdifEntry to LDIFstatic String
convertToLdif(LdifEntry entry, int length)
Convert an LdifEntry to LDIFstatic 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
-
-
-
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:- 00 (NUL)
- 10 (LF)
- 13 (CR)
- 32 (SPACE)
- 58 (:)
- 60 (<)
- Any character with value greater than 127
- 00 (NUL)
- 10 (LF)
- 13 (CR)
- Any character with value greater than 127
- 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 convertlength
- 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 convertdn
- The Dn for this entrylength
- 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 convertdn
- 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)
Convert an Entry to LDIF- Parameters:
entry
- the Entry to convert- Returns:
- the corresponding LDIF code as a String
-
convertToLdif
public static String convertToLdif(Entry entry, boolean includeVersionInfo)
Convert an Entry to LDIF including a version number at the top- Parameters:
entry
- the Entry to convertincludeVersionInfo
- flag to tell whether to include version number or not- Returns:
- the corresponding LDIF code as a String
-
convertAttributesToLdif
public static String convertAttributesToLdif(Entry entry)
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
-
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)
Convert an Entry as LDIF- Parameters:
entry
- the Entry to convertlength
- the expected line length- Returns:
- the corresponding LDIF code as a String
-
convertAttributesToLdif
public static String convertAttributesToLdif(Entry entry, int length)
Convert the Entry's attributes to LDIF. The Dn is not written.- Parameters:
entry
- the Entry to convertlength
- the expected line length- Returns:
- the corresponding LDIF code as a String
-
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 convertlength
- 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)
Converts an EntryAttribute to LDIF- Parameters:
attr
- the EntryAttribute to convert- Returns:
- the corresponding LDIF code as a String
-
convertToLdif
public static String convertToLdif(Attribute attr, int length)
Converts an EntryAttribute as LDIF- Parameters:
attr
- the EntryAttribute to convertlength
- the expected line length- Returns:
- the corresponding LDIF code as a String
-
stripLineToNChars
public static String stripLineToNChars(String str, int nbChars)
Strips the String every n specified characters- Parameters:
str
- the string to stripnbChars
- 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
-
-