r11 - in trunk: . src/main/java/org/chorem/bow src/main/webapp
Author: bbrossaud Date: 2010-05-07 12:35:52 +0200 (Fri, 07 May 2010) New Revision: 11 Url: http://chorem.org/repositories/revision/bow/11 Log: The research works now, the tags cloud diplay is OK 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-06 16:18:00 UTC (rev 10) +++ trunk/pom.xml 2010-05-07 10:35:52 UTC (rev 11) @@ -83,6 +83,12 @@ <artifactId>h2</artifactId> <version>1.2.134</version> </dependency> + + <dependency> + <groupId>org.nuiton</groupId> + <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-06 16:18:00 UTC (rev 10) +++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-07 10:35:52 UTC (rev 11) @@ -12,6 +12,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.nuiton.util.StringUtil; /** * @@ -53,28 +54,44 @@ } public void createTagsCloud() { + tagsCloud.clear(); + if (tagsSearch.isEmpty()) { + fillTagsCloud(); + } else { + fillTagsCloudBySearch(); + } + } - Iterator itTags = tagsSearch.iterator(); + protected void addBookmarkTagsToTagCloud(Bookmark bookmark) { + Set<String> tags = bookmark.getTags(); + for (String tag : tags) { + if (!tagsSearch.contains(tag)) { + if (tagsCloud.containsKey(tag)) { + Integer count = tagsCloud.get(tag); + ++count; + tagsCloud.put(tag, count); + } else { + tagsCloud.put(tag, 1); + } + } + } + } + public void fillTagsCloud() { + for (Bookmark bookmark : bookmarks) { + addBookmarkTagsToTagCloud(bookmark); + } + } + + public void fillTagsCloudBySearch() { tagsCloud.clear(); - while (itTags.hasNext()) { - String tag = (String) itTags.next(); - Iterator it = bookmarks.iterator(); - while (it.hasNext()) { - Bookmark bookmark = (Bookmark) it.next(); + for (String tag : tagsSearch) { + List<Bookmark> bookmarksList = new ArrayList<Bookmark>(bookmarks); + for (Bookmark bookmark : bookmarksList) { if (bookmark.getTags().contains(tag) == false) { - it.remove(); + bookmarks.remove(bookmark); } else { - Set<String> tags = bookmark.getTags(); - for (String key : tags) { - if (tagsCloud.containsKey(key)) { - Integer count = tagsCloud.get(key); - ++count; - tagsCloud.put(key, count); - } else { - tagsCloud.put(key, 1); - } - } + addBookmarkTagsToTagCloud(bookmark); } } } @@ -87,7 +104,6 @@ tmax = -1; tmin = -1; int value; - while (it.hasNext()) { value = (Integer) it.next(); if (tmax < value) { @@ -108,7 +124,8 @@ } public void addTags(String[] tags) { - for (int i = 0; i < tags.length; i++) { + for (int i = 0; i + < tags.length; i++) { if (!tagsSearch.contains(tags[i])) { tagsSearch.add(tags[i]); } @@ -116,22 +133,11 @@ } public String getSearchLine() { - String line = ""; - - Iterator it = tagsSearch.iterator(); - - while (it.hasNext()) { - String tag = (String) it.next(); - line += tag; - if (it.hasNext()) - line += " "; - } - return line; + return StringUtil.join(tagsSearch, " ", true); } public int getFont(int ti) { int font = 1; - if (tmax > tmin) { font = (15 * (ti - tmin)) / (tmax - tmin); } @@ -141,6 +147,7 @@ public void reset() { bookmarks.clear(); tagsCloud.clear(); + tagsSearch.clear(); tmax = -1; tmin = -1; } @@ -149,8 +156,13 @@ return tagsCloud; } + public List<String> getTagsSearch() { + return tagsSearch; + } + public void setBookmarks(List<Bookmark> bookmarksList) { - bookmarks = bookmarksList; + List<Bookmark> newList = new ArrayList(bookmarksList); + bookmarks = newList; } public int getTmin() { Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java =================================================================== --- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-06 16:18:00 UTC (rev 10) +++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-07 10:35:52 UTC (rev 11) @@ -10,6 +10,7 @@ */ import java.io.IOException; import java.util.ArrayList; +import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -50,6 +51,7 @@ String action = request.getParameter("action"); response.setContentType("text/html"); + request.setAttribute("bookmarkActions", bookmarkActions); if (action != null) { if (action.equals("register")) { log.debug("Going to actionRegister"); @@ -85,30 +87,30 @@ log.debug("URL = {" + url + "}"); log.debug("Adding URL"); } - request.setAttribute("bookmarkActions", bookmarkActions); request.getRequestDispatcher("search.jsp").forward(request, response); } protected void actionSearch(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String words = request.getParameter("words"); - - request.setAttribute("bookmarkActions", bookmarkActions); + bookmarkActions.reset(); + List<Bookmark> bookList = model.getProxy(). + findAllByCriteria(Bookmark.class, null).getAll(); + if (bookList != null) { + bookmarkActions.setBookmarks(bookList); + } if (words != null) { if (!words.isEmpty()) { - if (bookmarkActions.getBookmarks().isEmpty()) { - bookmarkActions.setBookmarks(new ArrayList( - model.getProxy().findAllByCriteria(Bookmark.class, null).getAll())); - } - log.debug("ListSize before = {" + String.valueOf(bookmarkActions.getBookmarks().size()) + "}"); String[] tags = words.split("\\s+"); bookmarkActions.addTags(tags); - bookmarkActions.createTagsCloud(); log.debug("TabSize = {" + String.valueOf(tags.length) + "}"); - log.debug("ListSize after = {" + String.valueOf(bookmarkActions.getBookmarks().size()) + "}"); } } - request.setAttribute("bookmarkActions", bookmarkActions); + log.debug("ListSize before = {" + String.valueOf(bookmarkActions.getBookmarks().size()) + "}"); + log.debug("SearchLine = {" + words + "}"); + bookmarkActions.createTagsCloud(); + log.debug("TagCloudSize = {" + String.valueOf(bookmarkActions.getTagsCloud().size()) + "}"); + log.debug("ListSize after = {" + String.valueOf(bookmarkActions.getBookmarks().size()) + "}"); request.getRequestDispatcher("search.jsp").forward(request, response); } @@ -127,6 +129,12 @@ request.getRequestDispatcher("error.jsp").forward(request, response); } else { log.debug("adding to the Databases"); + List<Bookmark> bookList = model.getProxy(). + findAllByCriteria(Bookmark.class, null).getAll(); + if (bookList != null) { + bookmarkActions.setBookmarks(bookList); + } + bookmarkActions.createTagsCloud(); request.getRequestDispatcher("search.jsp").forward(request, response); } } @@ -143,7 +151,12 @@ if (user != null) { log.debug("User exists"); this.user = user; - request.setAttribute("bookmarkActions", bookmarkActions); + List<Bookmark> bookList = model.getProxy(). + findAllByCriteria(Bookmark.class, null).getAll(); + if (bookList != null) { + bookmarkActions.setBookmarks(bookList); + } + bookmarkActions.createTagsCloud(); request.getRequestDispatcher("search.jsp").forward(request, response); } else { log.debug("User doesn't exist"); Modified: trunk/src/main/webapp/search.jsp =================================================================== --- trunk/src/main/webapp/search.jsp 2010-05-06 16:18:00 UTC (rev 10) +++ trunk/src/main/webapp/search.jsp 2010-05-07 10:35:52 UTC (rev 11) @@ -1,9 +1,11 @@ <%@ page import="org.chorem.bow.BookmarkActions" %> +<%@ page import="org.chorem.bow.Bookmark" %> <%@ page import="java.util.HashMap" %> <%@ page import="java.util.Iterator" %> <%@ page import="java.util.Map" %> <%@ page import="java.util.Set" %> <%@ page import="java.util.ArrayList" %> +<%@ page import="java.util.List" %> <%BookmarkActions bookmarkActions = (BookmarkActions) request.getAttribute("bookmarkActions");%> @@ -17,19 +19,39 @@ </form> <form method="POST" action="search?action=check"> - <input type="text" name="words" size="20" value=<%=bookmarkActions.getSearchLine()%>><br /> + <input type="text" name="words" size="20" value="<%=bookmarkActions.getSearchLine()%>" ><br /> <input type="submit" value="Find"> </form> -<% if (bookmarkActions != null) { +<% if (bookmarkActions != null) { Map<String, Integer> tagsCloud = bookmarkActions.getTagsCloud(); Set<String> tags = tagsCloud.keySet(); for (String tag : tags) { - int font = bookmarkActions.getFont(tagsCloud.get(tag)); + int value = tagsCloud.get(tag); + int font = bookmarkActions.getFont(value); %> -<FONT SIZE=<%=font%>><%=tag%></FONT> + +<FONT SIZE="<%=font%>" ><%=tag%></FONT> + <% -}} + } + List<String> tagsSearch = bookmarkActions.getTagsSearch(); + List<Bookmark> bookmarkList = bookmarkActions.getBookmarks(); + if (!tagsSearch.isEmpty() || bookmarkList.size() == 1) { + if (tagsCloud.isEmpty()) { %> + RESULT:<br/> +<% + for (Bookmark bookmark : bookmarkList) { +%> + +<%=bookmark.getLink()%><br/> + +<% + } + } + } + } +%> </body> </html> \ No newline at end of file
participants (1)
-
bbrossaudï¼ users.chorem.org