List of usage examples for java.text SimpleDateFormat applyPattern
public void applyPattern(String pattern)
From source file:org.pentaho.di.job.entries.ftp.JobEntryFTP.java
/** * @param string/*from ww w .jav a 2 s. c o m*/ * the filename from the FTP server * * @return the calculated target filename */ private String returnTargetFilename(String filename) { String retval = null; // Replace possible environment variables... if (filename != null) { retval = filename; } else { return null; } int lenstring = retval.length(); int lastindexOfDot = retval.lastIndexOf("."); if (lastindexOfDot == -1) { lastindexOfDot = lenstring; } if (isAddDateBeforeExtension()) { retval = retval.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 (adddate) { daf.applyPattern("yyyyMMdd"); String d = daf.format(now); retval += "_" + d; } if (addtime) { daf.applyPattern("HHmmssSSS"); String t = daf.format(now); retval += "_" + t; } } if (isAddDateBeforeExtension()) { retval += retval.substring(lastindexOfDot, lenstring); } // Add foldername to filename retval = environmentSubstitute(targetDirectory) + Const.FILE_SEPARATOR + retval; return retval; }
From source file:org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta.java
public String buildFilename(String filename, String extension, VariableSpace space, int stepnr, String partnr, int splitnr, boolean ziparchive, TextFileOutputMeta meta) { SimpleDateFormat daf = new SimpleDateFormat(); // Replace possible environment variables... String retval = space.environmentSubstitute(filename); String realextension = space.environmentSubstitute(extension); if (meta.isFileAsCommand()) { return retval; }/*from w ww. jav a 2 s . com*/ Date now = new Date(); if (meta.isSpecifyingFormat() && !Const.isEmpty(meta.getDateTimeFormat())) { daf.applyPattern(meta.getDateTimeFormat()); String dt = daf.format(now); retval += dt; } else { if (meta.isDateInFilename()) { daf.applyPattern("yyyMMdd"); String d = daf.format(now); retval += "_" + d; } if (meta.isTimeInFilename()) { daf.applyPattern("HHmmss"); String t = daf.format(now); retval += "_" + t; } } if (meta.isStepNrInFilename()) { retval += "_" + stepnr; } if (meta.isPartNrInFilename()) { retval += "_" + partnr; } if (meta.getSplitEvery() > 0) { retval += "_" + splitnr; } if (meta.getFileCompression().equals("Zip")) { if (ziparchive) { retval += ".zip"; } else { if (realextension != null && realextension.length() != 0) { retval += "." + realextension; } } } else { if (realextension != null && realextension.length() != 0) { retval += "." + realextension; } if (meta.getFileCompression().equals("GZip")) { retval += ".gz"; } } return retval; }
From source file:org.pentaho.di.job.entries.pgpencryptfiles.JobEntryPGPEncryptFiles.java
private boolean EncryptFile(int actionType, String shortfilename, FileObject sourcefilename, String userID, FileObject destinationfilename, FileObject movetofolderfolder, Job parentJob, Result result) { FileObject destinationfile = null; boolean retval = false; try {/*from w w w . j a v a 2s .c o m*/ if (!destinationfilename.exists()) { doJob(actionType, sourcefilename, userID, destinationfilename); if (isDetailed()) { logDetailed(BaseMessages.getString(PKG, "JobPGPEncryptFiles.Log.FileEncrypted", sourcefilename.getName().toString(), destinationfilename.getName().toString())); } // add filename to result filename if (add_result_filesname && !iffileexists.equals("fail") && !iffileexists.equals("do_nothing")) { addFileToResultFilenames(destinationfilename.toString(), result, parentJob); } updateSuccess(); } else { if (isDetailed()) { logDetailed(BaseMessages.getString(PKG, "JobPGPEncryptFiles.Log.FileExists", destinationfilename.toString())); } if (iffileexists.equals("overwrite_file")) { doJob(actionType, sourcefilename, userID, destinationfilename); if (isDetailed()) { logDetailed(BaseMessages.getString(PKG, "JobPGPEncryptFiles.Log.FileOverwrite", destinationfilename.getName().toString())); } // add filename to result filename if (add_result_filesname && !iffileexists.equals("fail") && !iffileexists.equals("do_nothing")) { addFileToResultFilenames(destinationfilename.toString(), result, parentJob); } updateSuccess(); } else if (iffileexists.equals("unique_name")) { String short_filename = shortfilename; // return destination short filename try { short_filename = getMoveDestinationFilename(short_filename, "ddMMyyyy_HHmmssSSS"); } catch (Exception e) { logError(BaseMessages.getString(PKG, "JobPGPEncryptFiles.Error.GettingFilename", short_filename), e); return retval; } String movetofilenamefull = destinationfilename.getParent().toString() + Const.FILE_SEPARATOR + short_filename; destinationfile = KettleVFS.getFileObject(movetofilenamefull); doJob(actionType, sourcefilename, userID, destinationfilename); if (isDetailed()) { logDetailed(toString(), BaseMessages.getString(PKG, "JobPGPEncryptFiles.Log.FileEncrypted", sourcefilename.getName().toString(), destinationfile.getName().toString())); } // add filename to result filename if (add_result_filesname && !iffileexists.equals("fail") && !iffileexists.equals("do_nothing")) { addFileToResultFilenames(destinationfile.toString(), result, parentJob); } updateSuccess(); } else if (iffileexists.equals("delete_file")) { destinationfilename.delete(); if (isDetailed()) { logDetailed(BaseMessages.getString(PKG, "JobPGPEncryptFiles.Log.FileDeleted", destinationfilename.getName().toString())); } } else if (iffileexists.equals("move_file")) { String short_filename = shortfilename; // return destination short filename try { short_filename = getMoveDestinationFilename(short_filename, null); } catch (Exception e) { logError(BaseMessages.getString(PKG, "JobPGPEncryptFiles.Error.GettingFilename", short_filename), e); return retval; } String movetofilenamefull = movetofolderfolder.toString() + Const.FILE_SEPARATOR + short_filename; destinationfile = KettleVFS.getFileObject(movetofilenamefull); if (!destinationfile.exists()) { sourcefilename.moveTo(destinationfile); if (isDetailed()) { logDetailed(BaseMessages.getString(PKG, "JobPGPEncryptFiles.Log.FileEncrypted", sourcefilename.getName().toString(), destinationfile.getName().toString())); } // add filename to result filename if (add_result_filesname && !iffileexists.equals("fail") && !iffileexists.equals("do_nothing")) { addFileToResultFilenames(destinationfile.toString(), result, parentJob); } } else { if (ifmovedfileexists.equals("overwrite_file")) { sourcefilename.moveTo(destinationfile); if (isDetailed()) { logDetailed(BaseMessages.getString(PKG, "JobPGPEncryptFiles.Log.FileOverwrite", destinationfile.getName().toString())); } // add filename to result filename if (add_result_filesname && !iffileexists.equals("fail") && !iffileexists.equals("do_nothing")) { addFileToResultFilenames(destinationfile.toString(), result, parentJob); } updateSuccess(); } else if (ifmovedfileexists.equals("unique_name")) { SimpleDateFormat daf = new SimpleDateFormat(); Date now = new Date(); daf.applyPattern("ddMMyyyy_HHmmssSSS"); String dt = daf.format(now); short_filename += "_" + dt; String destinationfilenamefull = movetofolderfolder.toString() + Const.FILE_SEPARATOR + short_filename; destinationfile = KettleVFS.getFileObject(destinationfilenamefull); sourcefilename.moveTo(destinationfile); if (isDetailed()) { logDetailed(BaseMessages.getString(PKG, "JobPGPEncryptFiles.Log.FileEncrypted", destinationfile.getName().toString())); } // add filename to result filename if (add_result_filesname && !iffileexists.equals("fail") && !iffileexists.equals("do_nothing")) { addFileToResultFilenames(destinationfile.toString(), result, parentJob); } updateSuccess(); } else if (ifmovedfileexists.equals("fail")) { // Update Errors updateErrors(); } } } else if (iffileexists.equals("fail")) { // Update Errors updateErrors(); } } } catch (Exception e) { updateErrors(); logError(BaseMessages.getString(PKG, "JobPGPEncryptFiles.Error.Exception.MoveProcessError", sourcefilename.toString(), destinationfilename.toString(), e.getMessage())); } finally { if (destinationfile != null) { try { destinationfile.close(); } catch (IOException ex) { /* Ignore */ } } } return retval; }
From source file:org.openmrs.util.OpenmrsUtil.java
/** * Get the current user's time format Will look similar to "hh:mm a". Depends on user's locale. * /*from ww w . ja v a 2s . c om*/ * @return a simple time format * @should return a pattern with two h characters in it * @should not allow the returned SimpleDateFormat to be modified * @since 1.9 */ public static SimpleDateFormat getTimeFormat(Locale locale) { if (timeFormatCache.containsKey(locale)) { return (SimpleDateFormat) timeFormatCache.get(locale).clone(); } SimpleDateFormat sdf = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT, locale); String pattern = sdf.toPattern(); if (!(pattern.contains("hh") || pattern.contains("HH"))) { // otherwise, change the pattern to be a two digit hour pattern = pattern.replaceFirst("h", "hh").replaceFirst("H", "HH"); sdf.applyPattern(pattern); } timeFormatCache.put(locale, sdf); return (SimpleDateFormat) sdf.clone(); }
From source file:org.openmrs.util.OpenmrsUtil.java
/** * Get the current user's date format Will look similar to "mm-dd-yyyy". Depends on user's * locale.// w w w. j a v a2 s.co m * * @return a simple date format * @should return a pattern with four y characters in it * @should not allow the returned SimpleDateFormat to be modified * @since 1.5 */ public static SimpleDateFormat getDateFormat(Locale locale) { if (dateFormatCache.containsKey(locale)) { return (SimpleDateFormat) dateFormatCache.get(locale).clone(); } // note that we are using the custom OpenmrsDateFormat class here which prevents erroneous parsing of 2-digit years SimpleDateFormat sdf = new OpenmrsDateFormat( (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, locale), locale); String pattern = sdf.toPattern(); if (!pattern.contains("yyyy")) { // otherwise, change the pattern to be a four digit year pattern = pattern.replaceFirst("yy", "yyyy"); sdf.applyPattern(pattern); } if (!pattern.contains("MM")) { // change the pattern to be a two digit month pattern = pattern.replaceFirst("M", "MM"); sdf.applyPattern(pattern); } if (!pattern.contains("dd")) { // change the pattern to be a two digit day pattern = pattern.replaceFirst("d", "dd"); sdf.applyPattern(pattern); } dateFormatCache.put(locale, sdf); return (SimpleDateFormat) sdf.clone(); }
From source file:org.pentaho.di.trans.steps.exceloutput.ExcelOutputMeta.java
public String buildFilename(VariableSpace space, int stepnr, int splitnr) { SimpleDateFormat daf = new SimpleDateFormat(); // Replace possible environment variables... String retval = space.environmentSubstitute(fileName); String realextension = space.environmentSubstitute(extension); Date now = new Date(); if (SpecifyFormat && !Const.isEmpty(date_time_format)) { daf.applyPattern(date_time_format); String dt = daf.format(now); retval += dt;//from w ww. j a v a 2s.c o m } else { if (dateInFilename) { daf.applyPattern("yyyMMdd"); String d = daf.format(now); retval += "_" + d; } if (timeInFilename) { daf.applyPattern("HHmmss"); String t = daf.format(now); retval += "_" + t; } } if (stepNrInFilename) { retval += "_" + stepnr; } if (splitEvery > 0) { retval += "_" + splitnr; } if (realextension != null && realextension.length() != 0) { retval += "." + realextension; } return retval; }
From source file:com.rr.familyPlanning.ui.importexport.importExportController.java
/** * //from w w w.j av a2s .co m * @param surveyId * @param session * @param request * @return * @throws Exception */ @RequestMapping(value = "/saveParticipantExport.do", method = RequestMethod.POST) public ModelAndView saveExport(@ModelAttribute(value = "exportDetails") savedExports exportDetails, @RequestParam List<Integer> selectedSites, BindingResult errors, HttpSession session, HttpServletRequest request) throws Exception { if (errors.hasErrors()) { for (ObjectError error : errors.getAllErrors()) { System.out.println(error.getDefaultMessage()); } } User userDetails = (User) session.getAttribute("userDetails"); /** Log Here **/ userActivityLog ual = new userActivityLog(); ual.setSystemUserId(userDetails.getId()); ual.setMapping("/saveParticipantExport.do"); ual.setRequestMethod("POST"); ual.setMethodAccessed("saveExport"); ual.setModuleId(moduleId); ual.setProgramId(programId); SimpleDateFormat datesearchFormat = new SimpleDateFormat("MM/dd/yyyy"); Date startDate = datesearchFormat.parse(exportDetails.getStartDate()); Date endDate = datesearchFormat.parse(exportDetails.getEndDate()); datesearchFormat.applyPattern("yyyy-MM-dd"); String realStartDate = datesearchFormat.format(startDate); String realEndDate = datesearchFormat.format(endDate); String exportFileName = ""; String registryName = programmanager.getProgramById(programId).getProgramName().replaceAll(" ", "-") .toLowerCase(); /* Get the client engagements */ List<engagements> engagements = engagementmanager.getEngagementByMultipleEntity(programId, selectedSites, realStartDate, realEndDate); Integer exportId = 0; /* Loop through sessions here */ if (engagements != null && engagements.size() > 0) { exportDetails.setProgramId(programId); exportDetails.setSystemUserId(userDetails.getId()); exportDetails.setSelectedDateRange(exportDetails.getStartDate() + " - " + exportDetails.getEndDate()); exportDetails.setDownloadType(1); exportDetails.setTotalRecords(engagements.size()); exportId = exportManager.saveExport(exportDetails); if (selectedSites != null && !"".equals(selectedSites)) { StringBuilder selectedSiteNames = new StringBuilder(); for (Integer site : selectedSites) { programHierarchyDetails siteDetails = hierarchymanager.getProgramHierarchyItemDetails(site); savedExportSites exportSite = new savedExportSites(); exportSite.setExportId(exportId); exportSite.setSiteName(siteDetails.getName()); exportSite.setSiteId(site); exportManager.saveExportSite(exportSite); } } progressBar newProgressBar = new progressBar(); newProgressBar.setExportId(exportDetails.getUniqueId()); newProgressBar.setPercentComplete(0); exportManager.saveProgessBar(newProgressBar); DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssS"); Date date = new Date(); String fileName = ""; String delimiter = ","; if (exportDetails.getExportType() == 1) { fileName = new StringBuilder().append("clientExport").append(dateFormat.format(date)).append(".csv") .toString(); delimiter = ","; } else if (exportDetails.getExportType() == 2) { fileName = new StringBuilder().append("clientExport").append(dateFormat.format(date)).append(".txt") .toString(); delimiter = ","; } else if (exportDetails.getExportType() == 3) { fileName = new StringBuilder().append("clientExport").append(dateFormat.format(date)).append(".txt") .toString(); delimiter = "|"; } else if (exportDetails.getExportType() == 4) { fileName = new StringBuilder().append("clientExport").append(dateFormat.format(date)).append(".txt") .toString(); delimiter = "\t"; } /* Create new export file */ InputStream inputStream = null; OutputStream outputStream = null; fileSystem dir = new fileSystem(); dir.setDir(registryName, "exportFiles"); File newFile = new File(dir.getDir() + fileName); /* Create the empty file in the correct location */ try { if (newFile.exists()) { int i = 1; while (newFile.exists()) { int iDot = fileName.lastIndexOf("."); newFile = new File(dir.getDir() + fileName.substring(0, iDot) + "_(" + ++i + ")" + fileName.substring(iDot)); } fileName = newFile.getName(); newFile.createNewFile(); } else { newFile.createNewFile(); } } catch (IOException e) { e.printStackTrace(); } /* Read in the file */ FileInputStream fileInput = null; File file = new File(dir.getDir() + fileName); fileInput = new FileInputStream(file); exportFileName = fileName; FileWriter fw = null; try { fw = new FileWriter(file, true); } catch (IOException ex) { Logger.getLogger(exportManager.class.getName()).log(Level.SEVERE, null, ex); } exportDetails.setExportFile(exportFileName); exportManager.saveExport(exportDetails); StringBuilder exportRow = new StringBuilder(); exportRow.append("CLIENT IDENTIFIER").append(delimiter); exportRow.append("DOB").append(delimiter); exportRow.append("SEX").append(delimiter); /* P */ exportRow.append("VISIT DATE").append(delimiter); /* P */ exportRow.append("WEIGHT").append(delimiter); /* P */ exportRow.append("HEIGHT").append(delimiter); /* P */ exportRow.append("BP SYSTOLIC").append(delimiter); /* P */ exportRow.append("BP DIASTOLIC").append(delimiter); /* P */ exportRow.append(System.getProperty("line.separator")); fw.write(exportRow.toString()); Integer participantId = 0; List<programExportFields> exportFields = programmanager.getProgramExportFields(programId); List<String> tableinfo = new ArrayList<String>(); Integer fieldId = 0; Integer customFieldId = 0; Integer validationValue = 0; String fieldTypeValue = ""; Integer crosswalkId = 0; for (programExportFields field : exportFields) { if (field.getFieldType() == 1) { fieldTypeValue = "1"; programClientFields fieldDetails = clientmanager.getClientFieldDetails(programId, field.getFieldId()); fieldId = fieldDetails.getFieldId(); customFieldId = fieldDetails.getCustomfieldId(); validationValue = fieldDetails.getValidationId(); crosswalkId = fieldDetails.getCrosswalkId(); } else { fieldTypeValue = "2"; programEngagementFields fieldDetails = engagementmanager.getEngagementFieldDetails(programId, field.getFieldId()); fieldId = fieldDetails.getFieldId(); customFieldId = fieldDetails.getCustomfieldId(); validationValue = fieldDetails.getValidationId(); crosswalkId = fieldDetails.getCrosswalkId(); } if (fieldId > 0) { dataElements fieldDetails = clientmanager.getFieldDetails(fieldId); tableinfo.add(fieldTypeValue + "-" + fieldDetails.getSaveToTableName() + "-" + fieldDetails.getSaveToTableCol() + "-" + validationValue + "-" + crosswalkId); } else if (customFieldId > 0) { customProgramFields fieldDetails = clientmanager.getCustomFieldDetails(customFieldId); tableinfo.add(fieldTypeValue + "-" + fieldDetails.getSaveToTable() + "-" + fieldDetails.getSaveToTableCol() + "-" + validationValue + "-" + crosswalkId); } } Integer totalDone = 0; float percentComplete; progressBar exportProgressBar = exportManager.getProgressBar(exportDetails.getUniqueId()); for (engagements engagement : engagements) { exportRow = new StringBuilder(); programHierarchyDetails hierarchyDetails = hierarchymanager.getProgramHierarchyItemDetails( clientmanager.getClientEntities(engagement.getProgramPatientId()).getEntity3Id()); String siteDisplayId = ""; if (hierarchyDetails.getDisplayId() != null) { siteDisplayId = hierarchyDetails.getDisplayId(); } //exportRow.append(siteDisplayId).append(delimiter); if (tableinfo != null & tableinfo.size() > 0) { for (String table : tableinfo) { String[] tableInfoArray = table.split("-"); String fieldValue = ""; String fieldType = tableInfoArray[0]; String tablename = tableInfoArray[1]; String tableCol = tableInfoArray[2]; String validation = tableInfoArray[3]; String crosswalk = tableInfoArray[4]; if ("1".equals(fieldType)) { fieldValue = clientmanager.getTableData(tablename, tableCol, engagement.getProgramPatientId()); } else { fieldValue = engagementmanager.getTableData(tablename, tableCol, engagement.getId(), engagement.getProgramPatientId()); } if ("55".equals(crosswalk) && "0".equals(fieldValue)) { fieldValue = "2"; } /* If date format to correct display format */ if ("4".equals(validation)) { if ("dob".equals(tableCol)) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date dob = format.parse(fieldValue); Date today = new Date(); format.applyPattern("yyyy"); String dobAsString = format.format(dob); String todayAsString = format.format(today); Integer age = Integer.parseInt(todayAsString) - Integer.parseInt(dobAsString); exportRow.append(age).append(delimiter); } else { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date formatedDate = format.parse(fieldValue); format.applyPattern("MM/dd/yy"); exportRow.append(format.format(formatedDate)).append(delimiter); } } else { exportRow.append(fieldValue).append(delimiter); } } } exportRow.append(System.getProperty("line.separator")); fw.write(exportRow.toString()); //Update progress bar totalDone = totalDone + 1; percentComplete = ((float) totalDone) / engagements.size(); exportProgressBar.setPercentComplete(Math.round(percentComplete * 100)); exportManager.saveProgessBar(exportProgressBar); } fw.close(); } ModelAndView mav = new ModelAndView(); /* If no results are found */ if (exportFileName.isEmpty()) { mav.setViewName("/importExport/exportModal"); savedExports newexportDetails = new savedExports(); exportDetails.setExportType(1); programOrgHierarchy level1 = hierarchymanager.getProgramOrgHierarchyBydspPos(1, programId); programOrgHierarchy level2 = hierarchymanager.getProgramOrgHierarchyBydspPos(2, programId); programOrgHierarchy level3 = hierarchymanager.getProgramOrgHierarchyBydspPos(3, programId); Integer userId; if (userDetails.getRoleId() == 2) { userId = 0; } else { userId = userDetails.getId(); } List<programHierarchyDetails> level1Items = hierarchymanager.getProgramHierarchyItems(level1.getId(), userId); mav.addObject("level1Items", level1Items); mav.addObject("level1Name", level1.getName()); mav.addObject("level2Name", level2.getName()); mav.addObject("level3Name", level3.getName()); mav.addObject("exportDetails", newexportDetails); mav.addObject("showDateRange", true); mav.addObject("noresults", true); ual.setMiscNotes("mav view:" + mav.getViewName() + "^^^^^" + "No Results."); } else { if (exportDetails.getUniqueId() > 0) { /* Delete progress bar entry */ exportManager.deleteProgressBar(exportDetails.getUniqueId()); } mav.setViewName("/importExport/exportDownloadModal"); mav.addObject("exportFileName", exportFileName); ual.setMiscNotes("mav view:" + mav.getViewName() + "^^^^^exportFileName:" + exportFileName + "^^^^^exportDetails:" + exportDetails.getId()); } usermanager.saveUserActivityLog(ual); return mav; }
From source file:de.escoand.readdaily.MainActivity.java
@Override public void onDateSelected(final Date date) { final SimpleDateFormat frmt = new SimpleDateFormat(); String pattern;//from ww w . j av a 2s. c o m // default title toolbar.setTitle(getString(R.string.app_title)); toolbar.setSubtitle(null); playerButton.setVisibility(View.GONE); playerButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final PlayerDialogFragment player = new PlayerDialogFragment(); player.setDate(getBaseContext(), date); player.show(getSupportFragmentManager(), player.getClass().getName()); } }); // init buttons if (findViewById(R.id.button_bible_exegesis) != null) findViewById(R.id.button_bible_exegesis) .setOnClickListener(new OnBibleClickListener(this, date, Database.TYPE_EXEGESIS)); ((FloatingActionButton) findViewById(R.id.button_more)).setImageResource(R.drawable.icon_plus); toggleVisibility(R.id.button_more, View.GONE); toggleVisibility(R.id.button_intro, View.GONE); toggleVisibility(R.id.button_voty, View.GONE); if (date == null) return; // content cursor = Database.getInstance(this).getDay(date); while (cursor.moveToNext()) { switch (cursor.getString(cursor.getColumnIndex(Database.COLUMN_TYPE))) { // exegesis title case Database.TYPE_EXEGESIS: pattern = getString(R.string.toolbar_title); pattern = pattern.replaceAll("%app_title%", "'" + getString(R.string.app_title) + "'"); pattern = pattern.replaceAll("%app_subtitle%", "'" + getString(R.string.app_subtitle) + "'"); frmt.applyPattern(pattern); toolbar.setTitle(frmt.format(date)); pattern = getString(R.string.toolbar_subtitle); pattern = pattern.replaceAll("%app_title%", "'" + getString(R.string.app_title) + "'"); pattern = pattern.replaceAll("%app_subtitle%", "'" + getString(R.string.app_subtitle) + "'"); frmt.applyPattern(pattern); toolbar.setSubtitle(frmt.format(date)); break; // more button case Database.TYPE_YEAR: case Database.TYPE_INTRO: toggleVisibility(R.id.button_more, View.VISIBLE); break; // audio player case Database.TYPE_MEDIA: playerButton.setVisibility(View.VISIBLE); break; // do nothing default: break; } } }
From source file:org.LexGrid.LexBIG.gui.ValueSetDefinitionDetails.java
private boolean isDateValid(String dateStr) { String format = "M/d/yyyy"; String reFormat = Pattern.compile("d+|M+").matcher(Matcher.quoteReplacement(format)) .replaceAll("\\\\d{1,2}"); reFormat = Pattern.compile("y+").matcher(reFormat).replaceAll("\\\\d{4}"); if (Pattern.compile(reFormat).matcher(dateStr).matches()) { // date string matches format structure, // - now test it can be converted to a valid date SimpleDateFormat sdf = (SimpleDateFormat) DateFormat.getDateInstance(); sdf.setLenient(false);/*from w w w .ja v a2 s .c om*/ sdf.applyPattern(format); try { sdf.parse(dateStr); return true; } catch (ParseException e) { return false; } } return false; }