Example usage for java.text DateFormat MEDIUM

List of usage examples for java.text DateFormat MEDIUM

Introduction

In this page you can find the example usage for java.text DateFormat MEDIUM.

Prototype

int MEDIUM

To view the source code for java.text DateFormat MEDIUM.

Click Source Link

Document

Constant for medium style pattern.

Usage

From source file:org.hoteia.qalingo.core.web.mvc.factory.ViewBeanFactory.java

/**
 * /*from  ww  w  .jav a  2 s .  c o  m*/
 */
public StoreCustomerCommentViewBean buildViewBeanStoreCustomerComment(final RequestData requestData,
        final Store store, final StoreCustomerComment customerComment) throws Exception {
    final Localization localization = requestData.getMarketAreaLocalization();
    final String localizationCode = localization.getCode();

    final StoreCustomerCommentViewBean customerCommentViewBean = new StoreCustomerCommentViewBean();
    customerCommentViewBean.setTitle(customerComment.getTitle());
    customerCommentViewBean.setComment(customerComment.getComment());

    if (customerComment.getCustomer() != null) {
        customerCommentViewBean.setCustomerDisplayName(customerComment.getCustomer().getScreenName());
        customerCommentViewBean.setCustomerUrl(
                urlService.buildCustomerDetailsUrl(requestData, customerComment.getCustomer().getPermalink()));
        customerCommentViewBean.setCustomerAvatarImg(
                requestUtil.getCustomerAvatar(requestData.getRequest(), customerComment.getCustomer()));
    }

    customerCommentViewBean.setComment(customerComment.getComment());

    if (customerComment.getDateCreate() != null) {
        customerCommentViewBean
                .setDateCreate(buildCommonFormatDate(requestData, customerComment.getDateCreate()));
    }
    if (customerComment.getDateUpdate() != null) {
        customerCommentViewBean
                .setDateUpdate(buildCommonFormatDate(requestData, customerComment.getDateUpdate()));
    }

    ReviewDataVocabularyPojo reviewDataVocabulary = new ReviewDataVocabularyPojo();
    reviewDataVocabulary.setItemreviewed(store.getI18nName(localizationCode));
    if (customerComment.getCustomer() != null) {
        reviewDataVocabulary.setReviewer(customerComment.getCustomer().getScreenName());
    }
    //        DateFormat dateFormatDataVocabulary = requestUtil.getDataVocabularyFormatDate(requestData);
    DateFormat dateFormat = requestUtil.getCommonFormatDate(requestData, DateFormat.MEDIUM, DateFormat.MEDIUM);
    reviewDataVocabulary.setDtreviewed(dateFormat.format(customerComment.getDateCreate()));
    // reviewDataVocabulary.setSummary(summary);
    reviewDataVocabulary.setDescription(customerComment.getComment());
    // reviewDataVocabulary.setRating(rating);

    customerCommentViewBean.setReviewDataVocabulary(reviewDataVocabulary);

    return customerCommentViewBean;
}

From source file:mitm.common.security.certificate.GenerateTestCertificates.java

/**
 * Generates a certificate without extended key usage
 * /*from w w w.  j ava 2  s.  co m*/
 * @throws Exception
 */
private void generateCertificateNoExtendedKeyUsage() throws Exception {
    X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder();

    String encodedPublicKey = "30819f300d06092a864886f70d010101050003818d003081890281810080"
            + "5fea5eb9bb34314acd0569a985b89bbf79caca577bd186edf7d92be0d1a5"
            + "200d8b321ec3c5ea31bf71715c1744658f86ab65c4bf4e311179da255427"
            + "57b88052c4c9f73c7e288e5f2d17bc6624e39f7b53d07b21b7aca38592be"
            + "291510767ef112d10c9cf0bf39d5f6507a604e6fb128a10abb2bbe09a765" + "4001f93dd93f690203010001";

    String encodedPrivateKey = "30820275020100300d06092a864886f70d01010105000482025f3082025b"
            + "02010002818100805fea5eb9bb34314acd0569a985b89bbf79caca577bd1"
            + "86edf7d92be0d1a5200d8b321ec3c5ea31bf71715c1744658f86ab65c4bf"
            + "4e311179da25542757b88052c4c9f73c7e288e5f2d17bc6624e39f7b53d0"
            + "7b21b7aca38592be291510767ef112d10c9cf0bf39d5f6507a604e6fb128"
            + "a10abb2bbe09a7654001f93dd93f690203010001028180456896a584b24c"
            + "f3e1c79c07971aafc7b5ed39d1d11f2718570dcca3c6b853195379512e05"
            + "17bb1a0eb25d62374a49c7223f05952d022fd18d1a7f5852b541118962de"
            + "41d5c15725f6ee7a36936883a24f8eb60b740252897779175b86762f5cca"
            + "37d5f0f2119abf720acebccf2395167bd1d651cb28511e893fec3c9526d9"
            + "21024100d984779af9de3816e02b90fa274af4e8fc6d8ff07d6a514bdd08"
            + "7b1de1ab114a89ee3bd2786b4297a816ff80103da18d7e7f2cb6dc654a9c"
            + "007775855c5cc21502410097161a6840cf62768e6b9756cd71cd7576fcfb"
            + "e078895c7892f2dae70904a104a6923cfe5273bcb1cec76d032bcf2ca700"
            + "c8740fe33ffa5e1970df9741e1e105024049fe6c09863277f6202ff1d387"
            + "0652a5e729062c131dd5a5eefcf194caadbce61461bc6bee96de4264e5dd"
            + "e89c9dba953d90d98f230e3a01338f6fa4fc3479b9024041152564f95e1c"
            + "75239e973fae1a32be41f6726ddc9e9735dd5f3e0abde8bf8fe84d207711"
            + "7f87ae347bd5aac309689bbc0b9d6b66a21db0c156cd0a3438201d024068"
            + "6d5cbd6457d3cb83eaa111a540b5878129d5e6abc3d219eaa0446d9afc54"
            + "3a113148957cc1e6c6da5d1a0ddb18af723f01f30fd0241bfe9541a8f691" + "4895e7";

    PrivateKey privateKey = decodePrivateKey(encodedPrivateKey);
    PublicKey publicKey = decodePublicKey(encodedPublicKey);

    X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder();

    String email = "test@example.com";

    subjectBuilder.setCommonName("No extended key usage");
    subjectBuilder.setEmail(email);
    subjectBuilder.setCountryCode("NL");
    subjectBuilder.setLocality("Amsterdam");
    subjectBuilder.setState("NH");

    AltNamesBuilder altNamesBuider = new AltNamesBuilder();
    altNamesBuider.setRFC822Names(email);

    X500Principal subject = subjectBuilder.buildPrincipal();
    GeneralNames altNames = altNamesBuider.buildAltNames();

    Set<KeyUsageType> keyUsage = new TreeSet<KeyUsageType>();

    keyUsage.add(KeyUsageType.DIGITALSIGNATURE);
    keyUsage.add(KeyUsageType.KEYENCIPHERMENT);
    keyUsage.add(KeyUsageType.NONREPUDIATION);

    BigInteger serialNumber = new BigInteger("115fd08d3f0e6159746aea96a50c5d6", 16);

    Date now = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK)
            .parse("21-Nov-2007 11:50:35");

    certificateBuilder.setSubject(subject);
    certificateBuilder.setAltNames(altNames, true);
    certificateBuilder.setKeyUsage(keyUsage, true);
    certificateBuilder.setNotBefore(DateUtils.addDays(now, -20));
    certificateBuilder.setNotAfter(DateUtils.addYears(now, 20));
    certificateBuilder.setPublicKey(publicKey);
    certificateBuilder.setSerialNumber(serialNumber);
    certificateBuilder.setSignatureAlgorithm("SHA1WithRSAEncryption");

    X509Certificate certificate = certificateBuilder.generateCertificate(caPrivateKey, caCertificate);

    assertNotNull(certificate);

    certificates.add(certificate);

    Certificate[] chain = new Certificate[] { certificate, caCertificate, rootCertificate };

    keyStore.setKeyEntry("NoExtendedKeyUsage", privateKey, null, chain);
}

