Example usage for java.text SimpleDateFormat applyPattern

List of usage examples for java.text SimpleDateFormat applyPattern

Introduction

In this page you can find the example usage for java.text SimpleDateFormat applyPattern.

Prototype

public void applyPattern(String pattern) 

Source Link

Document

Applies the given pattern string to this date format.

Usage

From source file:org.sakaiproject.assignment2.logic.impl.ExternalContentReviewLogicImpl.java

public void createAssignment(Assignment2 assign) {
    Map opts = new HashMap();

    String[] tiioptKeys = new String[] { "submit_papers_to", "report_gen_speed", "s_paper_check",
            "internet_check", "journal_check", "institution_check", "s_view_report", "erater", "ets_handbook",
            "ets_dictionary", "ets_spelling", "ets_style", "ets_grammar", "ets_mechanics", "ets_usage" };

    for (Object key : assign.getProperties().keySet()) {
        if (ArrayUtil.contains(tiioptKeys, key)) {
            if (assign.getProperties().get(key) instanceof Boolean) {
                if (((Boolean) assign.getProperties().get(key)).booleanValue()) {
                    opts.put(key, "1");
                } else {
                    opts.put(key, "0");
                }/*from ww w .j a va  2s. com*/
            } else {
                opts.put(key.toString(), assign.getProperties().get(key).toString());
            }
        }
    }

    // ONC-2486
    opts.put("late_accept_flag", "1");

    SimpleDateFormat dform = ((SimpleDateFormat) DateFormat.getDateInstance());
    dform.applyPattern("yyyy-MM-dd HH:mm:ss");

    if (assign.getOpenDate() != null) {
        opts.put("dtstart", dform.format(assign.getOpenDate()));
    }

    if (assign.getDueDate() != null) {
        opts.put("dtdue", dform.format(assign.getDueDate()));
    }

    try {
        opts.put("title", assign.getTitle());
        contentReview.createAssignment(assign.getContextId(), this.getTaskId(assign), opts);
    } catch (Exception e) {
        log.warn("Exception saving Turnitin settings", e);
        throw new ContentReviewException("An exception occurred attempting to save TII settings", e);
    }
}

From source file:com.smi.travel.datalayer.dao.impl.TicketFareAirlineImpl.java

public String generatePVCode() {
    String PVCode = "";
    Session session = this.sessionFactory.openSession();
    List<MRunningCode> list = new LinkedList<MRunningCode>();
    Date thisdate = new Date();
    SimpleDateFormat df = new SimpleDateFormat();
    SimpleDateFormat date = new SimpleDateFormat();
    date.applyPattern("dd");
    if ("01".equals(String.valueOf(date.format(thisdate)))) {
        Query queryup = session/*from   ww  w .  j  av  a 2s  .  c  om*/
                .createQuery("update MRunningCode run set run.running = :running" + " where run.type = :type");
        queryup.setParameter("running", 0);
        queryup.setParameter("type", "IB");
        int result = queryup.executeUpdate();
    }
    df.applyPattern("yyMM");
    Query query = session.createQuery("from MRunningCode run where run.type =:type ");
    query.setParameter("type", "IB");
    query.setMaxResults(1);
    list = query.list();
    if (list.isEmpty()) {
        PVCode = "IB" + df.format(thisdate) + "-" + "0001";
    } else {
        PVCode = String.valueOf(list.get(0).getRunning());
        if (!PVCode.equalsIgnoreCase("")) {
            System.out.println("PVCode " + PVCode);
            int running = Integer.parseInt(PVCode.split("-")[0]) + 1;
            String temp = String.valueOf(running);
            System.out.println("temp.length() " + temp.length());
            for (int i = temp.length(); i < 4; i++) {
                temp = "0" + temp;
            }
            PVCode = "IB" + df.format(thisdate) + "-" + temp;

            Query queryup = session.createQuery(
                    "update MRunningCode run set run.running = :running" + " where run.type = :type");
            queryup.setParameter("running", list.get(0).getRunning() + 1);
            queryup.setParameter("type", "IB");
            int result = queryup.executeUpdate();
        }
    }
    session.close();
    this.sessionFactory.close();
    return PVCode.replace("-", "");
}

From source file:org.pentaho.di.trans.steps.propertyoutput.PropertyOutputMeta.java

public String buildFilename(VariableSpace space, int stepnr) {

    SimpleDateFormat daf = new SimpleDateFormat();

    // Replace possible environment variables...
    String retval = space.environmentSubstitute(fileName);

    Date now = new Date();

    if (dateInFilename) {
        daf.applyPattern("yyyMMdd");
        String d = daf.format(now);
        retval += "_" + d;
    }//  ww w .  j a v a  2 s .c  o  m
    if (timeInFilename) {
        daf.applyPattern("HHmmss");
        String t = daf.format(now);
        retval += "_" + t;
    }
    if (stepNrInFilename) {
        retval += "_" + stepnr;
    }

    if (extension != null && extension.length() != 0) {
        retval += "." + extension;
    }

    return retval;
}

