Bow-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
May 2010
- 1 participants
- 41 discussions
r27 - in trunk/src/main: java/org/chorem/bow webapp/WEB-INF
by bbrossaud@users.chorem.org 18 May '10
by bbrossaud@users.chorem.org 18 May '10
18 May '10
Author: bbrossaud
Date: 2010-05-18 17:26:01 +0200 (Tue, 18 May 2010)
New Revision: 27
Url: http://chorem.org/repositories/revision/bow/27
Log:
deleted useless servlet
Removed:
trunk/src/main/java/org/chorem/bow/OpenSearchXmlServlet.java
Modified:
trunk/src/main/webapp/WEB-INF/web.xml
Deleted: trunk/src/main/java/org/chorem/bow/OpenSearchXmlServlet.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/OpenSearchXmlServlet.java 2010-05-18 15:21:30 UTC (rev 26)
+++ trunk/src/main/java/org/chorem/bow/OpenSearchXmlServlet.java 2010-05-18 15:26:01 UTC (rev 27)
@@ -1,36 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package org.chorem.bow;
-
-import java.io.IOException;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- *
- * @author bbrossaud
- */
-public class OpenSearchXmlServlet extends HttpServlet {
-
- @Override
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws IOException, ServletException {
- this.doPost(request, response);
- }
-
- /* @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet error occurs
- */
- @Override
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws IOException, ServletException {
- request.getRequestDispatcher("xml.jsp").forward(request, response);
- }
-
-}
Modified: trunk/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/src/main/webapp/WEB-INF/web.xml 2010-05-18 15:21:30 UTC (rev 26)
+++ trunk/src/main/webapp/WEB-INF/web.xml 2010-05-18 15:26:01 UTC (rev 27)
@@ -8,11 +8,6 @@
<servlet-name>Controller</servlet-name>
</servlet>
- <servlet>
- <servlet-class>org.chorem.bow.OpenSearchXmlServlet</servlet-class>
- <servlet-name>XML</servlet-name>
- </servlet>
-
<!-- SERVLET MAPPING -->
<servlet-mapping>
@@ -20,9 +15,4 @@
<url-pattern>/bow</url-pattern>
</servlet-mapping>
- <servlet-mapping>
- <servlet-name>XML</servlet-name>
- <url-pattern>/xml</url-pattern>
- </servlet-mapping>
-
</web-app>
\ No newline at end of file
1
0
r26 - in trunk: . src/main/java/org/chorem/bow src/main/webapp src/main/webapp/WEB-INF
by bbrossaud@users.chorem.org 18 May '10
by bbrossaud@users.chorem.org 18 May '10
18 May '10
Author: bbrossaud
Date: 2010-05-18 17:21:30 +0200 (Tue, 18 May 2010)
New Revision: 26
Url: http://chorem.org/repositories/revision/bow/26
Log:
permanent and temporary opensearch functionalities addition
Added:
trunk/src/main/java/org/chorem/bow/OpenSearchActions.java
trunk/src/main/java/org/chorem/bow/OpenSearchXmlServlet.java
trunk/src/main/java/org/chorem/bow/Suggestion.java
trunk/src/main/java/org/chorem/bow/SuggestionsComparator.java
trunk/src/main/webapp/openSearchResult.jsp
trunk/src/main/webapp/permanentXml.jsp
trunk/src/main/webapp/suggestions.jsp
trunk/src/main/webapp/temporaryXml.jsp
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/java/org/chorem/bow/Model.java
trunk/src/main/webapp/WEB-INF/web.xml
trunk/src/main/webapp/generateToken.jsp
trunk/src/main/webapp/home.jsp
trunk/src/main/webapp/search.jsp
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-05-14 15:09:05 UTC (rev 25)
+++ trunk/pom.xml 2010-05-18 15:21:30 UTC (rev 26)
@@ -48,27 +48,20 @@
</dependency>
<dependency>
- <groupId>org.sharengo.wikengo</groupId>
- <artifactId>core-wikitty-api</artifactId>
+ <groupId>org.nuiton.wikitty</groupId>
+ <artifactId>wikitty-api</artifactId>
<version>${wikitty.version}</version>
</dependency>
<dependency>
- <groupId>org.sharengo.wikengo</groupId>
- <artifactId>core-wikitty-jdbc-impl</artifactId>
+ <groupId>org.nuiton.wikitty</groupId>
+ <artifactId>wikitty-jdbc-impl</artifactId>
<version>${wikitty.version}</version>
-
- <exclusions>
- <exclusion>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>jetty</artifactId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
- <groupId>org.sharengo.wikengo</groupId>
- <artifactId>core-wikitty-multistorage-impl</artifactId>
+ <groupId>org.nuiton.wikitty</groupId>
+ <artifactId>wikitty-multistorage-impl</artifactId>
<version>${wikitty.version}</version>
</dependency>
@@ -119,7 +112,7 @@
<!--projectId>core-wikitty</projectId-->
<!--platform>nuiton.org</platform-->
<projectId>bow</projectId>
- <wikitty.version>1.5-cl-SNAPSHOT</wikitty.version>
+ <wikitty.version>2.0-SNAPSHOT</wikitty.version>
<!-- common versions used in sub-poms -->
<junit.version>4.7</junit.version>
<siteLocales>en</siteLocales>
@@ -170,7 +163,7 @@
</xmiResources>
<includes>**/*.objectmodel</includes>
<resolver>org.nuiton.util.FasterCachedResourceResolver</resolver>
- <templates>org.sharengo.wikitty.generator.WikittyMetaGenerator</templates>
+ <templates>org.nuiton.wikitty.generator.WikittyMetaGenerator</templates>
<defaultPackage>com.jurismarches.vradi</defaultPackage>
<extractedPackages>org.chorem.bow</extractedPackages>
<generatedPackages>org.chorem.bow</generatedPackages>
@@ -185,8 +178,8 @@
<dependencies>
<dependency>
- <groupId>org.sharengo.wikengo</groupId>
- <artifactId>core-wikitty-generators</artifactId>
+ <groupId>org.nuiton.wikitty</groupId>
+ <artifactId>wikitty-generators</artifactId>
<version>${wikitty.version}</version>
</dependency>
<!-- Meta model uml d'eclipse -->
Modified: trunk/src/main/java/org/chorem/bow/BookmarkActions.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-14 15:09:05 UTC (rev 25)
+++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-18 15:21:30 UTC (rev 26)
@@ -35,7 +35,7 @@
* @return null if all fields are not correctly filled
* @return Bookmark the website bookmark
*/
- public Bookmark createBookmark(String url, String nameAndTags, User user) {
+ public static Bookmark createBookmark(String url, String nameAndTags, User user) {
Bookmark bookmark = (Bookmark) new BookmarkImpl();
@@ -69,7 +69,7 @@
return bookmark;
}
- public void updateBookmark(Bookmark bookmark, String nameAndTags) {
+ public static void updateBookmark(Bookmark bookmark, String nameAndTags) {
int nameIndex = nameAndTags.indexOf('|'); // get the index name of the website
if (nameIndex > 0) {
String name = nameAndTags.substring(0, nameIndex); // get the website name
@@ -172,11 +172,16 @@
}
}
- public void addTags(String[] tags) {
- for (int i = 0; i
- < tags.length; i++) {
- if (!tagsSearch.contains(tags[i])) {
- tagsSearch.add(tags[i]);
+ public void addTags(String str) {
+ if (str != null) {
+ if (!str.isEmpty()) {
+ str = str.trim();
+ String[] tags = str.split("\\s+");
+ for (int i = 0; i < tags.length; i++) {
+ if (!tagsSearch.contains(tags[i])) {
+ tagsSearch.add(tags[i]);
+ }
+ }
}
}
}
Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-14 15:09:05 UTC (rev 25)
+++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-18 15:21:30 UTC (rev 26)
@@ -18,9 +18,9 @@
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.sharengo.wikitty.Criteria;
-import org.sharengo.wikitty.WikittyProxy;
-import org.sharengo.wikitty.search.Search;
+import org.nuiton.wikitty.Criteria;
+import org.nuiton.wikitty.WikittyProxy;
+import org.nuiton.wikitty.search.Search;
/**
*
@@ -30,8 +30,6 @@
private static final Log log = LogFactory.getLog(ControllerServlet.class);
protected Model model = new Model();
- protected BookmarkActions bookmarkActions = new BookmarkActions();
- protected TokenActions tokenActions = new TokenActions();
protected String error = "";
@Override
@@ -47,13 +45,15 @@
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
- try {
+ try {
HttpSession session = request.getSession(true);
User user = (User) session.getAttribute("user");
+ String token = request.getParameter("token"); // token or not
+ if (token != null && !token.isEmpty()) {
+ user = checkToken(token, session);
+ }
String action = request.getParameter("action");
response.setContentType("text/html");
- request.setAttribute("bookmarkActions", bookmarkActions);
- request.setAttribute("tokenActions", tokenActions);
if (action != null) {
if (action.equals("register")) {
if (log.isDebugEnabled()) {
@@ -62,9 +62,7 @@
this.actionRegister(request, response, session);
} else if (action.equals("registration")) {
if (log.isDebugEnabled()) {
- if (log.isDebugEnabled()) {
- log.debug("Going to Register");
- }
+ log.debug("Going to Register");
}
request.getRequestDispatcher("register.jsp").forward(request, response);
} else if (action.equals("login")) {
@@ -77,61 +75,95 @@
log.debug("Going to actionLogin");
}
this.actionLogout(request, response, session);
- } else if (action.equals("addUrl")) {
+ } else if (action.equals("addUrl") && user != null) {
if (log.isDebugEnabled()) {
log.debug("Going to actionAddUrl");
}
- this.actionAddUrl(request, response, session);
+ this.actionAddUrl(request, response, user);
+ request.getRequestDispatcher("search.jsp").forward(request, response);
+
} else if (action.equals("search") && user != null) {
if (log.isDebugEnabled()) {
log.debug("Going to actionSearch");
}
this.actionSearch(request, response, user);
- } else if (action.equals("clickOnTag") && user != null) {
- if (log.isDebugEnabled()) {
- log.debug("Going to actionClickOnTag");
- }
- this.actionClickOnTag(request, response, user);
+ request.getRequestDispatcher("search.jsp").forward(request, response);
+
} else if (action.equals("generateToken") && user != null) {
if (log.isDebugEnabled()) {
log.debug("Going to actionGenerateToken");
}
- try {
- this.actionGenerateToken(request, response, user);
- } catch (NoSuchAlgorithmException ex) {
- log.error("No Such Algorithm", ex);
- request.getRequestDispatcher("error.jsp").forward(request, response);
- }
+ this.actionGenerateToken(request, response, user, session);
+ request.getRequestDispatcher("search.jsp").forward(request, response);
} else if (action.equals("deleteTag") && user != null) {
if (log.isDebugEnabled()) {
log.debug("Going to actionDeleteTag");
}
this.actionDeleteTag(request, response, user);
+ request.getRequestDispatcher("search.jsp").forward(request, response);
} else if (action.equals("removeBookmark") && user != null) {
if (log.isDebugEnabled()) {
log.debug("Going to actionRemoveBookmark");
}
this.actionRemoveBookmark(request, response, user);
+ request.getRequestDispatcher("search.jsp").forward(request, response);
} else if (action.equals("editBookmark") && user != null) {
if (log.isDebugEnabled()) {
log.debug("Going to actionEditBookmark");
}
this.actionEditBookmark(request, response, user);
+ request.getRequestDispatcher("search.jsp").forward(request, response);
} else if (action.equals("orderAsc") && user != null) {
if (log.isDebugEnabled()) {
log.debug("Going to actionOrderAsc");
}
this.actionOrderAsc(request, response, user);
+ request.getRequestDispatcher("search.jsp").forward(request, response);
+ } else if (action.equals("orderAscOS") && user != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Going to actionOrderAsc");
+ }
+ this.actionOrderAsc(request, response, user);
+ request.getRequestDispatcher("openSearchResult.jsp").forward(request, response);
} else if (action.equals("orderDesc") && user != null) {
if (log.isDebugEnabled()) {
log.debug("Going to actionOrderDesc");
}
this.actionOrderDesc(request, response, user);
+ request.getRequestDispatcher("search.jsp").forward(request, response);
+ } else if (action.equals("orderDescOS") && user != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Going to actionOrderDesc");
+ }
+ this.actionOrderDesc(request, response, user);
+ request.getRequestDispatcher("openSearchResult.jsp").forward(request, response);
} else if (action.equals("addClick") && user != null) {
if (log.isDebugEnabled()) {
log.debug("Going to actionAddClic");
}
this.actionAddClick(request, response);
+ } else if (action.equals("temporaryXml")) {
+ if (log.isDebugEnabled()) {
+ log.debug("Going to temporaryXml.jsp");
+ }
+ request.getRequestDispatcher("temporaryXml.jsp").forward(request, response);
+ } else if (action.equals("permanentXml")) {
+ if (log.isDebugEnabled()) {
+ log.debug("Going to permanentXml.jsp");
+ }
+ request.getRequestDispatcher("permanentXml.jsp").forward(request, response);
+ } else if (action.equals("openSearchSuggestion") && user != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Going to actionOpenSearchSuggestion");
+ }
+ this.actionOpenSearchSuggestion(request, response, user);
+ request.getRequestDispatcher("suggestions.jsp").forward(request, response);
+ } else if (action.equals("openSearchResult") && user != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Going to actionOpenSearchResult");
+ }
+ this.actionOpenSearchResult(request, response, user, token);
+ request.getRequestDispatcher("openSearchResult.jsp").forward(request, response);
} else {
if (log.isDebugEnabled()) {
log.debug("Going to home");
@@ -146,10 +178,40 @@
}
request.setAttribute("errorMessage", error);
} catch (Exception eee) {
- request.getRequestDispatcher("error.jsp").forward(request, response);
+ //request.getRequestDispatcher("error.jsp").forward(request, response);
+ throw new ServletException("DO GET ERROR", eee);
}
}
+ protected void actionOpenSearchResult(HttpServletRequest request, HttpServletResponse response, User user, String token)
+ 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();
+ createBookmarkActions(request, bookList);
+ request.setAttribute("token", token);
+ }
+
+ protected void actionOpenSearchSuggestion(HttpServletRequest request, HttpServletResponse response, User user)
+ throws IOException, ServletException {
+ if (user != null) {
+ String search = request.getParameter("search");
+ log.debug("search={" + search + "}");
+ if (search != null) {
+ OpenSearchActions openSearchActions = new OpenSearchActions();
+ WikittyProxy proxy = model.getProxy();
+ Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria();
+ List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll();
+ openSearchActions.setBookmarkList(bookList);
+ search = search.trim();
+ String[] words = search.split("\\s+");
+ openSearchActions.findSuggestions(words);
+ request.setAttribute("openSearchAction", openSearchActions);
+ }
+ }
+ }
+
protected void actionLogout(HttpServletRequest request, HttpServletResponse response, HttpSession session)
throws IOException, ServletException {
session.invalidate();
@@ -189,18 +251,14 @@
eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria().
addSortAscending(Bookmark.FQ_FIELD_DATE);
bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll();
- } else if(type.equals("click")) {
- Criteria criteria = Search.query().
+ } else if (type.equals("click")) {
+ Criteria criteria = Search.query().
eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria().
addSortAscending(Bookmark.FQ_FIELD_CLICK);
bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll();
}
- if (bookList != null) {
- bookmarkActions.setBookmarks(bookList);
- bookmarkActions.createTagsCloud();
- }
+ createBookmarkActions(request, bookList);
}
- request.getRequestDispatcher("search.jsp").forward(request, response);
}
protected void actionOrderDesc(HttpServletRequest request, HttpServletResponse response, User user)
@@ -219,18 +277,14 @@
eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria().
addSortDescending(Bookmark.FQ_FIELD_DATE);
bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll();
- } else if(type.equals("click")) {
- Criteria criteria = Search.query().
+ } else if (type.equals("click")) {
+ Criteria criteria = Search.query().
eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria().
addSortDescending(Bookmark.FQ_FIELD_CLICK);
bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll();
}
- if (bookList != null) {
- bookmarkActions.setBookmarks(bookList);
- bookmarkActions.createTagsCloud();
- }
+ createBookmarkActions(request, bookList);
}
- request.getRequestDispatcher("search.jsp").forward(request, response);
}
protected void actionEditBookmark(HttpServletRequest request, HttpServletResponse response, User user)
@@ -242,18 +296,14 @@
WikittyProxy proxy = model.getProxy();
Bookmark bookmark = proxy.restore(Bookmark.class, bookmarkId);
if (bookmark != null) {
- bookmarkActions.updateBookmark(bookmark, nameAndTags);
+ BookmarkActions.updateBookmark(bookmark, nameAndTags);
proxy.store(bookmark);
Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria();
List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user
- if (bookList != null) {
- bookmarkActions.setBookmarks(bookList);
- bookmarkActions.createTagsCloud();
- }
+ createBookmarkActions(request, bookList);
}
}
}
- request.getRequestDispatcher("search.jsp").forward(request, response);
}
protected void actionRemoveBookmark(HttpServletRequest request, HttpServletResponse response, User user)
@@ -265,19 +315,17 @@
Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria();
List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user
if (bookList != null) {
- bookmarkActions.setBookmarks(bookList);
- bookmarkActions.createTagsCloud();
+ createBookmarkActions(request, bookList);
}
}
- request.getRequestDispatcher("search.jsp").forward(request, response);
}
protected void actionDeleteTag(HttpServletRequest request, HttpServletResponse response, User user)
throws IOException, ServletException {
String bookmarkId = request.getParameter("bookmarkId");
- String tag = request.getParameter("tag");
+ String tag = request.getParameter("deleteTag");
if (tag != null && bookmarkId != null) {
- if (!tag.isEmpty() && !bookmarkId.isEmpty()) {
+ if (!bookmarkId.isEmpty()) {
WikittyProxy proxy = model.getProxy();
Bookmark bookmark = proxy.restore(Bookmark.class, bookmarkId);
if (bookmark != null) {
@@ -285,14 +333,10 @@
proxy.store(bookmark);
Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria();
List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user
- if (bookList != null) {
- bookmarkActions.setBookmarks(bookList);
- bookmarkActions.createTagsCloud();
- }
+ createBookmarkActions(request, bookList);
}
}
}
- request.getRequestDispatcher("search.jsp").forward(request, response);
}
@@ -300,7 +344,7 @@
* @param response servlet response
* @throws ServletException if a servlet error occurs
*/
- protected void actionGenerateToken(HttpServletRequest request, HttpServletResponse response, User user)
+ protected void actionGenerateToken(HttpServletRequest request, HttpServletResponse response, User user, HttpSession session)
throws IOException, ServletException, NoSuchAlgorithmException {
WikittyProxy proxy = model.getProxy();
@@ -309,45 +353,38 @@
if (currentToken != null) {
proxy.delete(currentToken.getWikittyId());
}
- String token = tokenActions.generateToken(); // Generate an encoding MD5 token
- criteria = Search.query().eq(Token.FQ_FIELD_TOKEN, token).criteria();
- if (proxy.findByCriteria(Token.class, criteria) == null) { // Check if the token already exists
- TokenImpl newToken = new TokenImpl();
- newToken.setToken(token);
- newToken.setEmail(user.getEmail());
- proxy.store((Token) newToken); // If the token doesn't exist, it is stored
- tokenActions.setPermanentToken(token);
- } else {
- tokenActions.setPermanentToken("");
+ TokenActions tokenActions = (TokenActions) session.getAttribute("tokenActions");
+ if (tokenActions != null) {
+ String token = tokenActions.generateToken(); // Generate an encoding MD5 token
+ criteria = Search.query().eq(Token.FQ_FIELD_TOKEN, token).criteria();
+ if (proxy.findByCriteria(Token.class, criteria) == null) { // Check if the token already exists
+ TokenImpl newToken = new TokenImpl();
+ newToken.setToken(token);
+ newToken.setEmail(user.getEmail());
+ proxy.store((Token) newToken); // If the token doesn't exist, it is stored
+ tokenActions.setPermanentToken(token);
+ } else {
+ tokenActions.setPermanentToken("");
+ }
}
- request.getRequestDispatcher("search.jsp").forward(request, response);
+ session.setAttribute("tokenActions", tokenActions);
+ actionSearch(request, response, user);
}
/* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet error occurs
*/
- protected void actionAddUrl(HttpServletRequest request, HttpServletResponse response, HttpSession session)
+ protected void actionAddUrl(HttpServletRequest request, HttpServletResponse response, User user)
throws IOException, ServletException {
- String token = request.getParameter("token"); // token or not
- if (token != null && !token.isEmpty()) {
- User user = checkToken(token, session);
- addUrl(request, user);
- }
- else {
- User user = (User) session.getAttribute("user");
- if (user != null) {
- addUrl(request, user);
- actionSearch(request, response, user);
- }
- }
-
+ addUrl(request, user);
+ actionSearch(request, response, user);
}
protected void addUrl(HttpServletRequest request, User user) {
String url = request.getParameter("url"); // url of the website
String nameAndTags = request.getParameter("nameAndTags"); // name and tags
- Bookmark bookmark = bookmarkActions.createBookmark(url, nameAndTags, user);
+ Bookmark bookmark = BookmarkActions.createBookmark(url, nameAndTags, user);
if (bookmark != null) {
WikittyProxy proxy = model.getProxy();
proxy.store(bookmark); // store the bookmark if all is Ok
@@ -357,7 +394,6 @@
}
}
-
protected User checkToken(String token, HttpSession session) {
if (checkTemporaryToken(token, session) == true) {
User user = (User) session.getAttribute("user");
@@ -367,7 +403,6 @@
return user;
}
-
/* @param token String which contains the MD5 encoding token
* @return null the token doesn't exist
* @return User the token owner
@@ -387,63 +422,43 @@
}
protected boolean checkTemporaryToken(String token, HttpSession session) {
- String temporaryToken = (String) session.getAttribute("temporaryToken");
- if (temporaryToken != null) {
- if (temporaryToken.equals(token)) {
- return true;
+ TokenActions tokenActions = (TokenActions) session.getAttribute("tokenActions");
+ if (tokenActions != null) {
+ String temporaryToken = tokenActions.getTemporaryToken();
+ if (temporaryToken != null) {
+ if (temporaryToken.equals(token)) {
+ return true;
+ }
}
}
return false;
-
}
/* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet error occurs
*/
- protected void actionClickOnTag(HttpServletRequest request, HttpServletResponse response, User user)
+ protected void actionSearch(HttpServletRequest request, HttpServletResponse response, User user)
throws IOException, ServletException {
WikittyProxy proxy = model.getProxy();
- String tag = request.getParameter("tag");
- bookmarkActions.getTagsCloud().clear();
Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria();
List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user
- if (bookList != null) {
- bookmarkActions.setBookmarks(bookList);
- }
- if (tag != null) {
- if (!tag.isEmpty()) {
- tag = tag.trim();
- bookmarkActions.addTag(tag); // if a new tag is selected, adding in tag list
- }
- }
- bookmarkActions.createTagsCloud(); // create the tags cloud with the new informations
- request.getRequestDispatcher("search.jsp").forward(request, response);
+ createBookmarkActions(request, bookList);
}
- /* @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet error occurs
- */
- protected void actionSearch(HttpServletRequest request, HttpServletResponse response, User user)
- throws IOException, ServletException {
- WikittyProxy proxy = model.getProxy();
- String words = request.getParameter("words"); // retrieve informations taping in the search field
- bookmarkActions.reset();
- Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria();
- List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user
+ protected void 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) {
bookmarkActions.setBookmarks(bookList);
}
- if (words != null) {
- if (!words.isEmpty()) {
- words = words.trim();
- String[] tags = words.split("\\s+");
- bookmarkActions.addTags(tags); // add the new tags
- }
+ bookmarkActions.addTags(words); // add the new tags
+ String tag = request.getParameter("addTag");
+ if (tag != null && !tag.isEmpty()) {
+ bookmarkActions.addTag(tag);
}
bookmarkActions.createTagsCloud(); // create the tags cloud with the new informations
- request.getRequestDispatcher("search.jsp").forward(request, response);
+ request.setAttribute("bookmarkActions", bookmarkActions);
}
/* @param request servlet request
@@ -466,20 +481,9 @@
request.getRequestDispatcher("error.jsp").forward(request, response);
} else {
session.setAttribute("user", login);
- Criteria criteria = Search.query().eq(User.FQ_FIELD_EMAIL, login.getEmail()).criteria();
- Token token = proxy.findByCriteria(Token.class, criteria);
- if (token == null) {
- token = new TokenImpl();
- String newToken = tokenActions.generateToken();
- token.setToken(newToken);
- token.setEmail(login.getEmail());
- proxy.store(token);
- }
- tokenActions.setPermanentToken(token.getToken());
- String temporaryToken = tokenActions.generateToken();
- tokenActions.setTemporaryToken(temporaryToken);
- session.setAttribute("temporaryToken", temporaryToken);
- this.actionSearch(request, response, login);
+ initializeToken(session, login);
+ actionSearch(request, response, login);
+ request.getRequestDispatcher("search.jsp").forward(request, response);
}
}
}
@@ -495,28 +499,37 @@
User login = this.checkLogin(email, password); // check if the user exists
if (login != null) {
- WikittyProxy proxy = model.getProxy();
session.setAttribute("user", login);
- Criteria criteria = Search.query().eq(User.FQ_FIELD_EMAIL, login.getEmail()).criteria();
- Token token = proxy.findByCriteria(Token.class, criteria);
- if (token == null) {
- token = new TokenImpl();
- String newToken = tokenActions.generateToken();
- token.setToken(newToken);
- token.setEmail(login.getEmail());
- proxy.store(token);
- }
- tokenActions.setPermanentToken(token.getToken());
- String temporaryToken = tokenActions.generateToken();
- tokenActions.setTemporaryToken(temporaryToken);
- session.setAttribute("temporaryToken", temporaryToken);
- this.actionSearch(request, response, login);
+ initializeToken(session, login);
+ actionSearch(request, response, login);
+ request.getRequestDispatcher("search.jsp").forward(request, response);
+
} else {
error = "Unknow email or incorrect password";
request.getRequestDispatcher("home.jsp").forward(request, response);
}
}
+ protected void initializeToken(HttpSession session, User login)
+ throws NoSuchAlgorithmException {
+ WikittyProxy proxy = model.getProxy();
+ Criteria criteria = Search.query().eq(User.FQ_FIELD_EMAIL, login.getEmail()).criteria();
+ Token token = proxy.findByCriteria(Token.class, criteria);
+ TokenActions tokenActions = new TokenActions();
+ if (token == null) {
+ token = new TokenImpl();
+ String newToken = tokenActions.generateToken();
+ token.setToken(newToken);
+ token.setEmail(login.getEmail());
+ proxy.store(token);
+ }
+ tokenActions.setPermanentToken(token.getToken());
+ String temporaryToken = tokenActions.generateToken();
+ tokenActions.setTemporaryToken(temporaryToken);
+ session.setAttribute("tokenActions", tokenActions);
+ }
+
+
/* @param email String which contains the user name (email)
* @param password String which contains the user password
* @return null the user doesn't exist
@@ -555,5 +568,4 @@
error = "Email and password must be correctly filled";
return true;
}
-
}
Modified: trunk/src/main/java/org/chorem/bow/Model.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/Model.java 2010-05-14 15:09:05 UTC (rev 25)
+++ trunk/src/main/java/org/chorem/bow/Model.java 2010-05-18 15:21:30 UTC (rev 26)
@@ -5,15 +5,15 @@
package org.chorem.bow;
import java.util.Properties;
-import org.sharengo.wikitty.WikittyExtensionStorage;
-import org.sharengo.wikitty.WikittyProxy;
-import org.sharengo.wikitty.WikittyService;
-import org.sharengo.wikitty.WikittyStorage;
-import org.sharengo.wikitty.jdbc.WikittyExtensionStorageJDBC;
-import org.sharengo.wikitty.jdbc.WikittyStorageJDBC;
-import org.sharengo.wikitty.multistorage.MultiStorageConfiguration;
-import org.sharengo.wikitty.multistorage.MultiStorageConfiguration.BasicConfiguration;
-import org.sharengo.wikitty.multistorage.WikittyServiceMultiStorage;
+import org.nuiton.wikitty.WikittyExtensionStorage;
+import org.nuiton.wikitty.WikittyProxy;
+import org.nuiton.wikitty.WikittyService;
+import org.nuiton.wikitty.WikittyStorage;
+import org.nuiton.wikitty.jdbc.WikittyExtensionStorageJDBC;
+import org.nuiton.wikitty.jdbc.WikittyStorageJDBC;
+import org.nuiton.wikitty.multistorage.MultiStorageConfiguration;
+import org.nuiton.wikitty.multistorage.MultiStorageConfiguration.BasicConfiguration;
+import org.nuiton.wikitty.multistorage.WikittyServiceMultiStorage;
/**
*
Added: trunk/src/main/java/org/chorem/bow/OpenSearchActions.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/OpenSearchActions.java (rev 0)
+++ trunk/src/main/java/org/chorem/bow/OpenSearchActions.java 2010-05-18 15:21:30 UTC (rev 26)
@@ -0,0 +1,149 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.chorem.bow;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.commons.lang.StringUtils;
+
+/**
+ *
+ * @author bbrossaud
+ */
+public class OpenSearchActions {
+
+ protected List<Bookmark> bookmarkList = new ArrayList<Bookmark>();
+ protected List<Suggestion> suggestions = new ArrayList<Suggestion>();
+ protected String[] search = null;
+
+ public void findSuggestions(String[] words) {
+ search = words;
+ if (!bookmarkList.isEmpty()) {
+ int i;
+ for (i = 0; i < (words.length - 1); ++i) {
+ List<Bookmark> newList = new ArrayList<Bookmark>(bookmarkList);
+ for (Bookmark bookmark : newList) {
+ if (!bookmarkHasTag(bookmark, words[i])) {
+ bookmarkList.remove(bookmark);
+ }
+ }
+ }
+ fieldSuggestionList(words[i]);
+ }
+ }
+
+ protected void fieldSuggestionList(String word) {
+ if (bookmarkList != null) {
+ 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) {
+ if (map.containsKey(tag)) {
+ Integer count = map.get(tag);
+ ++count;
+ map.put(tag, count);
+ } else {
+ map.put(tag, 1);
+ }
+ }
+ }
+ }
+ Set<String> keys = map.keySet();
+ for (String key : keys) {
+ Suggestion newSuggestion = new Suggestion();
+ newSuggestion.setName(key);
+ newSuggestion.setNb(map.get(key));
+ suggestions.add(newSuggestion);
+ }
+
+ Collections.sort(suggestions, new SuggestionsComparator());
+ }
+ }
+
+ protected boolean bookmarkHasTag(Bookmark bookmark, String tag) {
+ Set<String> tagList = bookmark.getTags();
+ if (tagList.contains(tag)) {
+ return true;
+ }
+ return false;
+ }
+
+ public void setBookmarkList(List<Bookmark> bookmarks) {
+ if (bookmarks != null) {
+ List<Bookmark> newList = new ArrayList(bookmarks);
+ bookmarkList = newList;
+ }
+ }
+
+ public String getJsonResult() {
+ String str = "[";
+
+ str += "\"" + StringUtils.join(search, ' ') + "\",";
+ str += getJsonSuggestions();
+ str += ",";
+ str += getJsonDescription();
+ str += "]";
+ return str;
+ }
+
+ public String getJsonSuggestions() {
+ String str = "[";
+ String srch = "";
+ Iterator<Suggestion> it = suggestions.iterator();
+ if (search.length > 1) {
+ srch = StringUtils.join(search, ' ', 0, (search.length - 1));
+ srch += " ";
+ }
+ while (it.hasNext()) {
+ Suggestion su = it.next();
+ str += "\"" + srch + su.getName() + "\"";
+ if (it.hasNext()) {
+ str += ",";
+ }
+ }
+ str += "]";
+ return str;
+ }
+
+ public String getJsonDescription() {
+ String str = "[";
+ Iterator<Suggestion> it = suggestions.iterator();
+ while (it.hasNext()) {
+ Suggestion su = it.next();
+ str += "\"" + su.getNb() + " results\"";
+ if (it.hasNext()) {
+ str += ",";
+ }
+ }
+ str += "]";
+ return str;
+ }
+
+ public void setSearch(String[] tab) {
+ search = tab;
+ }
+
+ public void setSuggestionList(List<Suggestion> list) {
+ suggestions = list;
+ }
+
+ public List<Bookmark> getBookmarkList() {
+ return bookmarkList;
+ }
+
+ public String[] getSearch() {
+ return search;
+ }
+
+ public List<Suggestion> getSuggestionList() {
+ return suggestions;
+ }
+}
Added: trunk/src/main/java/org/chorem/bow/OpenSearchXmlServlet.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/OpenSearchXmlServlet.java (rev 0)
+++ trunk/src/main/java/org/chorem/bow/OpenSearchXmlServlet.java 2010-05-18 15:21:30 UTC (rev 26)
@@ -0,0 +1,36 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.chorem.bow;
+
+import java.io.IOException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ *
+ * @author bbrossaud
+ */
+public class OpenSearchXmlServlet extends HttpServlet {
+
+ @Override
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException {
+ this.doPost(request, response);
+ }
+
+ /* @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet error occurs
+ */
+ @Override
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException {
+ request.getRequestDispatcher("xml.jsp").forward(request, response);
+ }
+
+}
Added: trunk/src/main/java/org/chorem/bow/Suggestion.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/Suggestion.java (rev 0)
+++ trunk/src/main/java/org/chorem/bow/Suggestion.java 2010-05-18 15:21:30 UTC (rev 26)
@@ -0,0 +1,31 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.chorem.bow;
+
+/**
+ *
+ * @author bbrossaud
+ */
+public class Suggestion {
+ int nb = 0;
+ String name = "";
+
+ public void setNb(int value) {
+ nb = value;
+ }
+
+ public void setName(String str) {
+ name = str;
+ }
+
+ public int getNb() {
+ return nb;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
Added: trunk/src/main/java/org/chorem/bow/SuggestionsComparator.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/SuggestionsComparator.java (rev 0)
+++ trunk/src/main/java/org/chorem/bow/SuggestionsComparator.java 2010-05-18 15:21:30 UTC (rev 26)
@@ -0,0 +1,24 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.chorem.bow;
+
+import java.util.Comparator;
+
+/**
+ *
+ * @author bbrossaud
+ */
+public class SuggestionsComparator implements Comparator<Suggestion> {
+
+ @Override
+ public int compare(Suggestion o1, Suggestion o2) {
+ if (o1.getNb() < o2.getNb())
+ return 1;
+ if (o1.getNb() > o2.getNb())
+ return -1;
+ return 0;
+ }
+}
Modified: trunk/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/src/main/webapp/WEB-INF/web.xml 2010-05-14 15:09:05 UTC (rev 25)
+++ trunk/src/main/webapp/WEB-INF/web.xml 2010-05-18 15:21:30 UTC (rev 26)
@@ -1,19 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http:/java.sun.com/dtd/web-app_2_3.dtd">
-<!-- SERVLET -->
+ <!-- SERVLET -->
<servlet>
<servlet-class>org.chorem.bow.ControllerServlet</servlet-class>
<servlet-name>Controller</servlet-name>
</servlet>
+ <servlet>
+ <servlet-class>org.chorem.bow.OpenSearchXmlServlet</servlet-class>
+ <servlet-name>XML</servlet-name>
+ </servlet>
-<!-- SERVLET MAPPING -->
+ <!-- SERVLET MAPPING -->
<servlet-mapping>
<servlet-name>Controller</servlet-name>
<url-pattern>/bow</url-pattern>
</servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>XML</servlet-name>
+ <url-pattern>/xml</url-pattern>
+ </servlet-mapping>
+
</web-app>
\ No newline at end of file
Modified: trunk/src/main/webapp/generateToken.jsp
===================================================================
--- trunk/src/main/webapp/generateToken.jsp 2010-05-14 15:09:05 UTC (rev 25)
+++ trunk/src/main/webapp/generateToken.jsp 2010-05-18 15:21:30 UTC (rev 26)
@@ -1,3 +1,4 @@
+
<%@ page import="org.chorem.bow.TokenActions" %>
<%TokenActions tokenActions = (TokenActions) request.getAttribute("tokenActions");
Modified: trunk/src/main/webapp/home.jsp
===================================================================
--- trunk/src/main/webapp/home.jsp 2010-05-14 15:09:05 UTC (rev 25)
+++ trunk/src/main/webapp/home.jsp 2010-05-18 15:21:30 UTC (rev 26)
@@ -1,16 +1,22 @@
-<%String error = (String) request.getAttribute("errorMessage");%>
+<%
+ String error = (String) request.getAttribute("errorMessage");
+ String url = request.getRequestURL().toString();
+ int index = url.indexOf("home.jsp");
+ url = url.substring(0, index);
+%>
+
<html>
- <body>
- <h1>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>
- <%}%>
- <br/><a href="bow?action=registration">register</a>
- </body>
+ <body>
+ <h1>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>
+ <%}%>
+ <br/><a href="bow?action=registration">register</a>
+ </body>
</html>
\ No newline at end of file
Added: trunk/src/main/webapp/openSearchResult.jsp
===================================================================
--- trunk/src/main/webapp/openSearchResult.jsp (rev 0)
+++ trunk/src/main/webapp/openSearchResult.jsp 2010-05-18 15:21:30 UTC (rev 26)
@@ -0,0 +1,104 @@
+
+<%@ 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" %>
+
+<%
+ BookmarkActions bookmarkActions = (BookmarkActions) request.getAttribute("bookmarkActions");
+ String searchLine = "";
+ if (bookmarkActions != null) {
+ searchLine = bookmarkActions.getSearchLine();
+ }
+ String url = request.getRequestURL().toString();
+ int index = url.indexOf("openSearchResult.jsp");
+ url = url.substring(0, index);
+%>
+
+<html>
+ <body>
+ <h1>Result</h1>
+
+ <% if (bookmarkActions != null) {
+ List<Bookmark> bookmarkList = bookmarkActions.getBookmarks();
+ if (!bookmarkList.isEmpty()) {
+ %>
+ <br/><br/>Results:<br/>
+ <table border="1">
+ <tr>
+ <th>
+ Date
+ <a style="text-decoration:none" href="bow?action=orderAscOS&type=date&searchLine=<%=searchLine%>" >
+ <IMG style="border:none" SRC="img/asc.png" ALT="order ASC" TITLE="Asc" />
+ </a>
+ <a style="text-decoration:none" href="bow?action=orderDescOS&type=date&searchLine=<%=searchLine%>">
+ <IMG style="border:none" SRC="img/desc.png" ALT="order DESC" TITLE="Desc" />
+ </a>
+ </th>
+ <th>
+ Name
+ <a style="text-decoration:none" href="bow?action=orderAscOS&type=name&searchLine=<%=searchLine%>">
+ <IMG style="border:none" SRC="img/asc.png" ALT="order ASC" TITLE="Asc" />
+ </a>
+ <a style="text-decoration:none" href="bow?action=orderDescOS&type=name&searchLine=<%=searchLine%>">
+ <IMG style="border:none" SRC="img/desc.png" ALT="order DESC" TITLE="Desc" />
+ </a>
+ </th>
+ <th>Tags</th>
+ <th>
+ Click
+ <a style="text-decoration:none" href="bow?action=orderAscOS&type=click&searchLine=<%=searchLine%>">
+ <IMG style="border:none" SRC="img/asc.png" ALT="order ASC" TITLE="Asc" />
+ </a>
+ <a style="text-decoration:none" href="bow?action=orderDescOS&type=click&searchLine=<%=searchLine%>">
+ <IMG style="border:none" SRC="img/desc.png" ALT="order DESC" TITLE="Desc" />
+ </a>
+ </th>
+ </tr>
+ <%
+ SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
+ for (Bookmark bookmark : bookmarkList) {
+ %>
+ <tr>
+ <td>
+ <%=sdf.format(bookmark.getDate())%>
+ </td>
+ <td>
+ <a href="bow?action=addClick&bookmarkId=<%=bookmark.getWikittyId()%>" target="_blank"><%=bookmark.getDescription()%></a>
+ </td>
+ <td>
+ <%
+ Set<String> tagList = bookmark.getTags();
+ if (tagList != null && !tagList.isEmpty()) {
+ for (String tag : tagList) {
+ %>
+ <%=tag%>
+ <%
+ }
+ %>
+ </td>
+ <%
+ }
+ %>
+ <td>
+ <%=bookmark.getClick()%>
+ </td>
+ <%
+ }
+ %>
+ </table>
+ <%
+ } else {
+ %>
+ <br/><br/>No Bookmarks found<br/><br/>
+ <% }
+ }
+ %>
+ </body>
+</html>
\ No newline at end of file
Added: trunk/src/main/webapp/permanentXml.jsp
===================================================================
--- trunk/src/main/webapp/permanentXml.jsp (rev 0)
+++ trunk/src/main/webapp/permanentXml.jsp 2010-05-18 15:21:30 UTC (rev 26)
@@ -0,0 +1,23 @@
+<%@ page import="org.chorem.bow.TokenActions" %>
+
+<%
+ TokenActions tokenActions = (TokenActions) session.getAttribute("tokenActions");
+ String token = "";
+ if (tokenActions != null) {
+ token = tokenActions.getPermanentToken();
+ }
+ String url = request.getRequestURL().toString();
+ int index = url.indexOf("permanentXml.jsp");
+ url = url.substring(0, index);
+%>
+
+<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
+ xmlns:moz="http://www.mozilla.org/2006/browser/search/">
+ <ShortName>bowTemporarySearchEngine</ShortName>
+ <Description>bookmarkSearch</Description>
+ <InputEncoding>inputEncoding</InputEncoding>
+ <Image width="16" height="16">data:image/x-icon;base64,imageData</Image>
+ <Url type="text/html" method="GET" template="<%=url%>bow?action=openSearchResult&token=<%=token%>&searchLine={searchTerms}" />
+ <Url type="application/x-suggestions+json" method="GET" template="<%=url%>bow?action=openSearchSuggestion&token=<%=token%>&search={searchTerms}" />
+ <moz:SearchForm><%=url%>bow</moz:SearchForm>
+</OpenSearchDescription>
\ No newline at end of file
Modified: trunk/src/main/webapp/search.jsp
===================================================================
--- trunk/src/main/webapp/search.jsp 2010-05-14 15:09:05 UTC (rev 25)
+++ trunk/src/main/webapp/search.jsp 2010-05-18 15:21:30 UTC (rev 26)
@@ -10,22 +10,30 @@
<%@ page import="java.util.List" %>
<%@ page import="org.chorem.bow.TokenActions" %>
-
<%
- TokenActions tokenActions = (TokenActions) request.getAttribute("tokenActions");
+ 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("search.jsp");
+ url = url.substring(0, index);
%>
<html>
+ <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>
<a href="bow?action=logout">Logout</a><br/>
- <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='http://localhost:8080/bow/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);">Temporary token</a>
+ <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>
<br/>
- <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='http://localhost:8080/bow/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);">Permanent token</a>
+ <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>
<br/>
- <a href="bow?action=generateToken">Generate Permanent Token</a><br/><br/>
+ <a href="bow?action=generateToken&searchLine=<%=searchLine%>">Regenerate Permanent Token</a><br/><br/>
<h1>Search</h1>
@@ -38,7 +46,7 @@
<br/><br/><a href="bow?action=generateToken">Generate Token</a><br/><br/>
<form method="POST" action="bow?action=search">
- <input type="text" name="words" size="20" value="<%=bookmarkActions.getSearchLine()%>" /><br />
+ <input type="text" name="searchLine" size="20" value="<%=searchLine%>" /><br />
<input type="submit" value="Find" />
</form>
@@ -50,11 +58,10 @@
int font = bookmarkActions.getFont(value);
%>
- <FONT SIZE="<%=font%>" ><a href="bow?action=clickOnTag&tag=<%=tag%>"><%=tag%></a></FONT>
+ <FONT SIZE="<%=font%>" ><a href="bow?action=search&addTag=<%=tag%>&searchLine=<%=searchLine%>"><%=tag%></a></FONT>
<%
}
- List<String> tagsSearch = bookmarkActions.getTagsSearch();
List<Bookmark> bookmarkList = bookmarkActions.getBookmarks();
if (!bookmarkList.isEmpty()) {
%>
@@ -64,19 +71,19 @@
<th>Remove</th>
<th>
Date
- <a style="text-decoration:none" href="bow?action=orderAsc&type=date" >
+ <a style="text-decoration:none" href="bow?action=orderAsc&type=date&searchLine=<%=searchLine%>" >
<IMG style="border:none" SRC="img/asc.png" ALT="order ASC" TITLE="Asc" />
</a>
- <a style="text-decoration:none" href="bow?action=orderDesc&type=date">
+ <a style="text-decoration:none" href="bow?action=orderDesc&type=date&searchLine=<%=searchLine%>">
<IMG style="border:none" SRC="img/desc.png" ALT="order DESC" TITLE="Desc" />
</a>
</th>
<th>
Name
- <a style="text-decoration:none" href="bow?action=orderAsc&type=name">
+ <a style="text-decoration:none" href="bow?action=orderAsc&type=name&searchLine=<%=searchLine%>">
<IMG style="border:none" SRC="img/asc.png" ALT="order ASC" TITLE="Asc" />
</a>
- <a style="text-decoration:none" href="bow?action=orderDesc&type=name">
+ <a style="text-decoration:none" href="bow?action=orderDesc&type=name&searchLine=<%=searchLine%>">
<IMG style="border:none" SRC="img/desc.png" ALT="order DESC" TITLE="Desc" />
</a>
</th>
@@ -84,10 +91,10 @@
<th>Edit</th>
<th>
Click
- <a style="text-decoration:none" href="bow?action=orderAsc&type=click">
+ <a style="text-decoration:none" href="bow?action=orderAsc&type=click&searchLine=<%=searchLine%>">
<IMG style="border:none" SRC="img/asc.png" ALT="order ASC" TITLE="Asc" />
</a>
- <a style="text-decoration:none" href="bow?action=orderDesc&type=click">
+ <a style="text-decoration:none" href="bow?action=orderDesc&type=click&searchLine=<%=searchLine%>">
<IMG style="border:none" SRC="img/desc.png" ALT="order DESC" TITLE="Desc" />
</a>
</th>
@@ -98,7 +105,7 @@
%>
<tr>
<td>
- <a style="border:none;" href="bow?action=removeBookmark&bookmarkId=<%=bookmark.getWikittyId()%>">
+ <a style="border:none;" href="bow?action=removeBookmark&bookmarkId=<%=bookmark.getWikittyId()%>&searchLine=<%=searchLine%>">
<IMG style="border:none;" SRC="img/remove.png" ALT="Remove bookmark" TITLE="Remove" />
</a>
</td>
@@ -115,22 +122,20 @@
for (String tag : tagList) {
%>
<%=tag%>
- <a style="text-decoration:none" href="bow?action=deleteTag&bookmarkId=<%=bookmark.getWikittyId()%>&tag=<%=tag%>">
+ <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>
<%
- }
+ }
+ }
%>
</td>
<td>
- <form style="display: inline" method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>">
+ <form style="display: inline" method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>&searchLine=<%=searchLine%>">
<input type="text" name="nameAndTags" size="50" value="<%=bookmark.getDescription()%>|tag1 tag2 tag3" />
<input type="image" src="img/edit.png" title="Edit"/>
</form>
</td>
- <%
- }
- %>
<td>
<%=bookmark.getClick()%>
</td>
Added: trunk/src/main/webapp/suggestions.jsp
===================================================================
--- trunk/src/main/webapp/suggestions.jsp (rev 0)
+++ trunk/src/main/webapp/suggestions.jsp 2010-05-18 15:21:30 UTC (rev 26)
@@ -0,0 +1,21 @@
+
+<%@page import="org.chorem.bow.OpenSearchActions" %>
+<%@page import="org.chorem.bow.Suggestion" %>
+<%@page import="java.util.List" %>
+<%@page import="java.util.Iterator" %>
+
+
+<%
+ OpenSearchActions osa = (OpenSearchActions) request.getAttribute("openSearchAction");
+ if (osa != null) {
+ String[] word = osa.getSearch();
+ if (word != null) {
+ List<Suggestion> suggestions = osa.getSuggestionList();
+ if (suggestions != null) {
+%>
+<%=osa.getJsonResult()%>
+<%
+ }
+ }
+ }
+%>
\ No newline at end of file
Added: trunk/src/main/webapp/temporaryXml.jsp
===================================================================
--- trunk/src/main/webapp/temporaryXml.jsp (rev 0)
+++ trunk/src/main/webapp/temporaryXml.jsp 2010-05-18 15:21:30 UTC (rev 26)
@@ -0,0 +1,23 @@
+<%@ page import="org.chorem.bow.TokenActions" %>
+
+<%
+ TokenActions tokenActions = (TokenActions) session.getAttribute("tokenActions");
+ String token = "";
+ if (tokenActions != null) {
+ token = tokenActions.getTemporaryToken();
+ }
+ String url = request.getRequestURL().toString();
+ int index = url.indexOf("temporaryXml.jsp");
+ url = url.substring(0, index);
+%>
+
+<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
+ xmlns:moz="http://www.mozilla.org/2006/browser/search/">
+ <ShortName>bowTemporarySearchEngine</ShortName>
+ <Description>bookmarkSearch</Description>
+ <InputEncoding>inputEncoding</InputEncoding>
+ <Image width="16" height="16">data:image/x-icon;base64,imageData</Image>
+ <Url type="text/html" method="GET" template="<%=url%>bow?action=openSearchResult&token=<%=token%>&searchLine={searchTerms}" />
+ <Url type="application/x-suggestions+json" method="GET" template="<%=url%>bow?action=openSearchSuggestion&token=<%=token%>&search={searchTerms}" />
+ <moz:SearchForm><%=url%>bow</moz:SearchForm>
+</OpenSearchDescription>
\ No newline at end of file
1
0
r25 - in trunk: . src/main/java/org/chorem/bow src/main/webapp
by bbrossaud@users.chorem.org 14 May '10
by bbrossaud@users.chorem.org 14 May '10
14 May '10
Author: bbrossaud
Date: 2010-05-14 17:09:05 +0200 (Fri, 14 May 2010)
New Revision: 25
Url: http://chorem.org/repositories/revision/bow/25
Log:
Session and temporary token works
Modified:
trunk/TODO.txt
trunk/src/main/java/org/chorem/bow/ControllerServlet.java
trunk/src/main/java/org/chorem/bow/TokenActions.java
trunk/src/main/webapp/search.jsp
Modified: trunk/TODO.txt
===================================================================
--- trunk/TODO.txt 2010-05-14 09:52:06 UTC (rev 24)
+++ trunk/TODO.txt 2010-05-14 15:09:05 UTC (rev 25)
@@ -1,12 +1,12 @@
le 11 mai 2010
A faire pour le vendredi 28 mai:
--> edition, suppression bookmark + tag (14 mai)
--> triage multiple(nbre de clics, date d'ajout, Alpha) (14 mai)
+-> edition, suppression bookmark + tag (14 mai) OK
+-> triage multiple(nbre de clics, date d'ajout, Alpha) (14 mai) OK
-> token temporaire (14 mai)
-> completion ==> openSearch(xml)
==> meta(ex:<link rel="search" type="application/opensearchdescription+xml" href="/w/opensearch_desc.php" title="Wikip�dia (fr)" />)
-> le && pour le nuage de tag (11 mai) OK
--> gestion des sessions
+-> gestion des sessions (14 mai)
-> javascript ==> var script = document.createElement('script');script.src = url;script.type='text/javascript';document.body.appendChild(script); (11 mai) NOK
-> Mise en forme (28 mai)
\ No newline at end of file
Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-14 09:52:06 UTC (rev 24)
+++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-14 15:09:05 UTC (rev 25)
@@ -11,13 +11,11 @@
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.List;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sharengo.wikitty.Criteria;
@@ -33,7 +31,6 @@
private static final Log log = LogFactory.getLog(ControllerServlet.class);
protected Model model = new Model();
protected BookmarkActions bookmarkActions = new BookmarkActions();
- protected User user = null;
protected TokenActions tokenActions = new TokenActions();
protected String error = "";
@@ -50,8 +47,9 @@
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
-// try {
- error = "";
+ try {
+ HttpSession session = request.getSession(true);
+ User user = (User) session.getAttribute("user");
String action = request.getParameter("action");
response.setContentType("text/html");
request.setAttribute("bookmarkActions", bookmarkActions);
@@ -61,7 +59,7 @@
if (log.isDebugEnabled()) {
log.debug("Going to actionRegister");
}
- this.actionRegister(request, response);
+ this.actionRegister(request, response, session);
} else if (action.equals("registration")) {
if (log.isDebugEnabled()) {
if (log.isDebugEnabled()) {
@@ -73,82 +71,90 @@
if (log.isDebugEnabled()) {
log.debug("Going to actionLogin");
}
- this.actionLogin(request, response);
+ this.actionLogin(request, response, session);
+ } else if (action.equals("logout")) {
+ if (log.isDebugEnabled()) {
+ log.debug("Going to actionLogin");
+ }
+ this.actionLogout(request, response, session);
} else if (action.equals("addUrl")) {
if (log.isDebugEnabled()) {
log.debug("Going to actionAddUrl");
}
- this.actionAddUrl(request, response);
+ this.actionAddUrl(request, response, session);
} else if (action.equals("search") && user != null) {
if (log.isDebugEnabled()) {
log.debug("Going to actionSearch");
}
- this.actionSearch(request, response);
+ this.actionSearch(request, response, user);
} else if (action.equals("clickOnTag") && user != null) {
if (log.isDebugEnabled()) {
log.debug("Going to actionClickOnTag");
}
- this.actionClickOnTag(request, response);
+ this.actionClickOnTag(request, response, user);
} else if (action.equals("generateToken") && user != null) {
if (log.isDebugEnabled()) {
log.debug("Going to actionGenerateToken");
}
try {
- this.actionGenerateToken(request, response);
+ this.actionGenerateToken(request, response, user);
} catch (NoSuchAlgorithmException ex) {
log.error("No Such Algorithm", ex);
request.getRequestDispatcher("error.jsp").forward(request, response);
}
- } else if (action.equals("deleteTag")) {
+ } else if (action.equals("deleteTag") && user != null) {
if (log.isDebugEnabled()) {
log.debug("Going to actionDeleteTag");
}
- this.actionDeleteTag(request, response);
- } else if (action.equals("removeBookmark")) {
+ this.actionDeleteTag(request, response, user);
+ } else if (action.equals("removeBookmark") && user != null) {
if (log.isDebugEnabled()) {
log.debug("Going to actionRemoveBookmark");
}
- this.actionRemoveBookmark(request, response);
- } else if (action.equals("editBookmark")) {
+ this.actionRemoveBookmark(request, response, user);
+ } else if (action.equals("editBookmark") && user != null) {
if (log.isDebugEnabled()) {
log.debug("Going to actionEditBookmark");
}
- this.actionEditBookmark(request, response);
- } else if (action.equals("orderAsc")) {
+ this.actionEditBookmark(request, response, user);
+ } else if (action.equals("orderAsc") && user != null) {
if (log.isDebugEnabled()) {
log.debug("Going to actionOrderAsc");
}
- this.actionOrderAsc(request, response);
- } else if (action.equals("orderDesc")) {
+ this.actionOrderAsc(request, response, user);
+ } else if (action.equals("orderDesc") && user != null) {
if (log.isDebugEnabled()) {
log.debug("Going to actionOrderDesc");
}
- this.actionOrderDesc(request, response);
- } else if (action.equals("addClick")) {
+ this.actionOrderDesc(request, response, user);
+ } else if (action.equals("addClick") && user != null) {
if (log.isDebugEnabled()) {
log.debug("Going to actionAddClic");
}
this.actionAddClick(request, response);
} else {
- user = null;
if (log.isDebugEnabled()) {
log.debug("Going to home");
}
request.getRequestDispatcher("home.jsp").forward(request, response);
}
} else {
- user = null;
if (log.isDebugEnabled()) {
log.debug("Going to home");
}
request.getRequestDispatcher("home.jsp").forward(request, response);
}
request.setAttribute("errorMessage", error);
-// } catch (Exception eee) {
-// request.getRequestDispatcher("error.jsp").forward(request, response);
-// }
+ } catch (Exception eee) {
+ request.getRequestDispatcher("error.jsp").forward(request, response);
+ }
}
+ protected void actionLogout(HttpServletRequest request, HttpServletResponse response, HttpSession session)
+ throws IOException, ServletException {
+ session.invalidate();
+ request.getRequestDispatcher("home.jsp").forward(request, response);
+ }
protected void actionAddClick(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
@@ -167,7 +173,7 @@
}
}
- protected void actionOrderAsc(HttpServletRequest request, HttpServletResponse response)
+ protected void actionOrderAsc(HttpServletRequest request, HttpServletResponse response, User user)
throws IOException, ServletException {
String type = request.getParameter("type");
if (type != null && !type.isEmpty()) {
@@ -197,7 +203,7 @@
request.getRequestDispatcher("search.jsp").forward(request, response);
}
- protected void actionOrderDesc(HttpServletRequest request, HttpServletResponse response)
+ protected void actionOrderDesc(HttpServletRequest request, HttpServletResponse response, User user)
throws IOException, ServletException {
String type = request.getParameter("type");
if (type != null && !type.isEmpty()) {
@@ -227,7 +233,7 @@
request.getRequestDispatcher("search.jsp").forward(request, response);
}
- protected void actionEditBookmark(HttpServletRequest request, HttpServletResponse response)
+ protected void actionEditBookmark(HttpServletRequest request, HttpServletResponse response, User user)
throws IOException, ServletException {
String nameAndTags = request.getParameter("nameAndTags");
String bookmarkId = request.getParameter("bookmarkId");
@@ -250,7 +256,7 @@
request.getRequestDispatcher("search.jsp").forward(request, response);
}
- protected void actionRemoveBookmark(HttpServletRequest request, HttpServletResponse response)
+ protected void actionRemoveBookmark(HttpServletRequest request, HttpServletResponse response, User user)
throws IOException, ServletException {
String bookmarkId = request.getParameter("bookmarkId");
if (bookmarkId != null && !bookmarkId.isEmpty()) {
@@ -266,7 +272,7 @@
request.getRequestDispatcher("search.jsp").forward(request, response);
}
- protected void actionDeleteTag(HttpServletRequest request, HttpServletResponse response)
+ protected void actionDeleteTag(HttpServletRequest request, HttpServletResponse response, User user)
throws IOException, ServletException {
String bookmarkId = request.getParameter("bookmarkId");
String tag = request.getParameter("tag");
@@ -294,65 +300,80 @@
* @param response servlet response
* @throws ServletException if a servlet error occurs
*/
- protected void actionGenerateToken(HttpServletRequest request, HttpServletResponse response)
+ protected void actionGenerateToken(HttpServletRequest request, HttpServletResponse response, User user)
throws IOException, ServletException, NoSuchAlgorithmException {
WikittyProxy proxy = model.getProxy();
+ Criteria criteria = Search.query().eq(User.FQ_FIELD_EMAIL, user.getEmail()).criteria();
+ Token currentToken = proxy.findByCriteria(Token.class, criteria);
+ if (currentToken != null) {
+ proxy.delete(currentToken.getWikittyId());
+ }
String token = tokenActions.generateToken(); // Generate an encoding MD5 token
- Criteria criteria = Search.query().eq(Token.FQ_FIELD_TOKEN, token).criteria();
+ criteria = Search.query().eq(Token.FQ_FIELD_TOKEN, token).criteria();
if (proxy.findByCriteria(Token.class, criteria) == null) { // Check if the token already exists
TokenImpl newToken = new TokenImpl();
newToken.setToken(token);
newToken.setEmail(user.getEmail());
proxy.store((Token) newToken); // If the token doesn't exist, it is stored
- tokenActions.setToken(token);
+ tokenActions.setPermanentToken(token);
} else {
- tokenActions.setToken("");
+ tokenActions.setPermanentToken("");
}
- request.getRequestDispatcher("generateToken.jsp").forward(request, response);
+ request.getRequestDispatcher("search.jsp").forward(request, response);
}
/* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet error occurs
*/
- protected void actionAddUrl(HttpServletRequest request, HttpServletResponse response)
+ protected void actionAddUrl(HttpServletRequest request, HttpServletResponse response, HttpSession session)
throws IOException, ServletException {
+ String token = request.getParameter("token"); // token or not
+ if (token != null && !token.isEmpty()) {
+ User user = checkToken(token, session);
+ addUrl(request, user);
+ }
+ else {
+ User user = (User) session.getAttribute("user");
+ if (user != null) {
+ addUrl(request, user);
+ actionSearch(request, response, user);
+ }
+ }
+ }
+
+ protected void addUrl(HttpServletRequest request, User user) {
String url = request.getParameter("url"); // url of the website
String nameAndTags = request.getParameter("nameAndTags"); // name and tags
- String token = request.getParameter("token"); // token or not
- if (url != null && nameAndTags != null) {
- if (user == null) { // If the user is null, it's maybe a bookmark addition by token
- user = checkToken(url, nameAndTags, token);
+ Bookmark bookmark = bookmarkActions.createBookmark(url, nameAndTags, user);
+ if (bookmark != null) {
+ WikittyProxy proxy = model.getProxy();
+ proxy.store(bookmark); // store the bookmark if all is Ok
+ if (log.isDebugEnabled()) {
+ log.debug("Adding URL");
}
- if (user != null) {
- if (!url.isEmpty() && !nameAndTags.isEmpty()) {
- Bookmark bookmark = bookmarkActions.createBookmark(url, nameAndTags, user);
- if (bookmark != null) {
- WikittyProxy proxy = model.getProxy();
- proxy.store(bookmark); // store the bookmark if all is Ok
- if (log.isDebugEnabled()) {
- log.debug("Adding URL");
- }
- if (token == null) {
- this.actionSearch(request, response);
- }
- }
- }
- }
}
}
- /* @param url String which contains the bookmark url
- * @param nameAndTags String which contains the name and the tags of the
- bookmark separated by '|' ==> name|tag1 tag2...
- * @param token String which contains the MD5 encoding token
+
+ protected User checkToken(String token, HttpSession session) {
+ if (checkTemporaryToken(token, session) == true) {
+ User user = (User) session.getAttribute("user");
+ return user;
+ }
+ User user = checkPermanentToken(token);
+ return user;
+ }
+
+
+ /* @param token String which contains the MD5 encoding token
* @return null the token doesn't exist
* @return User the token owner
*/
- protected User checkToken(String url, String nameAndTags, String token) {
- if (url != null && nameAndTags != null && token != null) {
+ protected User checkPermanentToken(String token) {
+ if (token != null) {
WikittyProxy proxy = model.getProxy();
Criteria criteria = Search.query().eq(Token.FQ_FIELD_TOKEN, token).criteria();
Token DbToken = proxy.findByCriteria(Token.class, criteria);
@@ -365,11 +386,22 @@
return null;
}
+ protected boolean checkTemporaryToken(String token, HttpSession session) {
+ String temporaryToken = (String) session.getAttribute("temporaryToken");
+ if (temporaryToken != null) {
+ if (temporaryToken.equals(token)) {
+ return true;
+ }
+ }
+ return false;
+
+ }
+
/* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet error occurs
*/
- protected void actionClickOnTag(HttpServletRequest request, HttpServletResponse response)
+ protected void actionClickOnTag(HttpServletRequest request, HttpServletResponse response, User user)
throws IOException, ServletException {
WikittyProxy proxy = model.getProxy();
String tag = request.getParameter("tag");
@@ -393,7 +425,7 @@
* @param response servlet response
* @throws ServletException if a servlet error occurs
*/
- protected void actionSearch(HttpServletRequest request, HttpServletResponse response)
+ protected void actionSearch(HttpServletRequest request, HttpServletResponse response, User user)
throws IOException, ServletException {
WikittyProxy proxy = model.getProxy();
String words = request.getParameter("words"); // retrieve informations taping in the search field
@@ -418,8 +450,8 @@
* @param response servlet response
* @throws ServletException if a servlet error occurs
*/
- protected void actionRegister(HttpServletRequest request, HttpServletResponse response)
- throws IOException, ServletException {
+ protected void actionRegister(HttpServletRequest request, HttpServletResponse response, HttpSession session)
+ throws IOException, ServletException, NoSuchAlgorithmException {
String email = request.getParameter("email");
String password = request.getParameter("password");
if (this.checkRegister(email, password)) { // check if all is well
@@ -429,12 +461,25 @@
UserImpl newUser = new UserImpl();
newUser.setPassword(request.getParameter("password"));
newUser.setEmail(request.getParameter("email"));
- this.user = proxy.store((User) newUser); // store the new user
- if (user == null) {
+ User login = proxy.store((User) newUser); // store the new user
+ if (login == null) {
request.getRequestDispatcher("error.jsp").forward(request, response);
} else {
- this.actionSearch(request, response);
- error="Email already exist";
+ session.setAttribute("user", login);
+ Criteria criteria = Search.query().eq(User.FQ_FIELD_EMAIL, login.getEmail()).criteria();
+ Token token = proxy.findByCriteria(Token.class, criteria);
+ if (token == null) {
+ token = new TokenImpl();
+ String newToken = tokenActions.generateToken();
+ token.setToken(newToken);
+ token.setEmail(login.getEmail());
+ proxy.store(token);
+ }
+ tokenActions.setPermanentToken(token.getToken());
+ String temporaryToken = tokenActions.generateToken();
+ tokenActions.setTemporaryToken(temporaryToken);
+ session.setAttribute("temporaryToken", temporaryToken);
+ this.actionSearch(request, response, login);
}
}
}
@@ -443,15 +488,29 @@
* @param response servlet response
* @throws ServletException if a servlet error occurs
*/
- protected void actionLogin(HttpServletRequest request, HttpServletResponse response)
- throws IOException, ServletException {
+ protected void actionLogin(HttpServletRequest request, HttpServletResponse response, HttpSession session)
+ throws IOException, ServletException, NoSuchAlgorithmException {
String email = request.getParameter("email");
String password = request.getParameter("password");
User login = this.checkLogin(email, password); // check if the user exists
if (login != null) {
- this.user = login;
- this.actionSearch(request, response);
+ WikittyProxy proxy = model.getProxy();
+ session.setAttribute("user", login);
+ Criteria criteria = Search.query().eq(User.FQ_FIELD_EMAIL, login.getEmail()).criteria();
+ Token token = proxy.findByCriteria(Token.class, criteria);
+ if (token == null) {
+ token = new TokenImpl();
+ String newToken = tokenActions.generateToken();
+ token.setToken(newToken);
+ token.setEmail(login.getEmail());
+ proxy.store(token);
+ }
+ tokenActions.setPermanentToken(token.getToken());
+ String temporaryToken = tokenActions.generateToken();
+ tokenActions.setTemporaryToken(temporaryToken);
+ session.setAttribute("temporaryToken", temporaryToken);
+ this.actionSearch(request, response, login);
} else {
error = "Unknow email or incorrect password";
request.getRequestDispatcher("home.jsp").forward(request, response);
@@ -497,11 +556,4 @@
return true;
}
- public void setUser(User user) {
- this.user = user;
- }
-
- public User getUser() {
- return user;
- }
}
Modified: trunk/src/main/java/org/chorem/bow/TokenActions.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/TokenActions.java 2010-05-14 09:52:06 UTC (rev 24)
+++ trunk/src/main/java/org/chorem/bow/TokenActions.java 2010-05-14 15:09:05 UTC (rev 25)
@@ -14,12 +14,17 @@
public class TokenActions {
- String token = "";
+ String temporaryToken = "";
+ String permanentToken = "";
- public String getToken() {
- return token;
+ public String getPermanentToken() {
+ return permanentToken;
}
+ public String getTemporaryToken() {
+ return temporaryToken;
+ }
+
public String generateToken()
throws NoSuchAlgorithmException {
Double rand = Math.random() * 1000000;
@@ -29,7 +34,11 @@
return tokenGenerated; // return the generate token
}
- public void setToken(String token) {
- this.token = token;
+ public void setPermanentToken(String token) {
+ permanentToken = token;
}
+
+ public void setTemporaryToken(String token) {
+ temporaryToken = token;
+ }
}
Modified: trunk/src/main/webapp/search.jsp
===================================================================
--- trunk/src/main/webapp/search.jsp 2010-05-14 09:52:06 UTC (rev 24)
+++ trunk/src/main/webapp/search.jsp 2010-05-14 15:09:05 UTC (rev 25)
@@ -8,12 +8,25 @@
<%@ page import="java.util.Set" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
+<%@ page import="org.chorem.bow.TokenActions" %>
-<%BookmarkActions bookmarkActions = (BookmarkActions) request.getAttribute("bookmarkActions");%>
+<%
+ TokenActions tokenActions = (TokenActions) request.getAttribute("tokenActions");
+ String temporaryToken = tokenActions.getTemporaryToken();
+ String permanentToken = tokenActions.getPermanentToken();
+ BookmarkActions bookmarkActions = (BookmarkActions) request.getAttribute("bookmarkActions");
+%>
+
<html>
<body>
<a href="bow?action=logout">Logout</a><br/>
+ <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='http://localhost:8080/bow/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);">Temporary token</a>
+ <br/>
+ <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='http://localhost:8080/bow/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);">Permanent token</a>
+ <br/>
+ <a href="bow?action=generateToken">Generate Permanent Token</a><br/><br/>
+
<h1>Search</h1>
<form method="POST" action="bow?action=addUrl">
@@ -106,7 +119,7 @@
<IMG style="border:none" SRC="img/delete.png" ALT="Delete tag" TITLE="Delete" />
</a>
<%
- }
+ }
%>
</td>
<td>
1
0
r24 - in trunk/src/main: java/org/chorem/bow resources webapp xmi
by bbrossaud@users.chorem.org 14 May '10
by bbrossaud@users.chorem.org 14 May '10
14 May '10
Author: bbrossaud
Date: 2010-05-14 11:52:06 +0200 (Fri, 14 May 2010)
New Revision: 24
Url: http://chorem.org/repositories/revision/bow/24
Log:
the count of the click works
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/Model.java
trunk/src/main/resources/wikitty-jdbc-config.properties
trunk/src/main/webapp/search.jsp
trunk/src/main/xmi/bow.zargo
Modified: trunk/src/main/java/org/chorem/bow/BookmarkActions.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-12 15:38:56 UTC (rev 23)
+++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-14 09:52:06 UTC (rev 24)
@@ -63,6 +63,7 @@
String link = url.trim();
bookmark.setLink(link);
}
+ bookmark.setClick(0);
bookmark.setEmail(user.getEmail()); // set the email (user name)
bookmark.setDate(new Date()); // set the date
return bookmark;
Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-12 15:38:56 UTC (rev 23)
+++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-14 09:52:06 UTC (rev 24)
@@ -124,6 +124,11 @@
log.debug("Going to actionOrderDesc");
}
this.actionOrderDesc(request, response);
+ } else if (action.equals("addClick")) {
+ if (log.isDebugEnabled()) {
+ log.debug("Going to actionAddClic");
+ }
+ this.actionAddClick(request, response);
} else {
user = null;
if (log.isDebugEnabled()) {
@@ -145,6 +150,23 @@
}
+ protected void actionAddClick(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException {
+ String bookmarkId = request.getParameter("bookmarkId");
+ if (bookmarkId != null && !bookmarkId.isEmpty()) {
+ WikittyProxy proxy = model.getProxy();
+ Bookmark bookmark = proxy.restore(Bookmark.class, bookmarkId);
+ if (bookmark != null) {
+ int click = bookmark.getClick();
+ ++click;
+ bookmark.setClick(click);
+ proxy.store(bookmark);
+ String url = bookmark.getLink();
+ response.sendRedirect(url);
+ }
+ }
+ }
+
protected void actionOrderAsc(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String type = request.getParameter("type");
@@ -161,6 +183,11 @@
eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria().
addSortAscending(Bookmark.FQ_FIELD_DATE);
bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll();
+ } else if(type.equals("click")) {
+ Criteria criteria = Search.query().
+ eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria().
+ addSortAscending(Bookmark.FQ_FIELD_CLICK);
+ bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll();
}
if (bookList != null) {
bookmarkActions.setBookmarks(bookList);
@@ -186,6 +213,11 @@
eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria().
addSortDescending(Bookmark.FQ_FIELD_DATE);
bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll();
+ } else if(type.equals("click")) {
+ Criteria criteria = Search.query().
+ eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria().
+ addSortDescending(Bookmark.FQ_FIELD_CLICK);
+ bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll();
}
if (bookList != null) {
bookmarkActions.setBookmarks(bookList);
Modified: trunk/src/main/java/org/chorem/bow/Model.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/Model.java 2010-05-12 15:38:56 UTC (rev 23)
+++ trunk/src/main/java/org/chorem/bow/Model.java 2010-05-14 09:52:06 UTC (rev 24)
@@ -24,7 +24,7 @@
protected WikittyProxy proxy = null;
Model() {
- System.setProperty("solr.data.dir", System.getProperty("user.home") + "/databases/bow/solr");
+ System.setProperty("solr.data.dir", System.getProperty("user.home") + "/.bow/solr");
this.init();
}
Modified: trunk/src/main/resources/wikitty-jdbc-config.properties
===================================================================
--- trunk/src/main/resources/wikitty-jdbc-config.properties 2010-05-12 15:38:56 UTC (rev 23)
+++ trunk/src/main/resources/wikitty-jdbc-config.properties 2010-05-14 09:52:06 UTC (rev 24)
@@ -1,5 +1,5 @@
#Connection parameters
jdbc.con.driver=org.h2.Driver
-jdbc.con.host=jdbc:h2:file:/home/bbrossaud/projets/bow/solr
+jdbc.con.host=jdbc:h2:file:~/.bow/localdb/localdb
jdbc.con.userName=sa
jdbc.con.password=
Modified: trunk/src/main/webapp/search.jsp
===================================================================
--- trunk/src/main/webapp/search.jsp 2010-05-12 15:38:56 UTC (rev 23)
+++ trunk/src/main/webapp/search.jsp 2010-05-14 09:52:06 UTC (rev 24)
@@ -1,6 +1,8 @@
+
+<%@ page import="org.chorem.bow.Bookmark" %>
<%@ page import="org.chorem.bow.BookmarkActions" %>
-<%@ page import="org.chorem.bow.Bookmark" %>
<%@ 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" %>
@@ -49,7 +51,7 @@
<th>Remove</th>
<th>
Date
- <a style="text-decoration:none" href="bow?action=orderAsc&type=date">
+ <a style="text-decoration:none" href="bow?action=orderAsc&type=date" >
<IMG style="border:none" SRC="img/asc.png" ALT="order ASC" TITLE="Asc" />
</a>
<a style="text-decoration:none" href="bow?action=orderDesc&type=date">
@@ -67,8 +69,18 @@
</th>
<th>Tags</th>
<th>Edit</th>
+ <th>
+ Click
+ <a style="text-decoration:none" href="bow?action=orderAsc&type=click">
+ <IMG style="border:none" SRC="img/asc.png" ALT="order ASC" TITLE="Asc" />
+ </a>
+ <a style="text-decoration:none" href="bow?action=orderDesc&type=click">
+ <IMG style="border:none" SRC="img/desc.png" ALT="order DESC" TITLE="Desc" />
+ </a>
+ </th>
</tr>
<%
+ SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
for (Bookmark bookmark : bookmarkList) {
%>
<tr>
@@ -78,10 +90,10 @@
</a>
</td>
<td>
- <%=bookmark.getDate()%>
+ <%=sdf.format(bookmark.getDate())%>
</td>
<td>
- <a href="<%=bookmark.getLink()%>"><%=bookmark.getDescription()%></a>
+ <a href="bow?action=addClick&bookmarkId=<%=bookmark.getWikittyId()%>" target="_blank"><%=bookmark.getDescription()%></a>
</td>
<td>
<%
@@ -100,12 +112,15 @@
<td>
<form style="display: inline" method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>">
<input type="text" name="nameAndTags" size="50" value="<%=bookmark.getDescription()%>|tag1 tag2 tag3" />
- <input type="image" src="img/edit.png" value="edit" />
+ <input type="image" src="img/edit.png" title="Edit"/>
</form>
</td>
<%
}
%>
+ <td>
+ <%=bookmark.getClick()%>
+ </td>
<%
}
%>
Modified: trunk/src/main/xmi/bow.zargo
===================================================================
(Binary files differ)
1
0
r23 - in trunk/src/main: java/org/chorem/bow webapp webapp/img
by bbrossaud@users.chorem.org 12 May '10
by bbrossaud@users.chorem.org 12 May '10
12 May '10
Author: bbrossaud
Date: 2010-05-12 17:38:56 +0200 (Wed, 12 May 2010)
New Revision: 23
Url: http://chorem.org/repositories/revision/bow/23
Log:
order by name and date work
Added:
trunk/src/main/webapp/img/asc.png
trunk/src/main/webapp/img/desc.png
Modified:
trunk/src/main/java/org/chorem/bow/ControllerServlet.java
trunk/src/main/webapp/search.jsp
Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-12 13:41:08 UTC (rev 22)
+++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-12 15:38:56 UTC (rev 23)
@@ -114,6 +114,16 @@
log.debug("Going to actionEditBookmark");
}
this.actionEditBookmark(request, response);
+ } else if (action.equals("orderAsc")) {
+ if (log.isDebugEnabled()) {
+ log.debug("Going to actionOrderAsc");
+ }
+ this.actionOrderAsc(request, response);
+ } else if (action.equals("orderDesc")) {
+ if (log.isDebugEnabled()) {
+ log.debug("Going to actionOrderDesc");
+ }
+ this.actionOrderDesc(request, response);
} else {
user = null;
if (log.isDebugEnabled()) {
@@ -134,6 +144,57 @@
// }
}
+
+ protected void actionOrderAsc(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException {
+ String type = request.getParameter("type");
+ if (type != null && !type.isEmpty()) {
+ WikittyProxy proxy = model.getProxy();
+ List<Bookmark> bookList = null;
+ if (type.equals("name")) {
+ Criteria criteria = Search.query().
+ eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria().
+ addSortAscending(Bookmark.FQ_FIELD_DESCRIPTION);
+ bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll();
+ } else if (type.equals("date")) {
+ Criteria criteria = Search.query().
+ eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria().
+ addSortAscending(Bookmark.FQ_FIELD_DATE);
+ bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll();
+ }
+ if (bookList != null) {
+ bookmarkActions.setBookmarks(bookList);
+ bookmarkActions.createTagsCloud();
+ }
+ }
+ request.getRequestDispatcher("search.jsp").forward(request, response);
+ }
+
+ protected void actionOrderDesc(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException {
+ String type = request.getParameter("type");
+ if (type != null && !type.isEmpty()) {
+ WikittyProxy proxy = model.getProxy();
+ List<Bookmark> bookList = null;
+ if (type.equals("name")) {
+ Criteria criteria = Search.query().
+ eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria().
+ addSortDescending(Bookmark.FQ_FIELD_DESCRIPTION);
+ bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll();
+ } else if (type.equals("date")) {
+ Criteria criteria = Search.query().
+ eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria().
+ addSortDescending(Bookmark.FQ_FIELD_DATE);
+ bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll();
+ }
+ if (bookList != null) {
+ bookmarkActions.setBookmarks(bookList);
+ bookmarkActions.createTagsCloud();
+ }
+ }
+ request.getRequestDispatcher("search.jsp").forward(request, response);
+ }
+
protected void actionEditBookmark(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String nameAndTags = request.getParameter("nameAndTags");
@@ -145,7 +206,6 @@
if (bookmark != null) {
bookmarkActions.updateBookmark(bookmark, nameAndTags);
proxy.store(bookmark);
- bookmarkActions.getBookmarks().clear();
Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria();
List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user
if (bookList != null) {
@@ -164,7 +224,6 @@
if (bookmarkId != null && !bookmarkId.isEmpty()) {
WikittyProxy proxy = model.getProxy();
proxy.delete(bookmarkId);
- bookmarkActions.getBookmarks().clear();
Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria();
List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user
if (bookList != null) {
@@ -186,7 +245,6 @@
if (bookmark != null) {
bookmark.removeTags(tag);
proxy.store(bookmark);
- bookmarkActions.getBookmarks().clear();
Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria();
List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user
if (bookList != null) {
@@ -283,7 +341,6 @@
throws IOException, ServletException {
WikittyProxy proxy = model.getProxy();
String tag = request.getParameter("tag");
- bookmarkActions.getBookmarks().clear();
bookmarkActions.getTagsCloud().clear();
Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria();
List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user
Added: trunk/src/main/webapp/img/asc.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/main/webapp/img/asc.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/src/main/webapp/img/desc.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/main/webapp/img/desc.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: trunk/src/main/webapp/search.jsp
===================================================================
--- trunk/src/main/webapp/search.jsp 2010-05-12 13:41:08 UTC (rev 22)
+++ trunk/src/main/webapp/search.jsp 2010-05-12 15:38:56 UTC (rev 23)
@@ -41,39 +41,79 @@
}
List<String> tagsSearch = bookmarkActions.getTagsSearch();
List<Bookmark> bookmarkList = bookmarkActions.getBookmarks();
- if (!bookmarkList.isEmpty() && !tagsSearch.isEmpty()) {
+ if (!bookmarkList.isEmpty()) {
%>
<br/><br/>Results:<br/>
+ <table border="1">
+ <tr>
+ <th>Remove</th>
+ <th>
+ Date
+ <a style="text-decoration:none" href="bow?action=orderAsc&type=date">
+ <IMG style="border:none" SRC="img/asc.png" ALT="order ASC" TITLE="Asc" />
+ </a>
+ <a style="text-decoration:none" href="bow?action=orderDesc&type=date">
+ <IMG style="border:none" SRC="img/desc.png" ALT="order DESC" TITLE="Desc" />
+ </a>
+ </th>
+ <th>
+ Name
+ <a style="text-decoration:none" href="bow?action=orderAsc&type=name">
+ <IMG style="border:none" SRC="img/asc.png" ALT="order ASC" TITLE="Asc" />
+ </a>
+ <a style="text-decoration:none" href="bow?action=orderDesc&type=name">
+ <IMG style="border:none" SRC="img/desc.png" ALT="order DESC" TITLE="Desc" />
+ </a>
+ </th>
+ <th>Tags</th>
+ <th>Edit</th>
+ </tr>
+ <%
+ for (Bookmark bookmark : bookmarkList) {
+ %>
+ <tr>
+ <td>
+ <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>
+ <%=bookmark.getDate()%>
+ </td>
+ <td>
+ <a href="<%=bookmark.getLink()%>"><%=bookmark.getDescription()%></a>
+ </td>
+ <td>
+ <%
+ Set<String> tagList = bookmark.getTags();
+ if (tagList != null && !tagList.isEmpty()) {
+ for (String tag : tagList) {
+ %>
+ <%=tag%>
+ <a style="text-decoration:none" href="bow?action=deleteTag&bookmarkId=<%=bookmark.getWikittyId()%>&tag=<%=tag%>">
+ <IMG style="border:none" SRC="img/delete.png" ALT="Delete tag" TITLE="Delete" />
+ </a>
+ <%
+ }
+ %>
+ </td>
+ <td>
+ <form style="display: inline" method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>">
+ <input type="text" name="nameAndTags" size="50" value="<%=bookmark.getDescription()%>|tag1 tag2 tag3" />
+ <input type="image" src="img/edit.png" value="edit" />
+ </form>
+ </td>
+ <%
+ }
+ %>
+ <%
+ }
+ %>
+ </table>
<%
- for (Bookmark bookmark : bookmarkList) {
+ } else {
%>
- <br/>
- <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>
- <a href="<%=bookmark.getLink()%>"><%=bookmark.getDescription()%></a>
- <%
- Set<String> tagList = bookmark.getTags();
- if (tagList != null && !tagList.isEmpty()) {
- for (String tag : tagList) {
- %>
- <%=tag%>
- <a style="text-decoration:none" href="bow?action=deleteTag&bookmarkId=<%=bookmark.getWikittyId()%>&tag=<%=tag%>">
- <IMG style="border:none" SRC="img/delete.png" ALT="Delete tag" TITLE="Delete" />
- </a>
- <%
- }
- %>
- <form style="display: inline" method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>">
- <input type="text" name="nameAndTags" size="50" value="<%=bookmark.getDescription()%>|tag1 tag2 tag3" />
- <input type="image" src="img/edit.png" value="edit" />
- </form>
- <%
- }
- }
- } else if (!tagsSearch.isEmpty() && bookmarkList.isEmpty()) {
- %>
- <br/><br/>No Result found<br/><br/>
+ <br/><br/>No Bookmarks<br/><br/>
<% }
}
%>
1
0
r22 - in trunk: . src/main/java/org/chorem/bow src/main/webapp src/main/webapp/img
by bbrossaud@users.chorem.org 12 May '10
by bbrossaud@users.chorem.org 12 May '10
12 May '10
Author: bbrossaud
Date: 2010-05-12 15:41:08 +0200 (Wed, 12 May 2010)
New Revision: 22
Url: http://chorem.org/repositories/revision/bow/22
Log:
the bookmark edition is done
Added:
trunk/src/main/webapp/img/delete.png
trunk/src/main/webapp/img/edit.png
trunk/src/main/webapp/img/remove.png
Removed:
trunk/src/main/webapp/img/delete.gif
trunk/src/main/webapp/img/remove.gif
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-12 10:09:44 UTC (rev 21)
+++ trunk/pom.xml 2010-05-12 13:41:08 UTC (rev 22)
@@ -89,6 +89,7 @@
<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-12 10:09:44 UTC (rev 21)
+++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-12 13:41:08 UTC (rev 22)
@@ -37,33 +37,63 @@
*/
public Bookmark createBookmark(String url, String nameAndTags, User user) {
+ Bookmark bookmark = (Bookmark) new BookmarkImpl();
+
int nameIndex = nameAndTags.indexOf('|'); // get the index name of the website
- if (nameIndex < 0) { // nameAndTags ==> name|tag1 tag2 tag3...
- return null;
+ if (nameIndex > 0) {
+ String name = nameAndTags.substring(0, nameIndex); // get the website name
+ name = name.trim();
+ bookmark.setDescription(name); // set the description (website name)
}
- Bookmark bookmark = (Bookmark) new BookmarkImpl();
- String link = url.trim();
- bookmark.setLink(link);
-
- String name = nameAndTags.substring(0, nameIndex); // get the website name
- name = name.trim();
- bookmark.setDescription(name); // set the description (website name)
-
- String tags = nameAndTags.substring(nameIndex + 1); // get tags, +1 because of '|'
+ String tags = nameAndTags;
+ if (nameIndex >= 0) {
+ tags = nameAndTags.substring(nameIndex + 1); // get tags, +1 because of '|'
+ }
tags = tags.trim();
String[] tagsTab = tags.split("\\s+"); // put the tags in an array
- if (tagsTab.length == 0)
+ if (tagsTab.length == 0) {
return null;
+ }
for (int i = 0; i < tagsTab.length; ++i) {
bookmark.addTags(tagsTab[i]); // Added tag for each rank (one tag by rank)
}
+ if (url != null && !url.isEmpty()) {
+ String link = url.trim();
+ bookmark.setLink(link);
+ }
bookmark.setEmail(user.getEmail()); // set the email (user name)
bookmark.setDate(new Date()); // set the date
return bookmark;
}
+ public void updateBookmark(Bookmark bookmark, String nameAndTags) {
+ int nameIndex = nameAndTags.indexOf('|'); // get the index name of the website
+ if (nameIndex > 0) {
+ String name = nameAndTags.substring(0, nameIndex); // get the website name
+ name = name.trim();
+ bookmark.setDescription(name); // set the description (website name)
+ }
+
+ String tags = nameAndTags;
+ if (nameIndex >= 0) {
+ tags = nameAndTags.substring(nameIndex + 1); // get tags, +1 because of '|'
+ }
+ tags = tags.trim();
+ String[] tagsTab = tags.split("\\s+"); // put the tags in an array
+ if (tagsTab.length != 0) {
+ for (int i = 0; i < tagsTab.length; ++i) {
+ Set<String> tagList = bookmark.getTags();
+ if (tagList != null) {
+ if (!tagList.contains(tagsTab[i])) {
+ bookmark.addTags(tagsTab[i]); // Added tag for each rank (one tag by rank)
+ }
+ }
+ }
+ }
+ }
+
public void createTagsCloud() {
tagCloud.clear();
deleteBookmarkBySearch();
Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-12 10:09:44 UTC (rev 21)
+++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-12 13:41:08 UTC (rev 22)
@@ -109,6 +109,11 @@
log.debug("Going to actionRemoveBookmark");
}
this.actionRemoveBookmark(request, response);
+ } else if (action.equals("editBookmark")) {
+ if (log.isDebugEnabled()) {
+ log.debug("Going to actionEditBookmark");
+ }
+ this.actionEditBookmark(request, response);
} else {
user = null;
if (log.isDebugEnabled()) {
@@ -129,6 +134,30 @@
// }
}
+ protected void actionEditBookmark(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException {
+ String nameAndTags = request.getParameter("nameAndTags");
+ String bookmarkId = request.getParameter("bookmarkId");
+ if (nameAndTags != null && bookmarkId != null) {
+ if (!nameAndTags.isEmpty() && !bookmarkId.isEmpty()) {
+ WikittyProxy proxy = model.getProxy();
+ Bookmark bookmark = proxy.restore(Bookmark.class, bookmarkId);
+ if (bookmark != null) {
+ bookmarkActions.updateBookmark(bookmark, nameAndTags);
+ proxy.store(bookmark);
+ bookmarkActions.getBookmarks().clear();
+ Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria();
+ List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user
+ if (bookList != null) {
+ bookmarkActions.setBookmarks(bookList);
+ bookmarkActions.createTagsCloud();
+ }
+ }
+ }
+ }
+ request.getRequestDispatcher("search.jsp").forward(request, response);
+ }
+
protected void actionRemoveBookmark(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String bookmarkId = request.getParameter("bookmarkId");
@@ -146,7 +175,6 @@
request.getRequestDispatcher("search.jsp").forward(request, response);
}
-
protected void actionDeleteTag(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String bookmarkId = request.getParameter("bookmarkId");
Deleted: trunk/src/main/webapp/img/delete.gif
===================================================================
(Binary files differ)
Added: trunk/src/main/webapp/img/delete.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/main/webapp/img/delete.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/src/main/webapp/img/edit.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/main/webapp/img/edit.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Deleted: trunk/src/main/webapp/img/remove.gif
===================================================================
(Binary files differ)
Added: trunk/src/main/webapp/img/remove.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/main/webapp/img/remove.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: trunk/src/main/webapp/search.jsp
===================================================================
--- trunk/src/main/webapp/search.jsp 2010-05-12 10:09:44 UTC (rev 21)
+++ trunk/src/main/webapp/search.jsp 2010-05-12 13:41:08 UTC (rev 22)
@@ -15,62 +15,67 @@
<h1>Search</h1>
<form method="POST" action="bow?action=addUrl">
- URL <input type="text" name="url" size="20" value="URL"><br />
- Name and Tags <input type="text" name="nameAndTags" size="20" value="name|tag1 tag2..."><br />
- <input type="submit" value="add">
+ URL <input type="text" name="url" size="20" value="URL" /><br />
+ Name and Tags <input type="text" name="nameAndTags" size="20" value="name|tag1 tag2..." /><br />
+ <input type="submit" value="add" />
</form>
<br/><br/><a href="bow?action=generateToken">Generate Token</a><br/><br/>
<form method="POST" action="bow?action=search">
- <input type="text" name="words" size="20" value="<%=bookmarkActions.getSearchLine()%>" ><br />
- <input type="submit" value="Find">
+ <input type="text" name="words" size="20" value="<%=bookmarkActions.getSearchLine()%>" /><br />
+ <input type="submit" value="Find" />
</form>
-<% 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);
-%>
+ <% 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);
+ %>
-<FONT SIZE="<%=font%>" ><a href="bow?action=clickOnTag&tag=<%=tag%>"><%=tag%></a></FONT>
+ <FONT SIZE="<%=font%>" ><a href="bow?action=clickOnTag&tag=<%=tag%>"><%=tag%></a></FONT>
-<%
- }
- List<String> tagsSearch = bookmarkActions.getTagsSearch();
- List<Bookmark> bookmarkList = bookmarkActions.getBookmarks();
- if (!bookmarkList.isEmpty() && !tagsSearch.isEmpty()) {
-%>
- <br/><br/>Results:<br/>
-<%
- for (Bookmark bookmark : bookmarkList) {
-%>
- <br/>
- <a style="border:none;" href="bow?action=removeBookmark&bookmarkId=<%=bookmark.getWikittyId()%>">
- <IMG style="border:none;" SRC="img/remove.gif" ALT="Remove bookmark" TITLE="Remove" />
- </a>
- <a href="<%=bookmark.getLink()%>"><%=bookmark.getDescription()%></a>
-<%
- Set<String> tagList = bookmark.getTags();
- if (tagList != null && !tagList.isEmpty()) {
- for (String tag : tagList) {
-%>
- <%=tag%>
- <a style="border:none;" href="bow?action=deleteTag&bookmarkId=<%=bookmark.getWikittyId()%>&tag=<%=tag%>">
- <IMG style="border:none;" SRC="img/delete.gif" ALT="Delete tag" TITLE="Delete" />
- </a>
-<%
+ <%
+ }
+ List<String> tagsSearch = bookmarkActions.getTagsSearch();
+ List<Bookmark> bookmarkList = bookmarkActions.getBookmarks();
+ if (!bookmarkList.isEmpty() && !tagsSearch.isEmpty()) {
+ %>
+ <br/><br/>Results:<br/>
+ <%
+ for (Bookmark bookmark : bookmarkList) {
+ %>
+ <br/>
+ <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>
+ <a href="<%=bookmark.getLink()%>"><%=bookmark.getDescription()%></a>
+ <%
+ Set<String> tagList = bookmark.getTags();
+ if (tagList != null && !tagList.isEmpty()) {
+ for (String tag : tagList) {
+ %>
+ <%=tag%>
+ <a style="text-decoration:none" href="bow?action=deleteTag&bookmarkId=<%=bookmark.getWikittyId()%>&tag=<%=tag%>">
+ <IMG style="border:none" SRC="img/delete.png" ALT="Delete tag" TITLE="Delete" />
+ </a>
+ <%
+ }
+ %>
+ <form style="display: inline" method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>">
+ <input type="text" name="nameAndTags" size="50" value="<%=bookmark.getDescription()%>|tag1 tag2 tag3" />
+ <input type="image" src="img/edit.png" value="edit" />
+ </form>
+ <%
+ }
+ }
+ } else if (!tagsSearch.isEmpty() && bookmarkList.isEmpty()) {
+ %>
+ <br/><br/>No Result found<br/><br/>
+ <% }
}
- }
- }
- } else if (!tagsSearch.isEmpty() && bookmarkList.isEmpty()) {
-%>
- <br/><br/>No Result found<br/><br/>
-<%
- }
- }
-%>
+ %>
</body>
</html>
\ No newline at end of file
1
0
r21 - in trunk: . src/main/java/org/chorem/bow src/main/webapp src/main/webapp/css src/main/webapp/img
by bbrossaud@users.chorem.org 12 May '10
by bbrossaud@users.chorem.org 12 May '10
12 May '10
Author: bbrossaud
Date: 2010-05-12 12:09:44 +0200 (Wed, 12 May 2010)
New Revision: 21
Url: http://chorem.org/repositories/revision/bow/21
Log:
remove bookmark and delete tag actions work
Added:
trunk/TODO.txt
trunk/src/main/webapp/css/
trunk/src/main/webapp/css/styles.css
trunk/src/main/webapp/img/
trunk/src/main/webapp/img/delete.gif
trunk/src/main/webapp/img/remove.gif
Modified:
trunk/src/main/java/org/chorem/bow/BookmarkActions.java
trunk/src/main/java/org/chorem/bow/ControllerServlet.java
trunk/src/main/webapp/generateToken.jsp
trunk/src/main/webapp/home.jsp
trunk/src/main/webapp/register.jsp
trunk/src/main/webapp/search.jsp
Added: trunk/TODO.txt
===================================================================
--- trunk/TODO.txt (rev 0)
+++ trunk/TODO.txt 2010-05-12 10:09:44 UTC (rev 21)
@@ -0,0 +1,12 @@
+le 11 mai 2010
+A faire pour le vendredi 28 mai:
+
+-> edition, suppression bookmark + tag (14 mai)
+-> triage multiple(nbre de clics, date d'ajout, Alpha) (14 mai)
+-> token temporaire (14 mai)
+-> completion ==> openSearch(xml)
+ ==> meta(ex:<link rel="search" type="application/opensearchdescription+xml" href="/w/opensearch_desc.php" title="Wikip�dia (fr)" />)
+-> le && pour le nuage de tag (11 mai) OK
+-> gestion des sessions
+-> javascript ==> var script = document.createElement('script');script.src = url;script.type='text/javascript';document.body.appendChild(script); (11 mai) NOK
+-> Mise en forme (28 mai)
\ No newline at end of file
Modified: trunk/src/main/java/org/chorem/bow/BookmarkActions.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-11 12:28:22 UTC (rev 20)
+++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-12 10:09:44 UTC (rev 21)
@@ -66,48 +66,51 @@
public void createTagsCloud() {
tagCloud.clear();
- if (tagsSearch.isEmpty()) {
- fillTagsCloud(); // if nothing is taped in the search field, the tags cloud must contains all tags
- } else {
- fillTagsCloudBySearch();
- }
- this.defineTValues(); // define t values for the font
+ deleteBookmarkBySearch();
+ createTagClougByBookmarks();
}
-
- /* @param bookmark user bookmark
- * @return void
- */
- protected void addBookmarkTagsToTagCloud(Bookmark bookmark) {
- Set<String> tags = bookmark.getTags(); // bookmark tags
- for (String tag : tags) {
- if (!tagsSearch.contains(tag)) { // the tags cloud mustn't contained the tags taped in the search field
- if (tagCloud.containsKey(tag)) { // check if it contains the tag
- Integer count = tagCloud.get(tag);
- ++count;
- tagCloud.put(tag, count);
- } else {
- tagCloud.put(tag, 1);
+ public void deleteBookmarkBySearch() {
+ List<Bookmark> bookmarksList = new ArrayList<Bookmark>(bookmarks);
+ for (Bookmark bookmark : bookmarksList) {
+ Iterator it = tagsSearch.iterator();
+ boolean remove = false;
+ while (it.hasNext() && remove == false) {
+ String tag = (String) it.next();
+ Set<String> tagList = bookmark.getTags();
+ if (tagList != null && !tagList.isEmpty()) {
+ if (!tagList.contains(tag)) {
+ bookmarks.remove(bookmark); // Delete bookmark which doesn't contain the tags from the search field
+ remove = true;
+ }
}
}
}
}
- public void fillTagsCloud() {
- for (Bookmark bookmark : bookmarks) {
+ public void createTagClougByBookmarks() {
+ List<Bookmark> bookmarksList = new ArrayList<Bookmark>(bookmarks);
+ for (Bookmark bookmark : bookmarksList) {
addBookmarkTagsToTagCloud(bookmark);
}
}
- public void fillTagsCloudBySearch() {
- tagCloud.clear();
- for (String tag : tagsSearch) {
- List<Bookmark> bookmarksList = new ArrayList<Bookmark>(bookmarks);
- for (Bookmark bookmark : bookmarksList) {
- if (bookmark.getTags().contains(tag) == false) {
- bookmarks.remove(bookmark); // Delete bookmark which doesn't contain the tags from the search field
- } else {
- addBookmarkTagsToTagCloud(bookmark);
+
+ /* @param bookmark user bookmark
+ * @return void
+ */
+ protected void addBookmarkTagsToTagCloud(Bookmark bookmark) {
+ Set<String> tags = bookmark.getTags(); // bookmark tags
+ if (tags != null && !tags.isEmpty()) {
+ for (String tag : tags) {
+ if (!tagsSearch.contains(tag)) { // the tags cloud mustn't contained the tags taped in the search field
+ if (tagCloud.containsKey(tag)) { // check if it contains the tag
+ Integer count = tagCloud.get(tag);
+ ++count;
+ tagCloud.put(tag, count);
+ } else {
+ tagCloud.put(tag, 1);
+ }
}
}
}
Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-11 12:28:22 UTC (rev 20)
+++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-12 10:09:44 UTC (rev 21)
@@ -11,6 +11,9 @@
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.List;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -32,6 +35,7 @@
protected BookmarkActions bookmarkActions = new BookmarkActions();
protected User user = null;
protected TokenActions tokenActions = new TokenActions();
+ protected String error = "";
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
@@ -46,7 +50,8 @@
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
- try {
+// try {
+ error = "";
String action = request.getParameter("action");
response.setContentType("text/html");
request.setAttribute("bookmarkActions", bookmarkActions);
@@ -94,6 +99,16 @@
log.error("No Such Algorithm", ex);
request.getRequestDispatcher("error.jsp").forward(request, response);
}
+ } else if (action.equals("deleteTag")) {
+ if (log.isDebugEnabled()) {
+ log.debug("Going to actionDeleteTag");
+ }
+ this.actionDeleteTag(request, response);
+ } else if (action.equals("removeBookmark")) {
+ if (log.isDebugEnabled()) {
+ log.debug("Going to actionRemoveBookmark");
+ }
+ this.actionRemoveBookmark(request, response);
} else {
user = null;
if (log.isDebugEnabled()) {
@@ -108,11 +123,55 @@
}
request.getRequestDispatcher("home.jsp").forward(request, response);
}
- } catch (Exception eee) {
- request.getRequestDispatcher("error.jsp").forward(request, response);
+ request.setAttribute("errorMessage", error);
+// } catch (Exception eee) {
+// request.getRequestDispatcher("error.jsp").forward(request, response);
+// }
+ }
+
+ protected void actionRemoveBookmark(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException {
+ String bookmarkId = request.getParameter("bookmarkId");
+ if (bookmarkId != null && !bookmarkId.isEmpty()) {
+ WikittyProxy proxy = model.getProxy();
+ proxy.delete(bookmarkId);
+ bookmarkActions.getBookmarks().clear();
+ Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria();
+ List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user
+ if (bookList != null) {
+ bookmarkActions.setBookmarks(bookList);
+ bookmarkActions.createTagsCloud();
+ }
}
+ request.getRequestDispatcher("search.jsp").forward(request, response);
}
+
+ protected void actionDeleteTag(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException {
+ String bookmarkId = request.getParameter("bookmarkId");
+ String tag = request.getParameter("tag");
+ if (tag != null && bookmarkId != null) {
+ if (!tag.isEmpty() && !bookmarkId.isEmpty()) {
+ WikittyProxy proxy = model.getProxy();
+ Bookmark bookmark = proxy.restore(Bookmark.class, bookmarkId);
+ if (bookmark != null) {
+ bookmark.removeTags(tag);
+ proxy.store(bookmark);
+ bookmarkActions.getBookmarks().clear();
+ Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria();
+ List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user
+ if (bookList != null) {
+ bookmarkActions.setBookmarks(bookList);
+ bookmarkActions.createTagsCloud();
+ }
+ }
+ }
+ }
+ request.getRequestDispatcher("search.jsp").forward(request, response);
+ }
+
+
/* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet error occurs
@@ -258,6 +317,7 @@
request.getRequestDispatcher("error.jsp").forward(request, response);
} else {
this.actionSearch(request, response);
+ error="Email already exist";
}
}
}
@@ -276,6 +336,7 @@
this.user = login;
this.actionSearch(request, response);
} else {
+ error = "Unknow email or incorrect password";
request.getRequestDispatcher("home.jsp").forward(request, response);
}
}
@@ -315,6 +376,7 @@
}
}
}
+ error = "Email and password must be correctly filled";
return true;
}
Added: trunk/src/main/webapp/css/styles.css
===================================================================
--- trunk/src/main/webapp/css/styles.css (rev 0)
+++ trunk/src/main/webapp/css/styles.css 2010-05-12 10:09:44 UTC (rev 21)
@@ -0,0 +1,3 @@
+test {
+
+}
\ No newline at end of file
Modified: trunk/src/main/webapp/generateToken.jsp
===================================================================
--- trunk/src/main/webapp/generateToken.jsp 2010-05-11 12:28:22 UTC (rev 20)
+++ trunk/src/main/webapp/generateToken.jsp 2010-05-12 10:09:44 UTC (rev 21)
@@ -9,7 +9,7 @@
<body>
Use it to add new bookmarks without authentication : <br/><br/>
- <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%20image=new%20Image();var%20link='http://localhost:8080/bow/bow?action=addUrl&token=<%=token%>&url='+encodeURIComponent(url)+'&nameAndTags='+encodeURIComponent(nameAndTags);image.src=link;window.location='';">Session</a>
+ <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='http://localhost:8080/bow/bow?action=addUrl&token=<%=token%>&url='+encodeURIComponent(url)+'&nameAndTags='+encodeURIComponent(nameAndTags);var%20script=document.createElement('script');script.src=link;script.type='text/javascript';document.body.appendChild(script);">Session</a>
<%
} else {
%>
Modified: trunk/src/main/webapp/home.jsp
===================================================================
--- trunk/src/main/webapp/home.jsp 2010-05-11 12:28:22 UTC (rev 20)
+++ trunk/src/main/webapp/home.jsp 2010-05-12 10:09:44 UTC (rev 21)
@@ -1,3 +1,5 @@
+<%String error = (String) request.getAttribute("errorMessage");%>
+
<html>
<body>
<h1>Login</h1>
@@ -6,6 +8,9 @@
password <input type=password name="password" size="20"><br />
<input type="submit" value="login">
</form>
- <a href="bow?action=registration">register</a>
+ <%if (error != null) {%>
+ <font color="red"><%=error%></font>
+ <%}%>
+ <br/><a href="bow?action=registration">register</a>
</body>
</html>
\ No newline at end of file
Added: trunk/src/main/webapp/img/delete.gif
===================================================================
(Binary files differ)
Property changes on: trunk/src/main/webapp/img/delete.gif
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/src/main/webapp/img/remove.gif
===================================================================
(Binary files differ)
Property changes on: trunk/src/main/webapp/img/remove.gif
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: trunk/src/main/webapp/register.jsp
===================================================================
--- trunk/src/main/webapp/register.jsp 2010-05-11 12:28:22 UTC (rev 20)
+++ trunk/src/main/webapp/register.jsp 2010-05-12 10:09:44 UTC (rev 21)
@@ -1,3 +1,5 @@
+
+<%String error = (String) request.getAttribute("errorMessage");%>
<html>
<body>
<h1>Register</h1>
@@ -7,6 +9,9 @@
password <input type=password name="password" size="20"><br />
<input type="submit" value="Register">
</form>
- <br/><br/><a href="bow?action=home">Return to the login page<a>
+ <%if (error != null && error.isEmpty() == false) {%>
+ <br/><font color="red"><%=error%></font>
+ <%}%>
+ <br/><a href="bow?action=home">Return to the login page<a>
</body>
</html>
\ No newline at end of file
Modified: trunk/src/main/webapp/search.jsp
===================================================================
--- trunk/src/main/webapp/search.jsp 2010-05-11 12:28:22 UTC (rev 20)
+++ trunk/src/main/webapp/search.jsp 2010-05-12 10:09:44 UTC (rev 21)
@@ -43,12 +43,27 @@
List<Bookmark> bookmarkList = bookmarkActions.getBookmarks();
if (!bookmarkList.isEmpty() && !tagsSearch.isEmpty()) {
%>
- <br/><br/>Results:<br/><br/>
+ <br/><br/>Results:<br/>
<%
for (Bookmark bookmark : bookmarkList) {
%>
- <a href="<%=bookmark.getLink()%>"><%=bookmark.getDescription()%></a><br/>
+ <br/>
+ <a style="border:none;" href="bow?action=removeBookmark&bookmarkId=<%=bookmark.getWikittyId()%>">
+ <IMG style="border:none;" SRC="img/remove.gif" ALT="Remove bookmark" TITLE="Remove" />
+ </a>
+ <a href="<%=bookmark.getLink()%>"><%=bookmark.getDescription()%></a>
<%
+ Set<String> tagList = bookmark.getTags();
+ if (tagList != null && !tagList.isEmpty()) {
+ for (String tag : tagList) {
+%>
+ <%=tag%>
+ <a style="border:none;" href="bow?action=deleteTag&bookmarkId=<%=bookmark.getWikittyId()%>&tag=<%=tag%>">
+ <IMG style="border:none;" SRC="img/delete.gif" ALT="Delete tag" TITLE="Delete" />
+ </a>
+<%
+ }
+ }
}
} else if (!tagsSearch.isEmpty() && bookmarkList.isEmpty()) {
%>
1
0
Author: bbrossaud
Date: 2010-05-11 14:28:22 +0200 (Tue, 11 May 2010)
New Revision: 20
Url: http://chorem.org/repositories/revision/bow/20
Log:
added last comments
Modified:
trunk/src/main/webapp/WEB-INF/web.xml
trunk/src/main/webapp/generateToken.jsp
trunk/src/main/webapp/home.jsp
Modified: trunk/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/src/main/webapp/WEB-INF/web.xml 2010-05-11 10:18:29 UTC (rev 19)
+++ trunk/src/main/webapp/WEB-INF/web.xml 2010-05-11 12:28:22 UTC (rev 20)
@@ -13,7 +13,7 @@
<servlet-mapping>
<servlet-name>Controller</servlet-name>
- <url-pattern>/</url-pattern>
+ <url-pattern>/bow</url-pattern>
</servlet-mapping>
</web-app>
\ No newline at end of file
Modified: trunk/src/main/webapp/generateToken.jsp
===================================================================
--- trunk/src/main/webapp/generateToken.jsp 2010-05-11 10:18:29 UTC (rev 19)
+++ trunk/src/main/webapp/generateToken.jsp 2010-05-11 12:28:22 UTC (rev 20)
@@ -4,11 +4,12 @@
String token = tokenActions.getToken();
if (token != null && token.isEmpty() == false) {
%>
+
<html>
<body>
Use it to add new bookmarks without authentication : <br/><br/>
- <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%20image=new%20Image();var%20link='http://localhost:8080/bow/bow?action=addUrl&token=<%=token%>&url='+encodeURIComponent(url)+'&nameAndTags='+encodeURIComponent(nameAndTags);image.src=link;document.body.appendChild(image);window.location=url;">Session</a>
+ <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%20image=new%20Image();var%20link='http://localhost:8080/bow/bow?action=addUrl&token=<%=token%>&url='+encodeURIComponent(url)+'&nameAndTags='+encodeURIComponent(nameAndTags);image.src=link;window.location='';">Session</a>
<%
} else {
%>
Modified: trunk/src/main/webapp/home.jsp
===================================================================
--- trunk/src/main/webapp/home.jsp 2010-05-11 10:18:29 UTC (rev 19)
+++ trunk/src/main/webapp/home.jsp 2010-05-11 12:28:22 UTC (rev 20)
@@ -1,7 +1,7 @@
<html>
<body>
<h1>Login</h1>
- <form method="POST" action="home?action=login">
+ <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">
1
0
Author: bbrossaud
Date: 2010-05-11 12:18:29 +0200 (Tue, 11 May 2010)
New Revision: 19
Url: http://chorem.org/repositories/revision/bow/19
Log:
added the TokenActions comments
Modified:
trunk/src/main/java/org/chorem/bow/TokenActions.java
Modified: trunk/src/main/java/org/chorem/bow/TokenActions.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/TokenActions.java 2010-05-11 10:11:30 UTC (rev 18)
+++ trunk/src/main/java/org/chorem/bow/TokenActions.java 2010-05-11 10:18:29 UTC (rev 19)
@@ -23,10 +23,10 @@
public String generateToken()
throws NoSuchAlgorithmException {
Double rand = Math.random() * 1000000;
- int res = (int) Math.abs(rand);
+ int res = (int) Math.abs(rand); // generate a token between 0 and 1 000 000
String tokenGenerated = String.valueOf(res);
- tokenGenerated = StringUtil.encodeMD5(tokenGenerated);
- return tokenGenerated;
+ tokenGenerated = StringUtil.encodeMD5(tokenGenerated); // encode the token in MD5
+ return tokenGenerated; // return the generate token
}
public void setToken(String token) {
1
0
Author: bbrossaud
Date: 2010-05-11 12:11:30 +0200 (Tue, 11 May 2010)
New Revision: 18
Url: http://chorem.org/repositories/revision/bow/18
Log:
added the BookmarkActions comments
Modified:
trunk/src/main/java/org/chorem/bow/BookmarkActions.java
Modified: trunk/src/main/java/org/chorem/bow/BookmarkActions.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-11 09:14:13 UTC (rev 17)
+++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-11 10:11:30 UTC (rev 18)
@@ -20,16 +20,25 @@
*/
public class BookmarkActions {
- protected List<Bookmark> bookmarks = new ArrayList<Bookmark>();
- protected Map<String, Integer> tagsCloud = new HashMap<String, Integer>();
- protected List<String> tagsSearch = new ArrayList<String>();
+ protected List<Bookmark> bookmarks = new ArrayList<Bookmark>(); // bookmarks which contain the search tags
+ 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
protected int tmax = -1;
protected int tmin = -1;
+
+ /* @param url String which contains the bookmark url
+ * @param nameAndTags String which contains the name and the tags of the
+ bookmark separated by '|' ==> name|tag1 tag2...
+ * @param user bookmark user
+ * @return null if all fields are not correctly filled
+ * @return Bookmark the website bookmark
+ */
public Bookmark createBookmark(String url, String nameAndTags, User user) {
- int nameIndex = nameAndTags.indexOf('|');
- if (nameIndex < 0) {
+ int nameIndex = nameAndTags.indexOf('|'); // get the index name of the website
+ if (nameIndex < 0) { // nameAndTags ==> name|tag1 tag2 tag3...
return null;
}
Bookmark bookmark = (Bookmark) new BookmarkImpl();
@@ -37,45 +46,48 @@
String link = url.trim();
bookmark.setLink(link);
- String name = nameAndTags.substring(0, nameIndex);
+ String name = nameAndTags.substring(0, nameIndex); // get the website name
name = name.trim();
- bookmark.setDescription(name);
+ bookmark.setDescription(name); // set the description (website name)
- String tags = nameAndTags.substring(nameIndex + 1);
+ String tags = nameAndTags.substring(nameIndex + 1); // get tags, +1 because of '|'
tags = tags.trim();
- String[] tagsTab = tags.split("\\s+");
+ String[] tagsTab = tags.split("\\s+"); // put the tags in an array
+ if (tagsTab.length == 0)
+ return null;
for (int i = 0; i < tagsTab.length; ++i) {
- bookmark.addTags(tagsTab[i]);
+ bookmark.addTags(tagsTab[i]); // Added tag for each rank (one tag by rank)
}
- bookmark.setEmail(user.getEmail());
- bookmark.setDate(new Date());
+ bookmark.setEmail(user.getEmail()); // set the email (user name)
+ bookmark.setDate(new Date()); // set the date
return bookmark;
}
- public List<Bookmark> getBookmarks() {
- return bookmarks;
- }
-
public void createTagsCloud() {
- tagsCloud.clear();
+ tagCloud.clear();
if (tagsSearch.isEmpty()) {
- fillTagsCloud();
+ fillTagsCloud(); // if nothing is taped in the search field, the tags cloud must contains all tags
} else {
fillTagsCloudBySearch();
}
+ this.defineTValues(); // define t values for the font
}
+
+ /* @param bookmark user bookmark
+ * @return void
+ */
protected void addBookmarkTagsToTagCloud(Bookmark bookmark) {
- Set<String> tags = bookmark.getTags();
+ Set<String> tags = bookmark.getTags(); // bookmark tags
for (String tag : tags) {
- if (!tagsSearch.contains(tag)) {
- if (tagsCloud.containsKey(tag)) {
- Integer count = tagsCloud.get(tag);
+ if (!tagsSearch.contains(tag)) { // the tags cloud mustn't contained the tags taped in the search field
+ if (tagCloud.containsKey(tag)) { // check if it contains the tag
+ Integer count = tagCloud.get(tag);
++count;
- tagsCloud.put(tag, count);
+ tagCloud.put(tag, count);
} else {
- tagsCloud.put(tag, 1);
+ tagCloud.put(tag, 1);
}
}
}
@@ -88,34 +100,33 @@
}
public void fillTagsCloudBySearch() {
- tagsCloud.clear();
+ tagCloud.clear();
for (String tag : tagsSearch) {
List<Bookmark> bookmarksList = new ArrayList<Bookmark>(bookmarks);
for (Bookmark bookmark : bookmarksList) {
if (bookmark.getTags().contains(tag) == false) {
- bookmarks.remove(bookmark);
+ bookmarks.remove(bookmark); // Delete bookmark which doesn't contain the tags from the search field
} else {
addBookmarkTagsToTagCloud(bookmark);
}
}
}
- this.defineTValues();
}
protected void defineTValues() {
- Collection values = tagsCloud.values();
+ Collection values = tagCloud.values();
Iterator it = values.iterator();
- tmax = -1;
- tmin = -1;
+ tmax = -1; // correspond to the most tag frequency in the tag cloud
+ tmin = -1; // correspond to the less tag frequency in the tag cloud
int value;
while (it.hasNext()) {
value = (Integer) it.next();
- if (tmax < value) {
- tmax = value;
+ if (tmax < value) { // search the most tag frequancy
+ tmax = value;
}
if (tmin == -1) {
tmin = value;
- } else if (tmin > value) {
+ } else if (tmin > value) { // search less tag frequency
tmin = value;
}
}
@@ -136,37 +147,41 @@
}
}
+ public void reset() {
+ bookmarks.clear();
+ tagCloud.clear();
+ tagsSearch.clear();
+ tmax = -1;
+ tmin = -1;
+ }
+
+ public void setBookmarks(List<Bookmark> bookmarksList) {
+ List<Bookmark> newList = new ArrayList(bookmarksList);
+ bookmarks = newList;
+ }
+
public String getSearchLine() {
- return StringUtil.join(tagsSearch, " ", true);
+ return StringUtil.join(tagsSearch, " ", true); // return the search line created with the tags
}
public int getFont(int ti) {
int font = 1;
if (tmax > tmin) {
- font = (15 * (ti - tmin)) / (tmax - tmin);
+ font = (15 * (ti - tmin)) / (tmax - tmin); // get the font size for a tag frequency
}
return font;
}
- public void reset() {
- bookmarks.clear();
- tagsCloud.clear();
- tagsSearch.clear();
- tmax = -1;
- tmin = -1;
- }
-
public Map<String, Integer> getTagsCloud() {
- return tagsCloud;
+ return tagCloud;
}
public List<String> getTagsSearch() {
return tagsSearch;
}
- public void setBookmarks(List<Bookmark> bookmarksList) {
- List<Bookmark> newList = new ArrayList(bookmarksList);
- bookmarks = newList;
+ public List<Bookmark> getBookmarks() {
+ return bookmarks;
}
public int getTmin() {
1
0