From source file:org.hoteia.qalingo.core.web.mvc.factory.ViewBeanFactory.java

/**
 * /*w ww. j  a  v  a  2 s.c om*/
 */
public CustomerViewBean buildViewBeanCustomer(final RequestData requestData, final Customer customer)
        throws Exception {
    final HttpServletRequest request = requestData.getRequest();
    final Locale locale = requestData.getLocale();
    final CustomerViewBean customerViewBean = new CustomerViewBean();
    if (customer != null) {
        customerViewBean.setCode(customer.getCode());
        customerViewBean.setAvatarImg(requestUtil.getCustomerAvatar(request, customer));
        customerViewBean.setTitle(referentialDataService.getTitleByLocale(customer.getTitle(), locale));
        customerViewBean.setFirstname(customer.getFirstname());
        customerViewBean.setLastname(customer.getLastname());
        customerViewBean.setEmail(customer.getEmail());
        customerViewBean.setLogin(customer.getLogin());

        if (customer.getBirthday() != null) {
            customerViewBean.setBirthday(buildCommonFormatDate(requestData, customer.getBirthday()));
        }

        if (customer.getDateCreate() != null) {
            customerViewBean.setDateCreate(buildCommonFormatDate(requestData, customer.getDateCreate()));
        }
        if (customer.getDateUpdate() != null) {
            customerViewBean.setDateUpdate(buildCommonFormatDate(requestData, customer.getDateUpdate()));
        }

        if (customer.getGroups() != null && Hibernate.isInitialized(customer.getGroups())) {
            final Set<CustomerGroup> groups = customer.getGroups();
            for (CustomerGroup group : groups) {
                String keyCustomerGroup = group.getCode();
                String valueCustomerGroup = group.getName();
                customerViewBean.getGroups().put(keyCustomerGroup, valueCustomerGroup);

                if (group.getRoles() != null && Hibernate.isInitialized(group.getRoles())) {
                    final Set<CustomerRole> roles = group.getRoles();
                    for (CustomerRole role : roles) {
                        String keyCustomerRole = role.getCode();
                        String valueCustomerRole = role.getName();
                        customerViewBean.getRoles().put(keyCustomerRole, valueCustomerRole);

                        if (role.getPermissions() != null && Hibernate.isInitialized(role.getPermissions())) {
                            final Set<CustomerPermission> permissions = role.getPermissions();
                            for (CustomerPermission permission : permissions) {
                                String keyCustomerPermission = permission.getCode();
                                String valueCustomerPermission = permission.getName();
                                customerViewBean.getPermissions().put(keyCustomerPermission,
                                        valueCustomerPermission);
                            }
                        }
                    }
                }
            }
        }

        if (customer.getConnectionLogs() != null && Hibernate.isInitialized(customer.getConnectionLogs())) {
            DateFormat dateFormat = requestUtil.getCommonFormatDate(requestData, DateFormat.MEDIUM,
                    DateFormat.MEDIUM);
            for (CustomerConnectionLog connectionLog : customer.getSortedConnectionLogs()) {
                if (connectionLog.getLoginDate() != null) {
                    customerViewBean.setLastConnectionDate(dateFormat.format(connectionLog.getLoginDate()));
                } else {
                    customerViewBean.setLastConnectionDate(Constants.NOT_AVAILABLE);
                }
                CustomerConnectionLogValueBean connectionLogValueBean = new CustomerConnectionLogValueBean();
                connectionLogValueBean.setDate(dateFormat.format(connectionLog.getLoginDate()));
                connectionLogValueBean.setHost(Constants.NOT_AVAILABLE);
                if (StringUtils.isNotEmpty(connectionLog.getHost())) {
                    connectionLogValueBean.setHost(connectionLog.getHost());
                }
                connectionLogValueBean.setPublicAddress(Constants.NOT_AVAILABLE);
                if (StringUtils.isNotEmpty(connectionLog.getPublicAddress())) {
                    connectionLogValueBean.setPublicAddress(connectionLog.getPublicAddress());
                }
                connectionLogValueBean.setPrivateAddress(Constants.NOT_AVAILABLE);
                if (StringUtils.isNotEmpty(connectionLog.getPrivateAddress())) {
                    connectionLogValueBean.setPublicAddress(connectionLog.getPrivateAddress());
                }
                customerViewBean.getCustomerConnectionLogs().add(connectionLogValueBean);
            }
        }

        if (customer.getAddresses() != null && Hibernate.isInitialized(customer.getAddresses())) {
            for (CustomerAddress address : customer.getAddresses()) {
                customerViewBean.getAddresses().add(buildViewBeanCustomerAddress(requestData, address));
            }
        }

        customerViewBean.setValidated(customer.isValidated());
        customerViewBean.setActive(customer.isActive());

        final ValueBean customerScreenNameValueBean = new ValueBean();
        customerScreenNameValueBean
                .setKey(getSpecificMessage(ScopeWebMessage.CUSTOMER, "screenname.label", locale));
        customerScreenNameValueBean.setValue(customer.getScreenName());
        customerViewBean.getCustomerAttributes().put(CustomerViewBean.SCREEN_NAME, customerScreenNameValueBean);

    }
    return customerViewBean;
}

From source file:mitm.common.security.certificate.GenerateTestCertificates.java

/**
 * Generates a certificate without key usage
 * //from  w  w w  .  j  a  v a  2s.  c om
 * @throws Exception
 */
