List of usage examples for java.text DateFormat parse
public Date parse(String source) throws ParseException
From source file:services.GoogleComputeEngineService.java
public static void listOperations(ActorRef actor, Date lastOperationDate) throws GoogleComputeEngineException { checkAuthentication();/*from w ww . j a v a2s. c o m*/ DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"); Inbox inbox = Inbox.create(Akka.system()); if (lastOperationDate != null) { lastOperationDate = new Date(lastOperationDate.getTime() + 1); } OperationsCache.cleanOldOperationsFromCache(); for (Operation o : client.getOperations()) { if (lastOperationDate != null) { if (!OperationsCache.statusHasChanged(o) && !"RUNNING".equalsIgnoreCase(o.getStatus())) { if (o.getStartTime() == null) { continue; } try { Date date = format.parse(o.getStartTime()); if (date.before(lastOperationDate)) { continue; } } catch (ParseException e) { continue; } } } OperationsCache.addOperation(o); inbox.send(actor, o); } }
From source file:info.rmapproject.core.rmapservice.impl.openrdf.ORMapStatementMgrTest.java
@Test public void testGetRelatedDiSCOs() { try {//from ww w .jav a 2 s . c o m //create new test agent RMapAgent agent = new ORMapAgent(AGENT_IRI, ID_PROVIDER_IRI, AUTH_ID_IRI, NAME); java.net.URI agentId = agent.getId().getIri(); if (!rmapService.isAgentId(agentId)) { rmapService.createAgent(agent, requestAgent); } if (rmapService.isAgentId(agentId)) { System.out.println("Test Agent successfully created! URI is " + agentId); } //create disco InputStream stream = new ByteArrayInputStream(discoRDF.getBytes(StandardCharsets.UTF_8)); RioRDFHandler handler = new RioRDFHandler(); Set<Statement> stmts = handler.convertRDFToStmtList(stream, RDFType.RDFXML, ""); ORMapDiSCO disco = new ORMapDiSCO(stmts); requestAgent.setAgentKeyId(new java.net.URI("ark:/29297/testkey")); discomgr.createDiSCO(disco, requestAgent, triplestore); RMapIri discoId = disco.getId(); //get related discos Set<URI> sysAgents = new HashSet<URI>(); sysAgents.add(agentId); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date dateFrom = dateFormat.parse("2014-1-1"); Date dateTo = dateFormat.parse("2050-1-1"); IRI subject = ORAdapter.getValueFactory().createIRI("http://dx.doi.org/10.1109/ACCESS.2014.2332453"); IRI predicate = ORAdapter.getValueFactory().createIRI("http://purl.org/dc/elements/1.1/subject"); Value object = ORAdapter.getValueFactory().createLiteral("Hadoop"); RMapSearchParams params = new RMapSearchParams(); params.setStatusCode(RMapStatusFilter.ACTIVE); params.setDateRange(dateFrom, dateTo); List<IRI> discoIds = stmtmgr.getRelatedDiSCOs(subject, predicate, object, params, triplestore); assertTrue(discoIds.size() == 1); Iterator<IRI> iter = discoIds.iterator(); IRI matchingDiscoId = iter.next(); assertTrue(matchingDiscoId.toString().equals(discoId.toString())); discomgr.updateDiSCO(matchingDiscoId, null, requestAgent, true, triplestore); discoIds = stmtmgr.getRelatedDiSCOs(subject, predicate, object, params, triplestore); assertTrue(discoIds.size() == 0); params.setStatusCode(RMapStatusFilter.INACTIVE); discoIds = stmtmgr.getRelatedDiSCOs(subject, predicate, object, params, triplestore); assertTrue(discoIds.size() == 1); rmapService.deleteDiSCO(disco.getId().getIri(), requestAgent); } catch (Exception e) { e.printStackTrace(); fail(); } }
From source file:ispyb.common.util.upload.UploadShipmentUtils.java
public static String[] importFromXls(InputStream file, Integer shippingId, boolean deleteAllShipment, List<String> allowedSpaceGroups) throws Exception { String msgError = ""; String msgWarning = ""; Protein3Service proteinService = (Protein3Service) ejb3ServiceLocator .getLocalService(Protein3Service.class); Crystal3Service crystalService = (Crystal3Service) ejb3ServiceLocator .getLocalService(Crystal3Service.class); BLSample3Service sampleService = (BLSample3Service) ejb3ServiceLocator .getLocalService(BLSample3Service.class); DiffractionPlan3Service difPlanService = (DiffractionPlan3Service) ejb3ServiceLocator .getLocalService(DiffractionPlan3Service.class); Container3Service containerService = (Container3Service) ejb3ServiceLocator .getLocalService(Container3Service.class); Shipping3Service shippingService = (Shipping3Service) ejb3ServiceLocator .getLocalService(Shipping3Service.class); Shipping3VO shipment = shippingService.findByPk(shippingId, true); Set<Dewar3VO> dewars = shipment.getDewarVOs(); HSSFWorkbook workbook = null;//from www .j a v a 2 s . com Integer sheetProposalId = DBTools.getProposalIdFromShipping(shippingId); String courrierName = ""; String shippingDate = ""; String trackingNumber = ""; POIFSFileSystem fs = new POIFSFileSystem(file); // Now extract the workbook workbook = new HSSFWorkbook(fs); // Working through each of the worksheets in the spreadsheet // ASSUMPTION: one excel file = one shipment for (int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum++) { boolean sheetIsEmpty = true; HSSFSheet sheet = workbook.getSheetAt(sheetNum); // DeliveryAgent ---- // --- Retrieve Shipment related information if (sheetNum == 0) { if (sheet.getRow(courrierNameRow).getCell(courrierNameCol) == null) { msgError += "The format of the xls file is incorrect (courrier name missing)"; String[] msg = new String[2]; msg[0] = msgError; msg[1] = msgWarning; return msg; } courrierName = (sheet.getRow(courrierNameRow).getCell(courrierNameCol)).toString(); if (sheet.getRow(shippingDateRow).getCell(shippingDateCol) == null) { msgError += "The format of the xls file is incorrect (shipping Date missing)"; String[] msg = new String[2]; msg[0] = msgError; msg[1] = msgWarning; return msg; } shippingDate = (sheet.getRow(shippingDateRow).getCell(shippingDateCol)).toString(); if (sheet.getRow(trackingNumberRow).getCell(trackingNumberCol) == null) { msgError += "The format of the xls file is incorrect (tracking number missing)"; String[] msg = new String[2]; msg[0] = msgError; msg[1] = msgWarning; return msg; } trackingNumber = (sheet.getRow(trackingNumberRow).getCell(trackingNumberCol)).toString(); // retrieveShippingId(file); DateFormat fmt = new SimpleDateFormat("dd/MM/yyyy"); Date shipDate = null; Calendar shipCal = Calendar.getInstance(); try { shipDate = fmt.parse(shippingDate); shipCal.setTime(shipDate); } catch (Exception e) { shipCal = Calendar.getInstance(); } shipment.setDeliveryAgentAgentCode(trackingNumber); shipment.setDeliveryAgentAgentName(courrierName); shipment.setDeliveryAgentShippingDate(shipDate); } // Dewar String dewarCode = (sheet.getRow(dewarRow).getCell(dewarCol)).toString().trim(); Integer dewarId = null; Dewar3VO dewar = null; // check if dewar exists for (Dewar3VO dewar3vo : dewars) { if (dewar3vo.getCode().equals(dewarCode)) { dewarId = dewar3vo.getDewarId(); dewar = dewar3vo; break; } } Container3VO container = null; if (dewar == null) { msgError += "Dewar with code '" + dewarCode + "' does not correspond to any dewar. Please check the dewar's name.\n"; sheetIsEmpty = true; } else { // Puck container = new Container3VO(); container.setDewarVO(dewar); container.setContainerType("Puck"); container.setCode((sheet.getRow(puckRow).getCell(puckCol)).toString().trim()); container.setCapacity(Constants.BASKET_SAMPLE_CAPACITY); container.setTimeStamp(StringUtils.getCurrentTimeStamp()); if (!deleteAllShipment) { // check sheet empty before boolean sheetEmpty = true; for (int i = dataRow; i < dataRow + Constants.BASKET_SAMPLE_CAPACITY; i += 1) { boolean sampleRowOK = true; String puckCode = cellToString(sheet.getRow(puckRow).getCell(puckCol)); String proteinAcronym = cellToString(sheet.getRow(i).getCell(proteinAcronymCol)); String sampleName = cellToString(sheet.getRow(i).getCell(sampleNameCol)); boolean sampleNameRulesOk = sampleName .matches(Constants.MASK_BASIC_CHARACTERS_WITH_DASH_UNDERSCORE_NO_SPACE); if (puckCode.isEmpty() || dewarCode.isEmpty() || proteinAcronym.isEmpty() || sampleName.isEmpty() || !sampleNameRulesOk) { sampleRowOK = false; } if (!sampleRowOK) { // Skip this line we do not create the sample } else { sheetEmpty = false; break; } } List<Container3VO> listContainerFromDB = containerService.findByCode(dewar.getDewarId(), container.getCode()); if (listContainerFromDB != null && listContainerFromDB.size() > 0 && !sheetEmpty) { // delete it in // order to be // replaced by // the new one containerService.deleteByPk(listContainerFromDB.get(0).getContainerId()); msgWarning += "The Puck " + container.getCode() + " has been deleted and a new one has been added."; } } container = containerService.create(container); // List<Crystal3VO> listCrystalCreated = new ArrayList<Crystal3VO>(); List<Crystal3VO> listCrystalCreated = crystalService.findByProposalId(sheetProposalId); // TBD: need to add sanity check that this puck has not already been put in the dewar! for (int i = dataRow; i < dataRow + Constants.BASKET_SAMPLE_CAPACITY; i += 1) { // --- Retrieve interesting values from spreadsheet String puckCode = cellToString(sheet.getRow(puckRow).getCell(puckCol)); String proteinName = cellToString(sheet.getRow(i).getCell(proteinNameCol)); String proteinAcronym = cellToString(sheet.getRow(i).getCell(proteinAcronymCol)); String samplePos = cellToString(sheet.getRow(i).getCell(samplePosCol)); String sampleName = cellToString(sheet.getRow(i).getCell(sampleNameCol)); String pinBarCode = cellToString(sheet.getRow(i).getCell(pinBarCodeCol)); double preObsResolution = cellToDouble(sheet.getRow(i).getCell(preObsResolutionCol)); double neededResolution = cellToDouble(sheet.getRow(i).getCell(neededResolutionCol)); double preferedBeamDiameter = cellToDouble(sheet.getRow(i).getCell(preferredBeamCol)); String experimentType = cellToString(sheet.getRow(i).getCell(experimentTypeCol)); int nbOfPositions = cellToInt(sheet.getRow(i).getCell(nbOfPositionsCol)); String spaceGroup = cellToString(sheet.getRow(i).getCell(spaceGroupCol)).toUpperCase().trim() .replace(" ", ""); double unitCellA = cellToDouble(sheet.getRow(i).getCell(unitCellACol)); double radiationSensitivity = cellToDouble(sheet.getRow(i).getCell(radiationSensitivityCol)); double requiredCompleteness = cellToDouble(sheet.getRow(i).getCell(requiredCompletenessCol)); double requiredMultiplicity = cellToDouble(sheet.getRow(i).getCell(requiredMultiplicityCol)); double unitCellB = cellToDouble(sheet.getRow(i).getCell(unitCellBCol)); double unitCellC = cellToDouble(sheet.getRow(i).getCell(unitCellCCol)); double unitCellAlpha = cellToDouble(sheet.getRow(i).getCell(unitCellAlphaCol)); double unitCellBeta = cellToDouble(sheet.getRow(i).getCell(unitCellBetaCol)); double unitCellGamma = cellToDouble(sheet.getRow(i).getCell(unitCellGammaCol)); String sampleComments = cellToString(sheet.getRow(i).getCell(commentsCol)); String smiles = cellToString(sheet.getRow(i).getCell(smilesCol)); double minOscWidth = cellToDouble(sheet.getRow(i).getCell(minOscWidthCol)); // Fill in values by default // Protein Name if (proteinName.equalsIgnoreCase("")) proteinName = proteinAcronym; // --- Check the Sheet is not empty for this line and all required fields are present --- boolean sampleRowOK = true; boolean sampleNameRulesOk = sampleName .matches(Constants.MASK_BASIC_CHARACTERS_WITH_DASH_UNDERSCORE_NO_SPACE); if (puckCode.isEmpty() || dewarCode.isEmpty() || proteinAcronym.isEmpty() || sampleName.isEmpty() || sampleName.length() > Constants.BLSAMPLE_NAME_NB_CHAR || !sampleNameRulesOk) { sampleRowOK = false; if (!(sampleName.isEmpty() && proteinAcronym.isEmpty())) { msgError += "Error with the sample: " + sampleName; if (puckCode.isEmpty()) { msgError += " (The puck code is empty)"; } if (dewarCode.isEmpty()) { msgError += " (The dewar code is empty)"; } if (proteinAcronym.isEmpty()) { msgError += " (The protein acronym is empty)"; } if (sampleName.isEmpty()) { msgError += " (The sample name is empty)"; } if (sampleName.length() > Constants.BLSAMPLE_NAME_NB_CHAR) { msgError += " (The sample name is too long : max 8 characters)"; } if (!sampleNameRulesOk) { msgError += " (The sample name is not well formatted)"; } msgError += "\n."; } } if (!sampleRowOK) { // Skip this line we do not create the sample } else { sheetIsEmpty = false; String crystalID = UUID.randomUUID().toString(); // String diffractionPlanUUID = uuidGenerator.generateRandomBasedUUID().toString(); if ((null != crystalID) && (!crystalID.equals(""))) { // Parse ProteinAcronym - SpaceGroup // Pre-filled spreadsheet (including protein_acronym - SpaceGroup) int separatorStart = proteinAcronym .indexOf(Constants.PROTEIN_ACRONYM_SPACE_GROUP_SEPARATOR); if (separatorStart != -1) { String acronym = proteinAcronym.substring(0, separatorStart); String prefilledSpaceGroup = proteinAcronym.substring( separatorStart + Constants.PROTEIN_ACRONYM_SPACE_GROUP_SEPARATOR.length(), proteinAcronym.length()); proteinAcronym = acronym; if (allowedSpaceGroups.contains(spaceGroup.toUpperCase())) { // Do nothing = use spaceGroup from dropdown list } else if (allowedSpaceGroups.contains(prefilledSpaceGroup.toUpperCase())) { // Used pre-filled space group spaceGroup = prefilledSpaceGroup; } } // Protein // We might eventually want to include more details in the spreadsheet, but for the time // being // just the name is sufficient. List<Protein3VO> proteinTab = proteinService.findByAcronymAndProposalId(sheetProposalId, proteinAcronym); if (proteinTab == null || proteinTab.size() == 0) { msgError += "Protein '" + proteinAcronym + "' can't be found \n "; } else { Protein3VO protein = proteinTab.get(0); // unique sample name List<BLSample3VO> samplesWithSameName = sampleService .findByNameAndProteinId(sampleName, protein.getProteinId(), shippingId); boolean validName = true; if (!samplesWithSameName.isEmpty()) { validName = false; msgError += "[" + protein.getAcronym() + " + " + sampleName + "] is already existing, and should be unique.\n"; } if (validName) { // Diffraction Plan DiffractionPlan3VO difPlan = new DiffractionPlan3VO(); difPlan.setNumberOfPositions(nbOfPositions); difPlan.setObservedResolution(preObsResolution); difPlan.setRequiredResolution(neededResolution); difPlan.setExposureTime((double) 0); difPlan.setPreferredBeamDiameter(preferedBeamDiameter); if (experimentType == null || experimentType.isEmpty()) { experimentType = "Default"; } difPlan.setExperimentKind(experimentType); difPlan.setRadiationSensitivity(radiationSensitivity); difPlan.setRequiredCompleteness(requiredCompleteness); difPlan.setRequiredMultiplicity(requiredMultiplicity); difPlan.setMinOscWidth(minOscWidth); difPlan = difPlanService.create(difPlan); // Crystal Crystal3VO crystal = new Crystal3VO(); crystal.setProteinVO(protein); crystal.setDiffractionPlanVO(difPlan); crystal.setCrystalUUID(crystalID); crystal.setSpaceGroup(spaceGroup); if ((crystal.getSpaceGroup() == null) || (crystal.getSpaceGroup().equals(""))) { crystal.setSpaceGroup("Undefined"); } else { // TODO SD in the case where space group is not empty and no cell dimensions // have been // entered, // fill the crystal with the default value of the crystal = protein + space // group List<Crystal3VO> tab = crystalService.findFiltered(sheetProposalId, null, proteinAcronym, spaceGroup); if (tab != null && tab.size() > 0) { Crystal3VO newCrystal3VO = new Crystal3VO(); int j = 0; for (Crystal3VO crystal3vo : tab) { newCrystal3VO = tab.get(j); j = j + 1; } if (newCrystal3VO != null && unitCellA == 0 && unitCellB == 0 && unitCellC == 0 && unitCellAlpha == 0 && unitCellBeta == 0 && unitCellGamma == 0) { unitCellA = (newCrystal3VO.getCellA() == null ? 0 : newCrystal3VO.getCellA()); unitCellB = (newCrystal3VO.getCellB() == null ? 0 : newCrystal3VO.getCellB()); unitCellC = (newCrystal3VO.getCellC() == null ? 0 : newCrystal3VO.getCellC()); unitCellAlpha = (newCrystal3VO.getCellAlpha() == null ? 0 : newCrystal3VO.getCellAlpha()); unitCellBeta = (newCrystal3VO.getCellBeta() == null ? 0 : newCrystal3VO.getCellBeta()); unitCellGamma = (newCrystal3VO.getCellGamma() == null ? 0 : newCrystal3VO.getCellGamma()); } } } // crystal.setResolution(preObsResolution); // Create the crystal name from the uuid and ligandid String crystalName = crystal.getCrystalUUID(); crystal.setName(crystalName); crystal.setCellA(unitCellA); crystal.setCellB(unitCellB); crystal.setCellC(unitCellC); crystal.setCellAlpha(unitCellAlpha); crystal.setCellBeta(unitCellBeta); crystal.setCellGamma(unitCellGamma); // crystal = crystalService.create(crystal); Crystal3VO crystalC = getCrystal(listCrystalCreated, crystal); if (crystalC == null) { crystal = crystalService.create(crystal); listCrystalCreated.add(crystal); } else { crystal = crystalC; } if (!crystal.hasCellInfo()) { msgWarning += "Warning: the unit cell parameters are not filled for the spaceGroup " + crystal.getSpaceGroup() + " (" + proteinAcronym + ")!"; } // And add the crystal to the list // addCrystal(crystal); // Holder BLSample3VO holder = new BLSample3VO(); holder.setCrystalVO(crystal); holder.setName(sampleName); holder.setCode(pinBarCode); holder.setLocation(samplePos); holder.setSmiles(smiles); // ASSUMPTION: holder is SPINE standard! holder.setHolderLength(holderLength); holder.setLoopLength(0.5); holder.setLoopType(loopType); holder.setWireWidth(0.010); holder.setComments(sampleComments); // Add holder to the container... holder.setContainerVO(container); holder = sampleService.create(holder); // container.addSampleVO(holder); holder.setDiffractionPlanVO(difPlan); holder = sampleService.update(holder); } // end validName } // end protein } // end crystalID } // end sampleRowOK } // for dataRow } // end dewar != null // all samples were empty if (sheetIsEmpty) { if (container != null) { // remove the container containerService.deleteByPk(container.getContainerId()); } // TODO understand the following and remove it // remove the dewar if no containers // Dewar3Service dewarService = (Dewar3Service) ejb3ServiceLocator.getLocalService(Dewar3Service.class); // boolean removedOK = true; // if (dewar != null) { // Dewar3VO existingDewar = dewarService.findByPk(dewar.getDewarId(), false, false); // if (existingDewarList == null || existingDewarList.isEmpty()) { // Dewar did not exist // removedOK = false; // } else {// Dewar was there, deleting it ... // dewar = dewarService.findByPk(dewar.getDewarId(), true, true); // if (dewar.getContainerVOs().size() == 0) { // dewars.remove(dewar); // } // } // } } } String[] msg = new String[2]; msg[0] = msgError; msg[1] = msgWarning; return msg; }
From source file:uk.gov.nationalarchives.discovery.taxonomy.batch.scheduler.updateSolrCloudTask.java
private List getNewCategorisedDocuments() { if (lastIAViewUpdate != null) { return categoriserService.getNewCategorisedDocumentsAfterDocumentAndUpToNSecondsInPast(lastIAViewUpdate, nbOfSecondsInPast, bulkUpdateSize); } else if (!StringUtils.isEmpty(startDateString)) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH); df.setCalendar(Calendar.getInstance(TimeZone.getTimeZone("UTC"))); Date startDate;/* w ww. j a v a 2s . c o m*/ try { startDate = df.parse(startDateString); return categoriserService.getNewCategorisedDocumentsFromDateToNSecondsInPast(startDate, nbOfSecondsInPast, bulkUpdateSize); } catch (ParseException e) { throw new TaxonomyException(TaxonomyErrorType.INVALID_PARAMETER, "the start date provided has wrong format"); } } else { return categoriserService.getNewCategorisedDocumentsFromDateToNSecondsInPast(null, nbOfSecondsInPast, bulkUpdateSize); } }
From source file:com.nesscomputing.syslog4j.server.impl.event.SyslogServerEvent.java
protected void parseDate() { if (this.message.length() >= 16 && this.message.charAt(3) == ' ' && this.message.charAt(6) == ' ') { String year = Integer.toString(Calendar.getInstance().get(Calendar.YEAR)); String originalDate = this.message.substring(0, 15) + " " + year; DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); try {//from w ww . j a va 2 s . c o m this.date = dateFormat.parse(originalDate); this.message = this.message.substring(16); } catch (ParseException pe) { this.date = new Date(); } } }
From source file:net.naijatek.myalumni.util.date.DateConverter.java
protected Object convertToDate(Class type, Object value, String pattern) { DateFormat df = new SimpleDateFormat(pattern); if (value instanceof String) { try {/*from w ww . ja v a 2s . c o m*/ if (StringUtils.isEmpty(value.toString())) { return null; } Date date = df.parse((String) value); if (type.equals(Timestamp.class)) { return new Timestamp(date.getTime()); } return date; } catch (Exception pe) { pe.printStackTrace(); throw new ConversionException("Error converting String to Date"); } } throw new ConversionException("Could not convert " + value.getClass().getName() + " to " + type.getName()); }
From source file:com.wso2telco.gsma.authenticators.attributeshare.AbstractAttributeShare.java
private boolean isLongLiveConsent(AuthenticationContext context, String scope) throws NamingException, DBUtilException { boolean isConsent = false; try {/*from w w w . j av a 2s . co m*/ UserConsentDetails userConsentDetails = getUserConsentDetails(context, scope); if (userConsentDetails == null) { isConsent = true; } else { if (userConsentDetails.getRevokeStatus().equalsIgnoreCase(Constants.TRUE)) { Date today = new Date(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); if (today.after(dateFormat.parse(userConsentDetails.getConsentExpireDatetime()))) { isConsent = true; } } else if (userConsentDetails.getRevokeStatus().equalsIgnoreCase(Constants.FALSE)) { isConsent = true; } } } catch (DBUtilException | NamingException e) { log.error("error occurred while accessing the database table : " + e.getMessage()); } catch (ParseException e) { log.error("error occurred while formatting the date : " + e.getMessage()); } return isConsent; }
From source file:com.liangc.hq.base.web.ConfiguratorListener.java
private void loadBuildNumber(ServletContext ctx) { final String SNAPSHOT_IDENTIFIER = "BUILD-SNAPSHOT"; final String BUILD_DATE_FORMAT_OUTPUT = "yyyy-MM-dd"; final String BUILD_DATE_FORMAT_INPUT = "MMM dd, yyyy"; try {/* ww w . j a va 2 s .co m*/ String version = ProductProperties.getVersion(); if (version.contains(SNAPSHOT_IDENTIFIER)) { try { // Get build date, format into Date object... String date = ProductProperties.getBuildDate(); DateFormat format = new SimpleDateFormat(BUILD_DATE_FORMAT_INPUT); Date buildDate = format.parse(date); // Take date object and format into different format for // display... format = new SimpleDateFormat(BUILD_DATE_FORMAT_OUTPUT); version += "-" + format.format(buildDate); } catch (ParseException e) { // Couldn't parse the date, so we fall back to using just // the version string... log.info("Couldn't parse the build date for display", e); } } ctx.setAttribute(Constants.APP_VERSION, version); ctx.setAttribute(Constants.APP_BUILD, ProductProperties.getBuildNumber()); } catch (Exception e) { error("Unable to load product version", e); } }
From source file:com.gisgraphy.util.DateConverter.java
/** * Convert a String to a Date with the specified pattern. * /*from w w w. j a va 2s. c o m*/ * @param type * String * @param value * value of String * @param pattern * date pattern to parse with * @return Converted value for property population */ @SuppressWarnings("unchecked") protected Object convertToDate(Class type, Object value, String pattern) { DateFormat df = new SimpleDateFormat(pattern); if (value instanceof String) { try { if (StringUtils.isEmpty(value.toString())) { return null; } Date date = df.parse((String) value); if (type.equals(Timestamp.class)) { return new Timestamp(date.getTime()); } return date; } catch (Exception pe) { throw new ConversionException("Error converting String to Date"); } } throw new ConversionException("Could not convert " + value.getClass().getName() + " to " + type.getName()); }
From source file:br.gov.jfrj.siga.vraptor.FeriadoController.java
public Date stringToDate(String data) throws Exception { if (data == null || data.equals("")) return null; Date date = null;/*from w w w . j a v a 2 s . com*/ try { DateFormat strDate = new SimpleDateFormat("dd/MM/yyyy"); date = (java.util.Date) strDate.parse(data); } catch (Exception e) { throw e; } return date; }