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:es.caib.seycon.ng.servei.XarxaServiceImpl.java

@Override
protected Maquina handleRegisterDynamicIP(String nomMaquina, String ip, String serialNumber)
        throws es.caib.seycon.ng.exception.UnknownHostException, UnknownNetworkException {
    boolean anyChange = false;
    // First. Test if this IP belongs to anybody else
    MaquinaEntity old = getMaquinaEntityDao().findByAdreca(ip);
    MaquinaEntity maquina = null;//from w  w w  .  j a  v  a2s .  c  o  m
    if (old != null) {
        if (serialNumber.equals(old.getSerialNumber())) {
            maquina = old;
            // Coincide serial number 
            if (!nomMaquina.equals(maquina.getNom())) {
                // Host name changed
                // Check if already exists such a name
                old = getMaquinaEntityDao().findByNom(nomMaquina);
                if (old != null) {
                    old.setDeleted(true);
                    getMaquinaEntityDao().update(old);
                }
                maquina.setNom(nomMaquina);
                anyChange = true;
            }
        } else {
            if (old.getDeleted().booleanValue() || old.getDynamicIP().booleanValue()) {
                old.setAdreca(null);
                old.setXarxa(null);
                getMaquinaEntityDao().update(old);
            } else {
                log.warn(String.format(Messages.getString("XarxaServiceImpl.HostsCollisionMessage"), //$NON-NLS-1$
                        nomMaquina, nomMaquina, ip, serialNumber));
                throw new UnknownHostException(
                        String.format(Messages.getString("XarxaServiceImpl.IPAssignedMessage"), //$NON-NLS-1$
                                ip, old.getNom()));
            }
        }
    }
    // Second. Test if this name belongs to anybody else
    if (maquina == null) {
        // Found a host with no serial number => Bind it
        old = getMaquinaEntityDao().findByNom(nomMaquina);
        if (old == null) {
            // Nothing to do
        } else if (old.getSerialNumber() == null && old.getDynamicIP().booleanValue()) {
            // Replace unused host
            maquina = old;
            maquina.setSerialNumber(serialNumber);
            maquina.setAdreca(ip);
            maquina.setLastSeen(new Date());
            getMaquinaEntityDao().update(maquina);
        } else if (serialNumber.equals(old.getSerialNumber())) {
            // Found host entry
            maquina = old;
        } else if (old.getDynamicIP().booleanValue()) {
            // Autodelete
            old.setDeleted(true);
            getMaquinaEntityDao().update(old);
        } else {
            log.warn(String.format(Messages.getString("XarxaServiceImpl.HostsCollisionMessage"), //$NON-NLS-1$
                    nomMaquina, nomMaquina, ip, serialNumber));
            throw new UnknownHostException(nomMaquina);
        }
    }
    // Third. Test if this serial is already used (with another name)
    if (maquina == null) {
        maquina = getMaquinaEntityDao().findBySerialNumber(serialNumber);
        if (maquina != null && !nomMaquina.equals(maquina.getNom())) {
            anyChange = true;
            maquina.setNom(nomMaquina);
        }
    }

    if (maquina == null) {
        try {
            InetAddress addr = InetAddress.getByName(ip);
            XarxaEntity x = guessNetwork(addr.getAddress());
            if (x == null) {
                String msg = String.format(Messages.getString("XarxaServiceImpl.RequestUnmanagedIP"), //$NON-NLS-1$
                        nomMaquina, ip);
                log.warn(msg);
                throw new UnknownNetworkException(msg);
            }
            maquina = getMaquinaEntityDao().newMaquinaEntity();
            maquina.setAdreca(ip);
            maquina.setCorreu("N"); //$NON-NLS-1$
            maquina.setDeleted(false);
            DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
            maquina.setDescripcio(Messages.getString("XarxaServiceImpl.AutocreatedMessage") + //$NON-NLS-1$
                    " " + // $NON-NLS-1$ //$NON-NLS-1$
                    df.format(new Date())); //$NON-NLS-1$
            maquina.setDynamicIP(new Boolean(true));
            maquina.setNom(nomMaquina);
            maquina.setOfimatica("N"); //$NON-NLS-1$
            maquina.setSerialNumber(serialNumber);
            maquina.setServidorImpressores("N"); //$NON-NLS-1$
            maquina.setOperatingSystem(getOsTypeEntityDao().findOSTypeByName("ALT")); //$NON-NLS-1$
            maquina.setXarxa(x);
            getMaquinaEntityDao().create(maquina);
        } catch (java.net.UnknownHostException e) {
            String msg = String.format(Messages.getString("XarxaServiceImpl.RequestUnmanagedIP"), nomMaquina, //$NON-NLS-1$
                    "??"); //$NON-NLS-1$ 
            log.warn(msg);
            throw new UnknownNetworkException(msg);
        }
    }

    if (!ip.equals(maquina.getAdreca()) || maquina.getXarxa() == null
            || !Boolean.FALSE.equals(maquina.getDeleted())) {
        try {
            InetAddress addr = InetAddress.getByName(ip);
            XarxaEntity x = guessNetwork(addr.getAddress());
            if (x != null) {
                if (x.isDchpSupport()) {
                    anyChange = true;
                    maquina.setDeleted(Boolean.FALSE);
                    maquina.setAdreca(ip);
                    maquina.setXarxa(x);
                } else {
                    throw new UnknownNetworkException(
                            String.format(Messages.getString("XarxaServiceImpl.RequestWithoutDHCP"), //$NON-NLS-1$
                                    nomMaquina, ip, x.getCodi()));
                }
            } else {
                throw new UnknownNetworkException(String
                        .format(Messages.getString("XarxaServiceImpl.RequestUnmanagedIP"), nomMaquina, ip)); //$NON-NLS-1$
            }
        } catch (java.net.UnknownHostException e) {
            String msg = String.format(Messages.getString("XarxaServiceImpl.RequestUnmanagedIP"), nomMaquina, //$NON-NLS-1$
                    "??"); //$NON-NLS-1$ 
            log.warn(msg);
            throw new UnknownNetworkException(msg);
        }
    }
    if (anyChange || maquina.getLastSeen() == null
            || System.currentTimeMillis() - maquina.getLastSeen().getTime() > 8 * 60L * 60L * 1000L) // each 8 hours update last seen
    {
        maquina.setLastSeen(new Date());
        getMaquinaEntityDao().update(maquina);
    }

    return getMaquinaEntityDao().toMaquina(maquina);
}

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

