List of usage examples for java.text DateFormat getDateInstance
public static final DateFormat getDateInstance(int style)
From source file:ca.oson.json.Oson.java
public <T> Oson setDateFormat(Class<T> type, int style) { cMap(type).setDateFormat(DateFormat.getDateInstance(style)); reset();/*w w w.j av a 2s. c o m*/ return this; }
From source file:org.nuxeo.ecm.core.storage.dbs.DBSSession.java
@Override public Document importDocument(String id, Document parent, String name, String typeName, Map<String, Serializable> properties) throws DocumentException { String parentId = parent == null ? null : parent.getUUID(); boolean isProxy = typeName.equals(CoreSession.IMPORT_PROXY_TYPE); Map<String, Serializable> props = new HashMap<String, Serializable>(); Long pos = null; // TODO pos DBSDocumentState docState;//from w w w . j a v a 2 s. c om if (isProxy) { // check that target exists and find its typeName String targetId = (String) properties.get(CoreSession.IMPORT_PROXY_TARGET_ID); if (targetId == null) { throw new DocumentException("Cannot import proxy " + id + " with null target"); } State targetState = transaction.getStateForRead(targetId); if (targetState == null) { throw new DocumentException("Cannot import proxy " + id + " with missing target " + targetId); } String versionSeriesId = (String) properties.get(CoreSession.IMPORT_PROXY_VERSIONABLE_ID); docState = addProxyState(id, parentId, name, pos, targetId, versionSeriesId); } else { // version & live document props.put(KEY_LIFECYCLE_POLICY, properties.get(CoreSession.IMPORT_LIFECYCLE_POLICY)); props.put(KEY_LIFECYCLE_STATE, properties.get(CoreSession.IMPORT_LIFECYCLE_STATE)); // compat with old lock import @SuppressWarnings("deprecation") String key = (String) properties.get(CoreSession.IMPORT_LOCK); if (key != null) { String[] values = key.split(":"); if (values.length == 2) { String owner = values[0]; Calendar created = new GregorianCalendar(); try { created.setTimeInMillis( DateFormat.getDateInstance(DateFormat.MEDIUM).parse(values[1]).getTime()); } catch (ParseException e) { // use current date } props.put(KEY_LOCK_OWNER, owner); props.put(KEY_LOCK_CREATED, created); } } Serializable importLockOwnerProp = properties.get(CoreSession.IMPORT_LOCK_OWNER); if (importLockOwnerProp != null) { props.put(KEY_LOCK_OWNER, importLockOwnerProp); } Serializable importLockCreatedProp = properties.get(CoreSession.IMPORT_LOCK_CREATED); if (importLockCreatedProp != null) { props.put(KEY_LOCK_CREATED, importLockCreatedProp); } props.put(KEY_MAJOR_VERSION, properties.get(CoreSession.IMPORT_VERSION_MAJOR)); props.put(KEY_MINOR_VERSION, properties.get(CoreSession.IMPORT_VERSION_MINOR)); Boolean isVersion = trueOrNull(properties.get(CoreSession.IMPORT_IS_VERSION)); props.put(KEY_IS_VERSION, isVersion); if (TRUE.equals(isVersion)) { // version props.put(KEY_VERSION_SERIES_ID, properties.get(CoreSession.IMPORT_VERSION_VERSIONABLE_ID)); props.put(KEY_VERSION_CREATED, properties.get(CoreSession.IMPORT_VERSION_CREATED)); props.put(KEY_VERSION_LABEL, properties.get(CoreSession.IMPORT_VERSION_LABEL)); props.put(KEY_VERSION_DESCRIPTION, properties.get(CoreSession.IMPORT_VERSION_DESCRIPTION)); // TODO maybe these should be recomputed at end of import: props.put(KEY_IS_LATEST_VERSION, trueOrNull(properties.get(CoreSession.IMPORT_VERSION_IS_LATEST))); props.put(KEY_IS_LATEST_MAJOR_VERSION, trueOrNull(properties.get(CoreSession.IMPORT_VERSION_IS_LATEST_MAJOR))); } else { // live document props.put(KEY_BASE_VERSION_ID, properties.get(CoreSession.IMPORT_BASE_VERSION_ID)); props.put(KEY_IS_CHECKED_IN, trueOrNull(properties.get(CoreSession.IMPORT_CHECKED_IN))); } docState = createChildState(id, parentId, name, pos, typeName); } for (Entry<String, Serializable> entry : props.entrySet()) { docState.put(entry.getKey(), entry.getValue()); } return getDocument(docState, false); // not readonly }
From source file:org.gbif.ipt.task.Eml2Rtf.java
/** * Add temporal coverages section./*www . j a v a 2 s .c o m*/ * * @param doc Document * @param eml EML * @throws DocumentException if problem occurs during add */ private void addTemporalCoverages(Document doc, Eml eml) throws DocumentException { if (exists(eml.getTemporalCoverages()) && !eml.getTemporalCoverages().isEmpty()) { Paragraph p = new Paragraph(); p.setAlignment(Element.ALIGN_JUSTIFIED); p.setFont(font); DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG); SimpleDateFormat timeFormat = new SimpleDateFormat("SSS"); SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy"); boolean firstCoverage = true; for (TemporalCoverage coverage : eml.getTemporalCoverages()) { if (coverage.getType().equals(TemporalCoverageType.SINGLE_DATE)) { if (coverage.getStartDate() != null) { if (firstCoverage) { firstCoverage = false; } else { p.add(Chunk.NEWLINE); } p.add(new Phrase(getText("rtf.tempcoverage") + ": ", fontTitle)); if (timeFormat.format(coverage.getStartDate()).equals("001")) { p.add(yearFormat.format(coverage.getStartDate())); } else { p.add(dateFormat.format(coverage.getStartDate())); } p.add(Chunk.NEWLINE); } } else if (coverage.getType() == TemporalCoverageType.DATE_RANGE) { if (coverage.getStartDate() != null && coverage.getEndDate() != null) { if (firstCoverage) { firstCoverage = false; } else { p.add(Chunk.NEWLINE); } p.add(new Phrase(getText("rtf.tempcoverage") + ": ", fontTitle)); if (timeFormat.format(coverage.getStartDate()).equals("001")) { p.add(yearFormat.format(coverage.getStartDate())); } else { p.add(dateFormat.format(coverage.getStartDate())); } p.add(" - "); if (timeFormat.format(coverage.getEndDate()).equals("001")) { p.add(yearFormat.format(coverage.getEndDate())); } else { p.add(dateFormat.format(coverage.getEndDate())); } p.add(Chunk.NEWLINE); } } } doc.add(p); p.clear(); } }
From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.MessageCenterFragment.java
protected String createDatestamp(Double seconds) { if (seconds != null && seconds > Double.MIN_VALUE) { Date date = new Date(Math.round(seconds * 1000)); DateFormat mediumDateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM); return mediumDateFormat.format(date); }//from w ww. j a va 2 s. c om return null; }
From source file:org.openehealth.pors.core.PorsCoreBean.java
/** * @see IPorsCore#assembleLoggingEntryDTO(UserHistory) *//*from w w w . j av a2 s .c o m*/ public LoggingEntryDTO assembleLoggingEntryDTO(UserHistory loggingEntry) { LoggingEntryDTO loggingEntryDto = new LoggingEntryDTO(); loggingEntryDto.setPorsUserId(loggingEntry.getEditingUserId()); loggingEntryDto.setUserName(loggingEntry.getEditingUserName()); 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.getDomainId()); return loggingEntryDto; }
From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java
@TargetApi(Build.VERSION_CODES.M) private void loadSecurityPatch() { Preference securityPatchPreference = findPreference(SECURITY_PATCH_KEY); if (!securityPatchPreference.isEnabled()) { return;/*from w w w. ja v a 2 s . c om*/ } String buildSecurityPatch = Build.VERSION.SECURITY_PATCH; final Date date; try { date = new SimpleDateFormat(SECURITY_PATCH_FORMAT).parse(buildSecurityPatch); } catch (ParseException e) { securityPatchPreference.setSummary(getString(R.string.invalid_security_patch, buildSecurityPatch)); return; } String display = DateFormat.getDateInstance(DateFormat.MEDIUM).format(date); securityPatchPreference.setSummary(display); }
From source file:org.nuxeo.ecm.core.api.AbstractSession.java
protected String oldLockKey(Lock lock) { if (lock == null) { return null; }//from ww w .j ava2s . 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.component.app.melete.ModuleDB.java
public void copyModule(Module module, String courseId, String userId) throws MeleteException { ResourceLoader bundle = new ResourceLoader("melete_license"); try {/*from www. j a v a2s . c o m*/ //get module and its sections Module copyMod = new Module(module); String firstName = UserDirectoryService.getCurrentUser().getFirstName(); String lastName = UserDirectoryService.getCurrentUser().getLastName(); DateFormat shortTime = DateFormat.getDateInstance(DateFormat.LONG); copyMod.setCreatedByFname(firstName); copyMod.setCreatedByLname(lastName); copyMod.setTitle(copyMod.getTitle() + " (" + bundle.getString("Copied") + " " + shortTime.format(new Date()) + " )"); ModuleShdates CopyModuleshowdates = new ModuleShdates((ModuleShdates) module.getModuleshdate()); // insert copy module with blank seq_xml and sections as null addModule(copyMod, CopyModuleshowdates, userId, courseId); String copyModSeqXml = module.getSeqXml(); //get sections List<Section> toCopySections = getSections(module.getModuleId().intValue()); if (toCopySections != null && toCopySections.size() > 0) { for (Section toCopySection : toCopySections) { // with title as copy of xxx and sectionResource Section copySection = new Section(toCopySection); copySection.setCreatedByFname(firstName); copySection.setCreatedByLname(lastName); copySection.setModule(copyMod); copySection.setTitle(copySection.getTitle() + " (" + bundle.getString("Copied") + " " + shortTime.format(new Date()) + " )"); //insert section Integer copySectionId = sectionDB.addSection(copyMod, copySection, false); copySection.setSectionId(copySectionId); //copySection.setModule(copyMod); if (toCopySection.getContentType() != null && !toCopySection.getContentType().equals("notype")) { // if section content type is composed than create a new copy if (toCopySection.getContentType().equals("typeEditor")) { String copyModCollId = meleteCHService.getCollectionId("typeEditor", copyMod.getModuleId()); String res_mime_type = meleteCHService.MIME_TYPE_EDITOR; ContentResource cr = meleteCHService .getResource(toCopySection.getSectionResource().getResource().getResourceId()); byte[] secContentData = cr.getContent(); boolean encodingFlag = true; String secResourceName = meleteCHService.getTypeEditorSectionName(copySectionId); String secResourceDescription = "compose content"; ResourcePropertiesEdit res = meleteCHService.fillInSectionResourceProperties( encodingFlag, secResourceName, secResourceDescription); String newResourceId = meleteCHService.addResourceItem(secResourceName, res_mime_type, copyModCollId, secContentData, res); MeleteResource copyMelResource = new MeleteResource( (MeleteResource) toCopySection.getSectionResource().getResource()); copyMelResource.setResourceId(newResourceId); sectionDB.insertMeleteResource(copySection, copyMelResource); } else if (toCopySection.getSectionResource() != null) { // insert section resource with same melete resource MeleteResource copyMr = (MeleteResource) toCopySection.getSectionResource() .getResource(); if (copyMr != null) sectionDB.insertSectionResource(copySection, copyMr); } } // replace with new copied section copyModSeqXml = copyModSeqXml.replace(toCopySection.getSectionId().toString(), copySectionId.toString()); } } // update module seq xml Module copyMod1 = getModule(copyMod.getModuleId()); copyMod1.setSeqXml(copyModSeqXml); updateModule(copyMod1); } catch (Exception ex) { ex.printStackTrace(); throw new MeleteException("copy_fail"); } }
From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java
protected void setAxisTickLabels(Axis axis, JRFont tickLabelFont, Paint tickLabelColor, String tickLabelMask, AxisSettings axisSettings) {//from w w w . ja v a 2s. com boolean axisTickLabelsVisible = axisSettings.getTickLabelsVisible() == null || axisSettings.getTickLabelsVisible().booleanValue();//FIXMETHEME axis visibility should be dealt with above; axis.setTickLabelsVisible(axisTickLabelsVisible); if (axisTickLabelsVisible) { JRBaseFont font = new JRBaseFont(); JRFontUtil.copyNonNullOwnProperties(axisSettings.getTickLabelFont(), font); JRFontUtil.copyNonNullOwnProperties(tickLabelFont, font); font = new JRBaseFont(getChart(), font); axis.setTickLabelFont(JRFontUtil.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(); 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); else if (tickLabelMask.equals("MEDIUM") || tickLabelMask.equals("DateFormat.MEDIUM")) fmt = DateFormat.getDateInstance(DateFormat.MEDIUM); else if (tickLabelMask.equals("LONG") || tickLabelMask.equals("DateFormat.LONG")) fmt = DateFormat.getDateInstance(DateFormat.LONG); else if (tickLabelMask.equals("FULL") || tickLabelMask.equals("DateFormat.FULL")) fmt = DateFormat.getDateInstance(DateFormat.FULL); else fmt = new SimpleDateFormat(tickLabelMask); // 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)); } // ignore mask for other axis types. } } }
From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java
protected void setAxisTickLabels(Axis axis, JRFont tickLabelFont, Paint tickLabelColor, String tickLabelMask, Integer baseFontSize) {// w w w.ja v a 2 s . c o m Boolean defaultAxisTickLabelsVisible = (Boolean) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_LABELS_VISIBLE); if (defaultAxisTickLabelsVisible != null && defaultAxisTickLabelsVisible.booleanValue()) { 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(); 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); else if (tickLabelMask.equals("MEDIUM") || tickLabelMask.equals("DateFormat.MEDIUM")) fmt = DateFormat.getDateInstance(DateFormat.MEDIUM); else if (tickLabelMask.equals("LONG") || tickLabelMask.equals("DateFormat.LONG")) fmt = DateFormat.getDateInstance(DateFormat.LONG); else if (tickLabelMask.equals("FULL") || tickLabelMask.equals("DateFormat.FULL")) fmt = DateFormat.getDateInstance(DateFormat.FULL); else fmt = new SimpleDateFormat(tickLabelMask); // 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)); } // ignore mask for other axis types. } } }