Author: bbrossaud Date: 2010-05-12 15:41:08 +0200 (Wed, 12 May 2010) New Revision: 22 Url: http://chorem.org/repositories/revision/bow/22 Log: the bookmark edition is done Added: trunk/src/main/webapp/img/delete.png trunk/src/main/webapp/img/edit.png trunk/src/main/webapp/img/remove.png Removed: trunk/src/main/webapp/img/delete.gif trunk/src/main/webapp/img/remove.gif Modified: trunk/pom.xml trunk/src/main/java/org/chorem/bow/BookmarkActions.java trunk/src/main/java/org/chorem/bow/ControllerServlet.java trunk/src/main/webapp/search.jsp Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-05-12 10:09:44 UTC (rev 21) +++ trunk/pom.xml 2010-05-12 13:41:08 UTC (rev 22) @@ -89,6 +89,7 @@ <artifactId>nuiton-utils</artifactId> <version>1.2.2</version> </dependency> + </dependencies> Modified: trunk/src/main/java/org/chorem/bow/BookmarkActions.java =================================================================== --- trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-12 10:09:44 UTC (rev 21) +++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-12 13:41:08 UTC (rev 22) @@ -37,33 +37,63 @@ */ public Bookmark createBookmark(String url, String nameAndTags, User user) { + Bookmark bookmark = (Bookmark) new BookmarkImpl(); + int nameIndex = nameAndTags.indexOf('|'); // get the index name of the website - if (nameIndex < 0) { // nameAndTags ==> name|tag1 tag2 tag3... - return null; + if (nameIndex > 0) { + String name = nameAndTags.substring(0, nameIndex); // get the website name + name = name.trim(); + bookmark.setDescription(name); // set the description (website name) } - Bookmark bookmark = (Bookmark) new BookmarkImpl(); - String link = url.trim(); - bookmark.setLink(link); - - String name = nameAndTags.substring(0, nameIndex); // get the website name - name = name.trim(); - bookmark.setDescription(name); // set the description (website name) - - String tags = nameAndTags.substring(nameIndex + 1); // get tags, +1 because of '|' + String tags = nameAndTags; + if (nameIndex >= 0) { + tags = nameAndTags.substring(nameIndex + 1); // get tags, +1 because of '|' + } tags = tags.trim(); String[] tagsTab = tags.split("\\s+"); // put the tags in an array - if (tagsTab.length == 0) + if (tagsTab.length == 0) { return null; + } for (int i = 0; i < tagsTab.length; ++i) { bookmark.addTags(tagsTab[i]); // Added tag for each rank (one tag by rank) } + if (url != null && !url.isEmpty()) { + String link = url.trim(); + bookmark.setLink(link); + } bookmark.setEmail(user.getEmail()); // set the email (user name) bookmark.setDate(new Date()); // set the date return bookmark; } + public void updateBookmark(Bookmark bookmark, String nameAndTags) { + int nameIndex = nameAndTags.indexOf('|'); // get the index name of the website + if (nameIndex > 0) { + String name = nameAndTags.substring(0, nameIndex); // get the website name + name = name.trim(); + bookmark.setDescription(name); // set the description (website name) + } + + String tags = nameAndTags; + if (nameIndex >= 0) { + tags = nameAndTags.substring(nameIndex + 1); // get tags, +1 because of '|' + } + tags = tags.trim(); + String[] tagsTab = tags.split("\\s+"); // put the tags in an array + if (tagsTab.length != 0) { + for (int i = 0; i < tagsTab.length; ++i) { + Set<String> tagList = bookmark.getTags(); + if (tagList != null) { + if (!tagList.contains(tagsTab[i])) { + bookmark.addTags(tagsTab[i]); // Added tag for each rank (one tag by rank) + } + } + } + } + } + public void createTagsCloud() { tagCloud.clear(); deleteBookmarkBySearch(); Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java =================================================================== --- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-12 10:09:44 UTC (rev 21) +++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-12 13:41:08 UTC (rev 22) @@ -109,6 +109,11 @@ log.debug("Going to actionRemoveBookmark"); } this.actionRemoveBookmark(request, response); + } else if (action.equals("editBookmark")) { + if (log.isDebugEnabled()) { + log.debug("Going to actionEditBookmark"); + } + this.actionEditBookmark(request, response); } else { user = null; if (log.isDebugEnabled()) { @@ -129,6 +134,30 @@ // } } + protected void actionEditBookmark(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + String nameAndTags = request.getParameter("nameAndTags"); + String bookmarkId = request.getParameter("bookmarkId"); + if (nameAndTags != null && bookmarkId != null) { + if (!nameAndTags.isEmpty() && !bookmarkId.isEmpty()) { + WikittyProxy proxy = model.getProxy(); + Bookmark bookmark = proxy.restore(Bookmark.class, bookmarkId); + if (bookmark != null) { + bookmarkActions.updateBookmark(bookmark, nameAndTags); + 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); + } + protected void actionRemoveBookmark(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String bookmarkId = request.getParameter("bookmarkId"); @@ -146,7 +175,6 @@ request.getRequestDispatcher("search.jsp").forward(request, response); } - protected void actionDeleteTag(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String bookmarkId = request.getParameter("bookmarkId"); Deleted: trunk/src/main/webapp/img/delete.gif =================================================================== (Binary files differ) Added: trunk/src/main/webapp/img/delete.png =================================================================== (Binary files differ) Property changes on: trunk/src/main/webapp/img/delete.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/src/main/webapp/img/edit.png =================================================================== (Binary files differ) Property changes on: trunk/src/main/webapp/img/edit.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: trunk/src/main/webapp/img/remove.gif =================================================================== (Binary files differ) Added: trunk/src/main/webapp/img/remove.png =================================================================== (Binary files differ) Property changes on: trunk/src/main/webapp/img/remove.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/src/main/webapp/search.jsp =================================================================== --- trunk/src/main/webapp/search.jsp 2010-05-12 10:09:44 UTC (rev 21) +++ trunk/src/main/webapp/search.jsp 2010-05-12 13:41:08 UTC (rev 22) @@ -15,62 +15,67 @@ <h1>Search</h1> <form method="POST" action="bow?action=addUrl"> - URL <input type="text" name="url" size="20" value="URL"><br /> - Name and Tags <input type="text" name="nameAndTags" size="20" value="name|tag1 tag2..."><br /> - <input type="submit" value="add"> + URL <input type="text" name="url" size="20" value="URL" /><br /> + Name and Tags <input type="text" name="nameAndTags" size="20" value="name|tag1 tag2..." /><br /> + <input type="submit" value="add" /> </form> <br/><br/><a href="bow?action=generateToken">Generate Token</a><br/><br/> <form method="POST" action="bow?action=search"> - <input type="text" name="words" size="20" value="<%=bookmarkActions.getSearchLine()%>" ><br /> - <input type="submit" value="Find"> + <input type="text" name="words" size="20" value="<%=bookmarkActions.getSearchLine()%>" /><br /> + <input type="submit" value="Find" /> </form> -<% if (bookmarkActions != null) { - Map<String, Integer> tagsCloud = bookmarkActions.getTagsCloud(); - Set<String> tags = tagsCloud.keySet(); - for (String tag : tags) { - int value = tagsCloud.get(tag); - int font = bookmarkActions.getFont(value); -%> + <% if (bookmarkActions != null) { + Map<String, Integer> tagsCloud = bookmarkActions.getTagsCloud(); + Set<String> tags = tagsCloud.keySet(); + for (String tag : tags) { + int value = tagsCloud.get(tag); + int font = bookmarkActions.getFont(value); + %> -<FONT SIZE="<%=font%>" ><a href="bow?action=clickOnTag&tag=<%=tag%>"><%=tag%></a></FONT> + <FONT SIZE="<%=font%>" ><a href="bow?action=clickOnTag&tag=<%=tag%>"><%=tag%></a></FONT> -<% - } - List<String> tagsSearch = bookmarkActions.getTagsSearch(); - List<Bookmark> bookmarkList = bookmarkActions.getBookmarks(); - if (!bookmarkList.isEmpty() && !tagsSearch.isEmpty()) { -%> - <br/><br/>Results:<br/> -<% - for (Bookmark bookmark : bookmarkList) { -%> - <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> -<% + <% + } + List<String> tagsSearch = bookmarkActions.getTagsSearch(); + List<Bookmark> bookmarkList = bookmarkActions.getBookmarks(); + if (!bookmarkList.isEmpty() && !tagsSearch.isEmpty()) { + %> + <br/><br/>Results:<br/> + <% + for (Bookmark bookmark : bookmarkList) { + %> + <br/> + <a style="border:none;" href="bow?action=removeBookmark&bookmarkId=<%=bookmark.getWikittyId()%>"> + <IMG style="border:none;" SRC="img/remove.png" 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="text-decoration:none" href="bow?action=deleteTag&bookmarkId=<%=bookmark.getWikittyId()%>&tag=<%=tag%>"> + <IMG style="border:none" SRC="img/delete.png" ALT="Delete tag" TITLE="Delete" /> + </a> + <% + } + %> + <form style="display: inline" method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>"> + <input type="text" name="nameAndTags" size="50" value="<%=bookmark.getDescription()%>|tag1 tag2 tag3" /> + <input type="image" src="img/edit.png" value="edit" /> + </form> + <% + } + } + } else if (!tagsSearch.isEmpty() && bookmarkList.isEmpty()) { + %> + <br/><br/>No Result found<br/><br/> + <% } } - } - } - } else if (!tagsSearch.isEmpty() && bookmarkList.isEmpty()) { -%> - <br/><br/>No Result found<br/><br/> -<% - } - } -%> + %> </body> </html> \ No newline at end of file