/**
 * Generates a certificate with MD5 Hash algorithm
 * /*from   w ww .j  a v a  2 s  .  c o m*/
 * @throws Exception
 */
private void generateCertificateMD5Hash() throws Exception {
    X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder();

    String encodedPublicKey = "30819f300d06092a864886f70d010101050003818d003081890281810080"
            + "204142a37fe819010c9c5e021b8df7ee54083c588a04c31ffd714695ce18"
            + "51721b0f00a392643fa91392aa7bcf1426d2e2f724a5d996740d97b8586c"
            + "f59cc7bc8d865bf3957a629c8f36bb9b71017c53e8baf71821cf622ca025"
            + "d3c523c084700a5c1af9b624639c86c556d8038a7afc2235d2f1d0f226c4" + "48a40c2e0327dd0203010001";

    String encodedPrivateKey = "30820275020100300d06092a864886f70d01010105000482025f3082025b"
            + "0201000281810080204142a37fe819010c9c5e021b8df7ee54083c588a04"
            + "c31ffd714695ce1851721b0f00a392643fa91392aa7bcf1426d2e2f724a5"
            + "d996740d97b8586cf59cc7bc8d865bf3957a629c8f36bb9b71017c53e8ba"
            + "f71821cf622ca025d3c523c084700a5c1af9b624639c86c556d8038a7afc"
            + "2235d2f1d0f226c448a40c2e0327dd020301000102818028427a5f2722fc"
            + "da468320eb453c454adf9f960ae8434e25c5fa8c4a82ae04e42ab7a7ea2a"
            + "7bc8765c7962ffa0f1bbc24b47b822d2de61314c481d4be3c8f59f3497f6"
            + "4d6d84e7d61b7858f20e88e803ff924f8d98a311a2f39398b149100a158c"
            + "ac03df61da458599e87da0ca48b749dee040f66c8fe3eda072f44ec4829f"
            + "3d024100e4361bd0489cb47e204af8905d617e1e04e7102fec2c22711b85"
            + "9dbade040aa41f0f2a349b88444da57c6b5a16f198ea9ac70350855eece1"
            + "6eafe7789a2c33730241008fba3f47889514c507b76a289d097a220f07d8"
            + "0dea9fd55191b6519646d11ad6399d97924906768ea19f8262cad28c7a16"
            + "b76d8cdc069b6c639fdce3a027836f0240678ca9b82b8a7757977d8d25ac"
            + "497579578e24c929e7a8c51bd0d80e17794bfec65d123086b6210ffe5be3"
            + "36209d055ec6563109d34a8c3f8a02e50bd320e543024033d5e4049489cf"
            + "d7cf94a2c0cb0223fe2c9593a251401bdb334621dea4e3bd5e0da17c8cd1"
            + "b17708b1d9a9589ff5979c609cfef19258ffacf3b130251819a819024018"
            + "81b9dae35212866780b9ce93e0c10fa40e3679773e3b067d5743bfdb8c74"
            + "ce8d1ed3a0d5312f220f7d0eb44c074c46898acbcfdba15c480385458d90" + "14fd7b";

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

    X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder();

    String email[] = new String[] { "test@example.com" };

    subjectBuilder.setCommonName("md5 Hash");
    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("115fd1392a8ff07aa727558fa50b262", 16);

    Date now = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK)
            .parse("21-Nov-2007 11:54: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("MD5WithRSAEncryption");

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

    assertNotNull(certificate);

    certificates.add(certificate);

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

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

From source file:org.domainmath.gui.MainFrame.java

private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
    this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
    MainFrame.octavePanel.start();/*w  w  w.j  av  a2  s.  co m*/

    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM,
            Locale.getDefault());

    String t = "# -- " + formatter.format(new Date()) + " -- #";

    histArea.append(t + "\n");

    String path = Character.toString('"') + System.getProperty("user.dir") + File.separator + "scripts"
            + Character.toString('"');

    MainFrame.octavePanel.evaluate("addpath(genpath(" + path + "));savepath();");
    MainFrame.octavePanel.evaluate("DomainMath_OctavePaths('" + parent_root + "DomainMath_OctavePaths.dat');");

    MainFrame.octavePanel
            .evaluate("DomainMath_OctavePackages('" + parent_root + "DomainMath_OctavePackages.dat');");
    MainFrame.octavePanel
            .evaluate("DomainMath_OctaveVariables('" + parent_root + "DomainMath_OctaveVariables.dat',whos);");
    // MainFrame.workspace.reload();
    MainFrame.octavePanel
            .evaluate("DomainMath_OctaveConfig('" + parent_root + "DomainMath_OctaveConfig.dat');");

    String f = System.getProperty("user.dir") + File.separator + "cache" + File.separator + "pkg_list.xml";
    MainFrame.octavePanel.evaluate("DomainMath_PkgContents('" + f + "');");

    loadLayout();
    MainFrame.reloadWorkspace();
    loadPackageAuto();
    setDirComboContent();
    this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    new ModuleLoader().load(this, false);
    DMILogger.msg("DMI is Ready.");
}

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

