get LDAP Attribute String Value - Java javax.naming.directory

Java examples for javax.naming.directory:Attributes

Description

get LDAP Attribute String Value

Demo Code


import java.util.Properties;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import org.apache.log4j.Logger;

public class Main{
    public static String getAttrStringValue(Attributes attrs, String elem) {
        String value = "";
        try {//from  w w w.j  a  va  2  s . c  om
            if (attrs.get(elem) != null) {
                for (int i = 0; i < attrs.get(elem).size(); i++) {
                    value += "," + attrs.get(elem).get(i).toString();
                }
                value = value.substring(1);
            }
        } catch (NamingException e) {
            e.printStackTrace();
        }
        return value;
    }
}

Related Tutorials