Author: bbrossaud Date: 2010-05-31 12:21:08 +0200 (Mon, 31 May 2010) New Revision: 44 Url: http://chorem.org/repositories/revision/bow/44 Log: addition tag works if bookmard doesn't have tag, importation adds the folder name as a tag to the bookmark tagList Modified: trunk/TODO.txt trunk/src/main/java/org/chorem/bow/BookmarkActions.java trunk/src/main/java/org/chorem/bow/ControllerServlet.java Modified: trunk/TODO.txt =================================================================== --- trunk/TODO.txt 2010-05-28 15:09:08 UTC (rev 43) +++ trunk/TODO.txt 2010-05-31 10:21:08 UTC (rev 44) @@ -9,4 +9,21 @@ -> le && pour le nuage de tag (11 mai) OK -> gestion des sessions (14 mai) OK -> javascript ==> (11 mai) OK --> Mise en forme (28 mai) \ No newline at end of file +-> Mise en forme (28 mai) + + +===> corriger ajout de tag quand vide + +===> ajout des tags par repertoire + +===> seeks.fr + champs pour recherche + +===> champ recherche fulltext + +===> class bokkmarkFile = Id proprietaire, list<userID> writer, list<userId> reader; + +===> class bookmark = idBookmarkFile a la place de UserID; + +===> dans class user = String SearchEngine; + +===> openSearch ==> proposer des url Modified: trunk/src/main/java/org/chorem/bow/BookmarkActions.java =================================================================== --- trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-28 15:09:08 UTC (rev 43) +++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-31 10:21:08 UTC (rev 44) @@ -30,6 +30,14 @@ protected int tmax = -1; protected int tmin = -1; + public static Bookmark createBookmarkFromHtml(String html, String name, User user) { + String link = getUrlFromHtml(html); + String tags = getTagsFromHtml(html); + Date date = getDateFromHtml(html); + Bookmark bookmark = createBookmark(link, name, tags, user, date); + return bookmark; + } + public static Date getDateFromHtml(String html) { Date date = null; if (html != null) { @@ -140,17 +148,37 @@ } public static void addTagsToBookmark(String tags, Bookmark bookmark) { - if (tags != null) { + if (tags != null && !tags.isEmpty()) { tags = tags.trim(); String[] tagsTab = tags.split("\\s+"); // put the tags in an array for (int i = 0; i < tagsTab.length; ++i) { - if (!tagsTab[i].isEmpty()) { - bookmark.addTags(tagsTab[i]); // Added tag for each rank (one tag by rank) + Set<String> tagList = bookmark.getTags(); + if (tagList != null) { + if (!tagList.contains(tagsTab[i]) && !tagsTab[i].isEmpty()) { + bookmark.addTags(tagsTab[i]); // Added tag for each rank (one tag by rank) + } + } else { + bookmark.addTags(tagsTab[i]); } } } } + public static void addTagsToBookmark(List<String> tagList, Bookmark bookmark) { + if (tagList != null && !tagList.isEmpty()) { + for (String tag : tagList) { + Set<String> bookmarTags = bookmark.getTags(); + if (bookmarTags != null) { + if (!bookmarTags.contains(tag) && !tag.isEmpty()) { + bookmark.addTags(tag); // Added tag for each rank (one tag by rank) + } + } else if (!tag.isEmpty()) { + bookmark.addTags(tag); + } + } + } + } + public static Bookmark createBookmark(String url, String name, String tags, User user, Date date) { Bookmark bookmark = (Bookmark) new BookmarkImpl(); if (name != null) { @@ -190,21 +218,6 @@ } } - public static void updateBookmarkTags(Bookmark bookmark, String tags) { - if (tags != null && !tags.isEmpty()) { - tags = tags.trim(); - String[] tagsTab = tags.split("\\s+"); // put the tags in an array - for (int i = 0; i < tagsTab.length; ++i) { - Set<String> tagList = bookmark.getTags(); - if (tagList != null) { - if (!tagList.contains(tagsTab[i]) && !tagsTab[i].isEmpty()) { - bookmark.addTags(tagsTab[i]); // Added tag for each rank (one tag by rank) - } - } - } - } - } - public static String getBookmarkTagsString(Bookmark bookmark) { if (bookmark != null) { Set<String> tags = bookmark.getTags(); Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java =================================================================== --- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-28 15:09:08 UTC (rev 43) +++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-31 10:21:08 UTC (rev 44) @@ -221,7 +221,8 @@ request.getRequestDispatcher("login.jsp").forward(request, response); } } catch (Exception eee) { - request.getRequestDispatcher("error.jsp").forward(request, response); + throw new ServletException("msg", eee); + // request.getRequestDispatcher("error.jsp").forward(request, response); } } @@ -345,7 +346,7 @@ Bookmark bookmark = proxy.restore(Bookmark.class, bookmarkId); if (bookmark != null) { BookmarkActions.updateBookmarkName(bookmark, name); - BookmarkActions.updateBookmarkTags(bookmark, tags); + BookmarkActions.addTagsToBookmark(tags, bookmark); proxy.store(bookmark); } } @@ -687,7 +688,7 @@ Parser parser = new Parser(content); NodeList list = parser.parse(null); List<Bookmark> bookmarks = new ArrayList<Bookmark>(); - parseHtmlToBookmarks(list, user, bookmarks); + parseHtmlToBookmarks(list, user, bookmarks, new ArrayList<String>()); proxy.store(bookmarks); } } @@ -695,28 +696,39 @@ response.sendRedirect("bow?action=home"); } - protected void parseHtmlToBookmarks(NodeList list, User user, List<Bookmark> bookmarks) + protected void parseHtmlToBookmarks(NodeList list, User user, List<Bookmark> bookmarks, List<String> tagList) throws ParserException { if (list != null) { + boolean isFolder = false; SimpleNodeIterator it = list.elements(); while (it.hasMoreNodes()) { Node node = it.nextNode(); String plainText = node.toPlainTextString(); String text = node.getText(); - if (text != null && text.contains("A HREF")) { - String url = BookmarkActions.getUrlFromHtml(text); - String tags = BookmarkActions.getTagsFromHtml(text); - Date date = BookmarkActions.getDateFromHtml(text); - Bookmark bookmark = BookmarkActions.createBookmark(url, plainText, tags, user, date); + if (text != null && text.startsWith("H3")) { + log.debug(text); + if (plainText != null && !plainText.isEmpty()) { + tagList.add(plainText); + isFolder = true; + } + } else if (text != null && text.startsWith("A HREF")) { + Bookmark bookmark = BookmarkActions.createBookmarkFromHtml(text, plainText, user); + BookmarkActions.addTagsToBookmark(tagList, bookmark); if (bookmark != null) { bookmarks.add(bookmark); } } NodeList children = node.getChildren(); if (children != null) { - parseHtmlToBookmarks(children, user, bookmarks); + parseHtmlToBookmarks(children, user, bookmarks, tagList); } } + if (isFolder == true) { + int index = tagList.size() - 1; + if (index > -1) { + tagList.remove(index); + } + } } }