/**
 * Generates a certificate with SHA256 Hash algorithm
 * //  w  w w .  ja v  a2  s .  com
 * @throws Exception
 */
private void generateCertificateSHA256Hash() throws Exception {
    X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder();

    String encodedPublicKey = "30819f300d06092a864886f70d010101050003818d00308189028181008b"
            + "08d9d440857d8b6e0adf44301cecacc9e3619e25e3ecb2735a0c25a8d65c"
            + "005d44c92fea1e82693d676c25653d4f4a30702aefde057983ab4fd1d381"
            + "a18938318dcf07f635e68b32b47b5ec8246e783c912e7287c9d2e75c5f01"
            + "24653694c0dcf8b5983bf7659fa2558426f44978db1e5e81a4abae5ea245" + "f915d6ef663af70203010001";

    String encodedPrivateKey = "30820277020100300d06092a864886f70d0101010500048202613082025d"
            + "020100028181008b08d9d440857d8b6e0adf44301cecacc9e3619e25e3ec"
            + "b2735a0c25a8d65c005d44c92fea1e82693d676c25653d4f4a30702aefde"
            + "057983ab4fd1d381a18938318dcf07f635e68b32b47b5ec8246e783c912e"
            + "7287c9d2e75c5f0124653694c0dcf8b5983bf7659fa2558426f44978db1e"
            + "5e81a4abae5ea245f915d6ef663af702030100010281807277ce07ef3b38"
            + "7ac415d56de982d6e507aeda5eff69212666cc3b760204c2685661dc9643"
            + "55ed1ec23c551090c2a2763d5d0c2cc289955aef7f5f0c990caad0c4be38"
            + "ea093a0ff82f987fb85432ff0c97acec554b9ffe6bdccec9b2c30b57e866"
            + "b9f964cd64d007311e2b477f88d15c4fccc57fbd06afdf815624c92ba03d"
            + "a9024100f508e549437f5ec1b2307b6843f692f189feed369389a598172c"
            + "859a768bc5b3e02765b0a8e672e54b1096f526c8df741d12910296be0c16"
            + "e93f7bb77fb13bd502410091419f88e027d1b0f99408eaab6dd26b2bd0a6"
            + "62e47f5d40f20d191dab1864a6bfea4a9c5b1b3f1aea35c4134bdf005cd0"
            + "25d4a0e98299e6aa2be46591607d9b024100f119f8a9f70d4bca612f8d2e"
            + "11b97beac8729b2c194dd62f6995f83bfd2b18b41dfa05f826a8e222b592"
            + "b446b20bf2bac8a46d24d3f859e2ed4cf6c99e8e60a502410085a22ee858"
            + "f8a934bcd7d1403c08a42e0eb83d6afbb6a50f6be05afbed7d5a940239c4"
            + "fc85e0d234abc65d263785e8aa7aa06336cabd696349a969cd7b6a9f0302"
            + "405653037277299bfd0d055bc55b5f8f9892e7254f7ddf09cb0a5a159095"
            + "746a3d914caa2c2a8c24d1ab57c1d065cf9c31ef4820855b2dbfa6f7a91c" + "96b152f9ef";

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

    X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder();

    String email[] = new String[] { "test@example.com" };

    subjectBuilder.setCommonName("SHA256 Hash");
    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("115fd16008275f2616b8a235d761fff", 16);

    Date now = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK)
            .parse("21-Nov-2007 06:38: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("SHA256WithRSAEncryption");

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

    assertNotNull(certificate);

    certificates.add(certificate);

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

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

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

/**
 * /*w  ww .j a  v  a2  s. co  m*/
 */
public ProductBrandCustomerCommentViewBean buildViewBeanProductBrandCustomerComment(
        final RequestData requestData, final ProductBrand productBrand,
        final ProductBrandCustomerComment customerComment) throws Exception {
    final Localization localization = requestData.getMarketAreaLocalization();
    final String localizationCode = localization.getCode();

    final ProductBrandCustomerCommentViewBean customerCommentViewBean = new ProductBrandCustomerCommentViewBean();
    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(productBrand.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:org.nuxeo.ecm.core.api.AbstractSession.java

protected String oldLockKey(Lock lock) {
    if (lock == null) {
        return null;
    }//from   w  w  w  .  j  av  a 2s.  c  o m
    // return deprecated format, like "someuser:Nov 29, 2010"
    String lockCreationDate = (lock.getCreated() == null) ? null
            : DateFormat.getDateInstance(DateFormat.MEDIUM)
                    .format(new Date(lock.getCreated().getTimeInMillis()));
    return lock.getOwner() + ':' + lockCreationDate;
}

From source file:org.etudes.mneme.impl.SubmissionServiceImpl.java

/**
 * Returns the text of an assessment evaluation notification sample with dates filled in
 * @param assmt Assessment object//  w  ww .  j a  v  a2 s.c  om
 * @return Evaluation notification sample
 */
public String getEvalNotificationSample(Assessment assmt) {
    StringBuilder contents = new StringBuilder();
    BufferedReader input = null;
    String message = null;
    InputStream inputStream = null;

    try {
        inputStream = AttachmentServiceImpl.class.getClassLoader().getResourceAsStream("evalnotif.html");

        input = new BufferedReader(new InputStreamReader(inputStream));

        String line = null;

        while ((line = input.readLine()) != null) {
            contents.append(line);
        }

        message = contents.toString();

        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
        if (assmt != null) {
            Date finalDate;
            if (assmt.getDates().getAcceptUntilDate() != null)
                finalDate = assmt.getDates().getAcceptUntilDate();
            else
                finalDate = assmt.getDates().getDueDate();
            if (assmt.getDates().getOpenDate() != null && finalDate != null) {
                message = message.replace("date.info",
                        "It opens on " + dateFormat.format(assmt.getDates().getOpenDate()) + " and closes on "
                                + dateFormat.format(finalDate) + ".");
            } else {
                if (assmt.getDates().getOpenDate() != null && finalDate == null)
                    message = message.replace("date.info",
                            "It opens on " + dateFormat.format(assmt.getDates().getOpenDate()) + ".");
                if (assmt.getDates().getOpenDate() == null && finalDate != null)
                    message = message.replace("date.info",
                            "It closes on " + dateFormat.format(finalDate) + ".");
                if (assmt.getDates().getOpenDate() == null && finalDate == null)
                    message = message.replace("date.info", " ");
            }
        }
    } catch (Exception e) {
        M_log.warn("Error in getEvalNotificationSample", e);
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
            }
        }

        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {

            }
        }
    }
    return message;
}

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

