List of usage examples for java.text DateFormat MEDIUM
int MEDIUM
To view the source code for java.text DateFormat MEDIUM.
Click Source Link
From source file:org.nuxeo.ecm.platform.ui.web.component.seam.UICellExcel.java
/** * Converts string value as returned by widget to the target type for an accurate cell format in the XLS/CSV export. * <ul>//from www . j av a2 s . c om * <li>If force type is set to "number", convert value to a double (null if empty).</li> * <li>If force type is set to "bool", convert value to a boolean (null if empty).</li> * <li>If force type is set to "date", convert value to a date using most frequent date parsers using the short, * medium, long and full formats and current locale, trying first with time information and after with only date * information. Returns null if date is empty or could not be parsed.</li> * </ul> * * @since 5.6 */ protected Object convertStringToTargetType(String value, String forceType) { if (CellType.number.name().equals(forceType)) { if (StringUtils.isBlank(value)) { return null; } return Double.valueOf(value); } else if (CellType.date.name().equals(forceType)) { if (StringUtils.isBlank(value)) { return null; } Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); int[] formats = { DateFormat.SHORT, DateFormat.MEDIUM, DateFormat.LONG, DateFormat.FULL }; for (int format : formats) { try { return DateFormat.getDateTimeInstance(format, format, locale).parse(value); } catch (ParseException e) { // ignore } try { return DateFormat.getDateInstance(format, locale).parse(value); } catch (ParseException e) { // ignore } } log.warn("Could not convert value to a date instance: " + value); return null; } else if (CellType.bool.name().equals(forceType)) { if (StringUtils.isBlank(value)) { return null; } return Boolean.valueOf(value); } return value; }
From source file:org.jactr.eclipse.runtime.launching.env.EnvironmentConfigurator.java
static public IFile createRuntimeEnvironmentFile(ILaunchConfiguration config, String mode, IProgressMonitor monitor) throws CoreException { /*/*from www .j a v a 2 s .com*/ * make sure we have runs/ */ IFile configurationFile = null; IProject project = ACTRLaunchConfigurationUtils.getProject(config); if (config.getAttribute(ACTRLaunchConstants.ATTR_SAVE_RUN, true)) { IFolder runtimeFolder = project.getFolder("runs"); if (!runtimeFolder.exists()) runtimeFolder.create(true, true, monitor); /* * create {now} */ Date now = new Date(); DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); String name = df.format(now); name = name.replace("/", "."); IFolder thisRun = runtimeFolder.getFolder(name); if (!thisRun.exists()) thisRun.create(true, true, monitor); df = DateFormat.getTimeInstance(DateFormat.MEDIUM); name = df.format(now).replace(":", ".").replace(" ", ""); thisRun = thisRun.getFolder(name); if (!thisRun.exists()) thisRun.create(true, true, monitor); configurationFile = thisRun.getFile("environment.xml"); } else { // tmp directory and temp file IPath workingLocation = project.getWorkingLocation(RuntimePlugin.PLUGIN_ID); workingLocation.append("/tmp/"); IFolder tmpLocation = project.getFolder(workingLocation); tmpLocation.create(true, true, monitor); // TODO this could screw up if you try to run multiple instances at once configurationFile = tmpLocation.getFile(project.getName() + "-environment.xml"); } return configurationFile; }
From source file:lucee.commons.i18n.FormatUtil.java
public static DateFormat[] getTimeFormats(Locale locale, TimeZone tz, boolean lenient) { String id = "t-" + locale.hashCode() + "-" + tz.getID() + "-" + lenient; DateFormat[] df = formats.get(id); if (df == null) { List<DateFormat> list = new ArrayList<DateFormat>(); list.add(DateFormat.getTimeInstance(DateFormat.FULL, locale)); list.add(DateFormat.getTimeInstance(DateFormat.LONG, locale)); list.add(DateFormat.getTimeInstance(DateFormat.MEDIUM, locale)); list.add(DateFormat.getTimeInstance(DateFormat.SHORT, locale)); add24(list, locale);/*from w w w . j a va2 s .c o m*/ addCustom(list, locale, FORMAT_TYPE_TIME); df = list.toArray(new DateFormat[list.size()]); for (int i = 0; i < df.length; i++) { df[i].setLenient(lenient); df[i].setTimeZone(tz); } formats.put(id, df); } return df; }
From source file:org.openvpms.web.resource.i18n.format.DateFormatter.java
/** * Returns a time format./* w w w.ja v a2s . c o m*/ * <p/> * This will use the <em>time.format.edit</em> and <em>time.format.view</em> properties if specified in * <em>messages.properties</em>, else it will fall back to those provided by the locale. * * @param edit if {@code true} return a format for editing otherwise * return a format for viewing dates * @return a date format */ public static DateFormat getTimeFormat(boolean edit) { DateFormat format; Locale locale = Messages.getLocale(); String pattern = (edit) ? TIME_EDIT_PATTERN : TIME_VIEW_PATTERN; if (pattern == null) { if (edit) { // specify SHORT style when parsing, so that 2 digit years // are handled correctly format = DateFormat.getTimeInstance(DateFormat.SHORT, locale); } else { format = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale); } } else { format = new SimpleDateFormat(pattern, locale); } return format; }
From source file:org.webguitoolkit.ui.util.export.PDFEvent.java
public void onEndPage(PdfWriter writer, Document document) { TableExportOptions exportOptions = wgtTable.getExportOptions(); try {//from w ww . j a v a2 s . co m Rectangle page = document.getPageSize(); if (exportOptions.isShowDefaultHeader() || StringUtils.isNotEmpty(exportOptions.getHeaderImage())) { PdfPTable head = new PdfPTable(3); head.getDefaultCell().setBorder(Rectangle.NO_BORDER); Paragraph title = new Paragraph(wgtTable.getTitle()); title.setAlignment(Element.ALIGN_LEFT); head.addCell(title); Paragraph empty = new Paragraph(""); head.addCell(empty); if (StringUtils.isNotEmpty(exportOptions.getHeaderImage())) { try { URL absoluteFileUrl = wgtTable.getPage().getClass() .getResource("/" + exportOptions.getHeaderImage()); if (absoluteFileUrl != null) { String path = absoluteFileUrl.getPath(); Image jpg = Image.getInstance(path); jpg.scaleAbsoluteHeight(40); jpg.scaleAbsoluteWidth(200); head.addCell(jpg); } } catch (Exception e) { logger.error(e.getMessage()); Paragraph noImage = new Paragraph("Image not found!"); head.addCell(noImage); } } else { head.addCell(empty); } head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent()); } if (exportOptions.isShowDefaultFooter() || StringUtils.isNotEmpty(exportOptions.getFooterText()) || exportOptions.isShowPageNumber()) { PdfPTable foot = new PdfPTable(3); String footerText = exportOptions.getFooterText() != null ? exportOptions.getFooterText() : ""; if (!exportOptions.isShowDefaultFooter()) { foot.addCell(new Paragraph(footerText)); foot.addCell(new Paragraph("")); } else { foot.getDefaultCell().setBorder(Rectangle.NO_BORDER); String leftText = ""; if (StringUtils.isNotEmpty(exportOptions.getFooterText())) { leftText = exportOptions.getFooterText(); } Paragraph left = new Paragraph(leftText); left.setAlignment(Element.ALIGN_LEFT); foot.addCell(left); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM, TextService.getLocale()); Date today = new Date(); String date = df.format(today); Paragraph center = new Paragraph(date); center.setAlignment(Element.ALIGN_CENTER); foot.addCell(center); } if (exportOptions.isShowPageNumber()) { Paragraph right = new Paragraph( TextService.getString("pdf.page@Page:") + " " + writer.getPageNumber()); right.setAlignment(Element.ALIGN_LEFT); foot.addCell(right); foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(), writer.getDirectContent()); } else { foot.addCell(new Paragraph("")); } } } catch (Exception e) { throw new ExceptionConverter(e); } }
From source file:com.egoists.coco_nut.android.util.EtcUtils.java
public static String getSimpleDateString(long millis) { String time = null;//w w w . j av a2s . c om if (Locale.getDefault().equals(Locale.KOREA) || Locale.getDefault().equals(Locale.KOREAN)) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy M d? a h mm", Locale.getDefault()); time = formatter.format(new Date(millis)); } else { time = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.getDefault()) .format(new Date(millis)); } return time; }
From source file:org.mariotaku.twidere.adapter.DirectMessagesEntryAdapter.java
@Override public void bindView(final View view, final Context context, final Cursor cursor) { final DirectMessageEntryViewHolder holder = (DirectMessageEntryViewHolder) view.getTag(); final long account_id = cursor.getLong(ConversationsEntry.IDX_ACCOUNT_ID); final long conversation_id = cursor.getLong(ConversationsEntry.IDX_CONVERSATION_ID); final long message_timestamp = cursor.getLong(ConversationsEntry.IDX_MESSAGE_TIMESTAMP); final boolean is_outgoing = cursor.getInt(ConversationsEntry.IDX_IS_OUTGOING) == 1; final String name = cursor.getString(IDX_NAME); final String screen_name = cursor.getString(IDX_SCREEN_NAME); holder.setAccountColorEnabled(mShowAccountColor); if (mShowAccountColor) { holder.setAccountColor(getAccountColor(mContext, account_id)); }/*from ww w.j a v a2 s. c om*/ if (!mFastProcessingEnabled) { holder.setUserColor(getUserColor(mContext, conversation_id)); } else { holder.setUserColor(Color.TRANSPARENT); } holder.setTextSize(mTextSize); switch (mNameDisplayOption) { case NAME_DISPLAY_OPTION_CODE_NAME: { holder.name.setText(name); holder.screen_name.setText(null); holder.screen_name.setVisibility(View.GONE); break; } case NAME_DISPLAY_OPTION_CODE_SCREEN_NAME: { holder.name.setText("@" + screen_name); holder.screen_name.setText(null); holder.screen_name.setVisibility(View.GONE); break; } default: { holder.name.setText(name); holder.screen_name.setText("@" + screen_name); holder.screen_name.setVisibility(View.VISIBLE); break; } } holder.text.setText(toPlainText(cursor.getString(IDX_TEXT))); if (mShowAbsoluteTime) { holder.time.setText(formatSameDayTime(message_timestamp, System.currentTimeMillis(), DateFormat.MEDIUM, DateFormat.SHORT)); } else { holder.time.setText(getRelativeTimeSpanString(message_timestamp)); } holder.time.setCompoundDrawablesWithIntrinsicBounds(0, 0, is_outgoing ? R.drawable.ic_indicator_outgoing : R.drawable.ic_indicator_incoming, 0); holder.profile_image.setVisibility(mDisplayProfileImage ? View.VISIBLE : View.GONE); if (mDisplayProfileImage) { final String profile_image_url_string = cursor.getString(IDX_PROFILE_IMAGE_URL); mProfileImageLoader.displayImage(holder.profile_image, profile_image_url_string); } super.bindView(view, context, cursor); }
From source file:org.apache.hadoop.http.StaticServlet.java
public String getListHTML(Resource resource, String base, boolean parent) throws IOException { base = URIUtil.canonicalPath(base);// w ww . j a v a 2 s . co m if (base == null || !resource.isDirectory()) return null; String[] ls = resource.list(); if (ls == null) return null; Arrays.sort(ls); String decodedBase = URIUtil.decodePath(base); String title = "Directory: " + deTag(decodedBase); StringBuffer buf = new StringBuffer(4096); buf.append("<HTML><HEAD><TITLE>"); buf.append(title); buf.append("</TITLE></HEAD><BODY>\n<H1>"); buf.append(title); buf.append("</H1>\n<TABLE BORDER=0>\n"); if (parent) { buf.append("<TR><TD><A HREF=\""); buf.append(URIUtil.addPaths(base, "../")); buf.append("\">Parent Directory</A></TD><TD></TD><TD></TD></TR>\n"); } String defangedBase = defangURI(base); DateFormat dfmt = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); for (int i = 0; i < ls.length; i++) { Resource item = resource.addPath(ls[i]); buf.append("\n<TR><TD><A HREF=\""); String path = URIUtil.addPaths(defangedBase, URIUtil.encodePath(ls[i])); buf.append(URIUtil.encodePath(ls[i])); if (item.isDirectory() && !path.endsWith("/")) buf.append(URIUtil.SLASH); // URIUtil.encodePath(buf,path); buf.append("\">"); buf.append(deTag(ls[i])); buf.append(" "); buf.append("</TD><TD ALIGN=right>"); buf.append(item.length()); buf.append(" bytes </TD><TD>"); buf.append(dfmt.format(new Date(item.lastModified()))); buf.append("</TD></TR>"); } buf.append("</TABLE>\n"); buf.append("</BODY></HTML>\n"); return buf.toString(); }
From source file:org.telscenter.sail.webapp.presentation.web.controllers.student.brainstorm.XMLBrainstorm.java
public static String getXMLComment(Comment comment) { Date timestamp = comment.getTimestamp(); String formattedTime = DateFormat.getTimeInstance(DateFormat.SHORT).format(timestamp); String formattedDate = DateFormat.getDateInstance(DateFormat.MEDIUM).format(timestamp); String XMLComment = "<comment><id>" + comment.getId() + "</id><timestamp>" + formattedTime + " " + formattedDate + "</timestamp>" + getXMLWorkgroup(comment.getWorkgroup()) + "<body>" + StringEscapeUtils.escapeHtml(comment.getBody()) + "</body><anon>" + comment.isAnonymous() + "</anon></comment>"; return XMLComment; }