private void generateCertificateNoKeyUsage() throws Exception {
    X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder();

    String encodedPublicKey = "30819f300d06092a864886f70d010101050003818d0030818902818100b2"
            + "0e2afe37e1235b93919e2c30207b3c52547a7ca4b5929d3ac63984b5d951"
            + "244d6ee103a1cf5fd1e57f67a4becd0cb1be3c5cfe884130c412c46fdc13"
            + "cb175b51b3d6707130a57063e6e98c92ec5ec274cbb3c53d29be5b02383a"
            + "ab5f26581a84b2a32e20c84a84d182720737ccd53d7b1331b7db0d816e9c" + "b85927158c288f0203010001";

    String encodedPrivateKey = "30820276020100300d06092a864886f70d0101010500048202603082025c"
            + "02010002818100b20e2afe37e1235b93919e2c30207b3c52547a7ca4b592"
            + "9d3ac63984b5d951244d6ee103a1cf5fd1e57f67a4becd0cb1be3c5cfe88"
            + "4130c412c46fdc13cb175b51b3d6707130a57063e6e98c92ec5ec274cbb3"
            + "c53d29be5b02383aab5f26581a84b2a32e20c84a84d182720737ccd53d7b"
            + "1331b7db0d816e9cb85927158c288f020301000102818076054e1a138ff7"
            + "8fcbd0c9b7206f674024923a5e440ed68fc15582eaa45ed799e879864c92"
            + "0492cede000502fe358c2484a41e3fd8b0dd5219de7b06b557f8b242eb9a"
            + "0c7650dc8a9d68b20ab32aca5fbff4a01a15a2a3e90930d4040540e695ef"
            + "90c21fc7383364cb111f509aa559889830a9b3846777a9b8b755152482f8"
            + "81024100e8dfecea5ee39b456a552eed6c51f917c191dda274edbe2ea550"
            + "d1360bd531aed9a5e740ab9468fde289dbdb8d8b2cf57eea3317cf0b0a7f"
            + "89e6b8b17e6d2b7d024100c3bca3e3b3457ac7280902a3d5ab4a2a7f6f34"
            + "6f37e4e9f233d4498f336aea8169c2cccd702880e58432e43bbae9301283"
            + "093519c9a888bf744f3c3fb191a9fb0240361eec919f91e8211ed04342bc"
            + "7ce49627cf7da1e6e8e5dd33606feece9b329bbf4b764e2a52288070a8b7"
            + "66f42357448ac565307056d18ec87ecd87baa926850240130977cf1f9274"
            + "5c86524a05713495a4087ce256a6d306c5ddb099eee98b4e7f83afc4877e"
            + "8f11ea40af4a6f5cc06d427fa81798087af1c1dd280fae0a31269d024100"
            + "98982a55da07b7d2ed807e3f960265180ae755edd5cb8df393c7dfdc70ec"
            + "db9ce973f9aa9f14834c6bf92f9e36de5163b5e27a998a0935645f2f4ec2" + "d3e685c7";

    PrivateKey privateKey = decodePrivateKey(encodedPrivateKey);
    PublicKey publicKey = decodePublicKey(encodedPublicKey);

    X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder();

    String email = "test@example.com";

    subjectBuilder.setCommonName("No key usage");
    subjectBuilder.setEmail(email);
    subjectBuilder.setCountryCode("NL");
    subjectBuilder.setLocality("Amsterdam");
    subjectBuilder.setState("NH");

    AltNamesBuilder altNamesBuider = new AltNamesBuilder();
    altNamesBuider.setRFC822Names(email);

    X500Principal subject = subjectBuilder.buildPrincipal();
    GeneralNames altNames = altNamesBuider.buildAltNames();

    Set<ExtendedKeyUsageType> extendedKeyUsage = new TreeSet<ExtendedKeyUsageType>();

    extendedKeyUsage.add(ExtendedKeyUsageType.CLIENTAUTH);
    extendedKeyUsage.add(ExtendedKeyUsageType.EMAILPROTECTION);

    BigInteger serialNumber = new BigInteger("115fd0bd417e7a6f347eeacb7ff3f38", 16);

    Date now = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK)
            .parse("21-Nov-2007 11:51:35");

    certificateBuilder.setSubject(subject);
    certificateBuilder.setAltNames(altNames, true);
    certificateBuilder.setExtendedKeyUsage(extendedKeyUsage, false);
    certificateBuilder.setNotBefore(DateUtils.addDays(now, -20));
    certificateBuilder.setNotAfter(DateUtils.addYears(now, 20));
    certificateBuilder.setPublicKey(publicKey);
    certificateBuilder.setSerialNumber(serialNumber);
    certificateBuilder.setSignatureAlgorithm("SHA1WithRSAEncryption");

    X509Certificate certificate = certificateBuilder.generateCertificate(caPrivateKey, caCertificate);

    assertNotNull(certificate);

    certificates.add(certificate);

    Certificate[] chain = new Certificate[] { certificate, caCertificate, rootCertificate };

    keyStore.setKeyEntry("NoKeyUsage", privateKey, null, chain);
}

From source file:org.ejbca.core.model.ra.raadmin.EndEntityProfile.java

