Example usage for java.text DateFormat getDateTimeInstance

List of usage examples for java.text DateFormat getDateTimeInstance

Introduction

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

Prototype

public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale aLocale) 

Source Link

Document

Gets the date/time formatter with the given formatting styles for the given locale.

Usage

From source file:com.sonicle.webtop.mail.Service.java

private String getReplyBody(Message msg, String body, int format, boolean isHtml, String fromtitle,
        String totitle, String cctitle, String datetitle, String subjecttitle, ArrayList<String> attnames)
        throws MessagingException {
    UserProfile profile = environment.getProfile();
    Locale locale = profile.getLocale();
    String msgSubject = msg.getSubject();
    if (msgSubject == null) {
        msgSubject = "";
    }/* w w  w. java 2  s  . co  m*/
    msgSubject = MailUtils.htmlescape(msgSubject);
    Address ad[] = msg.getFrom();
    String msgFrom = "";
    if (ad != null) {
        msgFrom = isHtml ? getHTMLDecodedAddress(ad[0]) : getDecodedAddress(ad[0]);
    }
    java.util.Date dt = msg.getSentDate();
    String msgDate = "";
    if (dt != null) {
        msgDate = DateFormat.getDateTimeInstance(java.text.DateFormat.LONG, java.text.DateFormat.LONG, locale)
                .format(dt);
    }
    ad = msg.getRecipients(Message.RecipientType.TO);
    String msgTo = null;
    if (ad != null) {
        msgTo = "";
        for (int j = 0; j < ad.length; ++j) {
            msgTo += isHtml ? getHTMLDecodedAddress(ad[j]) : getDecodedAddress(ad[j]) + " ";
        }
    }
    ad = msg.getRecipients(Message.RecipientType.CC);
    String msgCc = null;
    if (ad != null) {
        msgCc = "";
        for (int j = 0; j < ad.length; ++j) {
            msgCc += isHtml ? getHTMLDecodedAddress(ad[j]) : getDecodedAddress(ad[j]) + " ";
        }
    }

    //
    /*String sfrom = "";
    try {
       if (msg.getFrom() != null) {
    InternetAddress ia = (InternetAddress) msg.getFrom()[0];
    String personal = ia.getPersonal();
    String mail = ia.getAddress();
    if (personal == null || personal.equals(mail)) {
       sfrom = mail;
    } else {
       sfrom = personal + " <" + mail + ">";
    }
       }
    } catch (Exception exc) {
               
    }*/
    StringBuffer sb = new StringBuffer();
    String cr = "\n";
    if (format != SimpleMessage.FORMAT_TEXT) {
        cr = "<BR>";
    }
    if (format != SimpleMessage.FORMAT_HTML) {
        if (format == SimpleMessage.FORMAT_PREFORMATTED) {
            sb.append("<TT>");
        }
        sb.append(cr + cr + cr
                + "----------------------------------------------------------------------------------" + cr
                + cr);
        sb.append(fromtitle + ": " + msgFrom + cr);
        if (msgTo != null) {
            sb.append(totitle + ": " + msgTo + cr);
        }
        if (msgCc != null) {
            sb.append(cctitle + ": " + msgCc + cr);
        }
        sb.append(datetitle + ": " + msgDate + cr);
        sb.append(subjecttitle + ": " + msgSubject + cr + cr);
        if (format == SimpleMessage.FORMAT_PREFORMATTED) {
            sb.append("</TT>");
        }
    } else {
        sb.append(cr + "<HR>" + cr + cr);
        sb.append("<font face='Arial, Helvetica, sans-serif' size=2>");
        sb.append("<B>" + fromtitle + ":</B> " + msgFrom + "<BR>");
        if (msgTo != null) {
            sb.append("<B>" + totitle + ":</B> " + msgTo + "<BR>");
        }
        if (msgCc != null) {
            sb.append("<B>" + cctitle + ":</B> " + msgCc + "<BR>");
        }
        sb.append("<B>" + datetitle + ":</B> " + msgDate + "<BR>");
        sb.append("<B>" + subjecttitle + ":</B> " + msgSubject + "<BR>");
        sb.append("</font><br>" + cr);
    }

    // Prepend "> " for each line in the body
    //
    if (body != null) {
        if (format == SimpleMessage.FORMAT_HTML) {
            //        sb.append("<TABLE border=0 width='100%'><TR><td width=2 bgcolor=#000088></td><td width=2></td><td>");
            sb.append(
                    "<BLOCKQUOTE style='BORDER-LEFT: #000080 2px solid; MARGIN-LEFT: 5px; PADDING-LEFT: 5px'>");
        }
        if (!isHtml) {
            if (format == SimpleMessage.FORMAT_PREFORMATTED) {
                sb.append(
                        "<BLOCKQUOTE style='BORDER-LEFT: #000080 2px solid; MARGIN-LEFT: 5px; PADDING-LEFT: 5px'>");
                sb.append("<tt>");
            }
            StringTokenizer st = new StringTokenizer(body, "\n", true);
            while (st.hasMoreTokens()) {
                String token = st.nextToken();
                if (token.equals("\n")) {
                    sb.append(cr);
                } else {
                    if (format == SimpleMessage.FORMAT_TEXT) {
                        sb.append("> ");
                    }
                    //sb.append(MailUtils.htmlescape(token));
                    sb.append(token);
                }
            }
            if (format == SimpleMessage.FORMAT_PREFORMATTED) {
                sb.append("</tt>");
                sb.append("</BLOCKQUOTE>");
            }
        } else {
            /*
            //String ubody = body.toUpperCase();
            while (true) {
               int ix1 = StringUtils.indexOfIgnoreCase(body,"<BODY");
               if (ix1 < 0) {
                  break;
               }
               int ix2 = StringUtils.indexOfIgnoreCase(body,">", ix1 + 1);
               if (ix2 < 0) {
                  ix2 = ix1 + 4;
               }
               int ix3 = StringUtils.indexOfIgnoreCase(body,"</BODY", ix2 + 1);
               if (ix3 > 0) {
                  body = body.substring(ix2 + 1, ix3);
               } else {
                  body = body.substring(ix2 + 1);
               }
            }
            //body=removeStartEndTag(body,unwantedTags);
            */

            sb.append(body);
        }
        htmlAppendAttachmentNames(sb, attnames);
        if (format == SimpleMessage.FORMAT_HTML) {
            //        sb.append("</td></tr></table>");
            sb.append("</BLOCKQUOTE>");
        }
    }
    return sb.toString();
}

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