From source file:com.panet.imeta.job.entries.copymoveresultfilenames.JobEntryCopyMoveResultFilenames.java

private String getDestinationFilename(String shortsourcefilename) throws Exception {
    String shortfilename = shortsourcefilename;
    int lenstring = shortsourcefilename.length();
    int lastindexOfDot = shortfilename.lastIndexOf('.');
    if (isAddDateBeforeExtension())
        shortfilename = shortfilename.substring(0, lastindexOfDot);

    SimpleDateFormat daf = new SimpleDateFormat();
    Date now = new Date();

    if (isSpecifyFormat() && !Const.isEmpty(getDateTimeFormat())) {
        daf.applyPattern(getDateTimeFormat());
        String dt = daf.format(now);
        shortfilename += dt;/*from   www .j  a  va  2  s .c om*/
    } else {
        if (isAddDate()) {
            daf.applyPattern("yyyyMMdd");
            String d = daf.format(now);
            shortfilename += "_" + d;
        }
        if (isAddTime()) {
            daf.applyPattern("HHmmssSSS");
            String t = daf.format(now);
            shortfilename += "_" + t;
        }
    }
    if (isAddDateBeforeExtension())
        shortfilename += shortsourcefilename.substring(lastindexOfDot, lenstring);

    return shortfilename;
}

From source file:org.pentaho.di.job.entries.copymoveresultfilenames.JobEntryCopyMoveResultFilenames.java

private String getDestinationFilename(String shortsourcefilename) throws Exception {
    String shortfilename = shortsourcefilename;
    int lenstring = shortsourcefilename.length();
    int lastindexOfDot = shortfilename.lastIndexOf('.');
    if (isAddDateBeforeExtension()) {
        shortfilename = shortfilename.substring(0, lastindexOfDot);
    }/*from www. j a  v a  2  s .  c  o m*/

    SimpleDateFormat daf = new SimpleDateFormat();
    Date now = new Date();

    if (isSpecifyFormat() && !Const.isEmpty(getDateTimeFormat())) {
        daf.applyPattern(getDateTimeFormat());
        String dt = daf.format(now);
        shortfilename += dt;
    } else {
        if (isAddDate()) {
            daf.applyPattern("yyyyMMdd");
            String d = daf.format(now);
            shortfilename += "_" + d;
        }
        if (isAddTime()) {
            daf.applyPattern("HHmmssSSS");
            String t = daf.format(now);
            shortfilename += "_" + t;
        }
    }
    if (isAddDateBeforeExtension()) {
        shortfilename += shortsourcefilename.substring(lastindexOfDot, lenstring);
    }

    return shortfilename;
}

From source file:com.sun.syndication.propono.atom.server.impl.FileBasedCollection.java

/**
 * Creates a file name for a file based on a weblog handle, title string and a
 * content-type./*from w  w w  . ja  v a  2s  . co  m*/
 *
 * @param handle      Weblog handle
 * @param title       Title to be used as basis for file name (or null)
 * @param contentType Content type of file (must not be null)
 *
 * If a title is specified, the method will apply the same create-anchor
 * logic we use for weblog entries to create a file name based on the title.
 *
 * If title is null, the base file name will be the weblog handle plus a
 * YYYYMMDDHHSS timestamp.
 *
 * The extension will be formed by using the part of content type that
 * comes after he slash.
 *
 * For example:
 *    weblog.handle = "daveblog"
 *    title         = "Port Antonio"
 *    content-type  = "image/jpg"
 * Would result in port_antonio.jpg
 *
 * Another example:
 *    weblog.handle = "daveblog"
 *    title         = null
 *    content-type  = "image/jpg"
 * Might result in daveblog-200608201034.jpg
 */
