List of usage examples for java.text DateFormat SHORT
int SHORT
To view the source code for java.text DateFormat SHORT.
Click Source Link
From source file:se.streamsource.streamflow.web.application.pdf.CasePdfGenerator.java
public void generateConversations(Input<Conversation, RuntimeException> conversations) throws IOException { final Transforms.Counter<Conversation> counter = new Transforms.Counter<Conversation>(); Output<Conversation, IOException> output = Transforms.map(counter, new Output<Conversation, IOException>() { public <SenderThrowableType extends Throwable> void receiveFrom( Sender<? extends Conversation, SenderThrowableType> sender) throws IOException, SenderThrowableType { sender.sendTo(new Receiver<Conversation, IOException>() { public void receive(Conversation conversation) throws IOException { if (counter.getCount() == 1) { document.changeColor(headingColor) .print(bundle.getString("conversations"), valueFontBold) .changeColor(Color.BLACK); }/*from w w w . j a v a 2 s . c o m*/ List<Message> messages = ((Messages.Data) conversation).messages().toList(); if (!messages.isEmpty()) { document.print(conversation.getDescription(), valueFontBold); for (Message message : messages) { Message.Data data = ((Message.Data) message); String label = data.sender().get().getDescription() + ", " + DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale) .format(data.createdOn().get()) + ": "; String text = data.body().get(); if (MessageType.HTML.equals(data.messageType().get())) { text = Translator.htmlToText(text); } document.print(label, valueFontBold).print(text, valueFont).print("", valueFont); } } } }); } }); conversations.transferTo(output); }
From source file:org.freeplane.features.format.FormatController.java
private static Integer getDateStyle(final String string) { if (string.equals("SHORT")) return DateFormat.SHORT; if (string.equals("MEDIUM")) return DateFormat.MEDIUM; if (string.equals("LONG")) return DateFormat.LONG; if (string.equals("FULL")) return DateFormat.FULL; return null;/* w w w .j a v a2s . c om*/ }
From source file:com.webbfontaine.valuewebb.model.util.Utils.java
public static String dateToLocaleString(Date date) { String toStringDate;/*from ww w. j a va 2 s. c o m*/ if (date == null) { toStringDate = ""; } else { DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, LocaleSelector.instance().getLocale()); toStringDate = dateFormat.format(date); } return toStringDate; }
From source file:org.mifos.accounts.business.AccountBO.java
protected void addcustomFields(final List<CustomFieldDto> customFields) throws InvalidDateException { if (customFields != null) { for (CustomFieldDto view : customFields) { if (CustomFieldType.DATE.getValue().equals(view.getFieldType()) && org.apache.commons.lang.StringUtils.isNotBlank(view.getFieldValue())) { SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, getUserContext().getPreferredLocale()); String userfmt = DateUtils.convertToCurrentDateFormat(format.toPattern()); this.getAccountCustomFields().add(new AccountCustomFieldEntity(this, view.getFieldId(), DateUtils.convertUserToDbFmt(view.getFieldValue(), userfmt))); } else { this.getAccountCustomFields() .add(new AccountCustomFieldEntity(this, view.getFieldId(), view.getFieldValue())); }/*from ww w. j av a 2s . c o m*/ } } }
From source file:fr.paris.lutece.plugins.suggest.utils.SuggestUtils.java
/** * return a timestamp Object which correspond with the string specified in * parameter./*from w ww .j a v a 2 s . c o m*/ * @param strDate the date who must convert * @param locale the locale * @return a timestamp Object which correspond with the string specified in * parameter. */ public static Timestamp getFirstMinute(String strDate, Locale locale) { try { Date date; DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale); dateFormat.setLenient(false); date = dateFormat.parse(strDate.trim()); Calendar caldate = new GregorianCalendar(); caldate.setTime(date); caldate.set(Calendar.MILLISECOND, 0); caldate.set(Calendar.SECOND, 0); caldate.set(Calendar.HOUR_OF_DAY, caldate.getActualMinimum(Calendar.HOUR_OF_DAY)); caldate.set(Calendar.MINUTE, caldate.getActualMinimum(Calendar.MINUTE)); Timestamp timeStamp = new Timestamp(caldate.getTimeInMillis()); return timeStamp; } catch (ParseException e) { return null; } }
From source file:org.opencms.workflow.CmsExtendedWorkflowManager.java
/** * Generates the name for a new workflow project based on the user for whom it is created.<p> * * @param userCms the user's current CMS context * @param shortTime if true, the short time format will be used, else the medium time format * * @return the workflow project name/*from w w w .ja v a2 s . c o m*/ */ protected String generateProjectName(CmsObject userCms, boolean shortTime) { CmsUser user = userCms.getRequestContext().getCurrentUser(); long time = System.currentTimeMillis(); Date date = new Date(time); OpenCms.getLocaleManager(); Locale locale = CmsLocaleManager.getDefaultLocale(); DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale); DateFormat timeFormat = DateFormat.getTimeInstance(shortTime ? DateFormat.SHORT : DateFormat.MEDIUM, locale); String dateStr = dateFormat.format(date) + " " + timeFormat.format(date); String username = user.getName(); String result = Messages.get().getBundle(locale).key(Messages.GUI_WORKFLOW_PROJECT_NAME_2, username, dateStr); result = result.replaceAll("/", "|"); return result; }
From source file:com.webbfontaine.valuewebb.model.util.Utils.java
public static Date localeStringToDate(String date) throws ParseException { if (StringUtils.trimToEmpty(date).isEmpty()) { return null; }//from w ww.j av a2s . c o m DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, LocaleSelector.instance().getLocale()); return dateFormat.parse(date); }
From source file:org.muse.mneme.impl.AssessmentStorageSample.java
protected void fakeIt() { if (!fakedAlready) { fakedAlready = true;/* ww w .j a v a 2 s. c o m*/ Date now = new Date(); AssessmentImpl a = newAssessment(); a.initId("a1"); a.setPublished(Boolean.TRUE); a.setContext("mercury"); a.getCreatedBy().setUserId("admin"); a.setTries(3); a.setQuestionGrouping(QuestionGrouping.question); a.setRandomAccess(Boolean.TRUE); a.setTimeLimit(1200l * 1000l); a.setTitle("Ann Arbor"); a.setType(AssessmentType.test); // a.getAccess().setPassword("password"); a.getCreatedBy().setUserId("admin"); a.getCreatedBy().setDate(now); a.getModifiedBy().setUserId("admin"); a.getModifiedBy().setDate(now); try { a.getDates().setOpenDate(DateFormat.getDateInstance(DateFormat.SHORT).parse("10/01/07")); ((AssessmentDatesImpl) a.getDates()) .initDueDate(DateFormat.getDateInstance(DateFormat.SHORT).parse("12/22/07")); } catch (ParseException e) { } a.getGrading().setAutoRelease(Boolean.FALSE); a.getGrading().setGradebookIntegration(Boolean.FALSE); a.getGrading().setAnonymous(Boolean.FALSE); a.getPresentation().setText("This is assessment one."); a.getReview().setShowCorrectAnswer(ReviewShowCorrect.yes); a.getReview().setShowFeedback(Boolean.TRUE); a.getReview().setTiming(ReviewTiming.graded); a.getSubmitPresentation().setText("Thanks for all the fish!"); ManualPart p = a.getParts().addManualPart(); p.setRandomize(Boolean.FALSE); p.setTitle("Part one"); ((PartImpl) p).initId("p1"); p.addQuestion(this.questionService.getQuestion("q1")); p.addQuestion(this.questionService.getQuestion("q3")); p.addQuestion(this.questionService.getQuestion("q4")); p.getPresentation().setText("This is part one."); p = a.getParts().addManualPart(); p.setRandomize(Boolean.FALSE); p.setTitle("Part two"); ((PartImpl) p).initId("p2"); p.addQuestion(this.questionService.getQuestion("q5")); p.addQuestion(this.questionService.getQuestion("q7")); p.addQuestion(this.questionService.getQuestion("q8")); p.getPresentation().setText("This is part two."); a.clearChanged(); a.clearMint(); ((AssessmentGradingImpl) (a.getGrading())).initAutoRelease(a.getGrading().getAutoRelease()); ((AssessmentGradingImpl) (a.getGrading())) .initGradebookIntegration(a.getGrading().getGradebookIntegration()); a.initTitle(a.getTitle()); a.initPublished(a.getPublished()); this.assessments.put(a.getId(), a); // a = newAssessment(); a.setType(AssessmentType.assignment); a.initId("a2"); a.setPublished(Boolean.TRUE); a.setContext("mercury"); a.getCreatedBy().setUserId("admin"); a.setTries(5); a.setQuestionGrouping(QuestionGrouping.question); a.setRandomAccess(Boolean.TRUE); // a.setTimeLimit(1200l * 1000l); a.setTitle("Boston"); // a.getAccess().setPassword("password"); a.getCreatedBy().setUserId("admin"); a.getCreatedBy().setDate(now); a.getModifiedBy().setUserId("admin"); a.getModifiedBy().setDate(now); try { a.getDates().setOpenDate(DateFormat.getDateInstance(DateFormat.SHORT).parse("09/01/07")); ((AssessmentDatesImpl) a.getDates()) .initDueDate(DateFormat.getDateInstance(DateFormat.SHORT).parse("12/15/07")); } catch (ParseException e) { } a.getGrading().setAutoRelease(Boolean.TRUE); a.getGrading().setGradebookIntegration(Boolean.FALSE); a.getGrading().setAnonymous(Boolean.TRUE); a.getPresentation().setText("This is assessment two."); a.getReview().setShowCorrectAnswer(ReviewShowCorrect.yes); a.getReview().setShowFeedback(Boolean.TRUE); a.getReview().setTiming(ReviewTiming.submitted); a.getSubmitPresentation().setText("Have a nice day!"); DrawPart p2 = a.getParts().addDrawPart(); p2.addPool(this.poolService.getPool("b1"), 2); p2.setTitle("Part one"); ((PartImpl) p2).initId("p3"); p2.getPresentation().setText("This is part one."); a.clearChanged(); a.clearMint(); ((AssessmentGradingImpl) (a.getGrading())).initAutoRelease(a.getGrading().getAutoRelease()); ((AssessmentGradingImpl) (a.getGrading())) .initGradebookIntegration(a.getGrading().getGradebookIntegration()); a.initTitle(a.getTitle()); a.initPublished(a.getPublished()); this.assessments.put(a.getId(), a); // a = newAssessment(); a.setType(AssessmentType.test); a.initId("a3"); a.setPublished(Boolean.TRUE); a.setContext("mercury"); a.getCreatedBy().setUserId("admin"); a.setTries(5); a.setQuestionGrouping(QuestionGrouping.question); a.setRandomAccess(Boolean.TRUE); // a.setTimeLimit(1200l * 1000l); a.setTitle("Detroit"); // a.getAccess().setPassword("password"); a.getCreatedBy().setUserId("admin"); a.getCreatedBy().setDate(now); a.getModifiedBy().setUserId("admin"); a.getModifiedBy().setDate(now); a.getGrading().setAutoRelease(Boolean.TRUE); a.getGrading().setGradebookIntegration(Boolean.FALSE); a.getGrading().setAnonymous(Boolean.TRUE); a.getPresentation().setText("This is assessment three."); a.getReview().setShowCorrectAnswer(ReviewShowCorrect.yes); a.getReview().setShowFeedback(Boolean.TRUE); a.getReview().setTiming(ReviewTiming.submitted); a.getSubmitPresentation().setText("Have a nice day!"); p = a.getParts().addManualPart(); p.addQuestion(this.questionService.getQuestion("q3")); p.addQuestion(this.questionService.getQuestion("q4")); p.setTitle("Part one"); ((PartImpl) p).initId("p4"); p.getPresentation().setText("This is part 1."); a.clearChanged(); a.clearMint(); ((AssessmentGradingImpl) (a.getGrading())).initAutoRelease(a.getGrading().getAutoRelease()); ((AssessmentGradingImpl) (a.getGrading())) .initGradebookIntegration(a.getGrading().getGradebookIntegration()); a.initTitle(a.getTitle()); a.initPublished(a.getPublished()); this.assessments.put(a.getId(), a); } }
From source file:net.massbank.validator.RecordValidator.java
/** * ??/*from w w w. j ava 2 s . c om*/ * * @param db * DB * @param op * PrintWriter? * @param dataPath * ? * @param registPath * * @param ver * ? * @return ??Map<??, ?> * @throws IOException * */ private static TreeMap<String, String> validationRecord(DatabaseAccess dbx, PrintStream op, String dataPath, String registPath, int ver) throws IOException { if (ver == 1) { op.println(msgInfo("check record format version is [version 1].")); } final String[] dataList = (new File(dataPath)).list(); TreeMap<String, String> validationMap = new TreeMap<String, String>(); if (dataList.length == 0) { op.println(msgWarn("no file for validation.")); return validationMap; } // ---------------------------------------------------- // ??? // ---------------------------------------------------- String[] requiredList = new String[] { // Ver.2 "ACCESSION: ", "RECORD_TITLE: ", "DATE: ", "AUTHORS: ", "LICENSE: ", "CH$NAME: ", "CH$COMPOUND_CLASS: ", "CH$FORMULA: ", "CH$EXACT_MASS: ", "CH$SMILES: ", "CH$IUPAC: ", "AC$INSTRUMENT: ", "AC$INSTRUMENT_TYPE: ", "AC$MASS_SPECTROMETRY: MS_TYPE ", "AC$MASS_SPECTROMETRY: ION_MODE ", "PK$NUM_PEAK: ", "PK$PEAK: " }; if (ver == 1) { // Ver.1 requiredList = new String[] { "ACCESSION: ", "RECORD_TITLE: ", "DATE: ", "AUTHORS: ", "COPYRIGHT: ", "CH$NAME: ", "CH$COMPOUND_CLASS: ", "CH$FORMULA: ", "CH$EXACT_MASS: ", "CH$SMILES: ", "CH$IUPAC: ", "AC$INSTRUMENT: ", "AC$INSTRUMENT_TYPE: ", "AC$ANALYTICAL_CONDITION: MODE ", "PK$NUM_PEAK: ", "PK$PEAK: " }; } for (int i = 0; i < dataList.length; i++) { String name = dataList[i]; String status = ""; StringBuilder detailsErr = new StringBuilder(); StringBuilder detailsWarn = new StringBuilder(); // ???? File file = new File(dataPath + name); if (file.isDirectory()) { // ?? status = STATUS_ERR; detailsErr.append("[" + name + "] is directory."); validationMap.put(name, status + "\t" + detailsErr.toString()); continue; } else if (file.isHidden()) { // ??? status = STATUS_ERR; detailsErr.append("[" + name + "] is hidden."); validationMap.put(name, status + "\t" + detailsErr.toString()); continue; } else if (name.lastIndexOf(REC_EXTENSION) == -1) { // ???? status = STATUS_ERR; detailsErr.append("file extension of [" + name + "] is not [" + REC_EXTENSION + "]."); validationMap.put(name, status + "\t" + detailsErr.toString()); continue; } // ?? boolean isEndTagRead = false; boolean isInvalidInfo = false; boolean isDoubleByte = false; ArrayList<String> fileContents = new ArrayList<String>(); boolean existLicense = false; // LICENSE?Ver.1 ArrayList<String> workChName = new ArrayList<String>(); // RECORD_TITLE??CH$NAME??Ver.1? String workAcInstrumentType = ""; // RECORD_TITLE??AC$INSTRUMENT_TYPE??Ver.1? String workAcMsType = ""; // RECORD_TITLE??AC$MASS_SPECTROMETRY: // MS_TYPE??Ver.2 String line = ""; BufferedReader br = null; try { br = new BufferedReader(new FileReader(file)); while ((line = br.readLine()) != null) { if (isEndTagRead) { if (!line.equals("")) { isInvalidInfo = true; } } // if (line.startsWith("//")) { isEndTagRead = true; } fileContents.add(line); // LICENSE?Ver.1 if (line.startsWith("LICENSE: ")) { existLicense = true; } // CH$NAME?Ver.1? else if (line.startsWith("CH$NAME: ")) { workChName.add(line.trim().replaceAll("CH\\$NAME: ", "")); } // AC$INSTRUMENT_TYPE?Ver.1? else if (line.startsWith("AC$INSTRUMENT_TYPE: ")) { workAcInstrumentType = line.trim().replaceAll("AC\\$INSTRUMENT_TYPE: ", ""); } // AC$MASS_SPECTROMETRY: MS_TYPE?Ver.2 else if (ver != 1 && line.startsWith("AC$MASS_SPECTROMETRY: MS_TYPE ")) { workAcMsType = line.trim().replaceAll("AC\\$MASS_SPECTROMETRY: MS_TYPE ", ""); } // ? if (!isDoubleByte) { byte[] bytes = line.getBytes("MS932"); if (bytes.length != line.length()) { isDoubleByte = true; } } } } catch (IOException e) { Logger.getLogger("global").severe("file read failed." + NEW_LINE + " " + file.getPath()); e.printStackTrace(); op.println(msgErr("server error.")); validationMap.clear(); return validationMap; } finally { try { if (br != null) { br.close(); } } catch (IOException e) { } } if (isInvalidInfo) { // ????? if (status.equals("")) status = STATUS_WARN; detailsWarn.append("invalid after the end tag [//]."); } if (isDoubleByte) { // ????? if (status.equals("")) status = STATUS_ERR; detailsErr.append("double-byte character included."); } if (ver == 1 && existLicense) { // LICENSE???Ver.1 if (status.equals("")) status = STATUS_ERR; detailsErr.append("[LICENSE: ] tag can not be used in record format [version 1]."); } // ---------------------------------------------------- // ???? // ---------------------------------------------------- boolean isNameCheck = false; int peakNum = -1; for (int j = 0; j < requiredList.length; j++) { String requiredStr = requiredList[j]; ArrayList<String> valStrs = new ArrayList<String>(); // boolean findRequired = false; // boolean findValue = false; // boolean isPeakMode = false; // for (int k = 0; k < fileContents.size(); k++) { String lineStr = fileContents.get(k); // ????RELATED_RECORD?????? if (lineStr.startsWith("//")) { // Ver.1? break; } else if (ver == 1 && lineStr.startsWith("RELATED_RECORD:")) { // Ver.1 break; } // ????? else if (isPeakMode) { findRequired = true; if (!lineStr.trim().equals("")) { valStrs.add(lineStr); } } // ?????? else if (lineStr.indexOf(requiredStr) != -1) { // findRequired = true; if (requiredStr.equals("PK$PEAK: ")) { isPeakMode = true; findValue = true; valStrs.add(lineStr.replace(requiredStr, "")); } else { // String tmpVal = lineStr.replace(requiredStr, ""); if (!tmpVal.trim().equals("")) { findValue = true; valStrs.add(tmpVal); } break; } } } if (!findRequired) { // ?????? status = STATUS_ERR; detailsErr.append("no required item [" + requiredStr + "]."); } else { if (!findValue) { // ????? status = STATUS_ERR; detailsErr.append("no value of required item [" + requiredStr + "]."); } else { // ??? // ---------------------------------------------------- // ?? // ---------------------------------------------------- String val = (valStrs.size() > 0) ? valStrs.get(0) : ""; // ACESSIONVer.1? if (requiredStr.equals("ACCESSION: ")) { if (!val.equals(name.replace(REC_EXTENSION, ""))) { status = STATUS_ERR; detailsErr.append("value of required item [" + requiredStr + "] not correspond to file name."); } if (val.length() != 8) { status = STATUS_ERR; detailsErr.append( "value of required item [" + requiredStr + "] is 8 digits necessary."); } } // RECORD_TITLEVer.1? else if (requiredStr.equals("RECORD_TITLE: ")) { if (!val.equals(DEFAULT_VALUE)) { if (val.indexOf(";") != -1) { String[] recTitle = val.split(";"); if (!workChName.contains(recTitle[0].trim())) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "], compound name is not included in the [CH$NAME]."); } if (!workAcInstrumentType.equals(recTitle[1].trim())) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "], instrument type is different from [AC$INSTRUMENT_TYPE]."); } if (ver != 1 && !workAcMsType.equals(recTitle[2].trim())) { // Ver.2 if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "], ms type is different from [AC$MASS_SPECTROMETRY: MS_TYPE]."); } } else { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "] is not record title format."); if (!workChName.contains(val)) { detailsWarn.append("value of required item [" + requiredStr + "], compound name is not included in the [CH$NAME]."); } if (!workAcInstrumentType.equals(DEFAULT_VALUE)) { detailsWarn.append("value of required item [" + requiredStr + "], instrument type is different from [AC$INSTRUMENT_TYPE]."); } if (ver != 1 && !workAcMsType.equals(DEFAULT_VALUE)) { // Ver.2 detailsWarn.append("value of required item [" + requiredStr + "], ms type is different from [AC$MASS_SPECTROMETRY: MS_TYPE]."); } } } else { if (!workAcInstrumentType.equals(DEFAULT_VALUE)) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "], instrument type is different from [AC$INSTRUMENT_TYPE]."); } if (ver != 1 && !workAcMsType.equals(DEFAULT_VALUE)) { // Ver.2 if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "], ms type is different from [AC$MASS_SPECTROMETRY: MS_TYPE]."); } } } // DATEVer.1? else if (requiredStr.equals("DATE: ") && !val.equals(DEFAULT_VALUE)) { val = val.replace(".", "/"); val = val.replace("-", "/"); try { DateFormat.getDateInstance(DateFormat.SHORT, Locale.JAPAN).parse(val); } catch (ParseException e) { if (status.equals("")) status = STATUS_WARN; detailsWarn .append("value of required item [" + requiredStr + "] is not date format."); } } // CH$COMPOUND_CLASSVer.1? else if (requiredStr.equals("CH$COMPOUND_CLASS: ") && !val.equals(DEFAULT_VALUE)) { if (!val.startsWith("Natural Product") && !val.startsWith("Non-Natural Product")) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "] is not compound class format."); } } // CH$EXACT_MASSVer.1? else if (requiredStr.equals("CH$EXACT_MASS: ") && !val.equals(DEFAULT_VALUE)) { try { Double.parseDouble(val); } catch (NumberFormatException e) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "] is not numeric."); } } // AC$INSTRUMENT_TYPEVer.1? else if (requiredStr.equals("AC$INSTRUMENT_TYPE: ") && !val.equals(DEFAULT_VALUE)) { if (val.trim().indexOf(" ") != -1) { if (status.equals("")) status = STATUS_WARN; detailsWarn .append("value of required item [" + requiredStr + "] is space included."); } if (val.trim().indexOf(" ") != -1) { if (status.equals("")) status = STATUS_WARN; detailsWarn .append("value of required item [" + requiredStr + "] is space included."); } } // AC$MASS_SPECTROMETRY: MS_TYPEVer.2 else if (ver != 1 && requiredStr.equals("AC$MASS_SPECTROMETRY: MS_TYPE ") && !val.equals(DEFAULT_VALUE)) { boolean isMsType = true; if (val.startsWith("MS")) { val = val.replace("MS", ""); if (!val.equals("")) { try { Integer.parseInt(val); } catch (NumberFormatException e) { isMsType = false; } } } else { isMsType = false; } if (!isMsType) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "] is not \"MSn\"."); } } // AC$MASS_SPECTROMETRY: // ION_MODEVer.2?AC$ANALYTICAL_CONDITION: MODEVer.1 else if ((ver != 1 && requiredStr.equals("AC$MASS_SPECTROMETRY: ION_MODE ") && !val.equals(DEFAULT_VALUE)) || (ver == 1 && requiredStr.equals("AC$ANALYTICAL_CONDITION: MODE ") && !val.equals(DEFAULT_VALUE))) { if (!val.equals("POSITIVE") && !val.equals("NEGATIVE")) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "] is not \"POSITIVE\" or \"NEGATIVE\"."); } } // PK$NUM_PEAKVer.1? else if (requiredStr.equals("PK$NUM_PEAK: ") && !val.equals(DEFAULT_VALUE)) { try { peakNum = Integer.parseInt(val); } catch (NumberFormatException e) { status = STATUS_ERR; detailsErr.append("value of required item [" + requiredStr + "] is not numeric."); } } // PK$PEAK:Ver.1? else if (requiredStr.equals("PK$PEAK: ")) { if (valStrs.size() == 0 || !valStrs.get(0).startsWith("m/z int. rel.int.")) { status = STATUS_ERR; detailsErr.append( "value of required item [PK$PEAK: ] , the first line is not \"PK$PEAK: m/z int. rel.int.\"."); } else { boolean isNa = false; String peak = ""; String mz = ""; String intensity = ""; boolean mzDuplication = false; boolean mzNotNumeric = false; boolean intensityNotNumeric = false; boolean invalidFormat = false; HashSet<String> mzSet = new HashSet<String>(); for (int l = 0; l < valStrs.size(); l++) { peak = valStrs.get(l).trim(); // N/A if (peak.indexOf(DEFAULT_VALUE) != -1) { isNa = true; break; } if (l == 0) { continue; } // m/z int. rel.int.?????????? if (peak.indexOf(" ") != -1) { mz = peak.split(" ")[0]; if (!mzSet.add(mz)) { mzDuplication = true; } try { Double.parseDouble(mz); } catch (NumberFormatException e) { mzNotNumeric = true; } intensity = peak.split(" ")[1]; try { Double.parseDouble(intensity); } catch (NumberFormatException e) { intensityNotNumeric = true; } } else { invalidFormat = true; } if (mzDuplication && mzNotNumeric && intensityNotNumeric && invalidFormat) { break; } } if (isNa) {// PK$PEAK:?N/A?? if (peakNum != -1) { // PK$NUM_PEAK:N/A?? if (status.equals("")) status = STATUS_WARN; detailsWarn .append("value of required item [PK$NUM_PEAK: ] is mismatch or \"" + DEFAULT_VALUE + "\"."); } if (valStrs.size() - 1 > 0) { // PK$PEAK:???????? if (status.equals("")) status = STATUS_WARN; detailsWarn.append( "value of required item [PK$NUM_PEAK: ] is invalid peak information exists."); } } else { if (mzDuplication) { status = STATUS_ERR; detailsErr.append( "mz value of required item [" + requiredStr + "] is duplication."); } if (mzNotNumeric) { status = STATUS_ERR; detailsErr.append( "mz value of required item [" + requiredStr + "] is not numeric."); } if (intensityNotNumeric) { status = STATUS_ERR; detailsErr.append("intensity value of required item [" + requiredStr + "] is not numeric."); } if (invalidFormat) { status = STATUS_ERR; detailsErr.append( "value of required item [" + requiredStr + "] is not peak format."); } if (peakNum != 0 && valStrs.size() - 1 == 0) { // ?????N/A????PK$NUM_PEAK:?0??????? if (status.equals("")) status = STATUS_WARN; detailsWarn.append( "value of required item [PK$PEAK: ] is no value. at that time, please add \"" + DEFAULT_VALUE + "\". "); } if (peakNum != valStrs.size() - 1) { if (status.equals("")) status = STATUS_WARN; detailsWarn .append("value of required item [PK$NUM_PEAK: ] is mismatch or \"" + DEFAULT_VALUE + "\"."); } } } } } } } String details = detailsErr.toString() + detailsWarn.toString(); if (status.equals("")) { status = STATUS_OK; details = " "; } validationMap.put(name, status + "\t" + details); } // // ---------------------------------------------------- // // ???? // // ---------------------------------------------------- // // ?ID?DB // HashSet<String> regIdList = new HashSet<String>(); // String[] sqls = { "SELECT ID FROM SPECTRUM ORDER BY ID", // "SELECT ID FROM RECORD ORDER BY ID", // "SELECT ID FROM PEAK GROUP BY ID ORDER BY ID", // "SELECT ID FROM CH_NAME ID ORDER BY ID", // "SELECT ID FROM CH_LINK ID ORDER BY ID", // "SELECT ID FROM TREE WHERE ID IS NOT NULL AND ID<>'' ORDER BY ID" }; // for (int i = 0; i < sqls.length; i++) { // String execSql = sqls[i]; // ResultSet rs = null; // try { // rs = db.executeQuery(execSql); // while (rs.next()) { // String idStr = rs.getString("ID"); // regIdList.add(idStr); // } // } catch (SQLException e) { // Logger.getLogger("global").severe(" sql : " + execSql); // e.printStackTrace(); // op.println(msgErr("database access error.")); // return new TreeMap<String, String>(); // } finally { // try { // if (rs != null) { // rs.close(); // } // } catch (SQLException e) { // } // } // } // // ?ID? // final String[] recFileList = (new File(registPath)).list(); // for (int i = 0; i < recFileList.length; i++) { // String name = recFileList[i]; // File file = new File(registPath + File.separator + name); // if (!file.isFile() || file.isHidden() // || name.lastIndexOf(REC_EXTENSION) == -1) { // continue; // } // String idStr = name.replace(REC_EXTENSION, ""); // regIdList.add(idStr); // } // // ?? // for (Map.Entry<String, String> e : validationMap.entrySet()) { // String statusStr = e.getValue().split("\t")[0]; // if (statusStr.equals(STATUS_ERR)) { // continue; // } // String nameStr = e.getKey(); // String idStr = e.getKey().replace(REC_EXTENSION, ""); // String detailsStr = e.getValue().split("\t")[1]; // if (regIdList.contains(idStr)) { // statusStr = STATUS_WARN; // detailsStr += "id [" // + idStr + "] of file name [" // + nameStr // + "] already registered."; // validationMap.put(nameStr, statusStr + "\t" + detailsStr); // } // } return validationMap; }
From source file:net.sourceforge.vulcan.core.support.AbstractProjectDomBuilder.java
private void addTimestampNode(final Element parent, String nodeName, final Date date, final DateFormat format, Locale locale) {//from w w w . j av a 2s . c o m if (date != null) { final DateFormat textualDateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT, locale); final Element timestampNode = addChildNodeWithText(parent, nodeName, format.format(date)); timestampNode.setAttribute("millis", Long.toString(date.getTime())); timestampNode.setAttribute("text", textualDateFormat.format(date)); } }