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.sakaiproject.assignment2.logic.impl.ExternalLogicImpl.java

public DateFormat getDateFormat(Integer optionalDateStyle, Integer optionalTimeStyle, Locale locale,
        boolean currentUserTimezone) {
    int dateStyle = optionalDateStyle != null ? optionalDateStyle : DateFormat.MEDIUM;
    int timeStyle = optionalTimeStyle != null ? optionalTimeStyle : DateFormat.SHORT;

    DateFormat df = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);
    if (currentUserTimezone) {
        df.setTimeZone(timeService.getLocalTimeZone());
    }/*w ww . ja v a2 s  . com*/

    return df;
}

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

private void generateCertificateCriticalExtendedKeyUsage() throws Exception {
    X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder();

    String encodedPrivateKey = "30820276020100300d06092a864886f70d0101010500048202603082025c"
            + "0201000281810096990cdd93c7bd2ca4d406285833cd356cc668f2571338"
            + "46fb4dfc885f275bdfb9bf45d539f89e826e442c0a750206a33d40600711"
            + "09ba96eb400710edf90590604e13ff7b624001b4b75c3fd388d18bcd71b4"
            + "c3e4a06c08da3fed5365db5d08cfb10321235da904886ea0329dbf041fa1"
            + "890f97d2b53a366f643dd344cc2e69020301000102818050ee10d6e67ad9"
            + "73ab6471a6aeb7afd8bd0ae70d0cb43c7310cbf9210419afaacc3438fffc"
            + "765a2077c754ef8dafb807737c2bdec04e3d22ab6bae206ff27a05284a96"
            + "015d5437739ffdb6801f537b7b7406e6088a56324105bce1fcfc86bc8a29"
            + "e9adb0ae4152d23f695bfe585557d73da61bf7eb7c1bbdc164afed60e54e"
            + "bd024100ca4e8e4e7e905e4b273d1381f4323ce673d5d33ce5a75f46d719"
            + "8c4ea1bcc13b621f314fa6166cc6193ff912814c54a717b93804b258ec44"
            + "d0a212d371078cdf024100be9133919b1093a3d8c7afa1ff70ab769076c9"
            + "aeb5c548cdc9aef63812a57eccf77f0def9c979cfaf117d8ffb454f823de"
            + "245a1b90da34adaf57b8a561fde5b702407d8dcd51b7c89f4ca2f88bbfce"
            + "2ed38eee7ad8d3656fbf78b68c1b80bd6de8ba9305ead394af3c28a1890b"
            + "6a49a676af10d1198c08a7995287ecde242d74d31f024032a09ac5ad1f8b"
            + "49b536dfc736f8b4e4cbde7318523c366a4d9188e23eb9eee4ff3fa6f128"
            + "75f3038bf79cf3d9f1d4f69a76a7e5b8e6efa5d0f68a1c8ddb0923024100"
            + "b44f03887aa2d95203f3dee44298b12b90c163bffebdc077551208c53987"
            + "11e35c60f8d6348f7fd51f7a384bb397ead4957e37b0440addecc19f9fac" + "b129564b";

    String encodedPublicKey = "30819f300d06092a864886f70d010101050003818d003081890281810096"
            + "990cdd93c7bd2ca4d406285833cd356cc668f257133846fb4dfc885f275b"
            + "dfb9bf45d539f89e826e442c0a750206a33d4060071109ba96eb400710ed"
            + "f90590604e13ff7b624001b4b75c3fd388d18bcd71b4c3e4a06c08da3fed"
            + "5365db5d08cfb10321235da904886ea0329dbf041fa1890f97d2b53a366f" + "643dd344cc2e690203010001";

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

    X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder();

    String email = "test@example.com";

    subjectBuilder.setCommonName("Valid certificate");
    subjectBuilder.setEmail(email);//from w w  w  .j  a va2s  .c  o  m
    subjectBuilder.setCountryCode("NL");
    subjectBuilder.setLocality("Amsterdam");
    subjectBuilder.setState("NH");

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

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

    // use TreeSet because we want a deterministic certificate (ie. hash should not change)
    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("116a448f117ff69fe4f2d4d38f689d7", 16);

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

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

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

    assertNotNull(certificate);

    certificates.add(certificate);

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

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

From source file:org.mifos.framework.util.helpers.DateUtils.java

public static String getDBtoUserFormatString(java.util.Date dbDate, Locale userLocale) {
    // the following line is for 1.1 release and will be removed when date
    // is localized
    userLocale = internalLocale;/*from  w ww.  j  a va 2  s.  c  o m*/
    SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.MEDIUM, userLocale);
    return format.format(dbDate);
}