private String createFileName(String title, String contentType) {

    if (handle == null)
        throw new IllegalArgumentException("weblog handle cannot be null");
    if (contentType == null)
        throw new IllegalArgumentException("contentType cannot be null");

    String fileName = null;

    SimpleDateFormat sdf = new SimpleDateFormat();
    sdf.applyPattern("yyyyMMddHHssSSS");

    // Determine the extension based on the contentType. This is a hack.
    // The info we need to map from contentType to file extension is in
    // JRE/lib/content-type.properties, but Java Activation doesn't provide
    // a way to do a reverse mapping or to get at the data.
    String[] typeTokens = contentType.split("/");
    String ext = typeTokens[1];

    if (title != null && !title.trim().equals("")) {
        // We've got a title, so use it to build file name
        String base = Utilities.replaceNonAlphanumeric(title, ' ');
        StringTokenizer toker = new StringTokenizer(base);
        String tmp = null;
        int count = 0;
        while (toker.hasMoreTokens() && count < 5) {
            String s = toker.nextToken();
            s = s.toLowerCase();
            tmp = (tmp == null) ? s : tmp + "_" + s;
            count++;
        }
        fileName = tmp + "-" + sdf.format(new Date()) + "." + ext;

    } else {
        // No title or text, so instead we'll use the item's date
        // in YYYYMMDD format to form the file name
        fileName = handle + "-" + sdf.format(new Date()) + "." + ext;
    }

    return fileName;
}

From source file:org.opendatakit.common.android.utilities.WebUtils.java

@SuppressLint("SimpleDateFormat")
private Date parseDateSubset(String value, String[] parsePatterns, Locale l, TimeZone tz) {
    // borrowed from apache.commons.lang.DateUtils...
    Date d = null;/*from w  w  w .  j  av a 2 s.c  om*/
    SimpleDateFormat parser = null;
    ParsePosition pos = new ParsePosition(0);
    for (int i = 0; i < parsePatterns.length; i++) {
        if (i == 0) {
            if (l == null) {
                parser = new SimpleDateFormat(parsePatterns[0]);
            } else {
                parser = new SimpleDateFormat(parsePatterns[0], l);
            }
        } else {
            parser.applyPattern(parsePatterns[i]);
        }
        parser.setTimeZone(tz); // enforce UTC for formats without timezones
        pos.setIndex(0);
        d = parser.parse(value, pos);
        if (d != null && pos.getIndex() == value.length()) {
            return d;
        }
    }
    return d;
}

From source file:org.pentaho.di.job.entries.exportrepository.JobEntryExportRepository.java

public String buildFilename(String filename) {
    String retval = "";
    if (Const.isEmpty(filename)) {
        return null;
    }/*www . j a  v a2s . co  m*/

    int lenstring = filename.length();
    int lastindexOfDot = filename.lastIndexOf('.');
    if (lastindexOfDot == -1) {
        lastindexOfDot = lenstring;
    }

    retval = filename.substring(0, lastindexOfDot);

    SimpleDateFormat daf = new SimpleDateFormat();
    Date now = new Date();

    if (isSpecifyFormat() && !Const.isEmpty(getDateTimeFormat())) {
        daf.applyPattern(getDateTimeFormat());
        String dt = daf.format(now);
        retval += dt;
    } else {
        if (isAddDate()) {
            daf.applyPattern("yyyyMMdd");
            String d = daf.format(now);
            retval += "_" + d;
        }
        if (isAddTime()) {
            daf.applyPattern("HHmmssSSS");
            String t = daf.format(now);
            retval += "_" + t;
        }
    }
    retval += filename.substring(lastindexOfDot, lenstring);
    return retval;
}

From source file:com.panet.imeta.job.entries.exportrepository.JobEntryExportRepository.java

public String buildFilename(String filename) {
    String retval = "";
    if (Const.isEmpty(filename))
        return null;

    // Replace possible environment variables...
    String realfilename = filename;
    int lenstring = realfilename.length();
    int lastindexOfDot = realfilename.lastIndexOf('.');
    if (lastindexOfDot == -1)
        lastindexOfDot = lenstring;/*  w w  w.j  av a 2  s  .  c  o  m*/

    retval = realfilename.substring(0, lastindexOfDot);

    SimpleDateFormat daf = new SimpleDateFormat();
    Date now = new Date();

    if (SpecifyFormat && !Const.isEmpty(date_time_format)) {
        daf.applyPattern(date_time_format);
        String dt = daf.format(now);
        retval += dt;
    } else {
        if (add_date) {
            daf.applyPattern("yyyyMMdd");
            String d = daf.format(now);
            retval += "_" + d;
        }
        if (add_time) {
            daf.applyPattern("HHmmssSSS");
            String t = daf.format(now);
            retval += "_" + t;
        }
    }
    retval += realfilename.substring(lastindexOfDot, lenstring);
    return retval;

}

From source file:org.agnitas.web.ExportWizardAction.java

private String formatFormDateToDB(String dateString) {
    SimpleDateFormat formatter = new SimpleDateFormat(getDatesParameterFormat());
    try {/*from  www. j a v a  2  s  .  c  om*/
        Date parsed = formatter.parse(dateString);
        formatter.applyPattern(getDatesDBFormat());
        return formatter.format(parsed);
    } catch (ParseException e) {
        AgnUtils.userlogger().error("formatFormDateToDB: " + e);
        return "";
    }
}