private void edit(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String linkIdParam = request.getParameter(PARAM_LINK_ID); String title = request.getParameter(PARAM_TITLE); String image = request.getParameter(PARAM_IMAGE); String url = request.getParameter(PARAM_URL); if (linkIdParam == null || !Utils.isNumeric(linkIdParam)) { response.sendError(400); return; } try { long linkId = Long.valueOf(linkIdParam); Link link = linkDao.getLinkById(linkId); if (title != null) { link.setTitle(title); } if (image != null) { link.setImage(image); } if (url != null) { link.setUrl(url); } linkDao.updateLink(link); response.sendRedirect(LINK_PAGE_URL); } catch (NumberFormatException ex) { logger.log(Level.SEVERE, ex.getMessage(), ex); response.sendError(400, ex.getMessage()); } catch (DataAccessException ex) { logger.log(Level.SEVERE, ex.getMessage(), ex); response.sendError(500, ex.getMessage()); } }
private void add(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String title = request.getParameter(PARAM_TITLE); String image = request.getParameter(PARAM_IMAGE); String url = request.getParameter(PARAM_URL); if (title == null || url == null) { response.sendError(400); return; } try { if (image == null) { linkDao.createNewLink(title, url); } else { linkDao.createNewLink(title, image, url); } response.sendRedirect(LINK_PAGE_URL); } catch (DataAccessException ex) { logger.log(Level.SEVERE, ex.getMessage(), ex); response.sendError(500, ex.getMessage()); } }
private void delete(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String linkIdParam = request.getParameter(PARAM_LINK_ID); if (linkIdParam == null || !Utils.isNumeric(linkIdParam)) { response.sendError(400); return; } try { long linkId = Long.valueOf(linkIdParam); linkDao.deleteLink(linkId); response.sendRedirect(LINK_PAGE_URL); } catch (NumberFormatException ex) { logger.log(Level.SEVERE, ex.getMessage(), ex); response.sendError(400, ex.getMessage()); } catch (DataAccessException ex) { logger.log(Level.SEVERE, ex.getMessage(), ex); response.sendError(500, ex.getMessage()); } }