r36 - in trunk/src/main: java/org/chorem/bow webapp webapp/WEB-INF
Author: bbrossaud Date: 2010-05-27 17:21:05 +0200 (Thu, 27 May 2010) New Revision: 36 Url: http://chorem.org/repositories/revision/bow/36 Log: removed bugs and changed the interface Modified: trunk/src/main/java/org/chorem/bow/BookmarkActions.java trunk/src/main/java/org/chorem/bow/ControllerServlet.java trunk/src/main/java/org/chorem/bow/OpenSearchActions.java trunk/src/main/webapp/WEB-INF/web.xml trunk/src/main/webapp/home.jsp trunk/src/main/webapp/login.jsp trunk/src/main/webapp/register.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-27 12:29:26 UTC (rev 35) +++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-27 15:21:05 UTC (rev 36) @@ -4,6 +4,7 @@ */ package org.chorem.bow; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -30,6 +31,22 @@ protected int tmax = -1; protected int tmin = -1; + public static Date getDateFromHtml(String html) { + Date date = null; + if (html != null) { + Pattern p = Pattern.compile("ADD_DATE=\"([^\"]*)\""); + Matcher m = p.matcher(html); + if (m.find()) { + String str = m.group(1); + if (str != null && !str.isEmpty()) { + long time = Long.valueOf(str) * 1000; + date = new Date(time); + } + } + } + return date; + } + public static String getExportHtmlBookmark(List<Bookmark> bookmarks) { String export = ""; export = "<!DOCTYPE NETSCAPE-Bookmark-file-1>\n" @@ -39,6 +56,12 @@ for (Bookmark bookmark : bookmarks) { export += "<DT><A HREF=\""; export += bookmark.getLink() + "\" "; + Date date = bookmark.getDate(); + if (date != null) { + SimpleDateFormat sdf = new SimpleDateFormat("ss"); + String time = sdf.format(date); + export += "ADD_DATE=\"" + time + "\" LAST_MODIFIED=\"" + time + "\""; + } export += "LAST_CHARSET=\"UTF-8\" "; Set<String> tags = bookmark.getTags(); if (tags != null && !tags.isEmpty()) { @@ -128,7 +151,7 @@ } } - public static Bookmark createBookmark(String url, String name, String tags, User user) { + public static Bookmark createBookmark(String url, String name, String tags, User user, Date date) { Bookmark bookmark = (Bookmark) new BookmarkImpl(); if (name != null) { name = name.trim(); @@ -152,7 +175,10 @@ } bookmark.setClick(0); bookmark.setEmail(user.getEmail()); // set the email (user name) - bookmark.setDate(new Date()); // set the date + if (date == null) { + date = new Date(); + } + bookmark.setDate(date); // set the date return bookmark; } @@ -208,6 +234,9 @@ bookmarks.remove(bookmark); // Delete bookmark which doesn't contain the tags from the search field remove = true; } + } else { + bookmarks.remove(bookmark); // Delete bookmark which doesn't contain the tags from the search field + remove = true; } } } Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java =================================================================== --- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-27 12:29:26 UTC (rev 35) +++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-27 15:21:05 UTC (rev 36) @@ -15,7 +15,6 @@ import java.util.Date; import java.util.Iterator; import java.util.List; -import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; @@ -30,7 +29,6 @@ import org.apache.commons.logging.LogFactory; import org.htmlparser.Node; import org.htmlparser.Parser; -import org.htmlparser.filters.TagNameFilter; import org.htmlparser.util.NodeList; import org.htmlparser.util.ParserException; import org.htmlparser.util.SimpleNodeIterator; @@ -46,7 +44,6 @@ private static final Log log = LogFactory.getLog(ControllerServlet.class); protected Model model = new Model(); - protected String error = ""; @Override public void doGet(HttpServletRequest request, HttpServletResponse response) @@ -110,7 +107,7 @@ if (log.isDebugEnabled()) { log.debug("Going to actionExportBookmarks"); } - this.actionExportBookmarks(request, response, user); + this.actionExportBookmarks(response, user); } else if (action.equals("search") && user != null) { if (log.isDebugEnabled()) { log.debug("Going to actionSearch"); @@ -200,7 +197,6 @@ } request.getRequestDispatcher("login.jsp").forward(request, response); } - request.setAttribute("errorMessage", error); } catch (Exception eee) { //request.getRequestDispatcher("error.jsp").forward(request, response); throw new ServletException("DO GET ERROR", eee); @@ -332,7 +328,11 @@ } } String searchLine = request.getParameter("searchLine"); - response.sendRedirect("bow?action=search&searchLine=" + searchLine); + if (searchLine != null) { + response.sendRedirect("bow?action=search&searchLine=" + searchLine); + } else { + response.sendRedirect("bow?action=home"); + } } protected void actionRemoveBookmark(HttpServletRequest request, HttpServletResponse response, User user) @@ -340,10 +340,17 @@ String bookmarkId = request.getParameter("bookmarkId"); if (bookmarkId != null && !bookmarkId.isEmpty()) { WikittyProxy proxy = model.getProxy(); - proxy.delete(bookmarkId); + Bookmark bookmark = proxy.restore(Bookmark.class, bookmarkId); + if (bookmark != null) { + proxy.delete(bookmarkId); + } } String searchLine = request.getParameter("searchLine"); - response.sendRedirect("bow?action=search&searchLine=" + searchLine); + if (searchLine != null) { + response.sendRedirect("bow?action=search&searchLine=" + searchLine); + } else { + response.sendRedirect("bow?action=home"); + } } protected void actionDeleteTag(HttpServletRequest request, HttpServletResponse response, User user) @@ -361,7 +368,11 @@ } } String searchLine = request.getParameter("searchLine"); - response.sendRedirect("bow?action=search&searchLine=" + searchLine); + if (searchLine != null) { + response.sendRedirect("bow?action=search&searchLine=" + searchLine); + } else { + response.sendRedirect("bow?action=home"); + } } @@ -416,7 +427,7 @@ Bookmark bookmark = null; if (name != null) { String tags = request.getParameter("tags"); // tags - bookmark = BookmarkActions.createBookmark(url, name, tags, user); + bookmark = BookmarkActions.createBookmark(url, name, tags, user, null); } else { String nameAndTags = request.getParameter("nameAndTags"); bookmark = BookmarkActions.createBookmark(url, nameAndTags, user); @@ -513,6 +524,8 @@ String email = request.getParameter("email"); String password = request.getParameter("password"); if (this.checkRegister(email, password)) { // check if all is well + String error = "Email and password must be correctly filled"; + request.setAttribute("msgError", error); request.getRequestDispatcher("register.jsp").forward(request, response); } else { WikittyProxy proxy = model.getProxy(); @@ -548,7 +561,8 @@ request.getRequestDispatcher("home.jsp").forward(request, response); } else { - error = "Unknow email or incorrect password"; + String error = "Unknow email or incorrect password"; + request.setAttribute("msgError", error); request.getRequestDispatcher("login.jsp").forward(request, response); } } @@ -607,7 +621,6 @@ } } } - error = "Email and password must be correctly filled"; return true; } @@ -647,25 +660,23 @@ while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (!item.isFormField()) { - String fieldName = item.getFieldName(); - log.debug("fieldname={" + fieldName + "}"); - String fileName = item.getName(); - log.debug("fileName={" + fileName + "}"); + WikittyProxy proxy = model.getProxy(); String content = item.getString(); Parser parser = new Parser(content); NodeList list = parser.parse(null); - parseHtmlToBookmarks(list, user); + List<Bookmark> bookmarks = new ArrayList<Bookmark>(); + parseHtmlToBookmarks(list, user, bookmarks); + proxy.store(bookmarks); } } } response.sendRedirect("bow?action=home"); } - private void parseHtmlToBookmarks(NodeList list, User user) + private void parseHtmlToBookmarks(NodeList list, User user, List<Bookmark> bookmarks) throws ParserException { if (list != null) { SimpleNodeIterator it = list.elements(); - WikittyProxy proxy = model.getProxy(); while (it.hasMoreNodes()) { Node node = it.nextNode(); String plainText = node.toPlainTextString(); @@ -673,20 +684,21 @@ if (text != null && text.contains("A HREF")) { String url = BookmarkActions.getUrlFromHtml(text); String tags = BookmarkActions.getTagsFromHtml(text); - Bookmark bookmark = BookmarkActions.createBookmark(url, plainText, tags, user); + Date date = BookmarkActions.getDateFromHtml(text); + Bookmark bookmark = BookmarkActions.createBookmark(url, plainText, tags, user, date); if (bookmark != null) { - proxy.store(bookmark); + bookmarks.add(bookmark); } } NodeList children = node.getChildren(); if (children != null) { - parseHtmlToBookmarks(children, user); + parseHtmlToBookmarks(children, user, bookmarks); } } } } - private void actionExportBookmarks(HttpServletRequest request, HttpServletResponse response, User user) + private void actionExportBookmarks(HttpServletResponse response, User user) throws IOException { WikittyProxy proxy = model.getProxy(); Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(); @@ -696,7 +708,6 @@ ServletOutputStream op = response.getOutputStream(); response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename=\"bookmarks.html\""); - log.debug("export=["+export+"]"); response.setContentLength(buff.length); op.write(buff, 0, buff.length); op.flush(); Modified: trunk/src/main/java/org/chorem/bow/OpenSearchActions.java =================================================================== --- trunk/src/main/java/org/chorem/bow/OpenSearchActions.java 2010-05-27 12:29:26 UTC (rev 35) +++ trunk/src/main/java/org/chorem/bow/OpenSearchActions.java 2010-05-27 15:21:05 UTC (rev 36) @@ -45,14 +45,16 @@ Map<String, Integer> map = new HashMap<String, Integer>(); for (Bookmark bookmark : bookmarkList) { Set<String> tagList = bookmark.getTags(); - for (String tag : tagList) { - if (tag.indexOf(word) == 0 && !searchLine.contains(tag)) { - if (map.containsKey(tag)) { - Integer count = map.get(tag); - ++count; - map.put(tag, count); - } else { - map.put(tag, 1); + if (tagList != null) { + for (String tag : tagList) { + if (tag.indexOf(word) == 0 && !searchLine.contains(tag)) { + if (map.containsKey(tag)) { + Integer count = map.get(tag); + ++count; + map.put(tag, count); + } else { + map.put(tag, 1); + } } } } @@ -71,8 +73,10 @@ protected boolean bookmarkHasTag(Bookmark bookmark, String tag) { Set<String> tagList = bookmark.getTags(); - if (tagList.contains(tag)) { - return true; + if (tagList != null) { + if (tagList.contains(tag)) { + return true; + } } return false; } Modified: trunk/src/main/webapp/WEB-INF/web.xml =================================================================== --- trunk/src/main/webapp/WEB-INF/web.xml 2010-05-27 12:29:26 UTC (rev 35) +++ trunk/src/main/webapp/WEB-INF/web.xml 2010-05-27 15:21:05 UTC (rev 36) @@ -8,6 +8,11 @@ <servlet-name>Controller</servlet-name> </servlet> + <welcome-file-list> + <welcome-file>login.jsp</welcome-file> + </welcome-file-list> + + <!-- SERVLET MAPPING --> <servlet-mapping> Modified: trunk/src/main/webapp/home.jsp =================================================================== --- trunk/src/main/webapp/home.jsp 2010-05-27 12:29:26 UTC (rev 35) +++ trunk/src/main/webapp/home.jsp 2010-05-27 15:21:05 UTC (rev 36) @@ -36,9 +36,12 @@ List<Bookmark> bookmarkList = bookmarkActions.getBookmarks(); if (!bookmarkList.isEmpty()) { %> - <h2 class="result">The most using bookmarks</h2> + <h2 class="result">The most used bookmarks</h2> <table class="result"> <tr class="result"> + <th class ="result remove"> + remove + </th> <th class="result date"> Date </th> @@ -58,10 +61,19 @@ %> <tr class="result"> <td class="result"> + <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> + </td> + <td class="result"> <%=sdf.format(bookmark.getDate())%> </td> <td class="result"> <a href="bow?action=addClick&bookmarkId=<%=bookmark.getWikittyId()%>" target="_blank"><%=bookmark.getDescription()%></a> + <form method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>"> + <input type="text" name="name" size="35" value="<%=bookmark.getDescription()%>" /> + <input type="image" src="img/edit.png" title="Edit"/> + </form> </td> <td class="result" style="text-align: left"> <% @@ -69,13 +81,20 @@ if (tagList != null && !tagList.isEmpty()) { for (String tag : tagList) { %> - <div> + <div style="display: inline"> + <a style="text-decoration:none" href="bow?action=deleteTag&bookmarkId=<%=bookmark.getWikittyId()%>&deleteTag=<%=tag%>"> + <IMG style="border:none" SRC="img/delete.png" ALT="Delete tag" TITLE="Delete" /> + </a> <%=tag%> </div> <% } } %> + <form method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>"> + <input type="text" name="tags" size="35" value="<%=BookmarkActions.getBookmarkTagsString(bookmark)%>" /> + <input type="image" src="img/edit.png" title="Edit"/> + </form> </td> <td class="result"> <%=bookmark.getClick()%> @@ -92,6 +111,9 @@ <h2 class="result">The last addition bookmarks</h2> <table class="result"> <tr class="result"> + <th class ="result remove"> + remove + </th> <th class="result date"> Date </th> @@ -110,10 +132,19 @@ %> <tr class="result"> <td class="result"> + <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> + </td> + <td class="result"> <%=sdf.format(bookmark.getDate())%> </td> <td class="result"> <a href="bow?action=addClick&bookmarkId=<%=bookmark.getWikittyId()%>" target="_blank"><%=bookmark.getDescription()%></a> + <form method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>&searchLine=<%=searchLine%>"> + <input type="text" name="name" size="35" value="<%=bookmark.getDescription()%>" /> + <input type="image" src="img/edit.png" title="Edit"/> + </form> </td> <td class="result" style="text-align: left"> <% @@ -121,13 +152,20 @@ if (tagList != null && !tagList.isEmpty()) { for (String tag : tagList) { %> - <div> + <div style="display: inline"> + <a style="text-decoration:none" href="bow?action=deleteTag&bookmarkId=<%=bookmark.getWikittyId()%>&deleteTag=<%=tag%>"> + <IMG style="border:none" SRC="img/delete.png" ALT="Delete tag" TITLE="Delete" /> + </a> <%=tag%> </div> <% } } %> + <form method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>"> + <input type="text" name="tags" size="35" value="<%=BookmarkActions.getBookmarkTagsString(bookmark)%>" /> + <input type="image" src="img/edit.png" title="Edit"/> + </form> </td> <td class="result"> <%=bookmark.getClick()%> Modified: trunk/src/main/webapp/login.jsp =================================================================== --- trunk/src/main/webapp/login.jsp 2010-05-27 12:29:26 UTC (rev 35) +++ trunk/src/main/webapp/login.jsp 2010-05-27 15:21:05 UTC (rev 36) @@ -1,6 +1,6 @@ <%@page contentType="text/html" pageEncoding="UTF-8"%> <% - String error = (String) request.getAttribute("errorMessage"); + String error = (String) request.getAttribute("msgError"); %> <html> @@ -8,13 +8,16 @@ <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 /> + email <input type="text" name="email" size="20"> + <br /> + password <input type=password name="password" size="20"> + <br /> <input type="submit" value="login"> </form> + <a href="bow?action=registration">register</a> + <br /> <%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/register.jsp =================================================================== --- trunk/src/main/webapp/register.jsp 2010-05-27 12:29:26 UTC (rev 35) +++ trunk/src/main/webapp/register.jsp 2010-05-27 15:21:05 UTC (rev 36) @@ -1,18 +1,22 @@ <%@page contentType="text/html" pageEncoding="UTF-8"%> -<%String error = (String) request.getAttribute("errorMessage");%> +<%String error = (String) request.getAttribute("msgError");%> <html> <link rel="stylesheet" type="text/css" href="./css/styles.css" /> <body> <h1 class="login">Register</h1> <form method="POST" action="bow?action=register"> - email <input type="text" name="email" size="20"><br /> - password <input type=password name="password" size="20"><br /> + email <input type="text" name="email" size="20"> + <br /> + password <input type=password name="password" size="20"> + <br /> <input type="submit" value="Register"> </form> - <%if (error != null && error.isEmpty() == false) {%> - <br/><font color="red"><%=error%></font> - <%}%> <a href="bow?action=login">Return to the login page</a> + <br /> + <%if (error != null && error.isEmpty() == false) {%> + <font color="red"><%=error%></font> + <%}%> + </body> </html> \ No newline at end of file Modified: trunk/src/main/webapp/search.jsp =================================================================== --- trunk/src/main/webapp/search.jsp 2010-05-27 12:29:26 UTC (rev 35) +++ trunk/src/main/webapp/search.jsp 2010-05-27 15:21:05 UTC (rev 36) @@ -58,7 +58,6 @@ </a> </th> <th class ="result tags">Tags</th> - <th class="result edit">Edit</th> <th class=" result click"> Click <a style="text-decoration:none" href="bow?action=orderAsc&type=click&searchLine=<%=searchLine%>"> @@ -84,6 +83,10 @@ </td> <td class="result"> <a href="bow?action=addClick&bookmarkId=<%=bookmark.getWikittyId()%>" target="_blank"><%=bookmark.getDescription()%></a> + <form method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>&searchLine=<%=searchLine%>"> + <input type="text" name="name" size="35" value="<%=bookmark.getDescription()%>" /> + <input type="image" src="img/edit.png" title="Edit"/> + </form> </td> <td class="result" style="text-align: left"> <% @@ -91,7 +94,7 @@ if (tagList != null && !tagList.isEmpty()) { for (String tag : tagList) { %> - <div> + <div style="display: inline"> <a style="text-decoration:none" href="bow?action=deleteTag&bookmarkId=<%=bookmark.getWikittyId()%>&deleteTag=<%=tag%>&searchLine=<%=searchLine%>"> <IMG style="border:none" SRC="img/delete.png" ALT="Delete tag" TITLE="Delete" /> </a> @@ -101,10 +104,7 @@ } } %> - </td> - <td class="result"> - <form method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>&searchLine=<%=searchLine%>"> - <input type="text" name="name" size="35" value="<%=bookmark.getDescription()%>" /> + <form method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>&searchLine=<%=searchLine%>"> <input type="text" name="tags" size="35" value="<%=BookmarkActions.getBookmarkTagsString(bookmark)%>" /> <input type="image" src="img/edit.png" title="Edit"/> </form>
participants (1)
-
bbrossaudï¼ users.chorem.org