/** Implementation of UpgradableDataHashMap function upgrade. */
public void upgrade() {
    log.trace(">upgrade");
    if (Float.compare(LATEST_VERSION, getVersion()) != 0) {
        String msg = intres.getLocalizedMessage("ra.eeprofileupgrade", new Float(getVersion()));
        log.info(msg);/*from www.  ja v a  2  s. co  m*/
        // New version of the class, upgrade
        if (getVersion() < 1) {
            @SuppressWarnings("unchecked")
            ArrayList<Integer> numberarray = (ArrayList<Integer>) data.get(NUMBERARRAY);
            while (numberarray.size() < 37) {
                numberarray.add(Integer.valueOf(0));
            }
            data.put(NUMBERARRAY, numberarray);
        }
        if (getVersion() < 2) {
            @SuppressWarnings("unchecked")
            ArrayList<Integer> numberarray = (ArrayList<Integer>) data.get(NUMBERARRAY);
            while (numberarray.size() < 39) {
                numberarray.add(Integer.valueOf(0));
            }
            data.put(NUMBERARRAY, numberarray);
            addField(AVAILCAS);
            addField(DEFAULTCA);
            setRequired(AVAILCAS, 0, true);
            setRequired(DEFAULTCA, 0, true);
        }
        if (getVersion() < 3) {
            // These fields have been removed in version 8, no need for this upgrade
            //setNotificationSubject("");
            //setNotificationSender("");
            //setNotificationMessage("");
        }
        if (getVersion() < 4) {
            @SuppressWarnings("unchecked")
            ArrayList<Integer> numberoffields = (ArrayList<Integer>) data.get(NUMBERARRAY);
            for (int i = numberoffields.size(); i < dataConstants.size(); i++) {
                numberoffields.add(Integer.valueOf(0));
            }
            data.put(NUMBERARRAY, numberoffields);
        }
        // Support for DirectoryName altname field in profile version 5
        if (getVersion() < 5) {
            addField(DnComponents.DIRECTORYNAME);
            setValue(DnComponents.DIRECTORYNAME, 0, "");
            setRequired(DnComponents.DIRECTORYNAME, 0, false);
            setUse(DnComponents.DIRECTORYNAME, 0, true);
            setModifyable(DnComponents.DIRECTORYNAME, 0, true);
        }
        // Support for Subject Directory Attributes field in profile version 6
        if (getVersion() < 6) {
            @SuppressWarnings("unchecked")
            ArrayList<Integer> numberoffields = (ArrayList<Integer>) data.get(NUMBERARRAY);
            for (int i = numberoffields.size(); i < dataConstants.size(); i++) {
                numberoffields.add(Integer.valueOf(0));
            }
            data.put(NUMBERARRAY, numberoffields);
            data.put(SUBJECTDIRATTRFIELDORDER, new ArrayList<Integer>());

            for (int i = getParameterNumber(DnComponents.DATEOFBIRTH); i <= getParameterNumber(
                    DnComponents.COUNTRYOFRESIDENCE); i++) {
                addField(getParameter(i));
                setValue(getParameter(i), 0, "");
                setRequired(getParameter(i), 0, false);
                setUse(getParameter(i), 0, false);
                setModifyable(getParameter(i), 0, true);
            }
        }
        // Support for Start Time and End Time field in profile version 7
        if (getVersion() < 7) {
            @SuppressWarnings("unchecked")
            ArrayList<Integer> numberoffields = (ArrayList<Integer>) data.get(NUMBERARRAY);
            for (int i = numberoffields.size(); i < dataConstants.size(); i++) {
                numberoffields.add(Integer.valueOf(0));
            }
            data.put(NUMBERARRAY, numberoffields);
            addField(STARTTIME);
            setValue(STARTTIME, 0, "");
            setRequired(STARTTIME, 0, false);
            setUse(STARTTIME, 0, false);
            setModifyable(STARTTIME, 0, true);
            addField(ENDTIME);
            setValue(ENDTIME, 0, "");
            setRequired(ENDTIME, 0, false);
            setUse(ENDTIME, 0, false);
            setModifyable(ENDTIME, 0, true);
        }
        // Notifications is now a more general mechanism in version 8
        if (getVersion() < 8) {
            log.debug("Upgrading User Notifications");
            if (data.get(UserNotification.NOTIFICATIONSENDER) != null) {
                UserNotification not = new UserNotification();
                not.setNotificationSender((String) data.get(UserNotification.NOTIFICATIONSENDER));
                if (data.get(UserNotification.NOTIFICATIONSUBJECT) != null) {
                    not.setNotificationSubject((String) data.get(UserNotification.NOTIFICATIONSUBJECT));
                }
                if (data.get(UserNotification.NOTIFICATIONMESSAGE) != null) {
                    not.setNotificationMessage((String) data.get(UserNotification.NOTIFICATIONMESSAGE));
                }
                // Add the statuschanges we used to send notifications about
                String events = UserNotification.EVENTS_EDITUSER;
                not.setNotificationEvents(events);
                // The old recipients where always the user
                not.setNotificationRecipient(UserNotification.RCPT_USER);
                addUserNotification(not);
            }
        }
        // Support for allowed requests in profile version 9
        if (getVersion() < 9) {
            @SuppressWarnings("unchecked")
            ArrayList<Integer> numberoffields = (ArrayList<Integer>) data.get(NUMBERARRAY);
            for (int i = numberoffields.size(); i < dataConstants.size(); i++) {
                numberoffields.add(Integer.valueOf(0));
            }
            data.put(NUMBERARRAY, numberoffields);
            addField(ALLOWEDREQUESTS);
            setValue(ALLOWEDREQUESTS, 0, "");
            setRequired(ALLOWEDREQUESTS, 0, false);
            setUse(ALLOWEDREQUESTS, 0, false);
            setModifyable(ALLOWEDREQUESTS, 0, true);
        }
        // Support for merging DN from WS-API with default values in profile, in profile version 10
        if (getVersion() < 10) {
            setAllowMergeDnWebServices(false);
        }
        // Support for issuance revocation status in profile version 11
        if (getVersion() < 11) {
            setRequired(ISSUANCEREVOCATIONREASON, 0, false);
            setUse(ISSUANCEREVOCATIONREASON, 0, false);
            setModifyable(ISSUANCEREVOCATIONREASON, 0, true);
            setValue(ISSUANCEREVOCATIONREASON, 0, "" + RevokedCertInfo.NOT_REVOKED);
            setRequired(CARDNUMBER, 0, false);
            setUse(CARDNUMBER, 0, false);
            setModifyable(CARDNUMBER, 0, true);
        }
        // Support for maximum number of failed login attempts in profile version 12
        if (getVersion() < 12) {
            setRequired(MAXFAILEDLOGINS, 0, false);
            setUse(MAXFAILEDLOGINS, 0, false);
            setModifyable(MAXFAILEDLOGINS, 0, true);
            setValue(MAXFAILEDLOGINS, 0, Integer.toString(ExtendedInformation.DEFAULT_MAXLOGINATTEMPTS));
        }
        /* In EJBCA 4.0.0 we changed the date format to ISO 8601.
         * In the Admin GUI the example was:
         *     DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, ejbcawebbean.getLocale())
         * but the only absolute format that could have worked is the same enforced by the 
         * doesUserFullfillEndEntityProfile check and this is what need to upgrade from:
         *       DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.US)
         */
        if (getVersion() < 13) {
            final DateFormat oldDateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT,
                    Locale.US);
            final FastDateFormat newDateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm");
            try {
                final String oldStartTime = getValue(STARTTIME, 0);
                if (!isEmptyOrRelative(oldStartTime)) {
                    // We use an absolute time format, so we need to upgrade
                    final String newStartTime = newDateFormat.format(oldDateFormat.parse(oldStartTime));
                    setValue(STARTTIME, 0, newStartTime);
                    if (log.isDebugEnabled()) {
                        log.debug("Upgraded " + STARTTIME + " from \"" + oldStartTime + "\" to \""
                                + newStartTime + "\" in EndEntityProfile.");
                    }
                }
            } catch (ParseException e) {
                log.error("Unable to upgrade " + STARTTIME
                        + " in EndEntityProfile! Manual interaction is required (edit and verify).", e);
            }
            try {
                final String oldEndTime = getValue(ENDTIME, 0);
                if (!isEmptyOrRelative(oldEndTime)) {
                    // We use an absolute time format, so we need to upgrade
                    final String newEndTime = newDateFormat.format(oldDateFormat.parse(oldEndTime));
                    setValue(ENDTIME, 0, newEndTime);
                    if (log.isDebugEnabled()) {
                        log.debug("Upgraded " + ENDTIME + " from \"" + oldEndTime + "\" to \"" + newEndTime
                                + "\" in EndEntityProfile.");
                    }
                }
            } catch (ParseException e) {
                log.error("Unable to upgrade " + ENDTIME
                        + " in EndEntityProfile! Manual interaction is required (edit and verify).", e);
            }
        }
        /*
         * In version 13 we converted some dates to the "yyyy-MM-dd HH:mm" format using default Locale.
         * These needs to be converted to the same format but should be stored in UTC, so we always know what the times are.
         */
        if (getVersion() < 14) {
            final String[] timePatterns = { "yyyy-MM-dd HH:mm" };
            final String oldStartTime = getValue(STARTTIME, 0);
            if (!isEmptyOrRelative(oldStartTime)) {
                try {
                    final String newStartTime = ValidityDate
                            .formatAsUTC(DateUtils.parseDateStrictly(oldStartTime, timePatterns));
                    setValue(STARTTIME, 0, newStartTime);
                    if (log.isDebugEnabled()) {
                        log.debug("Upgraded " + STARTTIME + " from \"" + oldStartTime + "\" to \""
                                + newStartTime + "\" in EndEntityProfile.");
                    }
                } catch (ParseException e) {
                    log.error("Unable to upgrade " + STARTTIME
                            + " to UTC in EndEntityProfile! Manual interaction is required (edit and verify).",
                            e);
                }
            }
            final String oldEndTime = getValue(ENDTIME, 0);
            if (!isEmptyOrRelative(oldEndTime)) {
                // We use an absolute time format, so we need to upgrade
                try {
                    final String newEndTime = ValidityDate
                            .formatAsUTC(DateUtils.parseDateStrictly(oldEndTime, timePatterns));
                    setValue(ENDTIME, 0, newEndTime);
                    if (log.isDebugEnabled()) {
                        log.debug("Upgraded " + ENDTIME + " from \"" + oldEndTime + "\" to \"" + newEndTime
                                + "\" in EndEntityProfile.");
                    }
                } catch (ParseException e) {
                    log.error("Unable to upgrade " + ENDTIME
                            + " to UTC in EndEntityProfile! Manual interaction is required (edit and verify).",
                            e);
                }
            }
        }
        // Finally, update the version stored in the map to the current version
        data.put(VERSION, new Float(LATEST_VERSION));
    }
    log.trace("<upgrade");
}

