From bbrossaud@users.chorem.org Thu May 27 17:21:06 2010 From: bbrossaud@users.chorem.org To: bow-commits@list.chorem.org Subject: [Bow-commits] r36 - in trunk/src/main: java/org/chorem/bow webapp webapp/WEB-INF Date: Thu, 27 May 2010 17:21:05 +0200 Message-ID: <20100527152105.F1D0C15913@nuiton.codelutin.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6948257146389426834==" --===============6948257146389426834== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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; =20 +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -30,6 +31,22 @@ protected int tmax =3D -1; protected int tmin =3D -1; =20 + public static Date getDateFromHtml(String html) { + Date date =3D null; + if (html !=3D null) { + Pattern p =3D Pattern.compile("ADD_DATE=3D\"([^\"]*)\""); + Matcher m =3D p.matcher(html); + if (m.find()) { + String str =3D m.group(1); + if (str !=3D null && !str.isEmpty()) { + long time =3D Long.valueOf(str) * 1000; + date =3D new Date(time); + } + } + } + return date; + } + public static String getExportHtmlBookmark(List bookmarks) { String export =3D ""; export =3D "\n" @@ -39,6 +56,12 @@ for (Bookmark bookmark : bookmarks) { export +=3D "
tags =3D bookmark.getTags(); if (tags !=3D null && !tags.isEmpty()) { @@ -128,7 +151,7 @@ } } =20 - public static Bookmark createBookmark(String url, String name, String ta= gs, User user) { + public static Bookmark createBookmark(String url, String name, String ta= gs, User user, Date date) { Bookmark bookmark =3D (Bookmark) new BookmarkImpl(); if (name !=3D null) { name =3D 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 =3D=3D null) { + date =3D new Date(); + } + bookmark.setDate(date); // set the date return bookmark; } =20 @@ -208,6 +234,9 @@ bookmarks.remove(bookmark); // Delete bookmark which= doesn't contain the tags from the search field remove =3D true; } + } else { + bookmarks.remove(bookmark); // Delete bookmark which doe= sn't contain the tags from the search field + remove =3D true; } } } Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-27 12:2= 9:26 UTC (rev 35) +++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-27 15:2= 1: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 @@ =20 private static final Log log =3D LogFactory.getLog(ControllerServlet.cla= ss); protected Model model =3D new Model(); - protected String error =3D ""; =20 @Override public void doGet(HttpServletRequest request, HttpServletResponse respon= se) @@ -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 !=3D null) { if (log.isDebugEnabled()) { log.debug("Going to actionSearch"); @@ -200,7 +197,6 @@ } request.getRequestDispatcher("login.jsp").forward(request, r= esponse); } - request.setAttribute("errorMessage", error); } catch (Exception eee) { //request.getRequestDispatcher("error.jsp").forward(request, res= ponse); throw new ServletException("DO GET ERROR", eee); @@ -332,7 +328,11 @@ } } String searchLine =3D request.getParameter("searchLine"); - response.sendRedirect("bow?action=3Dsearch&searchLine=3D" + searchLi= ne); + if (searchLine !=3D null) { + response.sendRedirect("bow?action=3Dsearch&searchLine=3D" + sear= chLine); + } else { + response.sendRedirect("bow?action=3Dhome"); + } } =20 protected void actionRemoveBookmark(HttpServletRequest request, HttpServ= letResponse response, User user) @@ -340,10 +340,17 @@ String bookmarkId =3D request.getParameter("bookmarkId"); if (bookmarkId !=3D null && !bookmarkId.isEmpty()) { WikittyProxy proxy =3D model.getProxy(); - proxy.delete(bookmarkId); + Bookmark bookmark =3D proxy.restore(Bookmark.class, bookmarkId); + if (bookmark !=3D null) { + proxy.delete(bookmarkId); + } } String searchLine =3D request.getParameter("searchLine"); - response.sendRedirect("bow?action=3Dsearch&searchLine=3D" + searchLi= ne); + if (searchLine !=3D null) { + response.sendRedirect("bow?action=3Dsearch&searchLine=3D" + sear= chLine); + } else { + response.sendRedirect("bow?action=3Dhome"); + } } =20 protected void actionDeleteTag(HttpServletRequest request, HttpServletRe= sponse response, User user) @@ -361,7 +368,11 @@ } } String searchLine =3D request.getParameter("searchLine"); - response.sendRedirect("bow?action=3Dsearch&searchLine=3D" + searchLi= ne); + if (searchLine !=3D null) { + response.sendRedirect("bow?action=3Dsearch&searchLine=3D" + sear= chLine); + } else { + response.sendRedirect("bow?action=3Dhome"); + } } =20 =20 @@ -416,7 +427,7 @@ Bookmark bookmark =3D null; if (name !=3D null) { String tags =3D request.getParameter("tags"); // tags - bookmark =3D BookmarkActions.createBookmark(url, name, tags, use= r); + bookmark =3D BookmarkActions.createBookmark(url, name, tags, use= r, null); } else { String nameAndTags =3D request.getParameter("nameAndTags"); bookmark =3D BookmarkActions.createBookmark(url, nameAndTags, us= er); @@ -513,6 +524,8 @@ String email =3D request.getParameter("email"); String password =3D request.getParameter("password"); if (this.checkRegister(email, password)) { // check if all is well + String error =3D "Email and password must be correctly filled"; + request.setAttribute("msgError", error); request.getRequestDispatcher("register.jsp").forward(request, re= sponse); } else { WikittyProxy proxy =3D model.getProxy(); @@ -548,7 +561,8 @@ request.getRequestDispatcher("home.jsp").forward(request, respon= se); =20 } else { - error =3D "Unknow email or incorrect password"; + String error =3D "Unknow email or incorrect password"; + request.setAttribute("msgError", error); request.getRequestDispatcher("login.jsp").forward(request, respo= nse); } } @@ -607,7 +621,6 @@ } } } - error =3D "Email and password must be correctly filled"; return true; } =20 @@ -647,25 +660,23 @@ while (iter.hasNext()) { FileItem item =3D (FileItem) iter.next(); if (!item.isFormField()) { - String fieldName =3D item.getFieldName(); - log.debug("fieldname=3D{" + fieldName + "}"); - String fileName =3D item.getName(); - log.debug("fileName=3D{" + fileName + "}"); + WikittyProxy proxy =3D model.getProxy(); String content =3D item.getString(); Parser parser =3D new Parser(content); NodeList list =3D parser.parse(null); - parseHtmlToBookmarks(list, user); + List bookmarks =3D new ArrayList(); + parseHtmlToBookmarks(list, user, bookmarks); + proxy.store(bookmarks); } } } response.sendRedirect("bow?action=3Dhome"); } =20 - private void parseHtmlToBookmarks(NodeList list, User user) + private void parseHtmlToBookmarks(NodeList list, User user, List bookmarks) throws ParserException { if (list !=3D null) { SimpleNodeIterator it =3D list.elements(); - WikittyProxy proxy =3D model.getProxy(); while (it.hasMoreNodes()) { Node node =3D it.nextNode(); String plainText =3D node.toPlainTextString(); @@ -673,20 +684,21 @@ if (text !=3D null && text.contains("A HREF")) { String url =3D BookmarkActions.getUrlFromHtml(text); String tags =3D BookmarkActions.getTagsFromHtml(text); - Bookmark bookmark =3D BookmarkActions.createBookmark(url= , plainText, tags, user); + Date date =3D BookmarkActions.getDateFromHtml(text); + Bookmark bookmark =3D BookmarkActions.createBookmark(url= , plainText, tags, user, date); if (bookmark !=3D null) { - proxy.store(bookmark); + bookmarks.add(bookmark); } } NodeList children =3D node.getChildren(); if (children !=3D null) { - parseHtmlToBookmarks(children, user); + parseHtmlToBookmarks(children, user, bookmarks); } } } } =20 - private void actionExportBookmarks(HttpServletRequest request, HttpServl= etResponse response, User user) + private void actionExportBookmarks(HttpServletResponse response, User us= er) throws IOException { WikittyProxy proxy =3D model.getProxy(); Criteria criteria =3D Search.query().eq(Bookmark.FQ_FIELD_EMAIL, use= r.getEmail()).criteria(); @@ -696,7 +708,6 @@ ServletOutputStream op =3D response.getOutputStream(); response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename=3D\"= bookmarks.html\""); - log.debug("export=3D["+export+"]"); response.setContentLength(buff.length); op.write(buff, 0, buff.length); op.flush(); Modified: trunk/src/main/java/org/chorem/bow/OpenSearchActions.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/src/main/java/org/chorem/bow/OpenSearchActions.java 2010-05-27 12:2= 9:26 UTC (rev 35) +++ trunk/src/main/java/org/chorem/bow/OpenSearchActions.java 2010-05-27 15:2= 1:05 UTC (rev 36) @@ -45,14 +45,16 @@ Map map =3D new HashMap(); for (Bookmark bookmark : bookmarkList) { Set tagList =3D bookmark.getTags(); - for (String tag : tagList) { - if (tag.indexOf(word) =3D=3D 0 && !searchLine.contains(t= ag)) { - if (map.containsKey(tag)) { - Integer count =3D map.get(tag); - ++count; - map.put(tag, count); - } else { - map.put(tag, 1); + if (tagList !=3D null) { + for (String tag : tagList) { + if (tag.indexOf(word) =3D=3D 0 && !searchLine.contai= ns(tag)) { + if (map.containsKey(tag)) { + Integer count =3D map.get(tag); + ++count; + map.put(tag, count); + } else { + map.put(tag, 1); + } } } } @@ -71,8 +73,10 @@ =20 protected boolean bookmarkHasTag(Bookmark bookmark, String tag) { Set tagList =3D bookmark.getTags(); - if (tagList.contains(tag)) { - return true; + if (tagList !=3D null) { + if (tagList.contains(tag)) { + return true; + } } return false; } Modified: trunk/src/main/webapp/WEB-INF/web.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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 @@ Controller =20 + + login.jsp + + + =20 Modified: trunk/src/main/webapp/home.jsp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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 bookmarkList =3D bookmarkActions.= getBookmarks(); if (!bookmarkList.isEmpty()) { %> -

The most using bookmarks

+

The most used bookmarks

+ @@ -58,10 +61,19 @@ %> +
+ remove + Date
+ "> + 3D"Remove + + <%=3Dsdf.format(bookmark.getDate())%> " target=3D"_blank"><%=3Dbookmark.getDescription()%><= /a> +
"> + " /> + +
<% @@ -69,13 +81,20 @@ = if (tagList !=3D null && !tagList.isEmpty()) { = for (String tag : tagList) { %> -
+ <% = } } %> +
"> + " /> + +
<%=3Dbookmark.getClick()%> @@ -92,6 +111,9 @@

The last addition bookmarks

+ @@ -110,10 +132,19 @@ %> + - -
+ remove + Date
+ "> + 3D"Remove + + <%=3Dsdf.format(bookmark.getDate())%> " target=3D"_blank"><%=3Dbookmark.getDescription()%><= /a> +
&searchLine=3D<%=3DsearchLin= e%>"> + " /> + +
<% @@ -121,13 +152,20 @@ = if (tagList !=3D null && !tagList.isEmpty()) { = for (String tag : tagList) { %> -
+ <% = } = } %> +
"> + " /> + +
<%=3Dbookmark.getClick()%> Modified: trunk/src/main/webapp/login.jsp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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=3D"text/html" pageEncoding=3D"UTF-8"%> <% - String error =3D (String) request.getAttribute("errorMessage"); + String error =3D (String) request.getAttribute("msgError"); %> =20 @@ -8,13 +8,16 @@

Login

- email
- password + email +
+ password +
+ register +
<%if (error !=3D null) {%> <%=3Derror%> <%}%> - register \ No newline at end of file Modified: trunk/src/main/webapp/register.jsp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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=3D"text/html" pageEncoding=3D"UTF-8"%> -<%String error =3D (String) request.getAttribute("errorMessage");%> +<%String error =3D (String) request.getAttribute("msgError");%>

Register

=20
- email
- password + email +
+ password +
- <%if (error !=3D null && error.isEmpty() =3D=3D false) {%> -
<%=3Derror%> - <%}%> Return to the login page +
+ <%if (error !=3D null && error.isEmpty() =3D=3D false) {%> + <%=3Derror%> + <%}%> + \ No newline at end of file Modified: trunk/src/main/webapp/search.jsp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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 @@
TagsEdit Click "> @@ -84,6 +83,10 @@ " target=3D"_blank"><%=3Dbookmark.getDescription()%><= /a> +
&searchLine=3D<%=3DsearchLi= ne%>"> + " /> + +
<% @@ -91,7 +94,7 @@ = if (tagList !=3D null && !tagList.isEmpty()) { = for (String tag : tagList) { %> - -
&searchLine=3D<%=3DsearchLin= e%>"> - " /> + &searchLine=3D<%=3DsearchLi= ne%>"> " />
--===============6948257146389426834==--