Example usage for java.text DateFormat getDateTimeInstance

List of usage examples for java.text DateFormat getDateTimeInstance

Introduction

In this page you can find the example usage for java.text DateFormat getDateTimeInstance.

Prototype

public static final DateFormat getDateTimeInstance() 

Source Link

Document

Gets the date/time formatter with the default formatting style for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:org.openehr.am.template.PathMap.java

/**
 * Writes this path map to file//from  w ww .j  a  v a2 s  .c  om
 * 
 * @param filename
 * @throws IOException
 */
public void writeToFile(String filename) throws IOException {
    List<String> paths = new ArrayList<String>();
    DateFormat df = DateFormat.getDateTimeInstance();
    paths.add("# Generated path map on " + df.format(new Date()));

    int maxLen = 0;
    String maxLenKey = null;
    for (String key : keyPathMap.keySet()) {
        String path = keyPathMap.get(key);
        if (key.length() > maxLen) {
            maxLen = key.length();
            maxLenKey = key;
        }
        paths.add(key + DELIMITER + path);
    }

    log.debug("max length of key: " + maxLen + ", key: " + maxLenKey);

    File pathMapFile = new File(filename);
    FileUtils.writeLines(pathMapFile, UTF8, paths);

    log.info("total " + (paths.size() - 1) + " line(s) of path written to file");
}

From source file:org.rhq.enterprise.server.alert.engine.model.AvailabilityDurationCacheElement.java

/**
 * Each avail duration check is performed by triggering an execution of {@link AlertAvailabilityDurationJob}.
 * Note that each of the scheduled jobs is relevant to only 1 condition evaluation.
 *   //from   w w w  .  ja  va2  s.  c  om
 * @param cacheElement
 * @param resource
 */
private static void scheduleAvailabilityDurationCheck(AvailabilityDurationCacheElement cacheElement,
        Resource resource) {

    Log log = LogFactory.getLog(AvailabilityDurationCacheElement.class.getName());
    String jobName = AlertAvailabilityDurationJob.class.getName();
    String jobGroupName = AlertAvailabilityDurationJob.class.getName();
    String operator = cacheElement.getAlertConditionOperator().name();
    String triggerName = operator + "-" + resource.getId();
    String duration = (String) cacheElement.getAlertConditionOperatorOption();
    // convert from seconds to milliseconds
    Date jobTime = new Date(System.currentTimeMillis() + (Long.valueOf(duration).longValue() * 1000));

    if (log.isDebugEnabled()) {
        log.debug("Scheduling availability duration job for ["
                + DateFormat.getDateTimeInstance().format(jobTime) + "]");
    }

    JobDataMap jobDataMap = new JobDataMap();
    // the condition id is needed to ensure we limit the future avail checking to the one relevant alert condition
    jobDataMap.put(AlertAvailabilityDurationJob.DATAMAP_CONDITION_ID,
            String.valueOf(cacheElement.getAlertConditionTriggerId()));
    jobDataMap.put(AlertAvailabilityDurationJob.DATAMAP_RESOURCE_ID, String.valueOf(resource.getId()));
    jobDataMap.put(AlertAvailabilityDurationJob.DATAMAP_OPERATOR, operator);
    jobDataMap.put(AlertAvailabilityDurationJob.DATAMAP_DURATION, duration);

    Trigger trigger = new SimpleTrigger(triggerName, jobGroupName, jobTime);
    trigger.setJobName(jobName);
    trigger.setJobGroup(jobGroupName);
    trigger.setJobDataMap(jobDataMap);
    try {
        LookupUtil.getSchedulerBean().scheduleJob(trigger);
    } catch (Throwable t) {
        log.warn("Unable to schedule availability duration job for [" + resource + "] with JobData ["
                + jobDataMap.values() + "]", t);
    }
}

From source file:au.org.ala.delta.editor.directives.ImportExportStatus.java

private String currentTime() {
    DateFormat dateFormat = DateFormat.getDateTimeInstance();
    return dateFormat.format(new Date());
}

From source file:org.open18.action.TimerBeanImpl.java

public TimerBeanImpl() {
    dateFormatter = DateFormat.getDateTimeInstance();
    myId = ++id;
}

From source file:org.craftercms.security.authentication.impl.AuthenticationCookieFactory.java

/**
 * Returns the profile outdated after component of the cookie.
 *///from  w  ww  .j  a va2  s.c  o m
protected Date getProfileOutdatedAfterDate(String[] cookieData) {
    try {
        return DateFormat.getDateTimeInstance().parse(cookieData[PROFILE_OUTDATED_AFTER]);
    } catch (ParseException e) {
        throw new InvalidCookieException("Profile cookie: profile-outdated-after date has an invalid format",
                e);
    }
}

From source file:org.rhq.plugins.platform.win.WindowsSoftwareDelegate.java

private static Long getDate(String dateString) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

    Date date = null;// w  w  w . j  av  a2 s  . c  o m

    try {
        date = sdf.parse(dateString);
    } catch (ParseException e) {

        DateFormat df = DateFormat.getDateTimeInstance();
        try {
            date = df.parse(dateString);
        } catch (ParseException e1) {
            /* Poorly formatted dates are ignored */
        }
    }

    return (date == null ? null : date.getTime());
}