From source file:mitm.common.security.certificate.GenerateTestCertificates.java

/**
 * Generates a certificate without a CN/*  ww  w  . j  a  v  a 2  s  . c  o  m*/
 * 
 * @throws Exception
 */
private void generateCertificateNoCN() throws Exception {
    X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder();

    String encodedPublicKey = "30819f300d06092a864886f70d010101050003818d00308189028181008c"
            + "853445a83b7993183d8ed24a1eb8448bde884755c51341a20168343d2a9b"
            + "ab59477e643a5717e5bbea935dac51caa3a3fbff89059be9d6bf6af8d739"
            + "5bde8c8c45f89aeb4530805387f3402491defcd523031f2ef7085c63db71"
            + "bfe9e25378929f5b3c0b53e0e073e5ed7321de1ed6564e387250cef278dd" + "15a7727824620f0203010001";

    String encodedPrivateKey = "30820275020100300d06092a864886f70d01010105000482025f3082025b"
            + "020100028181008c853445a83b7993183d8ed24a1eb8448bde884755c513"
            + "41a20168343d2a9bab59477e643a5717e5bbea935dac51caa3a3fbff8905"
            + "9be9d6bf6af8d7395bde8c8c45f89aeb4530805387f3402491defcd52303"
            + "1f2ef7085c63db71bfe9e25378929f5b3c0b53e0e073e5ed7321de1ed656"
            + "4e387250cef278dd15a7727824620f02030100010281806efedcde54d7bd"
            + "dd71dd560e479be263cab3d9a3b75d372bb5c334c366b95c4349ff4e17ef"
            + "795218168a612331f55d824b0ac7bb3d21fde0b24cd60873775cdf2db306"
            + "a899f7733d36c11064b76efab7c1b9ab8a897737a5d0b4f05378a033ff71"
            + "a150ed772f1cdbba4cbf8d41025081c960072c07c1f62d7f20a76b6d549f"
            + "61024100cad28338a54224d1a56c32c9f1ad7e0f721e7059dd1bb0310d2b"
            + "04ecc900f57b8f58d773f908a8870ba8676b4363c6087fc44f516d21c9c7"
            + "ea761e07ac77363f024100b15cf740a7162c3bc998fbf57c2d5335e4426d"
            + "5085ed295a432084c1f4311da996a8d40768d3e064e2615e0b2660faf023"
            + "86ed0cbce55a1b4ef0aa6583ed003102402ea29ad3828423ed24892d606b"
            + "b6859ecd919c29bd82694fce044f3c96b726bac36a1d182871ca364b02ec"
            + "cca8111feec25a0416e7edf5f486bfa40605acdf87024064abff0fec8732"
            + "5e51448ba7406fbdae763c9a2dbd86eb14f7cb2a6fa8ba843ab1706cc133"
            + "e827933bc7c6888fa5366a3dd0251738d4f9fb4c28609fb46d3ed1024007"
            + "49ec34b3aa1be30efcc2bc5a18b7ed51ed7b670b9a215c05725ea5dea6da"
            + "6a71aa14e33ab2c8c5d05f4d8e33ed09e83b1df5cdeaf73571f87e67a412" + "864bde";

    PrivateKey privateKey = decodePrivateKey(encodedPrivateKey);
    PublicKey publicKey = decodePublicKey(encodedPublicKey);

    X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder();

    String email = "test@example.com";

    subjectBuilder.setEmail(email);
    subjectBuilder.setCountryCode("NL");
    subjectBuilder.setLocality("Amsterdam");
    subjectBuilder.setState("NH");

    AltNamesBuilder altNamesBuider = new AltNamesBuilder();
    altNamesBuider.setRFC822Names(email);

    X500Principal subject = subjectBuilder.buildPrincipal();
    GeneralNames altNames = altNamesBuider.buildAltNames();

    Set<KeyUsageType> keyUsage = new TreeSet<KeyUsageType>();

    keyUsage.add(KeyUsageType.DIGITALSIGNATURE);
    keyUsage.add(KeyUsageType.KEYENCIPHERMENT);
    keyUsage.add(KeyUsageType.NONREPUDIATION);

    Set<ExtendedKeyUsageType> extendedKeyUsage = new TreeSet<ExtendedKeyUsageType>();

    extendedKeyUsage.add(ExtendedKeyUsageType.CLIENTAUTH);
    extendedKeyUsage.add(ExtendedKeyUsageType.EMAILPROTECTION);

    BigInteger serialNumber = new BigInteger("115fd0e5ee990d9426c93dea720e970", 16);

    Date now = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK)
            .parse("21-Nov-2007 11:52:35");

    certificateBuilder.setSubject(subject);
    certificateBuilder.setAltNames(altNames, true);
    certificateBuilder.setKeyUsage(keyUsage, true);
    certificateBuilder.setExtendedKeyUsage(extendedKeyUsage, false);
    certificateBuilder.setNotBefore(DateUtils.addDays(now, -20));
    certificateBuilder.setNotAfter(DateUtils.addYears(now, 20));
    certificateBuilder.setPublicKey(publicKey);
    certificateBuilder.setSerialNumber(serialNumber);
    certificateBuilder.setSignatureAlgorithm("SHA1WithRSAEncryption");

    X509Certificate certificate = certificateBuilder.generateCertificate(caPrivateKey, caCertificate);

    assertNotNull(certificate);

    certificates.add(certificate);

    Certificate[] chain = new Certificate[] { certificate, caCertificate, rootCertificate };

    keyStore.setKeyEntry("NoCN", privateKey, null, chain);
}

From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java