/**
 * @throws Exception//  w  w w.  j  a  v  a2s . c o  m
 * 
 */
public DeliveryMethodViewBean buildDeliveryMethodViewBean(final RequestData requestData,
        final DeliveryMethod deliveryMethod) throws Exception {
    final MarketArea marketArea = requestData.getMarketArea();
    final Retailer retailer = requestData.getMarketAreaRetailer();

    final DeliveryMethodViewBean deliveryMethodViewBean = new DeliveryMethodViewBean();
    deliveryMethodViewBean.setId(deliveryMethod.getId());

    deliveryMethodViewBean.setVersion(deliveryMethod.getVersion());
    deliveryMethodViewBean.setName(deliveryMethod.getName());
    deliveryMethodViewBean.setDescription(deliveryMethod.getDescription());
    deliveryMethodViewBean.setCode(deliveryMethod.getCode());

    Set<DeliveryMethodPrice> prices = deliveryMethod.getPrices();
    for (DeliveryMethodPrice deliveryMethodPrice : prices) {
        if (deliveryMethodPrice.getMarketAreaId().equals(marketArea.getId())
                && deliveryMethodPrice.getRetailerId().equals(retailer.getId())) {
            deliveryMethodViewBean.setCatalogPrice(deliveryMethodPrice.getPrice().toString());
            deliveryMethodViewBean.setSalePrice(deliveryMethodPrice.getSalePrice().toString());
            deliveryMethodViewBean
                    .setPriceWithCurrencySign(deliveryMethodPrice.getPriceWithStandardCurrencySign());

            deliveryMethodViewBean.setCurrencySign(deliveryMethodPrice.getCurrency().getSign());
            deliveryMethodViewBean.setCurrencyAbbreviated(deliveryMethodPrice.getCurrency().getAbbreviated());

            break;
        }
    }

    DateFormat dateFormat = requestUtil.getFormatDate(requestData, DateFormat.MEDIUM, DateFormat.MEDIUM);
    if (deliveryMethod.getDateCreate() != null) {
        deliveryMethodViewBean.setDateCreate(dateFormat.format(deliveryMethod.getDateCreate()));
    } else {
        deliveryMethodViewBean.setDateCreate("NA");
    }
    if (deliveryMethod.getDateUpdate() != null) {
        deliveryMethodViewBean.setDateUpdate(dateFormat.format(deliveryMethod.getDateUpdate()));
    } else {
        deliveryMethodViewBean.setDateUpdate("NA");
    }

    // TODO : CMS page to describe Delivery Methods
    //        deliveryMethodViewBean.setDetailsUrl(urlService.generateUrl(FoUrls.DELIVERY_METHOD_DETAILS, requestData, deliveryMethod));
    //        deliveryMethodViewBean.setEditUrl(urlService.generateUrl(FoUrls.DELIVERY_METHOD_EDIT, requestData, deliveryMethod));

    return deliveryMethodViewBean;
}

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

