List of usage examples for java.text DateFormat getDateTimeInstance
public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle)
From source file:org.apache.commons.vfs.example.Shell.java
/** * Does an 'ls' command.//w ww . j a v a 2 s.com */ private void ls(final String[] cmd) throws FileSystemException { int pos = 1; final boolean recursive; if (cmd.length > pos && cmd[pos].equals("-R")) { recursive = true; pos++; } else { recursive = false; } final FileObject file; if (cmd.length > pos) { file = mgr.resolveFile(cwd, cmd[pos]); } else { file = cwd; } if (file.getType() == FileType.FOLDER) { // List the contents System.out.println("Contents of " + file.getName()); listChildren(file, recursive, ""); } else { // Stat the file System.out.println(file.getName()); final FileContent content = file.getContent(); System.out.println("Size: " + content.getSize() + " bytes."); final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); final String lastMod = dateFormat.format(new Date(content.getLastModifiedTime())); System.out.println("Last modified: " + lastMod); } }
From source file:eu.e43.impeller.Utils.java
public static String humanDate(long milis) { return DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(new Date(milis)) .replace(' ', '\u00A0'); }
From source file:com.nttec.everychan.ui.downloading.HtmlBuilder.java
public void write(SerializablePage page) throws IOException { this.res = MainApplication.getInstance().resources; this.chan = MainApplication.getInstance().getChanModule(page.boardModel.chan); this.pageModel = page.pageModel; this.boardModel = page.boardModel; this.dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); this.dateFormat.setTimeZone(TimeZone.getTimeZone(boardModel.timeZoneId)); String logo = (page.boardModel.boardDescription != null ? page.boardModel.boardDescription : page.boardModel.boardName); try {//from ww w .j a va 2s . com String url = chan.buildUrl(pageModel); logo += " <a href=\"" + url + "\">(" + chan.getChanName() + ")</a>"; } catch (Exception e) { /* ignore */ } buildHeader(buildTitle(page), logo); if (page.posts != null && page.posts.length != 0) { ThreadModel thread = new ThreadModel(); thread.posts = page.posts; thread.threadNumber = page.posts[0].number; thread.postsCount = -1; thread.attachmentsCount = -1; buildThread(thread); } if (page.threads != null) { for (ThreadModel thread : page.threads) buildThread(thread); } buf.write(HTML_FOOTER); buf.flush(); }
From source file:com.nttec.everychan.ui.presentation.PresentationModel.java
/** * ?// www .java 2 s . c om * @param source ?? ? - {@link SerializablePage} * @param localTime ?, ??? ? (? true), ? ?? (? false) * @param reduceNames ? true, ? (. ?) ?? * @param spanClickListener ?? URL ?, ?? ?, ?? e-mail (mailto) * @param imageGetter , ??? ? ? (, ?) * @param theme ? * @param floatingModels ?? ? ?. ? - ? * , - ? ? ? (gif, , ). * ? null, ? . */ public PresentationModel(SerializablePage source, boolean localTime, boolean reduceNames, URLSpanClickListener spanClickListener, ImageGetter imageGetter, Theme theme, FloatingModel[] floatingModels) { if (source.pageModel.type == UrlPageModel.TYPE_OTHERPAGE) throw new IllegalArgumentException(); this.source = source; this.spanClickListener = spanClickListener; this.imageGetter = imageGetter; this.theme = theme; this.floatingModels = floatingModels; this.reduceNames = reduceNames; Database database = MainApplication.getInstance().database; this.isHiddenDelegate = source.pageModel.type == UrlPageModel.TYPE_THREADPAGE ? database.getCachedIsHiddenDelegate(source.pageModel.chanName, source.pageModel.boardName, source.pageModel.threadNumber) : database.getDefaultIsHiddenDelegate(); this.autohideRules = new ArrayList<AutohideActivity.CompiledAutohideRule>(); try { JSONArray autohideJson = new JSONArray(MainApplication.getInstance().settings.getAutohideRulesJson()); for (int i = 0; i < autohideJson.length(); ++i) { AutohideActivity.AutohideRule rule = AutohideActivity.AutohideRule .fromJson(autohideJson.getJSONObject(i)); if (rule.matches(source.pageModel.chanName, source.pageModel.boardName, source.pageModel.threadNumber)) { this.autohideRules.add(new AutohideActivity.CompiledAutohideRule(rule)); } } } catch (Exception e) { Logger.e(TAG, "error while processing regex autohide rules", e); } AndroidDateFormat.initPattern(); String datePattern = AndroidDateFormat.getPattern(); DateFormat dateFormat = datePattern == null ? DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT) : new SimpleDateFormat(datePattern, Locale.US); dateFormat.setTimeZone( localTime ? TimeZone.getDefault() : TimeZone.getTimeZone(source.boardModel.timeZoneId)); this.dateFormat = dateFormat; this.size = getSerializablePageSize(source); }
From source file:op.FrmMain.java
public FrmMain() { initPhase = true;//w w w. j a v a 2s .com initComponents(); if (OPDE.isTraining()) { pnlMainMessage.setBackground(SYSConst.mediumorchid2.brighter().brighter()); } // pbTimeout.setToolTipText(SYSTools.xx("opde.mainframe.pbTimeout.tooltip")); // for the timeout function Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { @Override public void eventDispatched(AWTEvent event) { if (OPDE.getLogin() != null) { displayManager.touch(); } } }, AWTEvent.MOUSE_MOTION_EVENT_MASK); Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { @Override public void eventDispatched(AWTEvent event) { if (OPDE.getLogin() != null) { displayManager.touch(); } } }, AWTEvent.KEY_EVENT_MASK); currentVisiblePanel = null; currentResident = null; lblWait.setText(SYSTools.xx("misc.msg.wait")); lblWait.setVisible(false); listOfNursingrecords = new ArrayList<CollapsiblePane>(); btnHelp.setToolTipText(SYSTools.xx("opde.mainframe.btnHelp.tooltip")); iconPanels = Collections.synchronizedMap(new HashMap<Resident, JPanel>()); if (OPDE.isDebug()) { setSize(1366, 768); } else { this.setExtendedState(JFrame.MAXIMIZED_BOTH); } setTitle(SYSTools.getWindowTitle("")); displayManager = new DisplayManager(pbMsg, lblMainMsg, lblSubMsg, pnlIcons, pbTimeout, new Closure() { @Override public void execute(Object o) { OPDE.debug("TIMEOUT"); logout(); showLogin(); } }); displayManager.start(); printProcessor = new PrintProcessor(); printProcessor.start(); // StatusBar Setup final LabelStatusBarItem label = new LabelStatusBarItem("Line"); label.setText(OPDE.getUrl() + " [Build " + OPDE.getAppInfo().getBuildnum() + "]" + " [JVM " + System.getProperty("java.version") + "]"); if (OPDE.isCustomUrl()) { label.setForeground(Color.RED); } label.setFont(new Font("Arial", Font.PLAIN, 14)); statusBar.add(label, JideBoxLayout.FLEXIBLE); labelUSER = new LabelStatusBarItem("Line"); labelUSER.setText("--"); labelUSER.setAlignment(JLabel.CENTER); labelUSER.setFont(new Font("Arial", Font.PLAIN, 14)); statusBar.add(labelUSER, JideBoxLayout.FLEXIBLE); final TimeStatusBarItem time = new TimeStatusBarItem(); time.setFont(new Font("Arial", Font.PLAIN, 14)); time.setUpdateInterval(10000); time.setTextFormat(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT)); time.setAlignment(JLabel.CENTER); statusBar.add(time, JideBoxLayout.FLEXIBLE); final MemoryStatusBarItem gc = new MemoryStatusBarItem(); gc.setFont(new Font("Arial", Font.PLAIN, 14)); statusBar.add(gc, JideBoxLayout.FLEXIBLE); btnResetSplitpane.setToolTipText(SYSTools.xx("opde.mainframe.btnSplitReset.tooltip")); initPhase = false; // JDialog dlg = new JDialog(this, false); // // JPanel pnl = new JPanel(); // pnl.setLayout(new VerticalLayout()); // // for (float f = 0.0f; f <= 1.0; f = f + 0.01f){ // JLabel lbl = new JLabel(Float.toString(f)); // lbl.setForeground(GUITools.blend(Color.red, Color.WHITE, f)); // pnl.add(lbl); // } // // dlg.setContentPane(new JScrollPane(pnl)); // // dlg.pack(); // dlg.setVisible(true); }
From source file:egovframework.rte.fdl.filehandling.EgovFileUtil.java
/** * <p>/*from www . ja v a 2 s .c o m*/ * ? ??? . * </p> * @param cmd * <code>String[]</code> * @return ? ? ? * @throws FileSystemException */ public List ls(final String[] cmd) throws FileSystemException { List list = new ArrayList(); int pos = 1; final boolean recursive; if (cmd.length > pos && cmd[pos].equals("-R")) { recursive = true; pos++; } else { recursive = false; } final FileObject file; if (cmd.length > pos) { file = manager.resolveFile(basefile, cmd[pos]); } else { file = basefile; } if (file.getType() == FileType.FOLDER) { // List the contents log.info("Contents of " + file.getName()); log.info(listChildren(file, recursive, "")); // list.add(file.getName()); } else { // Stat the file log.info(file.getName()); final FileContent content = file.getContent(); log.info("Size: " + content.getSize() + " bytes."); final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); final String lastMod = dateFormat.format(new Date(content.getLastModifiedTime())); log.info("Last modified: " + lastMod); } return list; }
From source file:cz.zcu.kiv.eegdatabase.wui.ui.experiments.metadata.MetadataForm.java
public MetadataForm(String id, IModel<Section> model, final int experimentId) { super(id);/*www. j av a2 s. c om*/ this.model = new CompoundPropertyModel<Section>(model); setDefaultModel(this.model); setOutputMarkupId(true); wizardModel = new WizardModel(); if (model.getObject() != null) { for (Section section : model.getObject().getSections()) { wizardModel.add(new MetadataWizardStep(new Model<Section>(section))); } } else { wizardModel.add(new WizardStep()); } wizard = new Wizard("wizard", wizardModel, true) { private static final long serialVersionUID = 1L; @Override public void onFinish() { Section data = MetadataForm.this.model.getObject(); Experiment experiment = expFacade.getExperimentForDetail(experimentId); experiment.getElasticExperiment().setMetadata(data); expFacade.update(experiment); setResponsePage(ExperimentsDetailPage.class, PageParametersUtils.getDefaultPageParameters(experimentId)); } @Override public void onCancel() { throw new RestartResponseAtInterceptPageException(MetadataForm.this.getPage().getPageClass(), MetadataForm.this.getPage().getPageParameters()); } }; wizard.setOutputMarkupId(true); add(wizard.setVisible(model.getObject() != null)); int personId = EEGDataBaseSession.get().getLoggedUser().getPersonId(); List<Template> templatesByPerson = templateFacade.getTemplatesByPerson(personId); ChoiceRenderer<Template> templateChoiceRenderer = new ChoiceRenderer<Template>("name", "templateId"); AjaxDropDownChoice<Template> templateSelection = new AjaxDropDownChoice<Template>("template-choice", new Model<Template>(), templatesByPerson, templateChoiceRenderer) { private static final long serialVersionUID = 1L; @Override protected void onSelectionChangeAjaxified(AjaxRequestTarget target, Template template) { try { Reader reader = new Reader(); Section section = reader .load(new ByteInputStream(template.getTemplate(), template.getTemplate().length)); section.setName(template.getName()); MetadataForm.this.model.setObject(section); wizardModel = new WizardModel(); for (Section subsection : section.getSections()) { wizardModel.add(new MetadataWizardStep(new Model<Section>(subsection))); } Wizard wiz = new Wizard("wizard", wizardModel, true) { private static final long serialVersionUID = 1L; @Override public void onFinish() { Section data = MetadataForm.this.model.getObject(); Experiment experiment = expFacade.getExperimentForDetail(experimentId); experiment.getElasticExperiment().setMetadata(data); expFacade.update(experiment); setResponsePage(ExperimentsDetailPage.class, PageParametersUtils.getDefaultPageParameters(experimentId)); } @Override public void onCancel() { throw new RestartResponseAtInterceptPageException( MetadataForm.this.getPage().getPageClass(), MetadataForm.this.getPage().getPageParameters()); } }; wizard = (Wizard) wizard.replaceWith(wiz); } catch (Exception e) { log.error(e.getMessage(), e); error(ResourceUtils.getString("text.template.error.load")); } target.add(MetadataForm.this); } }; add(templateSelection); AjaxLink<Void> saveAsTemplate = new AjaxLink<Void>("saveAsTemplate") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { Section section = MetadataForm.this.model.getObject(); String templateName = section.getName() != null ? section.getName() + "-savedFromWizard" : "Template-savedFromWizard"; Date now = new Date(); templateName += "-" + DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(now); Writer writer = new Writer(section, true, true); ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); if (writer.write(byteStream)) { Template template = new Template(); byte[] templateXML = byteStream.toByteArray(); template.setTemplate(templateXML); template.setName(templateName); template.setPersonByPersonId(EEGDataBaseSession.get().getLoggedUser()); templateFacade.create(template); setResponsePage(ListTemplatePage.class); } else { error(ResourceUtils.getString("text.template.error.save")); } } }; add(saveAsTemplate); }
From source file:org.codehaus.groovy.grails.web.pages.GroovyPageWritable.java
/** * Writes the template to the specified Writer * * @param out The Writer to write to, normally the HttpServletResponse * @return Returns the passed Writer/*from w w w.j av a 2s . co m*/ * @throws IOException */ public Writer writeTo(Writer out) throws IOException { if (showSource) { // Set it to TEXT response.setContentType(GROOVY_SOURCE_CONTENT_TYPE); // must come before response.getOutputStream() writeGroovySourceToResponse(metaInfo, out); } else { // Set it to HTML by default if (metaInfo.getCompilationException() != null) { throw metaInfo.getCompilationException(); } // Set up the script context GroovyPageBinding parentBinding = null; boolean hasRequest = request != null; boolean newParentCreated = false; if (hasRequest) { parentBinding = (GroovyPageBinding) request.getAttribute(GrailsApplicationAttributes.PAGE_SCOPE); if (parentBinding == null) { if (webRequest != null) { parentBinding = new GroovyPageBinding(new GroovyPageRequestBinding(webRequest)); parentBinding.setRoot(true); newParentCreated = true; } } } if (allowSettingContentType && response != null) { // only try to set content type when evaluating top level GSP boolean contentTypeAlreadySet = response.isCommitted() || response.getContentType() != null; if (!contentTypeAlreadySet) { if (LOG.isDebugEnabled()) { LOG.debug("Writing response to [" + response.getClass() + "] with content type: " + metaInfo.getContentType()); } response.setContentType(metaInfo.getContentType()); // must come before response.getWriter() } } GroovyPageBinding binding = createBinding(parentBinding); String previousGspCode = GSP_NONE_CODEC_NAME; if (hasRequest) { request.setAttribute(GrailsApplicationAttributes.PAGE_SCOPE, binding); previousGspCode = (String) request.getAttribute(GrailsApplicationAttributes.GSP_CODEC); } makeLegacyCodecVariablesAvailable(hasRequest, binding); binding.setVariableDirectly(GroovyPage.RESPONSE, response); binding.setVariableDirectly(GroovyPage.REQUEST, request); // support development mode's evaluate (so that doesn't search for missing variable in parent bindings) GroovyPage page = null; try { page = (GroovyPage) metaInfo.getPageClass().newInstance(); } catch (Exception e) { throw new GroovyPagesException("Problem instantiating page class", e); } page.setBinding(binding); binding.setOwner(page); page.initRun(out, webRequest, metaInfo); int debugId = 0; long debugStartTimeMs = 0; if (debugTemplates) { debugId = debugTemplatesIdCounter.incrementAndGet(); out.write("<!-- GSP #"); out.write(String.valueOf(debugId)); out.write(" START template: "); out.write(page.getGroovyPageFileName()); out.write(" precompiled: "); out.write(String.valueOf(metaInfo.isPrecompiledMode())); out.write(" lastmodified: "); out.write(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT) .format(new Date(metaInfo.getLastModified()))); out.write(" -->"); debugStartTimeMs = System.currentTimeMillis(); } try { page.run(); } finally { page.cleanup(); if (hasRequest) { if (newParentCreated) { request.removeAttribute(GrailsApplicationAttributes.PAGE_SCOPE); } else { request.setAttribute(GrailsApplicationAttributes.PAGE_SCOPE, parentBinding); } request.setAttribute(GrailsApplicationAttributes.GSP_CODEC, previousGspCode != null ? previousGspCode : GSP_NONE_CODEC_NAME); } } if (debugTemplates) { out.write("<!-- GSP #"); out.write(String.valueOf(debugId)); out.write(" END template: "); out.write(page.getGroovyPageFileName()); out.write(" rendering time: "); out.write(String.valueOf(System.currentTimeMillis() - debugStartTimeMs)); out.write(" ms -->"); } } return out; }
From source file:org.duniter.elasticsearch.synchro.SynchroService.java
public SynchroResult synchronizePeer(final Peer peer, boolean enableSynchroWebsocket) { long startExecutionTime = System.currentTimeMillis(); // Check if peer alive and valid boolean isAliveAndValid = isAliveAndValid(peer); if (!isAliveAndValid) { logger.warn(String.format("[%s] [%s] Not reachable, or not running on this currency. Skipping.", peer.getCurrency(), peer)); return null; }//www .java 2 s . co m SynchroResult result = new SynchroResult(); // Get the last execution time (or 0 is never synchronized) // If not the first synchro, add a delay to last execution time // to avoid missing data because incorrect clock configuration long lastExecutionTime = forceFullResync ? 0 : getLastExecutionTime(peer); if (logger.isDebugEnabled() && lastExecutionTime > 0) { logger.debug(String.format( "[%s] [%s] Found last synchronization execution at {%s}. Will apply time offset of {-%s ms}", peer.getCurrency(), peer, DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM) .format(new Date(lastExecutionTime * 1000)), pluginSettings.getSynchroTimeOffset())); } final long fromTime = lastExecutionTime > 0 ? lastExecutionTime - pluginSettings.getSynchroTimeOffset() : 0; if (logger.isInfoEnabled()) { if (fromTime == 0) { logger.info(String.format("[%s] [%s] Synchronization {ALL}...", peer.getCurrency(), peer)); } else { logger.info(String.format("[%s] [%s] Synchronization delta since {%s}...", peer.getCurrency(), peer, DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM) .format(new Date(fromTime * 1000)))); } } // Execute actions List<SynchroAction> executedActions = actions.stream() .filter(a -> a.getEndPointApi().name().equals(peer.getApi())).map(a -> { try { a.handleSynchronize(peer, fromTime, result); } catch (Exception e) { logger.error(String.format("[%s] [%s] Failed to execute synchro action: %s", peer.getCurrency(), peer, e.getMessage()), e); } return a; }).collect(Collectors.toList()); if (logger.isDebugEnabled()) { logger.debug(String.format("[%s] [%s] Synchronized in %s ms: %s", peer.getCurrency(), peer, System.currentTimeMillis() - startExecutionTime, result.toString())); } saveExecution(peer, result, startExecutionTime); // Start listen changes on this peer if (enableSynchroWebsocket) { startListenChangesOnPeer(peer, executedActions); } return result; }
From source file:org.grails.web.pages.GroovyPageWritable.java
protected Writer doWriteTo(Writer out) throws IOException { if (showSource) { // Set it to TEXT response.setContentType(GROOVY_SOURCE_CONTENT_TYPE); // must come before response.getOutputStream() writeGroovySourceToResponse(metaInfo, out); } else {/*from w ww . j ava 2 s . c om*/ // Set it to HTML by default if (metaInfo.getCompilationException() != null) { throw metaInfo.getCompilationException(); } // Set up the script context TemplateVariableBinding parentBinding = null; boolean hasRequest = request != null; boolean newParentCreated = false; if (hasRequest) { parentBinding = (TemplateVariableBinding) request .getAttribute(GrailsApplicationAttributes.PAGE_SCOPE); if (parentBinding == null) { if (webRequest != null) { parentBinding = new TemplateVariableBinding( new WebRequestTemplateVariableBinding(webRequest)); parentBinding.setRoot(true); newParentCreated = true; } } } if (allowSettingContentType && response != null) { // only try to set content type when evaluating top level GSP boolean contentTypeAlreadySet = response.isCommitted() || response.getContentType() != null; if (!contentTypeAlreadySet) { if (LOG.isDebugEnabled()) { LOG.debug("Writing response to [" + response.getClass() + "] with content type: " + metaInfo.getContentType()); } response.setContentType(metaInfo.getContentType()); // must come before response.getWriter() } } GroovyPageBinding binding = createBinding(parentBinding); String previousGspCode = GSP_NONE_CODEC_NAME; if (hasRequest) { request.setAttribute(GrailsApplicationAttributes.PAGE_SCOPE, binding); previousGspCode = (String) request.getAttribute(GrailsApplicationAttributes.GSP_CODEC); } makeLegacyCodecVariablesAvailable(hasRequest, binding); binding.setVariableDirectly(GroovyPage.RESPONSE, response); binding.setVariableDirectly(GroovyPage.REQUEST, request); // support development mode's evaluate (so that doesn't search for missing variable in parent bindings) GroovyPage page = null; try { page = (GroovyPage) metaInfo.getPageClass().newInstance(); } catch (Exception e) { throw new GroovyPagesException("Problem instantiating page class", e); } page.setBinding(binding); binding.setOwner(page); page.initRun(out, webRequest, metaInfo); int debugId = 0; long debugStartTimeMs = 0; if (debugTemplates) { debugId = debugTemplatesIdCounter.incrementAndGet(); out.write("<!-- GSP #"); out.write(String.valueOf(debugId)); out.write(" START template: "); out.write(page.getGroovyPageFileName()); out.write(" precompiled: "); out.write(String.valueOf(metaInfo.isPrecompiledMode())); out.write(" lastmodified: "); out.write(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT) .format(new Date(metaInfo.getLastModified()))); out.write(" -->"); debugStartTimeMs = System.currentTimeMillis(); } try { page.run(); } finally { page.cleanup(); if (hasRequest) { if (newParentCreated) { request.removeAttribute(GrailsApplicationAttributes.PAGE_SCOPE); } else { request.setAttribute(GrailsApplicationAttributes.PAGE_SCOPE, parentBinding); } request.setAttribute(GrailsApplicationAttributes.GSP_CODEC, previousGspCode != null ? previousGspCode : GSP_NONE_CODEC_NAME); } } if (debugTemplates) { out.write("<!-- GSP #"); out.write(String.valueOf(debugId)); out.write(" END template: "); out.write(page.getGroovyPageFileName()); out.write(" rendering time: "); out.write(String.valueOf(System.currentTimeMillis() - debugStartTimeMs)); out.write(" ms -->"); } } return out; }