private CategoryPlot getCategoryPlot(List<cfCHARTSERIESData> series, String xAxisTitle, String yAxisTitle,
        String labelFormat, boolean bShowMarkers, int markerSize, boolean bShow3D, String tipStyle,
        String drillDownUrl, int xOffset, int yOffset, int yAxisUnits, String seriesPlacement,
        boolean bSortXAxis, int height, String[] yAxisSymbols, int gridLines) throws cfmRunTimeException {
    // Create a category plot
    CategoryPlot plot = new CategoryPlot();

    // Set the domain axis (the x-axis)
    org.jfree.chart.axis.CategoryAxis categoryAxis;
    if (bShow3D)/*w ww .  j  av  a2s .co  m*/
        categoryAxis = new CategoryAxis3D(xAxisTitle);
    else
        categoryAxis = new CategoryAxis(xAxisTitle);
    plot.setDomainAxis(categoryAxis);

    // Set the range axis (the y-axis)
    ValueAxis valueAxis;
    DateFormat dateFormat = null;
    NumberFormat numberFormat = null;

    // Ignore a label format of date if the y-axis is using symbols
    if (labelFormat.equals("date") && (yAxisSymbols == null)) {
        valueAxis = new DateAxis(yAxisTitle);
        dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
        ((DateAxis) valueAxis).setDateFormatOverride(dateFormat);
    } else {
        if (yAxisSymbols != null) {
            valueAxis = new SymbolAxis(yAxisTitle, yAxisSymbols);
            ((SymbolAxis) valueAxis).setGridBandsVisible(false);
            ((SymbolAxis) valueAxis).setAutoRangeStickyZero(true);
        } else if (bShow3D) {
            valueAxis = new NumberAxis3D(yAxisTitle);
        } else {
            valueAxis = new NumberAxis(yAxisTitle);
        }

        if (labelFormat.equals("currency")) {
            ((NumberAxis) valueAxis).setNumberFormatOverride(NumberFormat.getCurrencyInstance());
            numberFormat = NumberFormat.getCurrencyInstance();
        } else if (labelFormat.equals("percent")) {
            numberFormat = NumberFormat.getPercentInstance();
            numberFormat.setMaximumFractionDigits(3); // without this change .11443
                                                      // would be displayed as 11%
                                                      // instead of 11.443%
            ((NumberAxis) valueAxis).setNumberFormatOverride(numberFormat);
        } else {
            numberFormat = NumberFormat.getInstance();
        }

        if (yAxisUnits != 0)
            ((NumberAxis) valueAxis).setTickUnit(new NumberTickUnit(yAxisUnits));
    }
    plot.setRangeAxis(valueAxis);

    // Add a dataset and renderer for each series
    int barChartDatasetIndex = -1;
    int hBarChartDatasetIndex = -1;
    int num = 0;
    MinMaxData minMax = new MinMaxData();
    for (int i = 0; i < series.size(); i++) {
        cfCHARTSERIESData seriesData = series.get(i);

        // If the sortXAxis attribute was set to "yes" then sort the data.
        // NOTE: this attribute is only used with category charts.
        if (bSortXAxis)
            seriesData.sort();

        DefaultCategoryDataset dataset;
        if ((barChartDatasetIndex != -1) && (seriesData.getType().equals("bar"))) {
            dataset = (DefaultCategoryDataset) plot.getDataset(barChartDatasetIndex);

            addSeriesDataToDataset(seriesData, dataset, minMax);

            // Set the paint style for this series
            setPaintStyle(seriesData.getPaintStyle(), plot.getRenderer(barChartDatasetIndex),
                    dataset.getRowCount() - 1, height);

            // Add the color list for this series to the custom color renderer
            CustomColorRenderer cr = (CustomColorRenderer) plot.getRenderer(barChartDatasetIndex);
            cr.addColors(getColorList(seriesData));

            continue;
        } else if ((hBarChartDatasetIndex != -1) && (seriesData.getType().equals("horizontalbar"))) {
            dataset = (DefaultCategoryDataset) plot.getDataset(hBarChartDatasetIndex);

            addSeriesDataToDataset(seriesData, dataset, minMax);

            // Set the paint style for this series
            setPaintStyle(seriesData.getPaintStyle(), plot.getRenderer(hBarChartDatasetIndex),
                    dataset.getRowCount() - 1, height);

            // Add the color list for this series to the custom color renderer
            CustomColorRenderer cr = (CustomColorRenderer) plot.getRenderer(hBarChartDatasetIndex);
            cr.addColors(getColorList(seriesData));

            continue;
        } else {
            dataset = new DefaultCategoryDataset();

            addSeriesDataToDataset(seriesData, dataset, minMax);
        }

        plot.setDataset(num, dataset);

        AbstractCategoryItemRenderer renderer = null;
        if (seriesData.getType().equals("bar")) {
            plot.setOrientation(PlotOrientation.VERTICAL);
            renderer = getBarRenderer(seriesPlacement, bShow3D, xOffset, yOffset, getColorList(seriesData));
            ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                    TextAnchor.BOTTOM_CENTER);
            renderer.setPositiveItemLabelPosition(position1);
            ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                    TextAnchor.TOP_CENTER);
            renderer.setNegativeItemLabelPosition(position2);
            ((BarRenderer) renderer).setItemMargin(0.0); // The margin between items
                                                         // in the same category
            categoryAxis.setCategoryMargin(0.2); // The margin between each category

            barChartDatasetIndex = num;
        } else if (seriesData.getType().equals("horizontalbar")) {
            plot.setOrientation(PlotOrientation.HORIZONTAL);
            plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
            renderer = getBarRenderer(seriesPlacement, bShow3D, xOffset, yOffset, getColorList(seriesData));
            if (bShow3D) {
                // change rendering order to ensure that bar overlapping is the
                // right way around
                plot.setRowRenderingOrder(org.jfree.util.SortOrder.DESCENDING);
                plot.setColumnRenderingOrder(org.jfree.util.SortOrder.DESCENDING);
            }
            ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3,
                    TextAnchor.CENTER_LEFT);
            renderer.setPositiveItemLabelPosition(position1);
            ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9,
                    TextAnchor.CENTER_RIGHT);
            renderer.setNegativeItemLabelPosition(position2);
            ((BarRenderer) renderer).setItemMargin(0.0); // The margin between items
                                                         // in the same category
            categoryAxis.setCategoryMargin(0.2); // The margin between each category

            hBarChartDatasetIndex = num;
        } else if (seriesData.getType().equals("line")) {
            if (bShow3D) {
                renderer = new LineRenderer3D();
                ((LineRenderer3D) renderer).setXOffset(xOffset);
                ((LineRenderer3D) renderer).setYOffset(yOffset);
            } else {
                renderer = new LineAndShapeRenderer(true, false);
            }

            // Enable/Disable displaying of markers
            ((LineAndShapeRenderer) renderer).setShapesVisible(bShowMarkers);

            // Set the shape of the markers based on the markerSize value
            ((LineAndShapeRenderer) renderer).setShape(getMarker(seriesData.getMarkerStyle(), markerSize));
        } else if (seriesData.getType().equals("area")) {
            if (seriesPlacement.equals("stacked"))
                renderer = new StackedAreaRenderer(); // this doesn't work for some
                                                      // reason
            else
                renderer = new AreaRenderer();

            // Truncate the first and last values to match CFMX 7
            ((AreaRenderer) renderer).setEndType(AreaRendererEndType.TRUNCATE);

            categoryAxis.setCategoryMargin(0.0);
        } else if (seriesData.getType().equals("step")) {
            renderer = new CategoryStepRenderer(true);
        } else if (seriesData.getType().equals("scatter")) {
            renderer = new LineAndShapeRenderer(false, true);

            // Set the shape of the markers based on the markerSize value
            ((LineAndShapeRenderer) renderer).setShape(getMarker(seriesData.getMarkerStyle(), markerSize));
        }

        if (!tipStyle.equals("none")) {
            if (dateFormat != null)
                renderer.setBaseToolTipGenerator(
                        new StandardCategoryToolTipGenerator("({0}, {1}) = {2}", dateFormat));
            else
                renderer.setBaseToolTipGenerator(
                        new StandardCategoryToolTipGenerator("({0}, {1}) = {2}", numberFormat));
        }

        if (drillDownUrl != null) {
            if (dateFormat != null)
                renderer.setBaseItemURLGenerator(
                        new com.newatlanta.bluedragon.CategoryURLGenerator(drillDownUrl, dateFormat));
            else
                renderer.setBaseItemURLGenerator(
                        new com.newatlanta.bluedragon.CategoryURLGenerator(drillDownUrl, numberFormat));
        }

        if (seriesData.getSeriesColor() != null)
            renderer.setSeriesPaint(0, convertStringToColor(seriesData.getSeriesColor()));

        String dataLabelStyle = seriesData.getDataLabelStyle();
        if (labelFormat.equals("date")) {
            if (dataLabelStyle.equals("none")) {
                renderer.setItemLabelsVisible(false);
            } else {
                setCategoryItemLabelsData(renderer, seriesData);
                if (dataLabelStyle.equals("value"))
                    renderer.setItemLabelGenerator(
                            new CategoryItemLabelGenerator("{2}", dateFormat, yAxisSymbols));
                else if (dataLabelStyle.equals("rowlabel"))
                    renderer.setItemLabelGenerator(
                            new CategoryItemLabelGenerator("{0}", dateFormat, yAxisSymbols));
                else if (dataLabelStyle.equals("columnlabel"))
                    renderer.setItemLabelGenerator(
                            new CategoryItemLabelGenerator("{1}", dateFormat, yAxisSymbols));
                else if (dataLabelStyle.equals("pattern"))
                    renderer.setItemLabelGenerator(
                            new CategoryItemLabelGenerator("{1} {2}", dateFormat, yAxisSymbols));
                else
                    renderer.setItemLabelGenerator(
                            new CategoryItemLabelGenerator(dataLabelStyle, dateFormat, yAxisSymbols));
            }
        } else {
            if (dataLabelStyle.equals("none")) {
                renderer.setItemLabelsVisible(false);
            } else {
                setCategoryItemLabelsData(renderer, seriesData);
                if (dataLabelStyle.equals("value"))
                    renderer.setItemLabelGenerator(
                            new CategoryItemLabelGenerator("{2}", numberFormat, yAxisSymbols));
                else if (dataLabelStyle.equals("rowlabel"))
                    renderer.setItemLabelGenerator(
                            new CategoryItemLabelGenerator("{0}", numberFormat, yAxisSymbols));
                else if (dataLabelStyle.equals("columnlabel"))
                    renderer.setItemLabelGenerator(
                            new CategoryItemLabelGenerator("{1}", numberFormat, yAxisSymbols));
                else if (dataLabelStyle.equals("pattern"))
                    renderer.setItemLabelGenerator(
                            new CategoryItemLabelGenerator("{1} {2} ({3} of {4})", numberFormat, yAxisSymbols));
                else
                    renderer.setItemLabelGenerator(
                            new CategoryItemLabelGenerator(dataLabelStyle, numberFormat, yAxisSymbols));
            }
        }

        // Add the renderer to the plot.
        // NOTE: this must be done before the setPaintStyle() call so the
        // DrawingSupplier object
        // will be set up properly for the generation of default colors.
        plot.setRenderer(num, renderer);

        // Set the paint style for this series (series 0)
        if (seriesData.getType().equals("bar") || seriesData.getType().equals("horizontalbar")
                || seriesData.getType().equals("area"))
            setPaintStyle(seriesData.getPaintStyle(), renderer, 0, height);

        num++;
    }

    // If gridLines was specified then we need to calculate the yAxisUnits
    if ((gridLines != -1) && (valueAxis instanceof NumberAxis)) {
        // Calculate the yAxisUnits we need to use to create the number of
        // gridLines
        yAxisUnits = calculateYAxisUnits(gridLines, minMax);

        // Set the yAxisUnits
        ((NumberAxis) valueAxis).setTickUnit(new NumberTickUnit(yAxisUnits));
    }

    return plot;
}