/**
 * Generates a certificate with RSA 2048 key length
 * //from w w w. j  a v a  2  s  .c om
 * @throws Exception
 */
private void generateCertificateRSA2048() throws Exception {
    X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder();

    String encodedPublicKey = "30820122300d06092a864886f70d01010105000382010f003082010a0282"
            + "010100804e190456423f3253d25f622b11d6601cce51b2793cb752265461"
            + "6e34804282b081cf0b9389a7160649ce2d62a224201027113a74351b9fda"
            + "7a640d96615615e934cea567b1d809180f034660ab1692d2db3a04cbc439"
            + "a20e947bfe5552a1a32152b7b3501c54c7255943102c5712ec0648823b44"
            + "be3a8c85bf550f3fda7edf8adff1505dffe1fdd8e8100f5808e57f349d5b"
            + "cd41d2fc8cbc3e24e29f02468ecdaa152581e55e068e3e2af0ef5c7ad106"
            + "01934a3e698c485971e69a8820ad7a697b1492bd695747a8dedcbfb72a6f"
            + "f04e4adf8c56bdcc0592cd36288cc1daee35950e9e8676c52fe0fbee02d8"
            + "52c09ff906c7296b12aa2bc972240af9f4720f0203010001";

    String encodedPrivateKey = "308204bd020100300d06092a864886f70d0101010500048204a7308204a3"
            + "0201000282010100804e190456423f3253d25f622b11d6601cce51b2793c"
            + "b7522654616e34804282b081cf0b9389a7160649ce2d62a224201027113a"
            + "74351b9fda7a640d96615615e934cea567b1d809180f034660ab1692d2db"
            + "3a04cbc439a20e947bfe5552a1a32152b7b3501c54c7255943102c5712ec"
            + "0648823b44be3a8c85bf550f3fda7edf8adff1505dffe1fdd8e8100f5808"
            + "e57f349d5bcd41d2fc8cbc3e24e29f02468ecdaa152581e55e068e3e2af0"
            + "ef5c7ad10601934a3e698c485971e69a8820ad7a697b1492bd695747a8de"
            + "dcbfb72a6ff04e4adf8c56bdcc0592cd36288cc1daee35950e9e8676c52f"
            + "e0fbee02d852c09ff906c7296b12aa2bc972240af9f4720f020301000102"
            + "820100307fd4fb0bb42cf9543010782639aee453df358896457a326664bd"
            + "13906aef3941893fff6b3cbc5919f56a2743c2708f622bb25a7b34dc0557"
            + "ebadc86910d01ea6319cef6f3c0da29a628a655f032d1c40f237833a9729"
            + "05f626f09bda1acb18c3eee59bb56b902c5b14dbc1d050f5c91c32ea6f86"
            + "f3b5640ae6a13b8b7287446321e3c7c7543ce9bb95a2329be4e09f8ae3db"
            + "9eb6a886168fa91954595332091bb09580dcc83444c02e63a5915d80eaa8"
            + "894159bc0ec787b7cd897ce26014d537ef731d0f7d7726585fb5193b76e4"
            + "5d9c2baf1f8a80ed84cf15c591d0d09122c4377bdde75b7a72b0aaeec170"
            + "a604ffe77491038762c4125083463a11b7802902818100dcd8b76c1d0599"
            + "0e54a22a65fb5cdb41674f6496fa15b3d09d5b32417a5f02c477a0da482c"
            + "ea27fb3a5c11acf9770b83d66b43ba16d92f927ce6a3dab71ade3a918d97"
            + "b951d3b14ea5edeb8786df83ce46e204ece2c06ab445102ba2c74dff607a"
            + "84933e9f54dd987bf306079e337692df4d0d335f97f302c69106577134d9"
            + "030281810094ba67c454dc1b8cbaff49cde17cdc583319572d29b4f284d1"
            + "0b9740cb468678b0fa196626208406181717a4bc9acfaef8627ce086e0bb"
            + "8c95b14e911be6e8c5569a6c8198dcaa88291fc7d7ec560b19258a3d544c"
            + "8a6a81d09454521921c96f5b1f5c9dfc77c53d6ffe17b59fdfed04381233"
            + "27c1bbed740cab748324346705028181009d216097feaa2df52148644c3d"
            + "251b2714bf4b3d945ffe994e6c457c8af9b0b962b842b699a65c9e062edd"
            + "b0a9aa06ba5dc3e1e3344080f5840281d0aaf8e5e6dc0ad749d6ab7cfb0d"
            + "5a137b50fe15049e304ffacf76c234d2f2a76960cee1059f0656d17681e6"
            + "4c88dc278d220551b73c43d1419d213a98ddf8ef7f259fc94b0281805949"
            + "e39c31da06cc2143bc5a56c23042df429a5ca9ca5142bd81b8e794621dbe"
            + "fd78d8a0c3c90799e50290163d88afa07acc1dee69eb278d8a1ced6f1e92"
            + "2d32b400779e02589024b893b4d583b4506b63672fd499330c282d41afb1"
            + "ae16e3a8efcacf3ea5e07dd09998b1413fdf1e9b46d25e55c2f080e907e6"
            + "3347bc079dc502818021c107a9757dc38395f859e7d59ba1ef12c8719e62"
            + "ebbbf9d720bf29db7c48a19c2c63ab283254cd87ced3415381db08ca2714"
            + "0ea7cbdcf47a3bb091eeb1333caefdda0f78d41c073c166b187195fac3cd"
            + "54ca7ffbbc1056fe7ec2654e126ff09e2da201337f1c7733cbd28f8e2804"
            + "c2eb55c4224f84e28875aafab7a827a687";

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

    X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder();

    String email[] = new String[] { "test@example.com" };

    subjectBuilder.setCommonName("RSA 2048");
    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("115fd1606444bc50de5464af7d0d468", 16);

    Date now = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK)
            .parse("21-Nov-2007 06:38: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("rsa2048", privateKey, null, chain);
}

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