/**
 * Generates a certificate with multiple email addresses
 * //from  w w  w .j  av  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);
}

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

/**
 * Generates a certificate with MD5 Hash algorithm
 * //from   ww w . j  a  va  2  s  .com
 * @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();//from  w  w  w. j a va 2s .  c  o 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 a  2s .  c  o m
 * @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.domainmath.gui.MainFrame.java

public void saveHistory(File file) {
    try {/* w w  w.ja va2  s .  c o  m*/
        try (BufferedWriter r = new BufferedWriter(new FileWriter(file))) {
            DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG,
                    Locale.getDefault());
            r.append("# Created by DomainMath IDE on " + formatter.format(new Date()));
            r.newLine();
            histArea.write(r);
            r.close();
        }

    } catch (Exception re) {
        JOptionPane.showMessageDialog(this, re.toString(), "Error", JOptionPane.ERROR_MESSAGE);

    }
}

From source file:net.wastl.webmail.server.WebMailSession.java

private String formatDate(long date) {
    TimeZone tz = TimeZone.getDefault();
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.DEFAULT, getLocale());
    df.setTimeZone(tz);//w  w w  .  j  ava  2  s. co  m
    String now = df.format(new Date(date));
    return now;
}

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

/**
 * Generates a certificate with RSA 2048 key length
 * //  w w  w. j  av a2s .  c o  m
 * @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:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java

protected void setAxisTickLabels(Axis axis, JRFont tickLabelFont, Paint tickLabelColor, String tickLabelMask,
        AxisSettings axisSettings) {/*w w  w .  j a v a  2 s .  com*/
    boolean axisTickLabelsVisible = axisSettings.getTickLabelsVisible() == null
            || axisSettings.getTickLabelsVisible();//FIXMETHEME axis visibility should be dealt with above;

    axis.setTickLabelsVisible(axisTickLabelsVisible);

    if (axisTickLabelsVisible) {
        JRBaseFont font = new JRBaseFont();
        FontUtil.copyNonNullOwnProperties(axisSettings.getTickLabelFont(), font);
        FontUtil.copyNonNullOwnProperties(tickLabelFont, font);
        font = new JRBaseFont(getChart(), font);
        axis.setTickLabelFont(getFontUtil().getAwtFont(font, getLocale()));

        RectangleInsets tickLabelInsets = axisSettings.getTickLabelInsets();
        if (tickLabelInsets != null) {
            axis.setTickLabelInsets(tickLabelInsets);
        }

        Paint tickLabelPaint = tickLabelColor != null ? tickLabelColor
                : axisSettings.getTickLabelPaint() != null ? axisSettings.getTickLabelPaint().getPaint() : null;

        if (tickLabelPaint != null) {
            axis.setTickLabelPaint(tickLabelPaint);
        }

        TimeZone timeZone = getChartContext().getTimeZone();
        if (axis instanceof DateAxis && timeZone != null) {
            // used when no mask is set
            ((DateAxis) axis).setTimeZone(timeZone);
        }

        if (tickLabelMask != null) {
            if (axis instanceof NumberAxis) {
                NumberFormat fmt = NumberFormat.getInstance(getLocale());
                if (fmt instanceof DecimalFormat)
                    ((DecimalFormat) fmt).applyPattern(tickLabelMask);
                ((NumberAxis) axis).setNumberFormatOverride(fmt);
            } else if (axis instanceof DateAxis) {
                DateFormat fmt;
                if (tickLabelMask.equals("SHORT") || tickLabelMask.equals("DateFormat.SHORT"))
                    fmt = DateFormat.getDateInstance(DateFormat.SHORT, getLocale());
                else if (tickLabelMask.equals("MEDIUM") || tickLabelMask.equals("DateFormat.MEDIUM"))
                    fmt = DateFormat.getDateInstance(DateFormat.MEDIUM, getLocale());
                else if (tickLabelMask.equals("LONG") || tickLabelMask.equals("DateFormat.LONG"))
                    fmt = DateFormat.getDateInstance(DateFormat.LONG, getLocale());
                else if (tickLabelMask.equals("FULL") || tickLabelMask.equals("DateFormat.FULL"))
                    fmt = DateFormat.getDateInstance(DateFormat.FULL, getLocale());
                else
                    fmt = new SimpleDateFormat(tickLabelMask, getLocale());

                // FIXME fmt cannot be null
                if (fmt != null) {
                    if (timeZone != null) {
                        fmt.setTimeZone(timeZone);
                    }

                    ((DateAxis) axis).setDateFormatOverride(fmt);
                } else
                    ((DateAxis) axis).setDateFormatOverride(
                            DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, getLocale()));
            }
            // ignore mask for other axis types.
        }
    }
}