From source file:org.opencms.workflow.CmsExtendedWorkflowManager.java

/**
 * Generates the description for a new workflow project based on the user for whom it is created.<p>
 *
 * @param userCms the user's current CMS context
 *
 * @return the workflow project description
 *///w ww . j  a  v  a 2 s  . c o  m
protected String generateProjectDescription(CmsObject userCms) {

    CmsUser user = userCms.getRequestContext().getCurrentUser();
    OpenCms.getLocaleManager();
    Locale locale = CmsLocaleManager.getDefaultLocale();
    long time = System.currentTimeMillis();
    Date date = new Date(time);
    DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale);
    String dateString = format.format(date);
    String result = Messages.get().getBundle(locale).key(Messages.GUI_WORKFLOW_PROJECT_DESCRIPTION_2,
            user.getName(), dateString);
    return result;
}

From source file:org.robovm.eclipse.RoboVMPlugin.java

private static String now() {
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
    return df.format(new Date());
}

From source file:org.freeplane.features.format.FormatController.java

private static Integer getDateStyle(final String string) {
    if (string.equals("SHORT"))
        return DateFormat.SHORT;
    if (string.equals("MEDIUM"))
        return DateFormat.MEDIUM;
    if (string.equals("LONG"))
        return DateFormat.LONG;
    if (string.equals("FULL"))
        return DateFormat.FULL;
    return null;/* w  ww  .  j a  v  a2s .  c om*/
}

From source file:gov.nih.nci.ncicb.tcga.dcc.dam.processors.FilePackager.java

private void sendEmailToUser() {
    try {//from   ww  w .j ava  2s  .  co  m
        if (filePackagerBean.getEmail() != null && getMailSender() != null) {
            if (filePackagerBean.isDone()) {
                final StringBuilder buf = new StringBuilder();
                buf.append("The archive you created is available at ").append(filePackagerBean.getLinkText())
                        .append(DOUBLE_LINE_SEPARATOR);
                buf.append("It will be available for download for ").append(getHoursTillDeletion())
                        .append(" hours, after which it will be deleted from our servers.")
                        .append(DOUBLE_LINE_SEPARATOR);

                buf.append(
                        "IMPORTANT: Data downloaders are urged to use the data annotation search interface (https://tcga-data.nci.nih.gov/annotations/) to query the case, sample, and aliquot identifiers in their download to obtain the latest information associated with their data.");
                buf.append(DOUBLE_LINE_SEPARATOR);

                if (filePackagerBean.getFilterRequest() != null) {
                    buf.append(generateFilterTextForEmail());
                }
                if (isEmailTiming()) { //debug performance numbers
                    long fileProcessingTime = endFileProcessingTime - startTime;
                    long archiveGenerationTime = endTime - startArchiveCreationTime;
                    long totalTime = endTime - startTime;
                    long waitingInQueueTime = startTime - filePackagerBean.getCreationTime();
                    Date fpCreationDate = new Date(filePackagerBean.getCreationTime());
                    buf.append(DOUBLE_LINE_SEPARATOR).append("Archive Processing Details: ")
                            .append(DOUBLE_LINE_SEPARATOR);
                    buf.append("Total file processing time: ").append(formatTime(fileProcessingTime))
                            .append(DOUBLE_LINE_SEPARATOR);
                    buf.append("Total archive generation time: ").append(formatTime(archiveGenerationTime))
                            .append(DOUBLE_LINE_SEPARATOR);
                    buf.append("Total processing time: ").append(formatTime(totalTime))
                            .append(DOUBLE_LINE_SEPARATOR);
                    buf.append("When added to queue: ")
                            .append(DateFormat.getTimeInstance(DateFormat.MEDIUM).format(fpCreationDate))
                            .append(DOUBLE_LINE_SEPARATOR);
                    buf.append("Time waiting in queue: ").append(formatTime(waitingInQueueTime))
                            .append(DOUBLE_LINE_SEPARATOR);
                }
                buf.append(DOUBLE_LINE_SEPARATOR).append("The TCGA Data Coordinating Center");
                getMailSender().send(filePackagerBean.getEmail(), null, "Download Available", buf.toString(),
                        false);
            } else if (filePackagerBean.isFailed()) {
                final StringBuilder buf = new StringBuilder();
                String errmsg = filePackagerBean.getException().getMessage();
                if (errmsg == null) {
                    errmsg = filePackagerBean.getException().getClass().toString();
                }
                buf.append("Sorry, we were unable to process your archive. Please try again.")
                        .append(DOUBLE_LINE_SEPARATOR).append("Error message: ").append(errmsg)
                        .append(DOUBLE_LINE_SEPARATOR).append("The TCGA Data Coordinating Center");
                getMailSender().send(filePackagerBean.getEmail(), getFailEmail(), "Download Unavailable",
                        buf.toString(), true);
            }
        }
    } catch (Exception ex) {
        logger.logToLogger(Level.ERROR, "Could not send user email: " + ex.getMessage());
    }
}

