Author: bbrossaud Date: 2010-05-25 15:16:43 +0200 (Tue, 25 May 2010) New Revision: 33 Url: http://chorem.org/repositories/revision/bow/33 Log: addition the last bookmarks and the most clickable bookmarks to the home page Added: trunk/src/main/webapp/login.jsp Modified: trunk/src/main/java/org/chorem/bow/BookmarkActions.java trunk/src/main/java/org/chorem/bow/ControllerServlet.java trunk/src/main/webapp/home.jsp trunk/src/main/webapp/search.jsp Modified: trunk/src/main/java/org/chorem/bow/BookmarkActions.java =================================================================== --- trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-21 10:13:25 UTC (rev 32) +++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-25 13:16:43 UTC (rev 33) @@ -21,6 +21,7 @@ public class BookmarkActions { protected List<Bookmark> bookmarks = new ArrayList<Bookmark>(); // bookmarks which contain the search tags + protected List<Bookmark> lastBookmarks = new ArrayList<Bookmark>(); protected Map<String, Integer> tagCloud = new HashMap<String, Integer>(); // associate a tag with its frequency // among all bookmarks protected List<String> tagsSearch = new ArrayList<String>(); // contains the tags taped in the search field @@ -42,8 +43,10 @@ int nameIndex = nameAndTags.indexOf('|'); // get the index name of the website if (nameIndex > 0) { String name = nameAndTags.substring(0, nameIndex); // get the website name + if (!name.isEmpty()) { name = name.trim(); bookmark.setDescription(name); // set the description (website name) + } } String tags = nameAndTags; @@ -190,6 +193,16 @@ } } + public void emptySearchline() { + List<Bookmark> bookmarkList = new ArrayList<Bookmark>(bookmarks); + for (Bookmark bookmark : bookmarkList) { + Set<String> tags = bookmark.getTags(); + if (tags != null && !tags.isEmpty()) { + bookmarks.remove(bookmark); + } + } + } + public void reset() { bookmarks.clear(); tagCloud.clear(); @@ -203,6 +216,11 @@ bookmarks = newList; } + public void setLastBookmarks(List<Bookmark> bookmarksList) { + List<Bookmark> newList = new ArrayList(bookmarksList); + lastBookmarks = newList; + } + public String getSearchLine() { return StringUtil.join(tagsSearch, " ", true); // return the search line created with the tags } @@ -229,6 +247,10 @@ return bookmarks; } + public List<Bookmark> getLastBookmarks() { + return lastBookmarks; + } + public int getTmin() { return tmin; } Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java =================================================================== --- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-21 10:13:25 UTC (rev 32) +++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-25 13:16:43 UTC (rev 33) @@ -76,6 +76,12 @@ log.debug("Going to actionLogin"); } this.actionLogout(request, response, session); + } else if (action.equals("home") && user != null) { + if (log.isDebugEnabled()) { + log.debug("Going to actionHome.jsp"); + } + this.actionHome(request, user); + request.getRequestDispatcher("home.jsp").forward(request, response); } else if (action.equals("addUrl") && user != null) { if (log.isDebugEnabled()) { log.debug("Going to actionAddUrl"); @@ -85,7 +91,7 @@ if (log.isDebugEnabled()) { log.debug("Going to actionSearch"); } - this.actionSearch(request, response, user); + this.actionSearch(request, user); request.getRequestDispatcher("search.jsp").forward(request, response); } else if (action.equals("generateToken") && user != null) { if (log.isDebugEnabled()) { @@ -162,13 +168,13 @@ if (log.isDebugEnabled()) { log.debug("Going to home"); } - request.getRequestDispatcher("home.jsp").forward(request, response); + request.getRequestDispatcher("login.jsp").forward(request, response); } } else { if (log.isDebugEnabled()) { log.debug("Going to home"); } - request.getRequestDispatcher("home.jsp").forward(request, response); + request.getRequestDispatcher("login.jsp").forward(request, response); } request.setAttribute("errorMessage", error); } catch (Exception eee) { @@ -183,7 +189,8 @@ Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(). addSortDescending(Bookmark.FQ_FIELD_CLICK); List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); - createBookmarkActions(request, bookList); + BookmarkActions bookmarkActions = createBookmarkActions(request, bookList); + request.setAttribute("bookmarkActions", bookmarkActions); request.setAttribute("token", token); } @@ -212,7 +219,7 @@ protected void actionLogout(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws IOException, ServletException { session.invalidate(); - request.getRequestDispatcher("home.jsp").forward(request, response); + request.getRequestDispatcher("login.jsp").forward(request, response); } protected void actionAddClick(HttpServletRequest request, HttpServletResponse response) @@ -254,7 +261,8 @@ addSortAscending(Bookmark.FQ_FIELD_CLICK); bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); } - createBookmarkActions(request, bookList); + BookmarkActions bookmarkActions = createBookmarkActions(request, bookList); + request.setAttribute("bookmarkActions", bookmarkActions); } } @@ -280,7 +288,8 @@ addSortDescending(Bookmark.FQ_FIELD_CLICK); bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); } - createBookmarkActions(request, bookList); + BookmarkActions bookmarkActions = createBookmarkActions(request, bookList); + request.setAttribute("bookmarkActions", bookmarkActions); } } @@ -359,9 +368,7 @@ tokenActions.setPermanentToken(""); } } - session.setAttribute("tokenActions", tokenActions); - String searchLine = request.getParameter("searchLine"); - response.sendRedirect("bow?action=search&searchLine=" + searchLine); + response.sendRedirect("bow?action=home"); } /* @param request servlet request @@ -371,8 +378,7 @@ protected void actionAddUrl(HttpServletRequest request, HttpServletResponse response, User user) throws IOException, ServletException { addUrl(request, user); - String searchLine = request.getParameter("searchLine"); - response.sendRedirect("bow?action=search&searchLine=" + searchLine); + response.sendRedirect("bow?action=home"); } protected void addUrl(HttpServletRequest request, User user) { @@ -432,16 +438,22 @@ * @param response servlet response * @throws ServletException if a servlet error occurs */ - protected void actionSearch(HttpServletRequest request, HttpServletResponse response, User user) + protected void actionSearch(HttpServletRequest request, User user) throws IOException, ServletException { WikittyProxy proxy = model.getProxy(); Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(). addSortDescending(Bookmark.FQ_FIELD_CLICK); List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user - createBookmarkActions(request, bookList); + BookmarkActions bookmarkActions = createBookmarkActions(request, bookList); + String searchLine = bookmarkActions.getSearchLine(); + if (searchLine.isEmpty()) { + bookmarkActions.emptySearchline(); + } + request.setAttribute("bookmarkActions", bookmarkActions); + } - protected void createBookmarkActions(HttpServletRequest request, List<Bookmark> bookList) { + protected BookmarkActions createBookmarkActions(HttpServletRequest request, List<Bookmark> bookList) { String words = request.getParameter("searchLine"); // retrieve informations taping in the search field BookmarkActions bookmarkActions = new BookmarkActions(); if (bookList != null) { @@ -453,7 +465,7 @@ bookmarkActions.addTag(tag); } bookmarkActions.createTagsCloud(); // create the tags cloud with the new informations - request.setAttribute("bookmarkActions", bookmarkActions); + return bookmarkActions; } /* @param request servlet request @@ -477,8 +489,8 @@ } else { session.setAttribute("user", login); initializeToken(session, login); - actionSearch(request, response, login); - request.getRequestDispatcher("search.jsp").forward(request, response); + actionHome(request, login); + request.getRequestDispatcher("home.jsp").forward(request, response); } } } @@ -496,12 +508,12 @@ if (login != null) { session.setAttribute("user", login); initializeToken(session, login); - actionSearch(request, response, login); - request.getRequestDispatcher("search.jsp").forward(request, response); + actionHome(request, login); + request.getRequestDispatcher("home.jsp").forward(request, response); } else { error = "Unknow email or incorrect password"; - request.getRequestDispatcher("home.jsp").forward(request, response); + request.getRequestDispatcher("login.jsp").forward(request, response); } } @@ -531,7 +543,6 @@ * @return User the user exists */ protected User checkLogin(String email, String password) { - if (email != null && password != null) { if (!email.isEmpty() && !password.isEmpty()) { WikittyProxy proxy = model.getProxy(); @@ -563,4 +574,24 @@ error = "Email and password must be correctly filled"; return true; } + + private void actionHome(HttpServletRequest request, User user) { + WikittyProxy proxy = model.getProxy(); + Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(). + addSortDescending(Bookmark.FQ_FIELD_CLICK); + List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user + criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(). + addSortDescending(Bookmark.FQ_FIELD_DATE).setEndIndex(10); + List<Bookmark> lastBookmarks = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); + BookmarkActions bookmarkActions = createBookmarkActions(request, bookList); + bookList = bookmarkActions.getBookmarks(); + if (bookList.size() > 10) { + bookList = bookmarkActions.getBookmarks().subList(0, 10); + bookmarkActions.setBookmarks(bookList); + } + if (lastBookmarks != null) { + bookmarkActions.setLastBookmarks(lastBookmarks); + } + request.setAttribute("bookmarkActions", bookmarkActions); + } } Modified: trunk/src/main/webapp/home.jsp =================================================================== --- trunk/src/main/webapp/home.jsp 2010-05-21 10:13:25 UTC (rev 32) +++ trunk/src/main/webapp/home.jsp 2010-05-25 13:16:43 UTC (rev 33) @@ -1,20 +1,190 @@ <%@page contentType="text/html" pageEncoding="UTF-8"%> +<%@page import="org.chorem.bow.Bookmark" %> +<%@page import="org.chorem.bow.BookmarkActions" %> +<%@page import="java.util.HashMap" %> +<%@page import="java.text.SimpleDateFormat" %> +<%@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" %> +<%@page import="org.chorem.bow.TokenActions" %> + <% - String error = (String) request.getAttribute("errorMessage"); + TokenActions tokenActions = (TokenActions) session.getAttribute("tokenActions"); + String temporaryToken = tokenActions.getTemporaryToken(); + String permanentToken = tokenActions.getPermanentToken(); + BookmarkActions bookmarkActions = (BookmarkActions) request.getAttribute("bookmarkActions"); + String searchLine = ""; + if (bookmarkActions != null) { + searchLine = bookmarkActions.getSearchLine(); + } + String url = request.getRequestURL().toString(); + int index = url.indexOf("home.jsp"); + url = url.substring(0, index); %> <html> <link rel="stylesheet" type="text/css" href="./css/styles.css" /> + <link rel="search" type="application/opensearchdescription+xml" title="bowTemporarySearchEngine" href="<%=url%>bow?action=temporaryXml" /> + <link rel="search" type="application/opensearchdescription+xml" title="bowPermanentSearchEngine" href="<%=url%>bow?action=permanentXml" /> <body> - <h1 class="login">Login</h1> - <form method="POST" action="bow?action=login"> - email <input type="text" name="email" size="20"><br /> - password <input type=password name="password" size="20"><br /> - <input type="submit" value="login"> - </form> - <%if (error != null) {%> - <font color="red"><%=error%></font> - <%}%> - <a href="bow?action=registration">register</a> + <div id="table"> + <h1 class="result">Home</h1> + <% + if (bookmarkActions != null) { + List<Bookmark> bookmarkList = bookmarkActions.getBookmarks(); + if (!bookmarkList.isEmpty()) { + %> + <h2 class="result">The most using bookmarks</h2> + <table class="result"> + <tr class="result"> + <th class="result date"> + Date + </th> + <th class="result name"> + Name + </th> + <th class ="result tags"> + Tags + </th> + <th class=" result click"> + Click + </th> + </tr> + <% + SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); + for (Bookmark bookmark : bookmarkList) { + %> + <tr class="result"> + <td class="result"> + <%=sdf.format(bookmark.getDate())%> + </td> + <td class="result"> + <a href="bow?action=addClick&bookmarkId=<%=bookmark.getWikittyId()%>" target="_blank"><%=bookmark.getDescription()%></a> + </td> + <td class="result" style="text-align: left"> + <% + Set<String> tagList = bookmark.getTags(); + if (tagList != null && !tagList.isEmpty()) { + for (String tag : tagList) { + %> + <div> + <%=tag%> + </div> + <% + } + } + %> + </td> + <td class="result"> + <%=bookmark.getClick()%> + </td> + </tr> + <% + } + %> + </table> + <% + List<Bookmark> lastBookmarks = bookmarkActions.getLastBookmarks(); + if (!lastBookmarks.isEmpty()) { + %> + <h2 class="result">The last addition bookmarks</h2> + <table class="result"> + <tr class="result"> + <th class="result date"> + Date + </th> + <th class="result name"> + Name + </th> + <th class ="result tags"> + Tags + </th> + <th class=" result click"> + Click + </th> + </tr> + <% + for (Bookmark bookmark : lastBookmarks) { + %> + <tr class="result"> + <td class="result"> + <%=sdf.format(bookmark.getDate())%> + </td> + <td class="result"> + <a href="bow?action=addClick&bookmarkId=<%=bookmark.getWikittyId()%>" target="_blank"><%=bookmark.getDescription()%></a> + </td> + <td class="result" style="text-align: left"> + <% + Set<String> tagList = bookmark.getTags(); + if (tagList != null && !tagList.isEmpty()) { + for (String tag : tagList) { + %> + <div> + <%=tag%> + </div> + <% + } + } + %> + </td> + <td class="result"> + <%=bookmark.getClick()%> + </td> + </tr> + <% + } + %> + </table> + <% + } + } else { + %> + <h2 class="result">No Bookmarks</h2> + <% } + } + %> + </div> + <div id="menu"> + <div class="menu"> + <ul id="meta"> + <li><a href="bow?action=logout">Logout</a></li> + <li><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='<%=url%>bow?action=addUrl&token=<%=temporaryToken%>&url='+encodeURIComponent(url)+'&nameAndTags='+encodeURIComponent(nameAndTags);var%20script=document.createElement('script');script.src=link;script.type='text/javascript';document.body.appendChild(script);void(0);">Temporary token</a></li> + <li><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='<%=url%>bow?action=addUrl&token=<%=permanentToken%>&url='+encodeURIComponent(url)+'&nameAndTags='+encodeURIComponent(nameAndTags);var%20script=document.createElement('script');script.src=link;script.type='text/javascript';document.body.appendChild(script);void(0);">Current permanent token</a></li> + <li><a href="bow?action=generateToken&searchLine=<%=searchLine%>">Regenerate permanent token</a></li> + </ul> + </div> + <div class="menu"> + <form method="POST" action="bow?action=addUrl"> + URL<br /> + <input type="text" name="url" size="20" value="URL" /><br /> + Name and Tags<br /> + <input type="text" name="nameAndTags" size="20" value="name|tag1 tag2..." /><br /> + <input type="submit" value="add" /> + </form> + </div> + + <div class="menu"> + <div class="tagCloud"> + <% 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); + %> + <a href="bow?action=search&addTag=<%=tag%>&searchLine=<%=searchLine%>" title="<%=value%> results" class="tag" style="font-size: <%=font%>px;"><%=tag%></a> + <% + } + } + %> + <form method="POST" action="bow?action=search" style="text-align: center;margin-left: 20px;"> + <input style="float: left" type="text" name="searchLine" size="20" value="<%=searchLine%>" /> + <input style="float: left;" type="submit" value="Find" /> + </form> + </div> + </div> + </div> </body> </html> \ No newline at end of file Copied: trunk/src/main/webapp/login.jsp (from rev 32, trunk/src/main/webapp/home.jsp) =================================================================== --- trunk/src/main/webapp/login.jsp (rev 0) +++ trunk/src/main/webapp/login.jsp 2010-05-25 13:16:43 UTC (rev 33) @@ -0,0 +1,20 @@ +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<% + String error = (String) request.getAttribute("errorMessage"); +%> + +<html> + <link rel="stylesheet" type="text/css" href="./css/styles.css" /> + <body> + <h1 class="login">Login</h1> + <form method="POST" action="bow?action=login"> + email <input type="text" name="email" size="20"><br /> + password <input type=password name="password" size="20"><br /> + <input type="submit" value="login"> + </form> + <%if (error != null) {%> + <font color="red"><%=error%></font> + <%}%> + <a href="bow?action=registration">register</a> + </body> +</html> \ No newline at end of file Modified: trunk/src/main/webapp/search.jsp =================================================================== --- trunk/src/main/webapp/search.jsp 2010-05-21 10:13:25 UTC (rev 32) +++ trunk/src/main/webapp/search.jsp 2010-05-25 13:16:43 UTC (rev 33) @@ -128,9 +128,9 @@ <div class="menu"> <ul id="meta"> <li><a href="bow?action=logout">Logout</a></li> + <li><a href="bow?action=home">Home</a></li> <li><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='<%=url%>bow?action=addUrl&token=<%=temporaryToken%>&url='+encodeURIComponent(url)+'&nameAndTags='+encodeURIComponent(nameAndTags);var%20script=document.createElement('script');script.src=link;script.type='text/javascript';document.body.appendChild(script);void(0);">Temporary token</a></li> <li><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='<%=url%>bow?action=addUrl&token=<%=permanentToken%>&url='+encodeURIComponent(url)+'&nameAndTags='+encodeURIComponent(nameAndTags);var%20script=document.createElement('script');script.src=link;script.type='text/javascript';document.body.appendChild(script);void(0);">Current permanent token</a></li> - <li><a href="bow?action=generateToken&searchLine=<%=searchLine%>">Regenerate permanent token</a></li> </ul> </div> <div class="menu">