r21 - in trunk: . src/main/java/org/chorem/bow src/main/webapp src/main/webapp/css src/main/webapp/img
Author: bbrossaud Date: 2010-05-12 12:09:44 +0200 (Wed, 12 May 2010) New Revision: 21 Url: http://chorem.org/repositories/revision/bow/21 Log: remove bookmark and delete tag actions work Added: trunk/TODO.txt trunk/src/main/webapp/css/ trunk/src/main/webapp/css/styles.css trunk/src/main/webapp/img/ trunk/src/main/webapp/img/delete.gif trunk/src/main/webapp/img/remove.gif Modified: trunk/src/main/java/org/chorem/bow/BookmarkActions.java trunk/src/main/java/org/chorem/bow/ControllerServlet.java trunk/src/main/webapp/generateToken.jsp trunk/src/main/webapp/home.jsp trunk/src/main/webapp/register.jsp trunk/src/main/webapp/search.jsp Added: trunk/TODO.txt =================================================================== --- trunk/TODO.txt (rev 0) +++ trunk/TODO.txt 2010-05-12 10:09:44 UTC (rev 21) @@ -0,0 +1,12 @@ +le 11 mai 2010 +A faire pour le vendredi 28 mai: + +-> edition, suppression bookmark + tag (14 mai) +-> triage multiple(nbre de clics, date d'ajout, Alpha) (14 mai) +-> token temporaire (14 mai) +-> completion ==> openSearch(xml) + ==> meta(ex:<link rel="search" type="application/opensearchdescription+xml" href="/w/opensearch_desc.php" title="Wikip�dia (fr)" />) +-> le && pour le nuage de tag (11 mai) OK +-> gestion des sessions +-> javascript ==> var script = document.createElement('script');script.src = url;script.type='text/javascript';document.body.appendChild(script); (11 mai) NOK +-> Mise en forme (28 mai) \ No newline at end of file Modified: trunk/src/main/java/org/chorem/bow/BookmarkActions.java =================================================================== --- trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-11 12:28:22 UTC (rev 20) +++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-12 10:09:44 UTC (rev 21) @@ -66,48 +66,51 @@ public void createTagsCloud() { tagCloud.clear(); - if (tagsSearch.isEmpty()) { - fillTagsCloud(); // if nothing is taped in the search field, the tags cloud must contains all tags - } else { - fillTagsCloudBySearch(); - } - this.defineTValues(); // define t values for the font + deleteBookmarkBySearch(); + createTagClougByBookmarks(); } - - /* @param bookmark user bookmark - * @return void - */ - protected void addBookmarkTagsToTagCloud(Bookmark bookmark) { - Set<String> tags = bookmark.getTags(); // bookmark tags - for (String tag : tags) { - if (!tagsSearch.contains(tag)) { // the tags cloud mustn't contained the tags taped in the search field - if (tagCloud.containsKey(tag)) { // check if it contains the tag - Integer count = tagCloud.get(tag); - ++count; - tagCloud.put(tag, count); - } else { - tagCloud.put(tag, 1); + public void deleteBookmarkBySearch() { + List<Bookmark> bookmarksList = new ArrayList<Bookmark>(bookmarks); + for (Bookmark bookmark : bookmarksList) { + Iterator it = tagsSearch.iterator(); + boolean remove = false; + while (it.hasNext() && remove == false) { + String tag = (String) it.next(); + Set<String> tagList = bookmark.getTags(); + if (tagList != null && !tagList.isEmpty()) { + if (!tagList.contains(tag)) { + bookmarks.remove(bookmark); // Delete bookmark which doesn't contain the tags from the search field + remove = true; + } } } } } - public void fillTagsCloud() { - for (Bookmark bookmark : bookmarks) { + public void createTagClougByBookmarks() { + List<Bookmark> bookmarksList = new ArrayList<Bookmark>(bookmarks); + for (Bookmark bookmark : bookmarksList) { addBookmarkTagsToTagCloud(bookmark); } } - public void fillTagsCloudBySearch() { - tagCloud.clear(); - for (String tag : tagsSearch) { - List<Bookmark> bookmarksList = new ArrayList<Bookmark>(bookmarks); - for (Bookmark bookmark : bookmarksList) { - if (bookmark.getTags().contains(tag) == false) { - bookmarks.remove(bookmark); // Delete bookmark which doesn't contain the tags from the search field - } else { - addBookmarkTagsToTagCloud(bookmark); + + /* @param bookmark user bookmark + * @return void + */ + protected void addBookmarkTagsToTagCloud(Bookmark bookmark) { + Set<String> tags = bookmark.getTags(); // bookmark tags + if (tags != null && !tags.isEmpty()) { + for (String tag : tags) { + if (!tagsSearch.contains(tag)) { // the tags cloud mustn't contained the tags taped in the search field + if (tagCloud.containsKey(tag)) { // check if it contains the tag + Integer count = tagCloud.get(tag); + ++count; + tagCloud.put(tag, count); + } else { + tagCloud.put(tag, 1); + } } } } Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java =================================================================== --- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-11 12:28:22 UTC (rev 20) +++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-12 10:09:44 UTC (rev 21) @@ -11,6 +11,9 @@ import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.util.List; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -32,6 +35,7 @@ protected BookmarkActions bookmarkActions = new BookmarkActions(); protected User user = null; protected TokenActions tokenActions = new TokenActions(); + protected String error = ""; @Override public void doGet(HttpServletRequest request, HttpServletResponse response) @@ -46,7 +50,8 @@ @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - try { +// try { + error = ""; String action = request.getParameter("action"); response.setContentType("text/html"); request.setAttribute("bookmarkActions", bookmarkActions); @@ -94,6 +99,16 @@ log.error("No Such Algorithm", ex); request.getRequestDispatcher("error.jsp").forward(request, response); } + } else if (action.equals("deleteTag")) { + if (log.isDebugEnabled()) { + log.debug("Going to actionDeleteTag"); + } + this.actionDeleteTag(request, response); + } else if (action.equals("removeBookmark")) { + if (log.isDebugEnabled()) { + log.debug("Going to actionRemoveBookmark"); + } + this.actionRemoveBookmark(request, response); } else { user = null; if (log.isDebugEnabled()) { @@ -108,11 +123,55 @@ } request.getRequestDispatcher("home.jsp").forward(request, response); } - } catch (Exception eee) { - request.getRequestDispatcher("error.jsp").forward(request, response); + request.setAttribute("errorMessage", error); +// } catch (Exception eee) { +// request.getRequestDispatcher("error.jsp").forward(request, response); +// } + } + + protected void actionRemoveBookmark(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + String bookmarkId = request.getParameter("bookmarkId"); + if (bookmarkId != null && !bookmarkId.isEmpty()) { + WikittyProxy proxy = model.getProxy(); + proxy.delete(bookmarkId); + bookmarkActions.getBookmarks().clear(); + Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(); + List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user + if (bookList != null) { + bookmarkActions.setBookmarks(bookList); + bookmarkActions.createTagsCloud(); + } } + request.getRequestDispatcher("search.jsp").forward(request, response); } + + protected void actionDeleteTag(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + String bookmarkId = request.getParameter("bookmarkId"); + String tag = request.getParameter("tag"); + if (tag != null && bookmarkId != null) { + if (!tag.isEmpty() && !bookmarkId.isEmpty()) { + WikittyProxy proxy = model.getProxy(); + Bookmark bookmark = proxy.restore(Bookmark.class, bookmarkId); + if (bookmark != null) { + bookmark.removeTags(tag); + proxy.store(bookmark); + bookmarkActions.getBookmarks().clear(); + Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(); + List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user + if (bookList != null) { + bookmarkActions.setBookmarks(bookList); + bookmarkActions.createTagsCloud(); + } + } + } + } + request.getRequestDispatcher("search.jsp").forward(request, response); + } + + /* @param request servlet request * @param response servlet response * @throws ServletException if a servlet error occurs @@ -258,6 +317,7 @@ request.getRequestDispatcher("error.jsp").forward(request, response); } else { this.actionSearch(request, response); + error="Email already exist"; } } } @@ -276,6 +336,7 @@ this.user = login; this.actionSearch(request, response); } else { + error = "Unknow email or incorrect password"; request.getRequestDispatcher("home.jsp").forward(request, response); } } @@ -315,6 +376,7 @@ } } } + error = "Email and password must be correctly filled"; return true; } Added: trunk/src/main/webapp/css/styles.css =================================================================== --- trunk/src/main/webapp/css/styles.css (rev 0) +++ trunk/src/main/webapp/css/styles.css 2010-05-12 10:09:44 UTC (rev 21) @@ -0,0 +1,3 @@ +test { + +} \ No newline at end of file Modified: trunk/src/main/webapp/generateToken.jsp =================================================================== --- trunk/src/main/webapp/generateToken.jsp 2010-05-11 12:28:22 UTC (rev 20) +++ trunk/src/main/webapp/generateToken.jsp 2010-05-12 10:09:44 UTC (rev 21) @@ -9,7 +9,7 @@ <body> Use it to add new bookmarks without authentication : <br/><br/> - <a href="javascript:var%20url=location.href;var%20nameAndTags=prompt('Entrez%20le%20nom%20du%20lien%20et%20la%20liste%20des%20tags%20sous%20la%20forme:%20name|tag1%20tag2%20tag3',%20document.title+'|');var%20image=new%20Image();var%20link='http://localhost:8080/bow/bow?action=addUrl&token=<%=token%>&url='+encodeURIComponent(url)+'&nameAndTags='+encodeURIComponent(nameAndTags);image.src=link;window.location='';">Session</a> + <a href="javascript:var%20url=location.href;var%20nameAndTags=prompt('Entrez%20le%20nom%20du%20lien%20et%20la%20liste%20des%20tags%20sous%20la%20forme:%20name|tag1%20tag2%20tag3',%20document.title+'|');var%20link='http://localhost:8080/bow/bow?action=addUrl&token=<%=token%>&url='+encodeURIComponent(url)+'&nameAndTags='+encodeURIComponent(nameAndTags);var%20script=document.createElement('script');script.src=link;script.type='text/javascript';document.body.appendChild(script);">Session</a> <% } else { %> Modified: trunk/src/main/webapp/home.jsp =================================================================== --- trunk/src/main/webapp/home.jsp 2010-05-11 12:28:22 UTC (rev 20) +++ trunk/src/main/webapp/home.jsp 2010-05-12 10:09:44 UTC (rev 21) @@ -1,3 +1,5 @@ +<%String error = (String) request.getAttribute("errorMessage");%> + <html> <body> <h1>Login</h1> @@ -6,6 +8,9 @@ password <input type=password name="password" size="20"><br /> <input type="submit" value="login"> </form> - <a href="bow?action=registration">register</a> + <%if (error != null) {%> + <font color="red"><%=error%></font> + <%}%> + <br/><a href="bow?action=registration">register</a> </body> </html> \ No newline at end of file Added: trunk/src/main/webapp/img/delete.gif =================================================================== (Binary files differ) Property changes on: trunk/src/main/webapp/img/delete.gif ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/src/main/webapp/img/remove.gif =================================================================== (Binary files differ) Property changes on: trunk/src/main/webapp/img/remove.gif ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/src/main/webapp/register.jsp =================================================================== --- trunk/src/main/webapp/register.jsp 2010-05-11 12:28:22 UTC (rev 20) +++ trunk/src/main/webapp/register.jsp 2010-05-12 10:09:44 UTC (rev 21) @@ -1,3 +1,5 @@ + +<%String error = (String) request.getAttribute("errorMessage");%> <html> <body> <h1>Register</h1> @@ -7,6 +9,9 @@ password <input type=password name="password" size="20"><br /> <input type="submit" value="Register"> </form> - <br/><br/><a href="bow?action=home">Return to the login page<a> + <%if (error != null && error.isEmpty() == false) {%> + <br/><font color="red"><%=error%></font> + <%}%> + <br/><a href="bow?action=home">Return to the login page<a> </body> </html> \ No newline at end of file Modified: trunk/src/main/webapp/search.jsp =================================================================== --- trunk/src/main/webapp/search.jsp 2010-05-11 12:28:22 UTC (rev 20) +++ trunk/src/main/webapp/search.jsp 2010-05-12 10:09:44 UTC (rev 21) @@ -43,12 +43,27 @@ List<Bookmark> bookmarkList = bookmarkActions.getBookmarks(); if (!bookmarkList.isEmpty() && !tagsSearch.isEmpty()) { %> - <br/><br/>Results:<br/><br/> + <br/><br/>Results:<br/> <% for (Bookmark bookmark : bookmarkList) { %> - <a href="<%=bookmark.getLink()%>"><%=bookmark.getDescription()%></a><br/> + <br/> + <a style="border:none;" href="bow?action=removeBookmark&bookmarkId=<%=bookmark.getWikittyId()%>"> + <IMG style="border:none;" SRC="img/remove.gif" ALT="Remove bookmark" TITLE="Remove" /> + </a> + <a href="<%=bookmark.getLink()%>"><%=bookmark.getDescription()%></a> <% + Set<String> tagList = bookmark.getTags(); + if (tagList != null && !tagList.isEmpty()) { + for (String tag : tagList) { +%> + <%=tag%> + <a style="border:none;" href="bow?action=deleteTag&bookmarkId=<%=bookmark.getWikittyId()%>&tag=<%=tag%>"> + <IMG style="border:none;" SRC="img/delete.gif" ALT="Delete tag" TITLE="Delete" /> + </a> +<% + } + } } } else if (!tagsSearch.isEmpty() && bookmarkList.isEmpty()) { %>
participants (1)
-
bbrossaud@users.chorem.org