From source file:org.hoteia.qalingo.core.web.mvc.factory.impl.ViewBeanFactoryImpl.java

/**
 * /*from ww w . ja v a  2 s  .  c  om*/
 */
public OrderViewBean buildOrderViewBean(final RequestData requestData, final OrderCustomer order)
        throws Exception {
    final Locale locale = requestData.getLocale();
    final OrderViewBean orderViewBean = new OrderViewBean();
    orderViewBean.setOrderNum(order.getOrderNum());

    if (order != null) {
        DateFormat dateFormat = requestUtil.getFormatDate(requestData, DateFormat.MEDIUM, DateFormat.MEDIUM);
        if (order.getExpectedDeliveryDate() != null) {
            orderViewBean.setExpectedDeliveryDate(dateFormat.format(order.getExpectedDeliveryDate()));
        } else {
            orderViewBean.setExpectedDeliveryDate("NA");
        }

        Date dateCreate = order.getDateCreate();
        if (dateCreate != null) {
            orderViewBean.setCreatedDate(dateFormat.format(dateCreate));
        } else {
            orderViewBean.setCreatedDate("NA");
        }

        Date dateUpdate = order.getDateUpdate();
        if (dateUpdate != null) {
            orderViewBean.setUpdatedDate(dateFormat.format(dateUpdate));
        } else {
            orderViewBean.setUpdatedDate("NA");
        }

        // ITEMS PART
        final List<OrderItemViewBean> orderItemViewBeans = new ArrayList<OrderItemViewBean>();
        final Set<OrderItem> orderItems = order.getOrderItems();
        for (Iterator<OrderItem> iterator = orderItems.iterator(); iterator.hasNext();) {
            OrderItem orderItem = (OrderItem) iterator.next();
            orderItemViewBeans.add(buildOrderItemViewBean(requestData, orderItem));
        }
        orderViewBean.setOrderItems(orderItemViewBeans);

        // SUB PART : Shippings
        final List<OrderShippingViewBean> orderShippingViewBeans = new ArrayList<OrderShippingViewBean>();
        final Set<OrderShipment> orderShipments = order.getOrderShipments();
        if (orderShipments != null) {
            for (Iterator<OrderShipment> iterator = orderShipments.iterator(); iterator.hasNext();) {
                final OrderShipment orderShipment = (OrderShipment) iterator.next();
                final OrderShippingViewBean orderShippingViewBean = new OrderShippingViewBean();
                Object[] params = { orderShipment.getName() };
                orderShippingViewBean.setOrderShippingTotalLabel(getSpecificMessage(ScopeWebMessage.COMMON,
                        "shoppingcart.amount.deliveryMethods", params, locale));
                orderShippingViewBeans.add(orderShippingViewBean);
            }
            orderViewBean.setOrderShippings(orderShippingViewBeans);
        }

        // SUB PART : Taxes
        final List<OrderTaxViewBean> orderTaxViewBeans = new ArrayList<OrderTaxViewBean>();
        final Set<OrderTax> orderTaxes = order.getOrderTaxes();
        if (orderTaxes != null) {
            for (Iterator<OrderTax> iterator = orderTaxes.iterator(); iterator.hasNext();) {
                final OrderTax orderTax = (OrderTax) iterator.next();
                final OrderTaxViewBean orderTaxViewBean = new OrderTaxViewBean();
                Object[] params = { orderTax.getAmount() };
                orderTaxViewBean.setOrderTaxTotal(
                        order.getCurrency().formatPriceWithStandardCurrencySign(orderTax.getAmount()));
                orderTaxViewBean.setOrderTaxTotalLabel(getSpecificMessage(ScopeWebMessage.COMMON,
                        "shoppingcart.amount.taxes", params, locale));
                orderTaxViewBeans.add(orderTaxViewBean);
            }
            orderViewBean.setOrderTaxes(orderTaxViewBeans);
        }
        orderViewBean.setOrderItemsTotalWithCurrencySign(order.getOrderItemTotalWithStandardCurrencySign());
        orderViewBean.setOrderShippingTotalWithCurrencySign(order.getShippingTotalWithStandardCurrencySign());
        orderViewBean.setOrderTaxesTotalWithCurrencySign(order.getTaxTotalWithStandardCurrencySign());
        orderViewBean.setOrderTotalWithCurrencySign(order.getOrderTotalWithStandardCurrencySign());

        Map<String, String> getParams = new HashMap<String, String>();
        getParams.put(RequestConstants.REQUEST_PARAMETER_CUSTOMER_ORDER_GUID, order.getId().toString());

        orderViewBean
                .setDetailsUrl(urlService.generateUrl(FoUrls.PERSONAL_ORDER_DETAILS, requestData, getParams));
    }

    return orderViewBean;
}