private XYPlot getXYPlot(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, int height,
        int gridLines) throws cfmRunTimeException {
    // Create an XY plot
    XYPlot plot = new XYPlot();
    ValueAxis domainAxis;//from  w w w. j  av  a 2 s. co  m

    if (series.get(0).getSeriesDataType() == cfCHARTSERIESData.XY_NUMERIC_SERIES) {
        if (bShow3D)
            domainAxis = new NumberAxis3D(xAxisTitle);
        else
            domainAxis = new NumberAxis(xAxisTitle);
    } else {
        domainAxis = new DateAxis(xAxisTitle);
    }
    plot.setDomainAxis(domainAxis);

    ValueAxis valueAxis;
    DateFormat dateFormat = null;
    NumberFormat numberFormat = null;
    if (labelFormat.equals("date")) {
        valueAxis = new DateAxis(yAxisTitle);
        dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
        ((DateAxis) valueAxis).setDateFormatOverride(dateFormat);
    } 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);
        XYSeriesCollection dataset;
        if ((barChartDatasetIndex != -1) && (seriesData.getType().equals("bar"))) {
            dataset = (XYSeriesCollection) plot.getDataset(barChartDatasetIndex);

            addSeriesDataToDataset(seriesData, dataset, minMax);

            // Set the paint style for this series
            setPaintStyle(seriesData.getPaintStyle(), plot.getRenderer(barChartDatasetIndex),
                    dataset.getSeriesCount() - 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 = (XYSeriesCollection) plot.getDataset(hBarChartDatasetIndex);

            addSeriesDataToDataset(seriesData, dataset, minMax);

            // Set the paint style for this series
            setPaintStyle(seriesData.getPaintStyle(), plot.getRenderer(hBarChartDatasetIndex),
                    dataset.getSeriesCount() - 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 XYSeriesCollection();

            addSeriesDataToDataset(seriesData, dataset, minMax);
        }

        plot.setDataset(num, dataset);

        XYItemRenderer renderer = null;
        if (seriesData.getType().equals("bar")) {
            plot.setOrientation(PlotOrientation.VERTICAL);
            renderer = getXYBarRenderer(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);
            ((XYBarRenderer) renderer).setMargin(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 = getXYBarRenderer(seriesPlacement, bShow3D, xOffset, yOffset, getColorList(seriesData));
            ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3,
                    TextAnchor.CENTER_LEFT);
            renderer.setPositiveItemLabelPosition(position1);
            ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9,
                    TextAnchor.CENTER_RIGHT);
            renderer.setNegativeItemLabelPosition(position2);
            ((XYBarRenderer) renderer).setMargin(0.2); // The margin between each
                                                       // category

            hBarChartDatasetIndex = num;
        } else if (seriesData.getType().equals("line")) {
            renderer = new XYLineAndShapeRenderer(true, false);

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

            // Set the shape of the markers based on the markerSize value
            ((XYLineAndShapeRenderer) renderer).setShape(getMarker(seriesData.getMarkerStyle(), markerSize));
        } else if (seriesData.getType().equals("area")) {
            renderer = new CustomXYAreaRenderer();
        } else if (seriesData.getType().equals("step")) {
            renderer = new CustomXYStepRenderer();
        } else if (seriesData.getType().equals("scatter")) {
            renderer = new XYLineAndShapeRenderer(false, true);

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

        if (!tipStyle.equals("none")) {
            if (series.get(0).getSeriesDataType() == cfCHARTSERIESData.XY_DATE_SERIES) {
                renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: {1}",
                        DateFormat.getInstance(), DateFormat.getInstance()));
            } else {
                if (dateFormat != null)
                    renderer.setBaseToolTipGenerator(
                            new StandardXYToolTipGenerator("{0}: {2}", dateFormat, dateFormat));
                else
                    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})",
                            numberFormat, NumberFormat.getInstance()));
            }
        }

        if (drillDownUrl != null) {
            if (dateFormat != null)
                renderer.setURLGenerator(
                        new com.newatlanta.bluedragon.XYURLGenerator(drillDownUrl, dateFormat));
            else
                renderer.setURLGenerator(
                        new com.newatlanta.bluedragon.XYURLGenerator(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 {
                setXYItemLabelsData(renderer, seriesData);
                if (dataLabelStyle.equals("value"))
                    renderer.setItemLabelGenerator(
                            new StandardXYItemLabelGenerator("{2}", dateFormat, dateFormat));
                else if (dataLabelStyle.equals("rowlabel"))
                    renderer.setItemLabelGenerator(new StandardXYItemLabelGenerator("{0}",
                            NumberFormat.getInstance(), NumberFormat.getInstance()));
                else if (dataLabelStyle.equals("columnlabel"))
                    renderer.setItemLabelGenerator(new StandardXYItemLabelGenerator("{1}",
                            NumberFormat.getInstance(), NumberFormat.getInstance()));
                else if (dataLabelStyle.equals("pattern"))
                    renderer.setItemLabelGenerator(new XYItemLabelGenerator("{2}", dateFormat, dateFormat));
                else
                    renderer.setItemLabelGenerator(
                            new XYItemLabelGenerator(dataLabelStyle, dateFormat, dateFormat));
            }
        } else {
            if (dataLabelStyle.equals("none")) {
                renderer.setItemLabelsVisible(false);
            } else {
                setXYItemLabelsData(renderer, seriesData);
                if (dataLabelStyle.equals("value")) {

                    renderer.setItemLabelGenerator(
                            new StandardXYItemLabelGenerator("{2}", numberFormat, numberFormat));

                } else if (dataLabelStyle.equals("rowlabel")) {

                    renderer.setItemLabelGenerator(
                            new StandardXYItemLabelGenerator("{0}", numberFormat, numberFormat));

                } else if (dataLabelStyle.equals("columnlabel")) {

                    if (series.get(0).getSeriesDataType() == cfCHARTSERIESData.XY_DATE_SERIES) {
                        renderer.setItemLabelGenerator(new StandardXYItemLabelGenerator("{1}",
                                SimpleDateFormat.getInstance(), NumberFormat.getInstance()));
                    } else {
                        renderer.setItemLabelGenerator(new StandardXYItemLabelGenerator("{1}",
                                NumberFormat.getInstance(), NumberFormat.getInstance()));
                    }

                } else if (dataLabelStyle.equals("pattern")) {

                    if (series.get(0).getSeriesDataType() == cfCHARTSERIESData.XY_DATE_SERIES) {
                        renderer.setItemLabelGenerator(new XYItemLabelGenerator("{1} {2} ({3} of {4})",
                                SimpleDateFormat.getInstance(), numberFormat));
                    } else {
                        renderer.setItemLabelGenerator(new XYItemLabelGenerator("{1} {2} ({3} of {4})",
                                NumberFormat.getInstance(), numberFormat));
                    }

                } else {
                    renderer.setItemLabelGenerator(
                            new XYItemLabelGenerator(dataLabelStyle, NumberFormat.getInstance(), numberFormat));
                }
            }
        }

        // 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;
}