From source file:no.abmu.abmstatistikk.annualstatistic.service.hibernate2.AnnualStatisticServiceHelper.java

private void timeStampReport(Map<String, Object> report) {
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM,
            LocaleTypeNameConst.BOKMAAL);

    report.put("timestamp", dateFormat.format(new Date()));
}

From source file:org.opencms.workflow.CmsExtendedWorkflowManager.java

/**
 * Generates the name for a new workflow project based on the user for whom it is created.<p>
 *
 * @param userCms the user's current CMS context
 * @param shortTime if true, the short time format will be used, else the medium time format
 *
 * @return the workflow project name//from  w  w  w  . ja  v a 2s  .c o m
 */
protected String generateProjectName(CmsObject userCms, boolean shortTime) {

    CmsUser user = userCms.getRequestContext().getCurrentUser();
    long time = System.currentTimeMillis();
    Date date = new Date(time);
    OpenCms.getLocaleManager();
    Locale locale = CmsLocaleManager.getDefaultLocale();
    DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    DateFormat timeFormat = DateFormat.getTimeInstance(shortTime ? DateFormat.SHORT : DateFormat.MEDIUM,
            locale);
    String dateStr = dateFormat.format(date) + " " + timeFormat.format(date);
    String username = user.getName();
    String result = Messages.get().getBundle(locale).key(Messages.GUI_WORKFLOW_PROJECT_NAME_2, username,
            dateStr);
    result = result.replaceAll("/", "|");

    return result;
}

From source file:org.openehealth.pors.core.PorsCoreBean.java

/**
 * @see IPorsCore#assembleLoggingEntryDTO(History)
 *///from   w  w w.j  a v  a2 s.c  om
public LoggingEntryDTO assembleLoggingEntryDTO(History loggingEntry) {
    LoggingEntryDTO loggingEntryDto = new LoggingEntryDTO();
    loggingEntryDto.setPorsUserId(loggingEntry.getUserId());
    loggingEntryDto.setUserName(loggingEntry.getUserName());
    loggingEntryDto.setLogTime(loggingEntry.getLogTime());
    loggingEntryDto
            .setLogDateString(DateFormat.getDateInstance(DateFormat.MEDIUM).format(loggingEntry.getLogTime()));

    DateFormat dfmt = new SimpleDateFormat("HH:mm:ss:SS");

    loggingEntryDto.setLogTimeString(dfmt.format(loggingEntry.getLogTime()));
    loggingEntryDto.setDomain(loggingEntry.getDomain());
    loggingEntryDto.setAction(loggingEntry.getAction());
    loggingEntryDto.setLogEntryId(loggingEntry.getLogId());

    return loggingEntryDto;
}