Example usage for javax.xml.registry LifeCycleManager createPersonName

List of usage examples for javax.xml.registry LifeCycleManager createPersonName

Introduction

In this page you can find the example usage for javax.xml.registry LifeCycleManager createPersonName.

Prototype

public PersonName createPersonName(String firstName, String middleName, String lastName) throws JAXRException;

Source Link

Document

Creates a PersonName instance using the specified first, middle, and last names.

Usage

From source file:it.cnr.icar.eric.client.xml.registry.util.CertificateUtil.java

/**
 * DOCUMENT ME!/*w ww. j ava 2s  .c om*/
 * 
 * @param user
 *            DOCUMENT ME!
 * 
 * @return DOCUMENT ME!
 * 
 * @throws JAXRException
 *             DOCUMENT ME!
 */
private static String getDNameFromUser(UserRegistrationInfo userRegInfo) throws JAXRException {
    User user = userRegInfo.getUser();
    String dname = "CN=";

    LifeCycleManager lcm = user.getLifeCycleManager();
    Collection<?> addresses = user.getPostalAddresses();
    PostalAddress address;
    PersonName personName = user.getPersonName();

    // CN=Farrukh Najmi, OU=freebxml.org, O=ebxmlrr, L=Islamabad, ST=Punjab,
    // C=PK
    if (personName == null) {
        personName = lcm.createPersonName("firstName", "middleName", "lastName");
    }

    if ((addresses != null) && (addresses.size() > 0)) {
        address = (PostalAddress) (addresses.iterator().next());
    } else {
        address = lcm.createPostalAddress("number", "street", "city", "state", "country", "postalCode",
                "Office");
    }

    String city = address.getCity();

    if ((city == null) || (city.length() == 0)) {
        city = "Unknown";
    }

    String state = address.getStateOrProvince();

    if ((state == null) || (state.length() == 0)) {
        state = "Unknown";
    }

    String country = address.getCountry();

    if ((country == null) || (country.length() == 0)) {
        country = "US";
    }

    if (country.length() > 0) {
        country = country.substring(0, 2);
    }

    String organization = userRegInfo.getOrganization();

    if (organization == null || organization.trim().length() == 0) {
        organization = "Unknown";
    }

    String unit = userRegInfo.getOrganizationUnit();

    if (unit == null || unit.trim().length() == 0) {
        unit = "Unknown";
    }

    // Escape "," in formattedName per section 2.4 of RFC 2253. \u002c is
    // hex code for ","
    String formattedName = ((PersonNameImpl) personName).getFormattedName();
    formattedName = formattedName.replaceAll(",", "\\\\,");

    dname += (formattedName + ", OU=" + unit + ", O=" + organization + ", L=" + city + ", ST=" + state + ", C="
            + country);

    return dname;
}