From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java

protected void setAxisTickLabels(Axis axis, JRFont tickLabelFont, Paint tickLabelColor, String tickLabelMask,
        Integer baseFontSize) {//w  w  w .java2  s .  c o  m
    Boolean defaultAxisTickLabelsVisible = (Boolean) getDefaultValue(defaultAxisPropertiesMap,
            ChartThemesConstants.AXIS_TICK_LABELS_VISIBLE);
    if (defaultAxisTickLabelsVisible != null && defaultAxisTickLabelsVisible) {
        Font themeTickLabelFont = getFont(
                (JRFont) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_LABEL_FONT),
                tickLabelFont, baseFontSize);
        axis.setTickLabelFont(themeTickLabelFont);

        RectangleInsets defaultTickLabelInsets = (RectangleInsets) getDefaultValue(defaultAxisPropertiesMap,
                ChartThemesConstants.AXIS_TICK_LABEL_INSETS);
        if (defaultTickLabelInsets != null) {
            axis.setTickLabelInsets(defaultTickLabelInsets);
        }
        Paint tickLabelPaint = tickLabelColor != null ? tickLabelColor
                : (Paint) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_LABEL_PAINT);
        if (tickLabelPaint != null) {
            axis.setTickLabelPaint(tickLabelPaint);
        }

        TimeZone timeZone = getChartContext().getTimeZone();
        if (axis instanceof DateAxis && timeZone != null) {
            // used when no mask is set
            ((DateAxis) axis).setTimeZone(timeZone);
        }

        if (tickLabelMask != null) {
            if (axis instanceof NumberAxis) {
                NumberFormat fmt = NumberFormat.getInstance(getLocale());
                if (fmt instanceof DecimalFormat)
                    ((DecimalFormat) fmt).applyPattern(tickLabelMask);
                ((NumberAxis) axis).setNumberFormatOverride(fmt);
            } else if (axis instanceof DateAxis) {
                DateFormat fmt;
                if (tickLabelMask.equals("SHORT") || tickLabelMask.equals("DateFormat.SHORT"))
                    fmt = DateFormat.getDateInstance(DateFormat.SHORT, getLocale());
                else if (tickLabelMask.equals("MEDIUM") || tickLabelMask.equals("DateFormat.MEDIUM"))
                    fmt = DateFormat.getDateInstance(DateFormat.MEDIUM, getLocale());
                else if (tickLabelMask.equals("LONG") || tickLabelMask.equals("DateFormat.LONG"))
                    fmt = DateFormat.getDateInstance(DateFormat.LONG, getLocale());
                else if (tickLabelMask.equals("FULL") || tickLabelMask.equals("DateFormat.FULL"))
                    fmt = DateFormat.getDateInstance(DateFormat.FULL, getLocale());
                else
                    fmt = new SimpleDateFormat(tickLabelMask, getLocale());

                // FIXME fmt cannot be null
                if (fmt != null) {
                    if (timeZone != null) {
                        fmt.setTimeZone(timeZone);
                    }

                    ((DateAxis) axis).setDateFormatOverride(fmt);
                } else
                    ((DateAxis) axis).setDateFormatOverride(
                            DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, getLocale()));
            }
            // ignore mask for other axis types.
        }
    }
}