@WebMethod public void deleteArticle(User user, String title) { SocialApp app = null; try { app = getSocialApp(); } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (Article article : user.getBlog()) { if (article.getTitle().equals(title)) user.getBlog().remove(article); } try { app.save(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@WebMethod public String getPassword(String email) throws JAXBException, IOException { SocialApp app = getSocialApp(); Users users = app.getUsers(); User user = users.getUser(email); return user.getPassword(); }
private SocialApp getSocialApp() throws JAXBException, IOException { ServletContext application = (ServletContext) context.getMessageContext().get(MessageContext.SERVLET_CONTEXT); synchronized (application) { SocialApp socialApp = (SocialApp) application.getAttribute("socialApp"); if (socialApp == null) { socialApp = new SocialApp(); socialApp.setFilePath(application.getRealPath("users.xml")); application.setAttribute("socialApp", socialApp); } return socialApp; } }
@WebMethod public User login(String email, String password) throws JAXBException, IOException { SocialApp app = getSocialApp(); Users users = app.getUsers(); return users.logon(email, password); }
@WebMethod public User getUser(String email) throws JAXBException, IOException { SocialApp app = getSocialApp(); Users users = app.getUsers(); return users.getUser(email); }