List of usage examples for java.text DateFormat parse
public Date parse(String source) throws ParseException
From source file:com.sishistorico.sv.SvCadastraEleitor.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*ww w .j a va 2 s.c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF8"); response.setContentType("text/html;charset=UTF-8"); List<FileItem> items = null; byte[] foto = null; try { items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : items) { if (!item.isFormField()) { InputStream imageInput = item.getInputStream(); Image image = ImageIO.read(imageInput); BufferedImage thumb = Imagem.redimensionar(image, 400, 500); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(thumb, "JPG", baos); baos.flush(); foto = baos.toByteArray(); baos.close(); } } //dados do formulrio e metodos para salvar DateFormat formatter; Date date; formatter = new SimpleDateFormat("dd/MM/yyyy"); date = (Date) formatter.parse(items.get(1).getString()); // fim do tratamento Eleitor el = new Eleitor(); Endereco end = new Endereco(); el.setNome(items.get(0).getString("UTF-8").trim()); el.setData_nascimento(date); el.setCpf(items.get(2).getString("UTF-8").replaceAll("\\.|\\-|\\ ", "").trim()); el.setRg(items.get(3).getString("UTF-8").replaceAll("\\.|\\-|\\ ", "").trim()); el.setSus(items.get(4).getString("UTF-8").replaceAll("\\.|\\-|\\ ", "").trim()); el.setEmail(items.get(5).getString("UTF-8")); el.setTelefone(items.get(6).getString("UTF-8").replaceAll("\\(|\\)|\\-|\\ ", "").trim()); el.setWhats(items.get(7).getString("UTF-8").replaceAll("\\(|\\)|\\-|\\ ", "").trim()); el.setObs(items.get(8).getString("UTF-8").trim()); el.setReferencia_pessoal(items.get(9).getString("UTF-8").trim()); end.setRua(items.get(11).getString("UTF-8").trim()); end.setBairro(items.get(12).getString("UTF-8").trim()); end.setN(items.get(13).getString("UTF-8").trim()); end.setCidade(items.get(14).getString("UTF-8").trim()); end.setCep(items.get(15).getString("UTF-8").trim()); end.setLocalidade(Integer.parseInt(items.get(16).getString("UTF-8").trim())); el.setTipo(Integer.parseInt(items.get(17).getString("UTF-8").trim())); el.setPertence(Integer.parseInt(items.get(18).getString("UTF-8").trim())); el.setEnd(end); DaoEleitor daoEleitor = new DaoEleitor(); DaoFoto daoFoto = new DaoFoto(); int idretorno = daoEleitor.Eleitor_Salvar(el); daoFoto.inserirImagem(foto, idretorno); response.sendRedirect("cadastro_eleitor.jsp?msgok"); } catch (FileUploadException ex) { Logger.getLogger(SvCadastraEleitor.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(SvCadastraEleitor.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(SvCadastraEleitor.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(SvCadastraEleitor.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:edu.uiowa.icts.bluebutton.domain.LabTest.java
public void setDateCreated(String dateCreated) { try {// w w w . j av a 2 s . c o m DateFormat formatter = new SimpleDateFormat("dd-MMM-yy"); formatter.setLenient(true); this.dateCreated = formatter.parse(dateCreated); } catch (ParseException e) { log.error(" ParseException setting date for DateCreated", e); } }
From source file:edu.uiowa.icts.bluebutton.domain.LabTest.java
public void setDateUpdated(String dateUpdated) { try {/*w w w .j ava2 s .c o m*/ DateFormat formatter = new SimpleDateFormat("dd-MMM-yy"); formatter.setLenient(true); this.dateUpdated = formatter.parse(dateUpdated); } catch (ParseException e) { log.error(" ParseException setting date for DateUpdated", e); } }
From source file:net.opendasharchive.openarchive.db.MediaDeserializer.java
@Override public Media deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Media mediaResult = new Media(); JsonObject jobj = (JsonObject) json; if (jobj.has("mimeType")) mediaResult.setMimeType(jobj.get("mimeType").getAsString()); if (jobj.has("title")) mediaResult.setTitle(jobj.get("title").getAsString()); if (jobj.has("description")) mediaResult.setDescription(jobj.get("description").getAsString()); if (jobj.has("serverUrl")) mediaResult.setServerUrl(jobj.get("serverUrl").getAsString()); if (jobj.has("location")) mediaResult.setLocation(jobj.get("location").getAsString()); if (jobj.has("tags")) mediaResult.setTags(jobj.get("tags").getAsString()); if (jobj.has("licenseUrl")) mediaResult.setLicenseUrl(jobj.get("licenseUrl").getAsString()); if (jobj.has("author")) mediaResult.setAuthor(jobj.get("author").getAsString()); DateFormat ft = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL); try {/*from w w w . j a va2s. c o m*/ if (jobj.has("createDate")) mediaResult.setCreateDate(ft.parse(jobj.get("createDate").getAsString())); } catch (ParseException e) { Log.e("MediaDez", "unable to parse date", e); } try { if (jobj.has("updateDate")) mediaResult.setUpdateDate(ft.parse(jobj.get("updateDate").getAsString())); } catch (ParseException e) { Log.e("MediaDez", "unable to parse date", e); } return mediaResult; }
From source file:org.asqatasun.websnapshot.webapp.controller.IndexController.java
/** * * @param date/*from w w w. ja va2 s.c om*/ * @return */ public Date convertStringDateToDate(String date) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); try { return df.parse(date); } catch (ParseException ex) { return null; } }
From source file:th.co.geniustree.dental.controller.BillController.java
@RequestMapping(value = "/searchBill", method = RequestMethod.POST) public Page<Bill> serchBill(@RequestBody SearchData searchData, Pageable pageable) throws ParseException { String searchBy = searchData.getSearchBy(); String keyword = searchData.getKeyword(); Page<Bill> bills = null;/* w w w. j a va 2 s . c o m*/ if ("DateBill".equals(searchBy)) { DateFormat sim = new SimpleDateFormat("yyyy-MM-dd", Locale.US); Date date = sim.parse(keyword); bills = billService.searchByDateBill(date, pageable); } if ("SumPrice".equals(searchBy)) { bills = billService.searchBySumPrice(new Double(keyword), pageable); } return bills; }
From source file:th.co.geniustree.dental.controller.BillController.java
@RequestMapping(value = "/countsearchbill", method = RequestMethod.POST) public long countSearchBill(@RequestBody SearchData searchData) throws ParseException { String searchBy = searchData.getSearchBy(); String keyword = searchData.getKeyword(); long count = 0; if ("DateBill".equals(searchBy)) { DateFormat sim = new SimpleDateFormat("yyyy-MM-dd", Locale.US); Date date = sim.parse(keyword); count = billRepo.count(BillSpec.dateBillLike(date)); }/*from w w w .j a va2 s . co m*/ if ("SumPrice".equals(searchBy)) { count = billRepo.count(BillSpec.sumPriceLike(new Double(keyword))); } return count; }
From source file:com.sishistorico.sv.SvHistorico.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w .ja v a2s . c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF8"); response.setContentType("text/html;charset=UTF-8"); List<FileItem> items = null; try { items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); DateFormat formatter; Date data_entrada; Date data_agendada = null; formatter = new SimpleDateFormat("dd/MM/yyyy"); data_entrada = (Date) formatter.parse(items.get(2).getString()); if (!items.get(4).getString().equals("")) { data_agendada = (Date) formatter.parse(items.get(4).getString()); } // fim do tratamento Historico hi = new Historico(); hi.setId_eleitor(Integer.parseInt(items.get(0).getString().trim())); hi.setData_entrada(data_entrada); hi.setTipo(Integer.parseInt(items.get(3).getString().trim())); hi.setData_agendada(data_agendada); hi.setSituacao(Integer.parseInt(items.get(7).getString().trim())); hi.setSolicitacao(items.get(5).getString("UTF-8").trim()); DaoHistorico daoHistorico = new DaoHistorico(); daoHistorico.historico_Salvar(hi); response.sendRedirect("cadastro_historico.jsp?id=" + hi.getId_eleitor() + "&msgok=Salvo com sucesso!"); } catch (FileUploadException ex) { Logger.getLogger(SvHistorico.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(SvHistorico.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.sishistorico.sv.SvHistoricoEditar.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from ww w . j av a 2 s .c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF8"); response.setContentType("text/html;charset=UTF-8"); List<FileItem> items = null; try { items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); DateFormat formatter; Date data_entrada; Date data_agendada = null; formatter = new SimpleDateFormat("dd/MM/yyyy"); data_entrada = (Date) formatter.parse(items.get(2).getString()); if (!items.get(4).getString().equals("")) { data_agendada = (Date) formatter.parse(items.get(4).getString()); } // fim do tratamento Historico hi = new Historico(); hi.setId_eleitor(Integer.parseInt(items.get(0).getString().trim())); hi.setData_entrada(data_entrada); hi.setTipo(Integer.parseInt(items.get(3).getString().trim())); hi.setData_agendada(data_agendada); hi.setSituacao(Integer.parseInt(items.get(7).getString().trim())); hi.setSolicitacao(items.get(5).getString("UTF-8").trim()); hi.setId(Integer.parseInt(items.get(8).getString("UTF-8").trim())); DaoHistorico daoHistorico = new DaoHistorico(); daoHistorico.historico_editar(hi); response.sendRedirect("editar_historico.jsp?id=" + hi.getId() + "&msgok=Editado com sucesso!"); } catch (FileUploadException ex) { Logger.getLogger(SvHistoricoEditar.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(SvHistoricoEditar.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.sishistorico.sv.SvEditarEleitor.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w .j av a 2 s . c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF8"); response.setContentType("text/html;charset=UTF-8"); List<FileItem> items = null; byte[] foto = null; long vazio = 0; try { items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : items) { if (!item.isFormField()) { vazio = item.getSize(); System.out.println("tamanho/:::::::::::::::::::: " + vazio); InputStream imageInput = item.getInputStream(); Image image = ImageIO.read(imageInput); BufferedImage thumb = Imagem.redimensionar(image, 400, 500); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(thumb, "JPG", baos); baos.flush(); foto = baos.toByteArray(); baos.close(); } } //dados do formulrio e metodos para salvar DateFormat formatter; Date date; formatter = new SimpleDateFormat("dd/MM/yyyy"); date = (Date) formatter.parse(items.get(1).getString()); // fim do tratamento Eleitor el = new Eleitor(); Endereco end = new Endereco(); el.setId(Integer.parseInt(items.get(19).getString("UTF-8").trim())); el.setNome(items.get(0).getString("UTF-8").trim()); el.setData_nascimento(date); el.setCpf(items.get(2).getString("UTF-8").replaceAll("\\.|\\-|\\ ", "").trim()); el.setRg(items.get(3).getString("UTF-8").replaceAll("\\.|\\-|\\ ", "").trim()); el.setSus(items.get(4).getString("UTF-8").replaceAll("\\.|\\-|\\ ", "").trim()); el.setEmail(items.get(5).getString("UTF-8")); el.setTelefone(items.get(6).getString("UTF-8").replaceAll("\\(|\\)|\\-|\\ ", "").trim()); el.setWhats(items.get(7).getString("UTF-8").replaceAll("\\(|\\)|\\-|\\ ", "").trim()); el.setObs(items.get(8).getString("UTF-8").trim()); el.setReferencia_pessoal(items.get(9).getString("UTF-8").trim()); end.setRua(items.get(11).getString("UTF-8").trim()); end.setBairro(items.get(12).getString("UTF-8").trim()); end.setN(items.get(13).getString("UTF-8").trim()); end.setCidade(items.get(14).getString("UTF-8").trim()); end.setCep(items.get(15).getString("UTF-8").trim()); end.setLocalidade(Integer.parseInt(items.get(16).getString("UTF-8").trim())); el.setTipo(Integer.parseInt(items.get(17).getString("UTF-8").trim())); el.setPertence(Integer.parseInt(items.get(18).getString("UTF-8").trim())); el.setEnd(end); DaoEleitor daoEleitor = new DaoEleitor(); DaoFoto daoFoto = new DaoFoto(); int idretorno = daoEleitor.Eleitor_Editar(el); if (vazio > 1) { daoFoto.atualizarImagem(foto, idretorno); } response.sendRedirect("editar_eleitor.jsp?id=" + el.getId() + "&msgok=Editado com sucesso!"); } catch (FileUploadException ex) { Logger.getLogger(SvEditarEleitor.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(SvEditarEleitor.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(SvEditarEleitor.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(SvEditarEleitor.class.getName()).log(Level.SEVERE, null, ex); } }