From source file:org.jamwiki.servlets.HistoryServlet.java

/**
  */*from ww  w  .ja v a2s .c om*/
  */
private void viewVersion(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo)
        throws Exception {
    // display an older version
    String virtualWiki = pageInfo.getVirtualWikiName();
    String topicName = WikiUtil.getTopicFromRequest(request);
    Long topicVersionId = Long.parseLong(request.getParameter("topicVersionId"));
    TopicVersion topicVersion = WikiBase.getDataHandler().lookupTopicVersion(topicVersionId);
    if (topicVersion == null) {
        throw new WikiException(new WikiMessage("common.exception.notopic"));
    }
    Topic topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null);
    if (topic == null) {
        // the topic may have been deleted
        throw new WikiException(new WikiMessage("history.message.notopic", topicName));
    }
    topic.setTopicContent(topicVersion.getVersionContent());
    String versionDate = DateFormat.getDateTimeInstance().format(topicVersion.getEditDate());
    WikiMessage pageTitle = new WikiMessage("topic.title", topicName + " @" + versionDate);
    ServletUtil.viewTopic(request, next, pageInfo, pageTitle, topic, false, false);
}

From source file:org.nema.medical.mint.server.controller.ChangeLogController.java

@RequestMapping("/changelog")
public void changelogXML(@RequestParam(value = "since", required = false) final String since,
        @RequestParam(value = "limit", required = false) Integer limit,
        @RequestParam(value = "offset", required = false) Integer offset,
        @RequestParam(value = "consolidate", required = false, defaultValue = "true") boolean consolidate,
        final HttpServletResponse res) throws IOException, JiBXException {

    final List<org.nema.medical.mint.changelog.Change> changes = new ArrayList<org.nema.medical.mint.changelog.Change>();

    // TODO read limit from a config file
    if (limit == null) {
        limit = 50;/*  w ww  .j a v a  2  s. c  om*/
    }
    if (offset == null) {
        offset = 0;
    }
    final int firstIndex = offset * limit;

    final List<Change> changesFound;

    if (consolidate) {
        //only get a list of most recent changes for each study
        changesFound = changeDAO.findLastChanges();
    } else {
        if (since != null) {
            final Date date;
            try {
                final ISO8601DateUtils dateUtil = new org.nema.medical.mint.utils.JodaDateUtils();
                date = dateUtil.parseISO8601Basic(since);
            } catch (final DateTimeParseException e) {
                res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid date: " + since);
                return;
            }
            if (date.getTime() > System.currentTimeMillis()) {
                LOG.warn(String.format("Changelog requested with invalid future start date %s",
                        DateFormat.getDateTimeInstance().format(date)));
                res.setStatus(HttpServletResponse.SC_NO_CONTENT);
                return;
            }
            changesFound = changeDAO.findChanges(date, firstIndex, limit);
        } else {
            changesFound = changeDAO.findChanges(firstIndex, limit);
        }
    }

    if (changesFound != null) {
        for (final Change change : changesFound) {
            changes.add(new org.nema.medical.mint.changelog.Change(change.getStudyUUID(), change.getIndex(),
                    change.getType(), change.getDateTime(), change.getRemoteHost(), change.getRemoteUser(),
                    change.getOperation()));
        }
    }

    res.setBufferSize(fileResponseBufferSize);
    final ChangeSet changeSet = new ChangeSet(changes);
    final IBindingFactory bfact = BindingDirectory.getFactory("serverChangelog", ChangeSet.class);
    final IMarshallingContext mctx = bfact.createMarshallingContext();
    mctx.setIndent(2);
    mctx.startDocument("UTF-8", null, res.getOutputStream());
    mctx.getXmlWriter().writePI("xml-stylesheet", xmlStylesheet);
    mctx.marshalDocument(changeSet);
    mctx.endDocument();
}

From source file:org.cleverbus.core.common.version.VersionInfo.java

public String getDate() {
    try {/*ww  w.j a  v a  2 s  .  c o  m*/
        return DateFormat.getDateTimeInstance().format(new Date(Long.valueOf(getTimestamp())));
    } catch (Exception e) {
        return EMPTY;
    }
}

From source file:de.xwic.sandbox.server.installer.XmlExport.java

/**
 * @param secDump/*w ww.  ja  va2 s  . c  o m*/
 */
public void exportSecurity(File secDump) throws IOException, ConfigurationException {

    Document doc = DocumentFactory.getInstance().createDocument();
    Element root = doc.addElement(ELM_EXPORT);
    root.addAttribute("type", "security");

    Element info = root.addElement(ELM_EXPORTDDATE);
    info.setText(DateFormat.getDateTimeInstance().format(new Date()));

    Element data = root.addElement(ELM_DATA);

    addAll(IActionDAO.class, data);
    addAll(IActionSetDAO.class, data);
    addAll(IScopeDAO.class, data);
    addAll(IRoleDAO.class, data);
    addAll(IRightDAO.class, data);
    addAll(IUserDAO.class, data);

    OutputFormat prettyFormat = OutputFormat.createPrettyPrint();
    OutputStream out = new FileOutputStream(secDump);
    XMLWriter writer = new XMLWriter(out, prettyFormat);
    writer.write(doc);
    writer.flush();
    out.close();

}