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.wso2.carbon.core.services.loggeduserinfo.LoggedUserInfoAdmin.java

public LoggedUserInfo getUserInfo() throws Exception {
    try {/*w  ww  . j  a va 2 s.  com*/
        MessageContext messageContext = MessageContext.getCurrentMessageContext();
        HttpServletRequest request = (HttpServletRequest) messageContext
                .getProperty("transport.http.servletRequest");
        String userName = (String) request.getSession().getAttribute(ServerConstants.USER_LOGGED_IN);

        int index = userName.indexOf("/");
        if (index < 0) {
            String domainName = (String) request.getSession()
                    .getAttribute(CarbonAuthenticationUtil.LOGGED_IN_DOMAIN);

            if (domainName != null) {
                userName = domainName + "/" + userName;
            }
        }
        LoggedUserInfo loggedUserInfo = new LoggedUserInfo();
        UserRealm userRealm = (UserRealm) PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm();
        List<String> userPermissions = getUserPermissions(userName, userRealm);
        String[] permissions = userPermissions.toArray(new String[userPermissions.size()]);
        loggedUserInfo.setUIPermissionOfUser(permissions);
        Date date = userRealm.getUserStoreManager().getPasswordExpirationTime(userName);
        loggedUserInfo.setUserName(userName);
        if (date != null) {
            DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT);
            DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
            String passwordExpiration = timeFormat.format(date) + " on " + dateFormat.format(date);
            loggedUserInfo.setPasswordExpiration(passwordExpiration);
        }
        return loggedUserInfo;
    } catch (Exception e) {
        log.error(e);
        throw e;
    }
}

From source file:org.springsource.ide.eclipse.commons.gettingstarted.dashboard.BlogsProvider.java

private String buildFeed(SyndEntry entry) {
    String html = "";
    Date entryDate = new Date(0);
    if (entry.getUpdatedDate() != null) {
        entryDate = entry.getUpdatedDate();
    } else {//from  w w w  . j  a va 2 s.  co  m
        entryDate = entry.getPublishedDate();
    }

    String dateString = "";
    if (entryDate != null) {
        dateString = DateFormat.getDateInstance(DateFormat.MEDIUM).format(entryDate);
    }

    String entryAuthor = "";
    if (entry.getAuthor() != null && entry.getAuthor().trim() != "") {
        entryAuthor = entry.getAuthor();
    }
    html += "<div class=\"blog--container blog-preview\">";
    html += "   <div class=\"blog--title\">";
    if (lastUpdated.before(entryDate)) {
        html += "<i class=\"fa fa-star new-star\"></i>";
    }
    if (currentUpdated.before(entryDate)) {
        currentUpdated = entryDate;
    }
    html += "   <a href=\"\" onclick=\"return ide.call('openWebPage', '" + entry.getLink() + "')\">"
            + entry.getTitle() + "</a>";
    html += "   </div>";
    html += "   <div class=\"blog--post\">";
    html += "      <div>";
    html += "         <p>" + trimText(buildDescription(entry));
    html += "      <span class=\"author\">" + entryAuthor + " <i>" + dateString + "</i></span></p>";
    html += "      </div>";
    html += "   </div>";
    html += "</div>";
    return html;
}

From source file:com.exp.tracker.services.impl.EmailServicesHelper.java

/**
 * Sends settlement notice./*ww w.j a v  a  2s  .  c  om*/
 * 
 * @param sb
 *            The settlement bean.
 * @param ul
 *            The user bean list.
 * @param settlementReport
 *            The settlement report pdf bytes.
 * @param expenseReport
 *            The expense report PDF bytes.
 */
protected void sendSettlementNotice(SettlementBean sb, List<UserBean> ul, byte[] settlementReport,
        byte[] expenseReport) {
    // Attachment Map
    Map<String, byte[]> emailAttachments = new HashMap<String, byte[]>();
    emailAttachments.put("SettlementReport.pdf", settlementReport);
    emailAttachments.put("ExpenseReport.pdf", expenseReport);

    for (UserBean ub : ul) {
        // The email id array.
        String[] emailIdStrings = { ub.getEmailId() };
        // Email subject.
        String emailSubject = "New Settlement generated.";
        // Message Content
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("user", ub);
        DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
        String startDate = df.format(sb.getStartDate());
        String endDate = df.format(sb.getEndDate());
        model.put("startDate", startDate);
        model.put("endDate", endDate);

        sendEmailInternal(emailIdStrings, emailSubject,
                "com/exp/tracker/email/templates/velocity/settlement-notice.vm", model, emailAttachments);
    }
}

