Class LdifUtils

    • 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
        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 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)
        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 convert
        includeVersionInfo - 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
      • convertToLdif

        public static String convertToLdif​(Entry entry,
                                           int length)
        Convert an Entry as LDIF
        Parameters:
        entry - the Entry to convert
        length - 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 convert
        length - 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 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)
        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 convert
        length - 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 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