From source file:com.miz.functions.MizLib.java

public static String getPrettyDatePrecise(Context context, String date) {
    if (!TextUtils.isEmpty(date)) {
        try {// w  ww. ja v  a2s.c om
            String[] dateArray = date.split("-");
            Calendar cal = Calendar.getInstance();
            cal.set(Integer.parseInt(dateArray[0]), Integer.parseInt(dateArray[1]) - 1,
                    Integer.parseInt(dateArray[2]));

            return DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault()).format(cal.getTime());
        } catch (Exception e) { // Fall back if something goes wrong
            return date;
        }
    } else {
        return context.getString(R.string.stringNA);
    }
}

From source file:mitm.common.security.certificate.GenerateTestCertificates.java

/**
 * Generates a certificate with multiple email addresses
 * /*  w w  w.  ja v a  2  s  . c  o  m*/
 * @throws Exception
 */
private void generateCertificateMultipleEmail() throws Exception {
    X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder();

    String encodedPublicKey = "30819f300d06092a864886f70d010101050003818d00308189028181008e"
            + "1347f6e22318a40d4d8b9a97cdb06355d9a761f35f44b7d3356d4596ddf6"
            + "db2606fc572ed5b9c79fb2f76466f7f9bf2797de2ae1f8d9ea14d9380f2e"
            + "afe2040d6faab65f746d9705f7fab00956b918bc7b0c2e312895b24153b7"
            + "33ffede39bf6dfe0d419b8020c8772f9da1d8d1ca3d2a9da172fafdcfb7b" + "4ecff5048d46c90203010001";

    String encodedPrivateKey = "30820276020100300d06092a864886f70d0101010500048202603082025c"
            + "020100028181008e1347f6e22318a40d4d8b9a97cdb06355d9a761f35f44"
            + "b7d3356d4596ddf6db2606fc572ed5b9c79fb2f76466f7f9bf2797de2ae1"
            + "f8d9ea14d9380f2eafe2040d6faab65f746d9705f7fab00956b918bc7b0c"
            + "2e312895b24153b733ffede39bf6dfe0d419b8020c8772f9da1d8d1ca3d2"
            + "a9da172fafdcfb7b4ecff5048d46c90203010001028180723bc28318f40b"
            + "1decac4af133d9685796717889e33ad86fcd5c89cd882e540b8499dd4ee4"
            + "13685abf67104f24138235564a5f91af3b7d4b1f144064c4af1a53e045f7"
            + "1678bd7af11e33f02dbd846782ff0b8a6f7fea20d6c068b0a79f0c3b136c"
            + "dcd201443ecc7113d8e73e9a4f8faacdd87fd314c42f54c6532ffcceeb2d"
            + "d9024100cd8ffedb65cdfbafc3ffe2ba0743ab4f0ebf5298bddd542be36b"
            + "e9393788fccb1bc8218fe0f81e85c9c2eade11d68ae30284b931cf2654bb"
            + "8ace741dcf67450b024100b0ef76b44180f5d729619cd855e0da81d5129c"
            + "b8866fee97291961f3487a3a8b5d28049cd0b7062590a963420923331ce8"
            + "7f76d49f7e6d02837916dd0878dffb024067979084fa5a02e381efbb4faa"
            + "87849653c54117ae5f12a3077a034f8d5820a52ebbfd85e786c2c3037992"
            + "29156e3c11c8dc200424f39931e5f2c2fb9ee0d91f02410088005906ef3e"
            + "b8391db6c93fc4ab246a1da4c3d0568ddd2055d80be15bb9901ca58b6818"
            + "3d9a21606894bb15fc3e1140cc3985d6a38e232e866e62339e1a83570240"
            + "10b51e80ac96ea754e7232e633daeae50efaf8f0b9f55fcd113226722197"
            + "d9650870c7a245348be5d4f3dd2face76ad2e82f5c6b658c67b4cdfe6d14" + "dbaf86bd";

    PrivateKey privateKey = decodePrivateKey(encodedPrivateKey);
    PublicKey publicKey = decodePublicKey(encodedPublicKey);

    X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder();

    String email[] = new String[] { "test@example.com", "test2@example.com", "test3@example.com", "invalid" };

    subjectBuilder.setCommonName("multiple email");
    subjectBuilder.setEmail(email);
    subjectBuilder.setCountryCode("NL");
    subjectBuilder.setLocality("Amsterdam");
    subjectBuilder.setState("NH");

    AltNamesBuilder altNamesBuider = new AltNamesBuilder();
    altNamesBuider.setRFC822Names(email);

    X500Principal subject = subjectBuilder.buildPrincipal();
    GeneralNames altNames = altNamesBuider.buildAltNames();

    Set<KeyUsageType> keyUsage = new TreeSet<KeyUsageType>();

    keyUsage.add(KeyUsageType.DIGITALSIGNATURE);
    keyUsage.add(KeyUsageType.KEYENCIPHERMENT);
    keyUsage.add(KeyUsageType.NONREPUDIATION);

    Set<ExtendedKeyUsageType> extendedKeyUsage = new TreeSet<ExtendedKeyUsageType>();

    extendedKeyUsage.add(ExtendedKeyUsageType.CLIENTAUTH);
    extendedKeyUsage.add(ExtendedKeyUsageType.EMAILPROTECTION);

    BigInteger serialNumber = new BigInteger("115fd110a82f742d0ae14a71b651962", 16);

    Date now = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK)
            .parse("21-Nov-2007 11:52:35");

    certificateBuilder.setSubject(subject);
    certificateBuilder.setAltNames(altNames, true);
    certificateBuilder.setKeyUsage(keyUsage, true);
    certificateBuilder.setExtendedKeyUsage(extendedKeyUsage, false);
    certificateBuilder.setNotBefore(DateUtils.addDays(now, -20));
    certificateBuilder.setNotAfter(DateUtils.addYears(now, 20));
    certificateBuilder.setPublicKey(publicKey);
    certificateBuilder.setSerialNumber(serialNumber);
    certificateBuilder.setSignatureAlgorithm("SHA1WithRSAEncryption");

    X509Certificate certificate = certificateBuilder.generateCertificate(caPrivateKey, caCertificate);

    assertNotNull(certificate);

    certificates.add(certificate);

    Certificate[] chain = new Certificate[] { certificate, caCertificate, rootCertificate };

    keyStore.setKeyEntry("multipleEmail", privateKey, null, chain);
}