Example usage for javax.xml.registry LifeCycleManager createPostalAddress

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

Introduction

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

Prototype

public PostalAddress createPostalAddress(String streetNumber, String street, String city,
        String stateOrProvince, String country, String postalCode, String type) throws JAXRException;

Source Link

Document

Creates a PostalAddress instance using the specified parameters.

Usage

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

/**
 * DOCUMENT ME!//from   w ww .  ja va 2s.co m
 * 
 * @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;
}