From source file:com.robestone.hudson.compactcolumns.CompactColumnsTest.java

public void testDateTimeFormats() {
    doTestDateTimeFormats(Locale.US, DateFormat.SHORT, DateFormat.SHORT, "6/24/10 2:56 PM");
    doTestDateTimeFormats(Locale.US, DateFormat.MEDIUM, DateFormat.SHORT, "Jun 24, 2010 2:56 PM");
    doTestDateTimeFormats(Locale.GERMAN, DateFormat.SHORT, DateFormat.SHORT, "24.06.10 14:56");
}

From source file:lucee.commons.i18n.FormatUtil.java

public static DateFormat[] getDateFormats(Locale locale, TimeZone tz, boolean lenient) {
    String id = "d-" + locale.hashCode() + "-" + tz.getID() + "-" + lenient;
    DateFormat[] df = formats.get(id);
    if (df == null) {
        List<DateFormat> list = new ArrayList<DateFormat>();
        list.add(DateFormat.getDateInstance(DateFormat.FULL, locale));
        list.add(DateFormat.getDateInstance(DateFormat.LONG, locale));
        list.add(DateFormat.getDateInstance(DateFormat.MEDIUM, locale));
        list.add(DateFormat.getDateInstance(DateFormat.SHORT, locale));
        addCustom(list, locale, FORMAT_TYPE_DATE);
        df = list.toArray(new DateFormat[list.size()]);

        for (int i = 0; i < df.length; i++) {
            df[i].setLenient(lenient);//  w ww .ja  va 2 s .  c o m
            df[i].setTimeZone(tz);
        }
        formats.put(id, df);
    }
    return df;
}

From source file:org.openvpms.report.IMObjectExpressionEvaluatorTestCase.java

/**
 * Tests the {@link IMObjectExpressionEvaluator#getFormattedValue(String)}
 * method.//from w ww. j av a2s.  c  om
 */
@Test
public void testGetFormattedValue() {
    IArchetypeService service = getArchetypeService();
    ILookupService lookups = getLookupService();

    Party party = createCustomer();
    ActBean act = createAct("act.customerEstimation");
    Date date = java.sql.Date.valueOf("2006-08-04");
    BigDecimal lowTotal = new BigDecimal("100");
    act.setValue("startTime", date);
    act.setValue("lowTotal", lowTotal);
    act.setParticipant("participation.customer", party);

    Functions functions = applicationContext.getBean(Functions.class);
    ExpressionEvaluator eval = new IMObjectExpressionEvaluator(act.getAct(), null, service, lookups, functions);
    String expectedDate = DateFormat.getDateInstance(DateFormat.MEDIUM).format(date);
    assertEquals(expectedDate, eval.getFormattedValue("startTime"));
    assertEquals("$100.00", eval.getFormattedValue("lowTotal"));
    assertEquals("J", eval.getFormattedValue("customer.entity.firstName"));
    assertEquals("Zoo", eval.getFormattedValue("customer.entity.lastName"));

    // test [] expressions
    assertEquals("2.00", eval.getFormattedValue("[1 + 1]"));

    String expression = "[party:getBillingAddress(openvpms:get(., 'customer.entity'))]";
    assertEquals("1234 Foo St\nMelbourne VIC 3001", eval.getFormattedValue(expression));

    // test invalid nodes
    assertEquals("Invalid property name: act.customer.foo", eval.getValue("act.customer.foo"));
}

From source file:org.sakaiproject.lti.impl.LTIExportServiceImpl.java

public void export(OutputStream out, String siteId, ExportType exportType, String filterId) {
    String search = null;//from  w  ww .j  av  a2  s. co  m
    //check if we need to filter the tools by tool_id
    if (StringUtils.isNotEmpty(filterId)) {
        search = "tool_id:" + filterId;
    }
    List<Map<String, Object>> contents = ltiService.getContentsDao(search, null, 0, 0, siteId, isAdmin(siteId));
    LTIExporter exporter = null;
    switch (exportType) {
    case CSV:
        exporter = new ExporterCSV();
        break;
    case EXCEL:
        exporter = new ExporterExcel();
        break;
    }

    if (exporter != null) {
        DateFormat dateFormatter = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM,
                rb.getLocale());

        String attribution_name = serverConfigurationService.getString(
                LTIService.LTI_SITE_ATTRIBUTION_PROPERTY_NAME,
                LTIService.LTI_SITE_ATTRIBUTION_PROPERTY_NAME_DEFAULT);
        if (StringUtils.isNotEmpty(attribution_name)) {
            //check if given property is a translation key
            String aux = rb.getString(attribution_name);
            if (StringUtils.isNotEmpty(aux))
                attribution_name = aux;
        }

        boolean isAdmin = isAdmin(siteId);

        //set header row
        exporter.newLine();
        exporter.addCell(rb.getString("export.title"));
        exporter.addCell(rb.getString("export.url"));
        if (isAdmin) {
            exporter.addCell(rb.getString("export.siteid"));
            exporter.addCell(rb.getString("export.sitetitle"));
        }
        exporter.addCell(rb.getString("export.createdat"));
        if (isAdmin) {
            exporter.addCell(rb.getString("export.sitecontactname"));
            exporter.addCell(rb.getString("export.sitecontactemail"));
            if (StringUtils.isNotEmpty(attribution_name)) {
                exporter.addCell(attribution_name);
            }
        }

        //values rows
        for (Map<String, Object> content : contents) {
            exporter.newLine();
            exporter.addCell((String) content.get("title"));

            String url = (String) content.get("launch");
            if (StringUtils.isEmpty(url)) {
                try {
                    url = (String) (ltiService
                            .getToolDao(new Long(content.get(LTIService.LTI_TOOL_ID).toString()), siteId)
                            .get("launch"));
                } catch (Exception e) {
                    url = "-";
                }
            }
            exporter.addCell(url);

            if (isAdmin) {
                exporter.addCell((String) content.get("SITE_ID"));

                exporter.addCell((String) content.get("SITE_TITLE"));
            }

            try {
                exporter.addCell(dateFormatter.format(content.get("created_at")));
            } catch (Exception e) {
                exporter.addCell("-");
            }

            if (isAdmin) {
                exporter.addCell((String) content.get("SITE_CONTACT_NAME"));

                exporter.addCell((String) content.get("SITE_CONTACT_EMAIL"));

                if (StringUtils.isNotEmpty(attribution_name)) {
                    exporter.addCell((String) content.get("ATTRIBUTION"));
                }
            }
        }

        exporter.write(out);
    } else {
        M_log.error("Error exporting : no exporter found for " + exportType);
    }
}

From source file:org.openvpms.report.ObjectSetExpressionEvaluatorTestCase.java

/**
 * Tests the {@link ObjectSetExpressionEvaluator#getFormattedValue(String)}
 * method.//  w  w  w.  ja  va 2 s  .  co m
 */
@Test
public void testGetFormattedValue() {
    ObjectSet set = new ObjectSet();
    set.set("int", 10);
    set.set("string", "astring");
    set.set("money", new Money(100));
    Date date = java.sql.Date.valueOf("2007-01-11");
    set.set("date", date);
    IMObject customer = createCustomer("Foo", "Bar");
    set.set("act.customer", customer);

    Functions functions = applicationContext.getBean(Functions.class);
    ObjectSetExpressionEvaluator eval = new ObjectSetExpressionEvaluator(set, (PropertySet) null,
            getArchetypeService(), getLookupService(), functions);
    assertEquals("10", eval.getFormattedValue("int"));
    assertEquals("astring", eval.getFormattedValue("string"));
    assertEquals("$100.00", eval.getFormattedValue("money")); // todo localise
    String expectedDate = DateFormat.getDateInstance(DateFormat.MEDIUM).format(date);
    assertEquals(expectedDate, eval.getFormattedValue("date"));
    assertEquals(customer.getName(), eval.getFormattedValue("act.customer"));
    assertEquals("Foo", eval.getFormattedValue("act.customer.firstName"));
    assertEquals("Bar", eval.getFormattedValue("act.customer.lastName"));

    // test invalid nodes
    assertEquals("Invalid object/node name: foo", eval.getFormattedValue("foo"));
    assertEquals("Invalid property name: foo", eval.getFormattedValue("act.customer.foo"));

    // test expressions
    assertEquals("2.00", eval.getFormattedValue("[1 + 1]"));
}

From source file:pl.exsio.ca.module.config.preachers.AssignmentsDataTable.java

@Override
protected void doInit() {
    super.doInit();
    if (this.preacher == null) {
        this.setEnabled(false);
    }//from  ww  w .  ja v a  2s  .  c o m
    this.setHeight("250px");
    Converter dateConverter = new StringToDateConverter() {
        protected DateFormat getFormat(Locale locale) {
            return DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
        }
    };
    this.dataComponent.setConverter("date", dateConverter);
}