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
11 May '10
Author: bbrossaud
Date: 2010-05-11 11:14:13 +0200 (Tue, 11 May 2010)
New Revision: 17
Url: http://chorem.org/repositories/revision/bow/17
Log:
added the ControllerServelet comments
Modified:
trunk/src/main/java/org/chorem/bow/ControllerServlet.java
trunk/src/main/java/org/chorem/bow/TokenActions.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
Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-11 07:15:52 UTC (rev 16)
+++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-11 09:14:13 UTC (rev 17)
@@ -11,7 +11,6 @@
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.List;
-import java.util.Locale;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -21,22 +20,8 @@
import org.sharengo.wikitty.Criteria;
import org.sharengo.wikitty.WikittyProxy;
import org.sharengo.wikitty.search.Search;
-import org.nuiton.i18n.I18n;
/**
- * javascript:
- * var server = new XMLHttpRequest();
- * var url=location.href;
- * var nameAndTags = prompt('Entrez le nom du lien et la liste des tags sous la forme: name|tag1 tag2 tag3', document.title+'|');
- * server.onreadystatechange = function() {
- * if(server.readyState == 4) {
- * if (server.status != 200) {
- * alert('Erreur d\'ajout au bookmark: '+ server.status + '\n\n' + url + '\n\n' + nameAndTags);
- * }
- * }
- * };
- * server.open('GET', 'http://localhost:8080/bow/bow?action=addUrl&url='+encodeURIComponent(url)+'&nameAndTags='+encodeURIComponent(nameAndTags), true);
- * server.send(null);
*
* @author bbrossaud
*/
@@ -48,50 +33,73 @@
protected User user = null;
protected TokenActions tokenActions = new TokenActions();
- public ControllerServlet() {
- I18n.init(Locale.FRANCE);
- }
-
@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 {
- String action = request.getParameter("action");
-
- response.setContentType("text/html");
- request.setAttribute("bookmarkActions", bookmarkActions);
- request.setAttribute("tokenActions", tokenActions);
- if (action != null) {
- if (action.equals("register")) {
- log.debug("Going to actionRegister");
- this.actionRegister(request, response);
- } else if (action.equals("registration")) {
- log.debug("Going to Register");
- request.getRequestDispatcher("register.jsp").forward(request, response);
- } else if (action.equals("login")) {
- log.debug("Going to actionLogin");
- this.actionLogin(request, response);
- } else if (action.equals("addUrl")) {
- log.debug("Going to actionAddUrl");
- this.actionAddUrl(request, response);
- } else if (action.equals("search") && user != null) {
- log.debug("Going to actionSearch");
- this.actionSearch(request, response);
- } else if (action.equals("clickOnTag") && user != null) {
- log.debug("Going to actionClickOnTag");
- this.actionClickOnTag(request, response);
- } else if (action.equals("generateToken") && user != null) {
- log.debug("Going to actionGenerateToken");
- try {
- this.actionGenerateToken(request, response);
- } catch (NoSuchAlgorithmException ex) {
- log.error("No Such Algorithm", ex);
- request.getRequestDispatcher("error.jsp").forward(request, response);
+ try {
+ 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()) {
+ log.debug("Going to actionRegister");
+ }
+ this.actionRegister(request, response);
+ } else if (action.equals("registration")) {
+ if (log.isDebugEnabled()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Going to Register");
+ }
+ }
+ request.getRequestDispatcher("register.jsp").forward(request, response);
+ } else if (action.equals("login")) {
+ if (log.isDebugEnabled()) {
+ log.debug("Going to actionLogin");
+ }
+ this.actionLogin(request, response);
+ } else if (action.equals("addUrl")) {
+ if (log.isDebugEnabled()) {
+ log.debug("Going to actionAddUrl");
+ }
+ this.actionAddUrl(request, response);
+ } else if (action.equals("search") && user != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Going to actionSearch");
+ }
+ this.actionSearch(request, response);
+ } else if (action.equals("clickOnTag") && user != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Going to actionClickOnTag");
+ }
+ this.actionClickOnTag(request, response);
+ } else if (action.equals("generateToken") && user != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Going to actionGenerateToken");
+ }
+ try {
+ this.actionGenerateToken(request, response);
+ } catch (NoSuchAlgorithmException ex) {
+ log.error("No Such Algorithm", ex);
+ request.getRequestDispatcher("error.jsp").forward(request, response);
+ }
+ } else {
+ user = null;
+ if (log.isDebugEnabled()) {
+ log.debug("Going to home");
+ }
+ request.getRequestDispatcher("home.jsp").forward(request, response);
}
} else {
user = null;
@@ -100,26 +108,26 @@
}
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);
+ } catch (Exception eee) {
+ request.getRequestDispatcher("error.jsp").forward(request, response);
}
}
+ /* @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet error occurs
+ */
protected void actionGenerateToken(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException, NoSuchAlgorithmException {
WikittyProxy proxy = model.getProxy();
- String token = tokenActions.generateToken();
+ String token = tokenActions.generateToken(); // Generate an encoding MD5 token
Criteria criteria = Search.query().eq(Token.FQ_FIELD_TOKEN, token).criteria();
- if (proxy.findByCriteria(User.class, criteria) == null) {
+ 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);
+ proxy.store((Token) newToken); // If the token doesn't exist, it is stored
tokenActions.setToken(token);
} else {
tokenActions.setToken("");
@@ -127,23 +135,29 @@
request.getRequestDispatcher("generateToken.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)
throws IOException, ServletException {
- String url = request.getParameter("url");
- String nameAndTags = request.getParameter("nameAndTags");
- String token = request.getParameter("token");
- log.debug("URL = {" + url + "}");
+ 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 (user == null) { // If the user is null, it's maybe a bookmark addition by token
user = checkToken(url, nameAndTags, token);
}
if (user != null) {
if (!url.isEmpty() && !nameAndTags.isEmpty()) {
Bookmark bookmark = bookmarkActions.createBookmark(url, nameAndTags, user);
if (bookmark != null) {
- model.getProxy().store(bookmark);
- log.debug("Adding URL");
+ 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);
}
@@ -153,48 +167,63 @@
}
}
+ /* @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
+ * @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) {
WikittyProxy proxy = model.getProxy();
Criteria criteria = Search.query().eq(Token.FQ_FIELD_TOKEN, token).criteria();
Token DbToken = proxy.findByCriteria(Token.class, criteria);
- if (DbToken != null) {
- String userEmail = DbToken.getEmail();
- criteria = Search.query().eq(User.FQ_FIELD_EMAIL, userEmail).criteria();
+ if (DbToken != null) { // check if the token exists
+ String userEmail = DbToken.getEmail(); // the token owner user name (email)
+ criteria = Search.query().eq(User.FQ_FIELD_EMAIL, userEmail).criteria(); // retrieve user by token
return proxy.findByCriteria(User.class, criteria);
}
}
return null;
}
+ /* @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet error occurs
+ */
protected void actionClickOnTag(HttpServletRequest request, HttpServletResponse response)
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 = model.getProxy().
- findAllByCriteria(Bookmark.class, criteria).getAll();
+ 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);
+ bookmarkActions.addTag(tag); // if a new tag is selected, adding in tag list
}
}
- bookmarkActions.createTagsCloud();
+ bookmarkActions.createTagsCloud(); // create the tags cloud with the new informations
request.getRequestDispatcher("search.jsp").forward(request, response);
}
+ /* @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet error occurs
+ */
protected void actionSearch(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
- String words = request.getParameter("words");
+ 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 = model.getProxy().
- findAllByCriteria(Bookmark.class, criteria).getAll();
+ List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user
if (bookList != null) {
bookmarkActions.setBookmarks(bookList);
}
@@ -202,83 +231,88 @@
if (!words.isEmpty()) {
words = words.trim();
String[] tags = words.split("\\s+");
- bookmarkActions.addTags(tags);
+ bookmarkActions.addTags(tags); // add the new tags
}
}
- bookmarkActions.createTagsCloud();
+ bookmarkActions.createTagsCloud(); // create the tags cloud with the new informations
request.getRequestDispatcher("search.jsp").forward(request, response);
}
+ /* @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet error occurs
+ */
protected void actionRegister(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
- try {
- if (this.checkRegister(request, response)) {
- request.getRequestDispatcher("register.jsp").forward(request, response);
+ String email = request.getParameter("email");
+ String password = request.getParameter("password");
+ if (this.checkRegister(email, password)) { // check if all is well
+ request.getRequestDispatcher("register.jsp").forward(request, response);
+ } else {
+ WikittyProxy proxy = model.getProxy();
+ 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) {
+ request.getRequestDispatcher("error.jsp").forward(request, response);
} else {
- UserImpl newUser = new UserImpl();
- newUser.setPassword(request.getParameter("password"));
- newUser.setEmail(request.getParameter("email"));
- this.user = model.getProxy().store((User) newUser);
- if (user == null) {
- log.debug("Not put in the Databases");
- request.getRequestDispatcher("error.jsp").forward(request, response);
- } else {
- log.debug("adding to the Databases");
- this.actionSearch(request, response);
- }
+ this.actionSearch(request, response);
}
- } catch (Exception eee) {
- request.getRequestDispatcher("error.jsp").forward(request, response);
}
}
+ /* @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet error occurs
+ */
protected void actionLogin(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
- try {
- User user = this.checkLogin(request, response);
+ String email = request.getParameter("email");
+ String password = request.getParameter("password");
+ User login = this.checkLogin(email, password); // check if the user exists
- if (user != null) {
- log.debug("User exists");
- this.user = user;
- this.actionSearch(request, response);
- } else {
- log.debug("User doesn't exist");
- request.getRequestDispatcher("home.jsp").forward(request, response);
- }
- } catch (Exception eee) {
- request.getRequestDispatcher("error.jsp").forward(request, response);
+ if (login != null) {
+ this.user = login;
+ this.actionSearch(request, response);
+ } else {
+ request.getRequestDispatcher("home.jsp").forward(request, response);
}
-
}
- protected User checkLogin(HttpServletRequest request, HttpServletResponse response)
- throws IOException, ServletException {
- String email = request.getParameter("email");
- String password = request.getParameter("password");
+ /* @param email String which contains the user name (email)
+ * @param password String which contains the user password
+ * @return null the user doesn't exist
+ * @return User the user exists
+ */
+ protected User checkLogin(String email, String password) {
- if (!email.isEmpty() && !password.isEmpty()) {
- WikittyProxy proxy = model.getProxy();
+ if (email != null && password != null) {
+ if (!email.isEmpty() && !password.isEmpty()) {
+ WikittyProxy proxy = model.getProxy();
- Criteria criteria = Search.query().eq(User.FQ_FIELD_EMAIL, email).eq(User.FQ_FIELD_PASSWORD, password).criteria();
- return proxy.findByCriteria(User.class, criteria);
+ Criteria criteria = Search.query().eq(User.FQ_FIELD_EMAIL, email).
+ eq(User.FQ_FIELD_PASSWORD, password).criteria();
+ return proxy.findByCriteria(User.class, criteria); // retrieve user by user name (email) and password
+ }
}
- log.debug("Empty password or email");
return null;
}
- protected boolean checkRegister(HttpServletRequest request, HttpServletResponse response)
- throws IOException, ServletException {
- String email = request.getParameter("email");
- String password = request.getParameter("password");
- log.debug("email={" + email + "}");
- if (!email.isEmpty() && !password.isEmpty()) {
- WikittyProxy proxy = model.getProxy();
+ /* @param email String which contains the user name (email)
+ * @param password String which contains the user password
+ * @return bool false if the user doesn't exists or true
+ */
+ protected boolean checkRegister(String email, String password) {
+ if (email != null && password != null) {
+ if (!email.isEmpty() && !password.isEmpty()) {
+ WikittyProxy proxy = model.getProxy();
- Criteria criteria = Search.query().eq(User.FQ_FIELD_EMAIL, email).criteria();
- if (proxy.findByCriteria(User.class, criteria) == null) {
- log.debug("No user with this email");
- return false;
+ Criteria criteria = Search.query().eq(User.FQ_FIELD_EMAIL, email).criteria(); // retrieve user by user name (email)
+ if (proxy.findByCriteria(User.class, criteria) == null) {
+ return false;
+ }
}
}
return true;
Modified: trunk/src/main/java/org/chorem/bow/TokenActions.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/TokenActions.java 2010-05-11 07:15:52 UTC (rev 16)
+++ trunk/src/main/java/org/chorem/bow/TokenActions.java 2010-05-11 09:14:13 UTC (rev 17)
@@ -6,12 +6,12 @@
import java.security.NoSuchAlgorithmException;
import org.nuiton.util.StringUtil;
-import static org.nuiton.i18n.I18n._;
/**
*
* @author bbrossaud
*/
+
public class TokenActions {
String token = "";
Modified: trunk/src/main/webapp/generateToken.jsp
===================================================================
--- trunk/src/main/webapp/generateToken.jsp 2010-05-11 07:15:52 UTC (rev 16)
+++ trunk/src/main/webapp/generateToken.jsp 2010-05-11 09:14:13 UTC (rev 17)
@@ -4,14 +4,20 @@
String token = tokenActions.getToken();
if (token != null && token.isEmpty() == false) {
%>
+<html>
+ <body>
+ Use it to add new bookmarks without authentication : <br/><br/>
-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>
+ <%
+ } else {
+ %>
+ Token not available, try again later ...
+ <%
+ }
+ %>
+
+ <br/><br/><a href="bow?action=search">Return to the search page</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;document.body.appendChild(image);window.location=url;">Session</a>
-<%
- } else {
-%>
- Token not available, try again later ...
-<%
- }
-%>
\ No newline at end of file
+ </body>
+</html>
\ No newline at end of file
Modified: trunk/src/main/webapp/home.jsp
===================================================================
--- trunk/src/main/webapp/home.jsp 2010-05-11 07:15:52 UTC (rev 16)
+++ trunk/src/main/webapp/home.jsp 2010-05-11 09:14:13 UTC (rev 17)
@@ -4,8 +4,8 @@
<form method="POST" action="home?action=login">
email <input type="text" name="email" size="20"><br />
password <input type=password name="password" size="20"><br />
- <input type="submit" value="submit">
+ <input type="submit" value="login">
</form>
- <a href="main?action=registration">register</a>
+ <a href="bow?action=registration">register</a>
</body>
</html>
\ No newline at end of file
Modified: trunk/src/main/webapp/register.jsp
===================================================================
--- trunk/src/main/webapp/register.jsp 2010-05-11 07:15:52 UTC (rev 16)
+++ trunk/src/main/webapp/register.jsp 2010-05-11 09:14:13 UTC (rev 17)
@@ -2,11 +2,11 @@
<body>
<h1>Register</h1>
- <form method="POST" action="register?action=register">
+ <form method="POST" action="bow?action=register">
email <input type="text" name="email" size="20"><br />
password <input type=password name="password" size="20"><br />
- <input type="submit" value="submit">
+ <input type="submit" value="Register">
</form>
-
+ <br/><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 07:15:52 UTC (rev 16)
+++ trunk/src/main/webapp/search.jsp 2010-05-11 09:14:13 UTC (rev 17)
@@ -11,22 +11,22 @@
<html>
<body>
+ <a href="bow?action=logout">Logout</a><br/>
<h1>Search</h1>
- <form method="POST" action="search?action=addUrl">
+ <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">
</form>
- <br/><br/><a href="search?action=generateToken">Generate Token</a><br/><br/>
+ <br/><br/><a href="bow?action=generateToken">Generate Token</a><br/><br/>
- <form method="POST" action="search?action=search">
+ <form method="POST" action="bow?action=search">
<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();
@@ -35,7 +35,7 @@
int font = bookmarkActions.getFont(value);
%>
-<FONT SIZE="<%=font%>" ><a href="search?action=clickOnTag&tag=<%=tag%>"><%=tag%></a></FONT>
+<FONT SIZE="<%=font%>" ><a href="bow?action=clickOnTag&tag=<%=tag%>"><%=tag%></a></FONT>
<%
}
1
0
Author: bbrossaud
Date: 2010-05-11 09:15:52 +0200 (Tue, 11 May 2010)
New Revision: 16
Url: http://chorem.org/repositories/revision/bow/16
Log:
Bookmark addition with the javascript works now
Modified:
trunk/src/main/webapp/generateToken.jsp
Modified: trunk/src/main/webapp/generateToken.jsp
===================================================================
--- trunk/src/main/webapp/generateToken.jsp 2010-05-10 16:47:41 UTC (rev 15)
+++ trunk/src/main/webapp/generateToken.jsp 2010-05-11 07:15:52 UTC (rev 16)
@@ -7,7 +7,7 @@
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);document.location.href=encodeURIComponent(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;document.body.appendChild(image);window.location=url;">Session</a>
<%
} else {
%>
1
0
10 May '10
Author: bbrossaud
Date: 2010-05-10 18:47:41 +0200 (Mon, 10 May 2010)
New Revision: 15
Url: http://chorem.org/repositories/revision/bow/15
Log:
the autobookmark almost work
Modified:
trunk/src/main/java/org/chorem/bow/ControllerServlet.java
trunk/src/main/webapp/generateToken.jsp
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-10 12:47:12 UTC (rev 14)
+++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-10 16:47:41 UTC (rev 15)
@@ -25,16 +25,18 @@
/**
* javascript:
- * server = new XMLHttpRequest();
- * var url=location.href;
- * var nameAndTags = prompt("Entrez le nom du lien et la liste des tags sous la forme: <name>|tag1,tag2,tag3", document.title+'|');
- * server.onreadystatechange = function() {
- * if(server.readyState == 4)
- * if (server.status != 200)
- * alert("Error d'ajout au bookmark: "+ server.status + "\n\n" + url + "\n\n" + nameAndTags);
- * };
- * server.open("GET", 'http://localhost:8080/bow?action=addUrl&url='+encodeURIComponent(url)+'&nameAndtags='+encodeURIComponent(nameAndTags), true);
- * server.send(null);
+ * var server = new XMLHttpRequest();
+ * var url=location.href;
+ * var nameAndTags = prompt('Entrez le nom du lien et la liste des tags sous la forme: name|tag1 tag2 tag3', document.title+'|');
+ * server.onreadystatechange = function() {
+ * if(server.readyState == 4) {
+ * if (server.status != 200) {
+ * alert('Erreur d\'ajout au bookmark: '+ server.status + '\n\n' + url + '\n\n' + nameAndTags);
+ * }
+ * }
+ * };
+ * server.open('GET', 'http://localhost:8080/bow/bow?action=addUrl&url='+encodeURIComponent(url)+'&nameAndTags='+encodeURIComponent(nameAndTags), true);
+ * server.send(null);
*
* @author bbrossaud
*/
Modified: trunk/src/main/webapp/generateToken.jsp
===================================================================
--- trunk/src/main/webapp/generateToken.jsp 2010-05-10 12:47:12 UTC (rev 14)
+++ trunk/src/main/webapp/generateToken.jsp 2010-05-10 16:47:41 UTC (rev 15)
@@ -7,8 +7,7 @@
Use it to add new bookmarks without authentication : <br/><br/>
-javascript:server%20=%20new%20XMLHttpRequest();%20url=location.href;nameAndTags%20=%20prompt("Entrez%20le%20nom%20du%20lien%20et%20la%20liste%20des%20tags%20sous%20la%20forme:%20<name>|tag1,tag2,tag3",%20document.title+'|');server.onreadystatechange%20=%20function()%20{%20if(server.readyState%20==%204)%20if%20(server.status%20!=%20200)%20alert("Error%20d'ajout%20au%20bookmark:%20"+%20server.status%20+%20"\n\n"%20+%20url%20+%20"\n\n"%20+%20nameAndTags);};server.open("GET",%20'http://localhost:8080/bow/bow?action=addUrl&token=<%=token%>&url='+encodeURIComponent(url)+'&nameAndTags='+encodeURIComponent(nameAndTags),%20true);server.send(null);
-
+<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);document.location.href=encodeURIComponent(url);">Session</a>
<%
} else {
%>
Modified: trunk/src/main/webapp/search.jsp
===================================================================
--- trunk/src/main/webapp/search.jsp 2010-05-10 12:47:12 UTC (rev 14)
+++ trunk/src/main/webapp/search.jsp 2010-05-10 16:47:41 UTC (rev 15)
@@ -19,12 +19,13 @@
<input type="submit" value="add">
</form>
+ <br/><br/><a href="search?action=generateToken">Generate Token</a><br/><br/>
+
<form method="POST" action="search?action=search">
<input type="text" name="words" size="20" value="<%=bookmarkActions.getSearchLine()%>" ><br />
<input type="submit" value="Find">
</form>
- <a href="search?action=generateToken">Generate Token</a><br/>
<% if (bookmarkActions != null) {
Map<String, Integer> tagsCloud = bookmarkActions.getTagsCloud();
1
0
10 May '10
Author: bbrossaud
Date: 2010-05-10 14:47:12 +0200 (Mon, 10 May 2010)
New Revision: 14
Url: http://chorem.org/repositories/revision/bow/14
Log:
added generateToken.jsp and tokenActions.java
Added:
trunk/src/main/java/org/chorem/bow/TokenActions.java
trunk/src/main/webapp/generateToken.jsp
Added: trunk/src/main/java/org/chorem/bow/TokenActions.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/TokenActions.java (rev 0)
+++ trunk/src/main/java/org/chorem/bow/TokenActions.java 2010-05-10 12:47:12 UTC (rev 14)
@@ -0,0 +1,35 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.chorem.bow;
+
+import java.security.NoSuchAlgorithmException;
+import org.nuiton.util.StringUtil;
+import static org.nuiton.i18n.I18n._;
+
+/**
+ *
+ * @author bbrossaud
+ */
+public class TokenActions {
+
+ String token = "";
+
+ public String getToken() {
+ return token;
+ }
+
+ public String generateToken()
+ throws NoSuchAlgorithmException {
+ Double rand = Math.random() * 1000000;
+ int res = (int) Math.abs(rand);
+ String tokenGenerated = String.valueOf(res);
+ tokenGenerated = StringUtil.encodeMD5(tokenGenerated);
+ return tokenGenerated;
+ }
+
+ public void setToken(String token) {
+ this.token = token;
+ }
+}
Added: trunk/src/main/webapp/generateToken.jsp
===================================================================
--- trunk/src/main/webapp/generateToken.jsp (rev 0)
+++ trunk/src/main/webapp/generateToken.jsp 2010-05-10 12:47:12 UTC (rev 14)
@@ -0,0 +1,18 @@
+<%@ page import="org.chorem.bow.TokenActions" %>
+
+<%TokenActions tokenActions = (TokenActions) request.getAttribute("tokenActions");
+ String token = tokenActions.getToken();
+ if (token != null && token.isEmpty() == false) {
+%>
+
+Use it to add new bookmarks without authentication : <br/><br/>
+
+javascript:server%20=%20new%20XMLHttpRequest();%20url=location.href;nameAndTags%20=%20prompt("Entrez%20le%20nom%20du%20lien%20et%20la%20liste%20des%20tags%20sous%20la%20forme:%20<name>|tag1,tag2,tag3",%20document.title+'|');server.onreadystatechange%20=%20function()%20{%20if(server.readyState%20==%204)%20if%20(server.status%20!=%20200)%20alert("Error%20d'ajout%20au%20bookmark:%20"+%20server.status%20+%20"\n\n"%20+%20url%20+%20"\n\n"%20+%20nameAndTags);};server.open("GET",%20'http://localhost:8080/bow/bow?action=addUrl&token=<%=token%>&url='+encodeURIComponent(url)+'&nameAndTags='+encodeURIComponent(nameAndTags),%20true);server.send(null);
+
+<%
+ } else {
+%>
+ Token not available, try again later ...
+<%
+ }
+%>
\ No newline at end of file
1
0
10 May '10
Author: bbrossaud
Date: 2010-05-10 14:45:14 +0200 (Mon, 10 May 2010)
New Revision: 13
Url: http://chorem.org/repositories/revision/bow/13
Log:
the bookmark addition works, the token generation works but the javascript doesn't work
Removed:
trunk/src/main/java/org/chorem/bow/Login.java
Modified:
trunk/src/main/java/org/chorem/bow/BookmarkActions.java
trunk/src/main/java/org/chorem/bow/ControllerServlet.java
trunk/src/main/webapp/home.jsp
trunk/src/main/webapp/search.jsp
Modified: trunk/src/main/java/org/chorem/bow/BookmarkActions.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-07 13:29:16 UTC (rev 12)
+++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-10 12:45:14 UTC (rev 13)
@@ -26,22 +26,28 @@
protected int tmax = -1;
protected int tmin = -1;
- public Bookmark createBookmark(String query, User user) {
- Bookmark bookmark = (Bookmark) new BookmarkImpl();
+ public Bookmark createBookmark(String url, String nameAndTags, User user) {
- int linkIndex = query.indexOf('|');
- if (linkIndex < 0) {
+ int nameIndex = nameAndTags.indexOf('|');
+ if (nameIndex < 0) {
return null;
}
- String link = query.substring(0, linkIndex);
- link = link.replaceAll("\\s*|", "");
- query = query.substring(linkIndex + 1);
- query = query.trim();
- String[] tags = query.split("\\s+");
- for (int i = 0; i < tags.length; ++i) {
- bookmark.addTags(tags[i]);
+ Bookmark bookmark = (Bookmark) new BookmarkImpl();
+
+ String link = url.trim();
+ bookmark.setLink(link);
+
+ String name = nameAndTags.substring(0, nameIndex);
+ name = name.trim();
+ bookmark.setDescription(name);
+
+ String tags = nameAndTags.substring(nameIndex + 1);
+ tags = tags.trim();
+ String[] tagsTab = tags.split("\\s+");
+ for (int i = 0; i < tagsTab.length; ++i) {
+ bookmark.addTags(tagsTab[i]);
}
- bookmark.setLink(link);
+
bookmark.setEmail(user.getEmail());
bookmark.setDate(new Date());
return bookmark;
Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-07 13:29:16 UTC (rev 12)
+++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-10 12:45:14 UTC (rev 13)
@@ -9,8 +9,9 @@
* @author bbrossaud
*/
import java.io.IOException;
-import java.util.ArrayList;
+import java.security.NoSuchAlgorithmException;
import java.util.List;
+import java.util.Locale;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -20,33 +21,39 @@
import org.sharengo.wikitty.Criteria;
import org.sharengo.wikitty.WikittyProxy;
import org.sharengo.wikitty.search.Search;
+import org.nuiton.i18n.I18n;
+/**
+ * javascript:
+ * server = new XMLHttpRequest();
+ * var url=location.href;
+ * var nameAndTags = prompt("Entrez le nom du lien et la liste des tags sous la forme: <name>|tag1,tag2,tag3", document.title+'|');
+ * server.onreadystatechange = function() {
+ * if(server.readyState == 4)
+ * if (server.status != 200)
+ * alert("Error d'ajout au bookmark: "+ server.status + "\n\n" + url + "\n\n" + nameAndTags);
+ * };
+ * server.open("GET", 'http://localhost:8080/bow?action=addUrl&url='+encodeURIComponent(url)+'&nameAndtags='+encodeURIComponent(nameAndTags), true);
+ * server.send(null);
+ *
+ * @author bbrossaud
+ */
public class ControllerServlet extends HttpServlet {
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();
+ public ControllerServlet() {
+ I18n.init(Locale.FRANCE);
+ }
+
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
- String action = request.getParameter("action");
-
- response.setContentType("text/html");
- request.setAttribute("bookmarkActions", bookmarkActions);
- if (action != null) {
- if (action.equals("register")) {
- request.getRequestDispatcher("register.jsp").forward(request, response);
- } else if (action.equals("clickontag")) {
- log.debug("Going to actionClickOnTag");
- this.actionClickOnTag(request, response);
- } else {
- request.getRequestDispatcher("home.jsp").forward(request, response);
- }
- } else {
- request.getRequestDispatcher("home.jsp").forward(request, response);
- }
+ this.doPost(request, response);
}
@Override
@@ -56,42 +63,106 @@
response.setContentType("text/html");
request.setAttribute("bookmarkActions", bookmarkActions);
+ request.setAttribute("tokenActions", tokenActions);
if (action != null) {
if (action.equals("register")) {
log.debug("Going to actionRegister");
this.actionRegister(request, response);
+ } else if (action.equals("registration")) {
+ log.debug("Going to Register");
+ request.getRequestDispatcher("register.jsp").forward(request, response);
} else if (action.equals("login")) {
log.debug("Going to actionLogin");
this.actionLogin(request, response);
} else if (action.equals("addUrl")) {
log.debug("Going to actionAddUrl");
this.actionAddUrl(request, response);
- } else if (action.equals("search")) {
+ } else if (action.equals("search") && user != null) {
log.debug("Going to actionSearch");
this.actionSearch(request, response);
+ } else if (action.equals("clickOnTag") && user != null) {
+ log.debug("Going to actionClickOnTag");
+ this.actionClickOnTag(request, response);
+ } else if (action.equals("generateToken") && user != null) {
+ log.debug("Going to actionGenerateToken");
+ try {
+ this.actionGenerateToken(request, response);
+ } catch (NoSuchAlgorithmException ex) {
+ log.error("No Such Algorithm", ex);
+ request.getRequestDispatcher("error.jsp").forward(request, response);
+ }
} else {
- log.debug("Going to home");
+ 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);
}
}
+ protected void actionGenerateToken(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException, NoSuchAlgorithmException {
+
+ WikittyProxy proxy = model.getProxy();
+ String token = tokenActions.generateToken();
+ Criteria criteria = Search.query().eq(Token.FQ_FIELD_TOKEN, token).criteria();
+ if (proxy.findByCriteria(User.class, criteria) == null) {
+ TokenImpl newToken = new TokenImpl();
+ newToken.setToken(token);
+ newToken.setEmail(user.getEmail());
+ proxy.store((Token) newToken);
+ tokenActions.setToken(token);
+ } else {
+ tokenActions.setToken("");
+ }
+ request.getRequestDispatcher("generateToken.jsp").forward(request, response);
+ }
+
protected void actionAddUrl(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
+
String url = request.getParameter("url");
+ String nameAndTags = request.getParameter("nameAndTags");
+ String token = request.getParameter("token");
+ log.debug("URL = {" + url + "}");
+ if (url != null && nameAndTags != null) {
+ if (user == null) {
+ user = checkToken(url, nameAndTags, token);
+ }
+ if (user != null) {
+ if (!url.isEmpty() && !nameAndTags.isEmpty()) {
+ Bookmark bookmark = bookmarkActions.createBookmark(url, nameAndTags, user);
+ if (bookmark != null) {
+ model.getProxy().store(bookmark);
+ log.debug("Adding URL");
+ if (token == null) {
+ this.actionSearch(request, response);
+ }
+ }
+ }
+ }
+ }
+ }
- if (url != null) {
-
- log.debug("URL = {" + url + "}");
- Bookmark bookmark = bookmarkActions.createBookmark(url, user);
- if (bookmark != null) {
- model.getProxy().store(bookmark);
- log.debug("Adding URL");
+ protected User checkToken(String url, String nameAndTags, String token) {
+ if (url != null && nameAndTags != null && token != null) {
+ WikittyProxy proxy = model.getProxy();
+ Criteria criteria = Search.query().eq(Token.FQ_FIELD_TOKEN, token).criteria();
+ Token DbToken = proxy.findByCriteria(Token.class, criteria);
+ if (DbToken != null) {
+ String userEmail = DbToken.getEmail();
+ criteria = Search.query().eq(User.FQ_FIELD_EMAIL, userEmail).criteria();
+ return proxy.findByCriteria(User.class, criteria);
}
}
- request.getRequestDispatcher("search.jsp").forward(request, response);
+ return null;
}
protected void actionClickOnTag(HttpServletRequest request, HttpServletResponse response)
@@ -99,8 +170,9 @@
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 = model.getProxy().
- findAllByCriteria(Bookmark.class, null).getAll();
+ findAllByCriteria(Bookmark.class, criteria).getAll();
if (bookList != null) {
bookmarkActions.setBookmarks(bookList);
}
@@ -118,8 +190,9 @@
throws IOException, ServletException {
String words = request.getParameter("words");
bookmarkActions.reset();
+ Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria();
List<Bookmark> bookList = model.getProxy().
- findAllByCriteria(Bookmark.class, null).getAll();
+ findAllByCriteria(Bookmark.class, criteria).getAll();
if (bookList != null) {
bookmarkActions.setBookmarks(bookList);
}
@@ -149,13 +222,7 @@
request.getRequestDispatcher("error.jsp").forward(request, response);
} else {
log.debug("adding to the Databases");
- List<Bookmark> bookList = model.getProxy().
- findAllByCriteria(Bookmark.class, null).getAll();
- if (bookList != null) {
- bookmarkActions.setBookmarks(bookList);
- }
- bookmarkActions.createTagsCloud();
- request.getRequestDispatcher("search.jsp").forward(request, response);
+ this.actionSearch(request, response);
}
}
} catch (Exception eee) {
@@ -171,13 +238,7 @@
if (user != null) {
log.debug("User exists");
this.user = user;
- List<Bookmark> bookList = model.getProxy().
- findAllByCriteria(Bookmark.class, null).getAll();
- if (bookList != null) {
- bookmarkActions.setBookmarks(bookList);
- }
- bookmarkActions.createTagsCloud();
- request.getRequestDispatcher("search.jsp").forward(request, response);
+ this.actionSearch(request, response);
} else {
log.debug("User doesn't exist");
request.getRequestDispatcher("home.jsp").forward(request, response);
Deleted: trunk/src/main/java/org/chorem/bow/Login.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/Login.java 2010-05-07 13:29:16 UTC (rev 12)
+++ trunk/src/main/java/org/chorem/bow/Login.java 2010-05-10 12:45:14 UTC (rev 13)
@@ -1,55 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package org.chorem.bow;
-
-/**
- *
- * @author bbrossaud
- */
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import javax.servlet.ServletConfig;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-
-public class Login extends HttpServlet {
-
-
- @Override
- public void init(ServletConfig config) throws ServletException {
-
- }
-
- @Override
- public void init() throws ServletException {
-
- }
-
-
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws IOException, ServletException
- {
- String password;
- String email;
-
- password = request.getParameter("password");
- email = request.getParameter("email");
- if (!password.isEmpty() && !email.isEmpty())
- {
-
- }
- else
- {
- response.setContentType("text/html");
- request.getRequestDispatcher("auth.jsp").forward(request, response);
- }
- }
-}
Modified: trunk/src/main/webapp/home.jsp
===================================================================
--- trunk/src/main/webapp/home.jsp 2010-05-07 13:29:16 UTC (rev 12)
+++ trunk/src/main/webapp/home.jsp 2010-05-10 12:45:14 UTC (rev 13)
@@ -6,6 +6,6 @@
password <input type=password name="password" size="20"><br />
<input type="submit" value="submit">
</form>
- <a href="main?action=register">register</a>
+ <a href="main?action=registration">register</a>
</body>
</html>
\ No newline at end of file
Modified: trunk/src/main/webapp/search.jsp
===================================================================
--- trunk/src/main/webapp/search.jsp 2010-05-07 13:29:16 UTC (rev 12)
+++ trunk/src/main/webapp/search.jsp 2010-05-10 12:45:14 UTC (rev 13)
@@ -14,7 +14,8 @@
<h1>Search</h1>
<form method="POST" action="search?action=addUrl">
- URL <input type="text" name="url" size="20" value="URL|tag1 tag2..."><br />
+ 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>
@@ -23,6 +24,8 @@
<input type="submit" value="Find">
</form>
+ <a href="search?action=generateToken">Generate Token</a><br/>
+
<% if (bookmarkActions != null) {
Map<String, Integer> tagsCloud = bookmarkActions.getTagsCloud();
Set<String> tags = tagsCloud.keySet();
@@ -31,7 +34,7 @@
int font = bookmarkActions.getFont(value);
%>
-<FONT SIZE="<%=font%>" ><a href="search?action=clickontag&tag=<%=tag%>"><%=tag%></a></FONT>
+<FONT SIZE="<%=font%>" ><a href="search?action=clickOnTag&tag=<%=tag%>"><%=tag%></a></FONT>
<%
}
@@ -43,7 +46,7 @@
<%
for (Bookmark bookmark : bookmarkList) {
%>
- <%=bookmark.getLink()%><br/>
+ <a href="<%=bookmark.getLink()%>"><%=bookmark.getDescription()%></a><br/>
<%
}
} else if (!tagsSearch.isEmpty() && bookmarkList.isEmpty()) {
1
0
07 May '10
Author: bbrossaud
Date: 2010-05-07 15:29:16 +0200 (Fri, 07 May 2010)
New Revision: 12
Url: http://chorem.org/repositories/revision/bow/12
Log:
the click on tag works
Modified:
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/src/main/java/org/chorem/bow/BookmarkActions.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-07 10:35:52 UTC (rev 11)
+++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-07 13:29:16 UTC (rev 12)
@@ -29,21 +29,19 @@
public Bookmark createBookmark(String query, User user) {
Bookmark bookmark = (Bookmark) new BookmarkImpl();
- if (query.indexOf('|') > 0) {
- bookmark.setLink(query.substring(0, query.indexOf('|')));
- query = query.substring(query.indexOf('|') + 1);
- while (!query.isEmpty()) {
- if (query.indexOf(',') > 0) {
- bookmark.addTags(query.substring(0, query.indexOf(',')));
- query = query.substring(query.indexOf(',') + 1);
- } else {
- bookmark.addTags(query.substring(0, query.length()));
- query = "";
- }
- }
- } else {
- bookmark.setLink(query);
+ int linkIndex = query.indexOf('|');
+ if (linkIndex < 0) {
+ return null;
}
+ String link = query.substring(0, linkIndex);
+ link = link.replaceAll("\\s*|", "");
+ query = query.substring(linkIndex + 1);
+ query = query.trim();
+ String[] tags = query.split("\\s+");
+ for (int i = 0; i < tags.length; ++i) {
+ bookmark.addTags(tags[i]);
+ }
+ bookmark.setLink(link);
bookmark.setEmail(user.getEmail());
bookmark.setDate(new Date());
return bookmark;
Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-07 10:35:52 UTC (rev 11)
+++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-07 13:29:16 UTC (rev 12)
@@ -34,9 +34,13 @@
String action = request.getParameter("action");
response.setContentType("text/html");
+ request.setAttribute("bookmarkActions", bookmarkActions);
if (action != null) {
if (action.equals("register")) {
request.getRequestDispatcher("register.jsp").forward(request, response);
+ } else if (action.equals("clickontag")) {
+ log.debug("Going to actionClickOnTag");
+ this.actionClickOnTag(request, response);
} else {
request.getRequestDispatcher("home.jsp").forward(request, response);
}
@@ -62,7 +66,7 @@
} else if (action.equals("addUrl")) {
log.debug("Going to actionAddUrl");
this.actionAddUrl(request, response);
- } else if (action.equals("check")) {
+ } else if (action.equals("search")) {
log.debug("Going to actionSearch");
this.actionSearch(request, response);
} else {
@@ -79,38 +83,54 @@
String url = request.getParameter("url");
if (url != null) {
- bookmarkActions.getBookmarks().clear();
- bookmarkActions.getTagsCloud().clear();
- url = url.replaceAll("\\s*", "");
+
+ log.debug("URL = {" + url + "}");
Bookmark bookmark = bookmarkActions.createBookmark(url, user);
- model.getProxy().store(bookmark);
- log.debug("URL = {" + url + "}");
- log.debug("Adding URL");
+ if (bookmark != null) {
+ model.getProxy().store(bookmark);
+ log.debug("Adding URL");
+ }
}
request.getRequestDispatcher("search.jsp").forward(request, response);
}
+ protected void actionClickOnTag(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException {
+ String tag = request.getParameter("tag");
+ bookmarkActions.getBookmarks().clear();
+ bookmarkActions.getTagsCloud().clear();
+ List<Bookmark> bookList = model.getProxy().
+ findAllByCriteria(Bookmark.class, null).getAll();
+ if (bookList != null) {
+ bookmarkActions.setBookmarks(bookList);
+ }
+ if (tag != null) {
+ if (!tag.isEmpty()) {
+ tag = tag.trim();
+ bookmarkActions.addTag(tag);
+ }
+ }
+ bookmarkActions.createTagsCloud();
+ request.getRequestDispatcher("search.jsp").forward(request, response);
+ }
+
protected void actionSearch(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String words = request.getParameter("words");
bookmarkActions.reset();
List<Bookmark> bookList = model.getProxy().
- findAllByCriteria(Bookmark.class, null).getAll();
+ findAllByCriteria(Bookmark.class, null).getAll();
if (bookList != null) {
bookmarkActions.setBookmarks(bookList);
}
if (words != null) {
if (!words.isEmpty()) {
+ words = words.trim();
String[] tags = words.split("\\s+");
bookmarkActions.addTags(tags);
- log.debug("TabSize = {" + String.valueOf(tags.length) + "}");
}
}
- log.debug("ListSize before = {" + String.valueOf(bookmarkActions.getBookmarks().size()) + "}");
- log.debug("SearchLine = {" + words + "}");
bookmarkActions.createTagsCloud();
- log.debug("TagCloudSize = {" + String.valueOf(bookmarkActions.getTagsCloud().size()) + "}");
- log.debug("ListSize after = {" + String.valueOf(bookmarkActions.getBookmarks().size()) + "}");
request.getRequestDispatcher("search.jsp").forward(request, response);
}
Modified: trunk/src/main/webapp/search.jsp
===================================================================
--- trunk/src/main/webapp/search.jsp 2010-05-07 10:35:52 UTC (rev 11)
+++ trunk/src/main/webapp/search.jsp 2010-05-07 13:29:16 UTC (rev 12)
@@ -14,11 +14,11 @@
<h1>Search</h1>
<form method="POST" action="search?action=addUrl">
- URL <input type="text" name="url" size="20" value="URL|tag1,tag2..."><br />
+ URL <input type="text" name="url" size="20" value="URL|tag1 tag2..."><br />
<input type="submit" value="add">
</form>
- <form method="POST" action="search?action=check">
+ <form method="POST" action="search?action=search">
<input type="text" name="words" size="20" value="<%=bookmarkActions.getSearchLine()%>" ><br />
<input type="submit" value="Find">
</form>
@@ -31,25 +31,25 @@
int font = bookmarkActions.getFont(value);
%>
-<FONT SIZE="<%=font%>" ><%=tag%></FONT>
+<FONT SIZE="<%=font%>" ><a href="search?action=clickontag&tag=<%=tag%>"><%=tag%></a></FONT>
<%
}
List<String> tagsSearch = bookmarkActions.getTagsSearch();
List<Bookmark> bookmarkList = bookmarkActions.getBookmarks();
- if (!tagsSearch.isEmpty() || bookmarkList.size() == 1) {
- if (tagsCloud.isEmpty()) {
+ if (!bookmarkList.isEmpty() && !tagsSearch.isEmpty()) {
%>
- RESULT:<br/>
+ <br/><br/>Results:<br/><br/>
<%
- for (Bookmark bookmark : bookmarkList) {
+ for (Bookmark bookmark : bookmarkList) {
%>
-
-<%=bookmark.getLink()%><br/>
-
+ <%=bookmark.getLink()%><br/>
<%
- }
}
+ } else if (!tagsSearch.isEmpty() && bookmarkList.isEmpty()) {
+%>
+ <br/><br/>No Result found<br/><br/>
+<%
}
}
%>
1
0
r11 - in trunk: . src/main/java/org/chorem/bow src/main/webapp
by bbrossaud@users.chorem.org 07 May '10
by bbrossaud@users.chorem.org 07 May '10
07 May '10
Author: bbrossaud
Date: 2010-05-07 12:35:52 +0200 (Fri, 07 May 2010)
New Revision: 11
Url: http://chorem.org/repositories/revision/bow/11
Log:
The research works now, the tags cloud diplay is OK
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-06 16:18:00 UTC (rev 10)
+++ trunk/pom.xml 2010-05-07 10:35:52 UTC (rev 11)
@@ -83,6 +83,12 @@
<artifactId>h2</artifactId>
<version>1.2.134</version>
</dependency>
+
+ <dependency>
+ <groupId>org.nuiton</groupId>
+ <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-06 16:18:00 UTC (rev 10)
+++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-07 10:35:52 UTC (rev 11)
@@ -12,6 +12,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.nuiton.util.StringUtil;
/**
*
@@ -53,28 +54,44 @@
}
public void createTagsCloud() {
+ tagsCloud.clear();
+ if (tagsSearch.isEmpty()) {
+ fillTagsCloud();
+ } else {
+ fillTagsCloudBySearch();
+ }
+ }
- Iterator itTags = tagsSearch.iterator();
+ protected void addBookmarkTagsToTagCloud(Bookmark bookmark) {
+ Set<String> tags = bookmark.getTags();
+ for (String tag : tags) {
+ if (!tagsSearch.contains(tag)) {
+ if (tagsCloud.containsKey(tag)) {
+ Integer count = tagsCloud.get(tag);
+ ++count;
+ tagsCloud.put(tag, count);
+ } else {
+ tagsCloud.put(tag, 1);
+ }
+ }
+ }
+ }
+ public void fillTagsCloud() {
+ for (Bookmark bookmark : bookmarks) {
+ addBookmarkTagsToTagCloud(bookmark);
+ }
+ }
+
+ public void fillTagsCloudBySearch() {
tagsCloud.clear();
- while (itTags.hasNext()) {
- String tag = (String) itTags.next();
- Iterator it = bookmarks.iterator();
- while (it.hasNext()) {
- Bookmark bookmark = (Bookmark) it.next();
+ for (String tag : tagsSearch) {
+ List<Bookmark> bookmarksList = new ArrayList<Bookmark>(bookmarks);
+ for (Bookmark bookmark : bookmarksList) {
if (bookmark.getTags().contains(tag) == false) {
- it.remove();
+ bookmarks.remove(bookmark);
} else {
- Set<String> tags = bookmark.getTags();
- for (String key : tags) {
- if (tagsCloud.containsKey(key)) {
- Integer count = tagsCloud.get(key);
- ++count;
- tagsCloud.put(key, count);
- } else {
- tagsCloud.put(key, 1);
- }
- }
+ addBookmarkTagsToTagCloud(bookmark);
}
}
}
@@ -87,7 +104,6 @@
tmax = -1;
tmin = -1;
int value;
-
while (it.hasNext()) {
value = (Integer) it.next();
if (tmax < value) {
@@ -108,7 +124,8 @@
}
public void addTags(String[] tags) {
- for (int i = 0; i < tags.length; i++) {
+ for (int i = 0; i
+ < tags.length; i++) {
if (!tagsSearch.contains(tags[i])) {
tagsSearch.add(tags[i]);
}
@@ -116,22 +133,11 @@
}
public String getSearchLine() {
- String line = "";
-
- Iterator it = tagsSearch.iterator();
-
- while (it.hasNext()) {
- String tag = (String) it.next();
- line += tag;
- if (it.hasNext())
- line += " ";
- }
- return line;
+ return StringUtil.join(tagsSearch, " ", true);
}
public int getFont(int ti) {
int font = 1;
-
if (tmax > tmin) {
font = (15 * (ti - tmin)) / (tmax - tmin);
}
@@ -141,6 +147,7 @@
public void reset() {
bookmarks.clear();
tagsCloud.clear();
+ tagsSearch.clear();
tmax = -1;
tmin = -1;
}
@@ -149,8 +156,13 @@
return tagsCloud;
}
+ public List<String> getTagsSearch() {
+ return tagsSearch;
+ }
+
public void setBookmarks(List<Bookmark> bookmarksList) {
- bookmarks = bookmarksList;
+ List<Bookmark> newList = new ArrayList(bookmarksList);
+ bookmarks = newList;
}
public int getTmin() {
Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-06 16:18:00 UTC (rev 10)
+++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-07 10:35:52 UTC (rev 11)
@@ -10,6 +10,7 @@
*/
import java.io.IOException;
import java.util.ArrayList;
+import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -50,6 +51,7 @@
String action = request.getParameter("action");
response.setContentType("text/html");
+ request.setAttribute("bookmarkActions", bookmarkActions);
if (action != null) {
if (action.equals("register")) {
log.debug("Going to actionRegister");
@@ -85,30 +87,30 @@
log.debug("URL = {" + url + "}");
log.debug("Adding URL");
}
- request.setAttribute("bookmarkActions", bookmarkActions);
request.getRequestDispatcher("search.jsp").forward(request, response);
}
protected void actionSearch(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String words = request.getParameter("words");
-
- request.setAttribute("bookmarkActions", bookmarkActions);
+ bookmarkActions.reset();
+ List<Bookmark> bookList = model.getProxy().
+ findAllByCriteria(Bookmark.class, null).getAll();
+ if (bookList != null) {
+ bookmarkActions.setBookmarks(bookList);
+ }
if (words != null) {
if (!words.isEmpty()) {
- if (bookmarkActions.getBookmarks().isEmpty()) {
- bookmarkActions.setBookmarks(new ArrayList(
- model.getProxy().findAllByCriteria(Bookmark.class, null).getAll()));
- }
- log.debug("ListSize before = {" + String.valueOf(bookmarkActions.getBookmarks().size()) + "}");
String[] tags = words.split("\\s+");
bookmarkActions.addTags(tags);
- bookmarkActions.createTagsCloud();
log.debug("TabSize = {" + String.valueOf(tags.length) + "}");
- log.debug("ListSize after = {" + String.valueOf(bookmarkActions.getBookmarks().size()) + "}");
}
}
- request.setAttribute("bookmarkActions", bookmarkActions);
+ log.debug("ListSize before = {" + String.valueOf(bookmarkActions.getBookmarks().size()) + "}");
+ log.debug("SearchLine = {" + words + "}");
+ bookmarkActions.createTagsCloud();
+ log.debug("TagCloudSize = {" + String.valueOf(bookmarkActions.getTagsCloud().size()) + "}");
+ log.debug("ListSize after = {" + String.valueOf(bookmarkActions.getBookmarks().size()) + "}");
request.getRequestDispatcher("search.jsp").forward(request, response);
}
@@ -127,6 +129,12 @@
request.getRequestDispatcher("error.jsp").forward(request, response);
} else {
log.debug("adding to the Databases");
+ List<Bookmark> bookList = model.getProxy().
+ findAllByCriteria(Bookmark.class, null).getAll();
+ if (bookList != null) {
+ bookmarkActions.setBookmarks(bookList);
+ }
+ bookmarkActions.createTagsCloud();
request.getRequestDispatcher("search.jsp").forward(request, response);
}
}
@@ -143,7 +151,12 @@
if (user != null) {
log.debug("User exists");
this.user = user;
- request.setAttribute("bookmarkActions", bookmarkActions);
+ List<Bookmark> bookList = model.getProxy().
+ findAllByCriteria(Bookmark.class, null).getAll();
+ if (bookList != null) {
+ bookmarkActions.setBookmarks(bookList);
+ }
+ bookmarkActions.createTagsCloud();
request.getRequestDispatcher("search.jsp").forward(request, response);
} else {
log.debug("User doesn't exist");
Modified: trunk/src/main/webapp/search.jsp
===================================================================
--- trunk/src/main/webapp/search.jsp 2010-05-06 16:18:00 UTC (rev 10)
+++ trunk/src/main/webapp/search.jsp 2010-05-07 10:35:52 UTC (rev 11)
@@ -1,9 +1,11 @@
<%@ page import="org.chorem.bow.BookmarkActions" %>
+<%@ page import="org.chorem.bow.Bookmark" %>
<%@ page import="java.util.HashMap" %>
<%@ 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" %>
<%BookmarkActions bookmarkActions = (BookmarkActions) request.getAttribute("bookmarkActions");%>
@@ -17,19 +19,39 @@
</form>
<form method="POST" action="search?action=check">
- <input type="text" name="words" size="20" value=<%=bookmarkActions.getSearchLine()%>><br />
+ <input type="text" name="words" size="20" value="<%=bookmarkActions.getSearchLine()%>" ><br />
<input type="submit" value="Find">
</form>
-<% if (bookmarkActions != null) {
+<% if (bookmarkActions != null) {
Map<String, Integer> tagsCloud = bookmarkActions.getTagsCloud();
Set<String> tags = tagsCloud.keySet();
for (String tag : tags) {
- int font = bookmarkActions.getFont(tagsCloud.get(tag));
+ int value = tagsCloud.get(tag);
+ int font = bookmarkActions.getFont(value);
%>
-<FONT SIZE=<%=font%>><%=tag%></FONT>
+
+<FONT SIZE="<%=font%>" ><%=tag%></FONT>
+
<%
-}}
+ }
+ List<String> tagsSearch = bookmarkActions.getTagsSearch();
+ List<Bookmark> bookmarkList = bookmarkActions.getBookmarks();
+ if (!tagsSearch.isEmpty() || bookmarkList.size() == 1) {
+ if (tagsCloud.isEmpty()) {
%>
+ RESULT:<br/>
+<%
+ for (Bookmark bookmark : bookmarkList) {
+%>
+
+<%=bookmark.getLink()%><br/>
+
+<%
+ }
+ }
+ }
+ }
+%>
</body>
</html>
\ No newline at end of file
1
0
06 May '10
Author: bbrossaud
Date: 2010-05-06 18:18:00 +0200 (Thu, 06 May 2010)
New Revision: 10
Url: http://chorem.org/repositories/revision/bow/10
Log:
Added the tags display which almost works
Modified:
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/src/main/java/org/chorem/bow/BookmarkActions.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-06 09:52:18 UTC (rev 9)
+++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-06 16:18:00 UTC (rev 10)
@@ -5,20 +5,25 @@
package org.chorem.bow;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
*
* @author bbrossaud
*/
-
public class BookmarkActions {
- List<Bookmark> bookmarks = new ArrayList<Bookmark>();
- Map<String, Integer> tagsCloud = new HashMap<String, Integer>();
+ protected List<Bookmark> bookmarks = new ArrayList<Bookmark>();
+ protected Map<String, Integer> tagsCloud = new HashMap<String, Integer>();
+ protected List<String> tagsSearch = new ArrayList<String>();
+ protected int tmax = -1;
+ protected int tmin = -1;
public Bookmark createBookmark(String query, User user) {
Bookmark bookmark = (Bookmark) new BookmarkImpl();
@@ -35,7 +40,6 @@
query = "";
}
}
-
} else {
bookmark.setLink(query);
}
@@ -49,9 +53,98 @@
}
public void createTagsCloud() {
- ;
+
+ Iterator itTags = tagsSearch.iterator();
+
+ tagsCloud.clear();
+ while (itTags.hasNext()) {
+ String tag = (String) itTags.next();
+ Iterator it = bookmarks.iterator();
+ while (it.hasNext()) {
+ Bookmark bookmark = (Bookmark) it.next();
+ if (bookmark.getTags().contains(tag) == false) {
+ it.remove();
+ } else {
+ Set<String> tags = bookmark.getTags();
+ for (String key : tags) {
+ if (tagsCloud.containsKey(key)) {
+ Integer count = tagsCloud.get(key);
+ ++count;
+ tagsCloud.put(key, count);
+ } else {
+ tagsCloud.put(key, 1);
+ }
+ }
+ }
+ }
+ }
+ this.defineTValues();
}
+ protected void defineTValues() {
+ Collection values = tagsCloud.values();
+ Iterator it = values.iterator();
+ tmax = -1;
+ tmin = -1;
+ int value;
+
+ while (it.hasNext()) {
+ value = (Integer) it.next();
+ if (tmax < value) {
+ tmax = value;
+ }
+ if (tmin == -1) {
+ tmin = value;
+ } else if (tmin > value) {
+ tmin = value;
+ }
+ }
+ }
+
+ public void addTag(String tag) {
+ if (!tagsSearch.contains(tag)) {
+ tagsSearch.add(tag);
+ }
+ }
+
+ public void addTags(String[] tags) {
+ for (int i = 0; i < tags.length; i++) {
+ if (!tagsSearch.contains(tags[i])) {
+ tagsSearch.add(tags[i]);
+ }
+ }
+ }
+
+ public String getSearchLine() {
+ String line = "";
+
+ Iterator it = tagsSearch.iterator();
+
+ while (it.hasNext()) {
+ String tag = (String) it.next();
+ line += tag;
+ if (it.hasNext())
+ line += " ";
+ }
+ return line;
+ }
+
+ public int getFont(int ti) {
+ int font = 1;
+
+ if (tmax > tmin) {
+ font = (15 * (ti - tmin)) / (tmax - tmin);
+ }
+ return font;
+ }
+
+ public void reset() {
+ bookmarks.clear();
+ tagsCloud.clear();
+ tmax = -1;
+ tmin = -1;
+ }
+
public Map<String, Integer> getTagsCloud() {
return tagsCloud;
}
@@ -59,4 +152,12 @@
public void setBookmarks(List<Bookmark> bookmarksList) {
bookmarks = bookmarksList;
}
+
+ public int getTmin() {
+ return tmin;
+ }
+
+ public int getTmax() {
+ return tmax;
+ }
}
Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-06 09:52:18 UTC (rev 9)
+++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-06 16:18:00 UTC (rev 10)
@@ -8,8 +8,8 @@
*
* @author bbrossaud
*/
-
import java.io.IOException;
+import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -23,9 +23,9 @@
public class ControllerServlet extends HttpServlet {
private static final Log log = LogFactory.getLog(ControllerServlet.class);
- private Model model = new Model();
- private BookmarkActions bookmarkActions = new BookmarkActions();
- private User user = null;
+ protected Model model = new Model();
+ protected BookmarkActions bookmarkActions = new BookmarkActions();
+ protected User user = null;
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
@@ -72,28 +72,47 @@
}
}
- private void actionAddUrl(HttpServletRequest request, HttpServletResponse response)
+ protected void actionAddUrl(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
+ String url = request.getParameter("url");
- if (request.getParameter("url") != null) {
+ if (url != null) {
bookmarkActions.getBookmarks().clear();
- Bookmark bookmark = bookmarkActions.createBookmark(request.getParameter("url"), user);
+ bookmarkActions.getTagsCloud().clear();
+ url = url.replaceAll("\\s*", "");
+ Bookmark bookmark = bookmarkActions.createBookmark(url, user);
model.getProxy().store(bookmark);
+ log.debug("URL = {" + url + "}");
log.debug("Adding URL");
- request.getRequestDispatcher("search.jsp").forward(request, response);
}
+ request.setAttribute("bookmarkActions", bookmarkActions);
+ request.getRequestDispatcher("search.jsp").forward(request, response);
}
- private void actionSearch(HttpServletRequest request, HttpServletResponse response)
+ protected void actionSearch(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
- if (bookmarkActions.getBookmarks().isEmpty()) {
- bookmarkActions.setBookmarks(model.getProxy().findAllByCriteria(Bookmark.class, null).getAll());
-
+ String words = request.getParameter("words");
+
+ request.setAttribute("bookmarkActions", bookmarkActions);
+ if (words != null) {
+ if (!words.isEmpty()) {
+ if (bookmarkActions.getBookmarks().isEmpty()) {
+ bookmarkActions.setBookmarks(new ArrayList(
+ model.getProxy().findAllByCriteria(Bookmark.class, null).getAll()));
+ }
+ log.debug("ListSize before = {" + String.valueOf(bookmarkActions.getBookmarks().size()) + "}");
+ String[] tags = words.split("\\s+");
+ bookmarkActions.addTags(tags);
+ bookmarkActions.createTagsCloud();
+ log.debug("TabSize = {" + String.valueOf(tags.length) + "}");
+ log.debug("ListSize after = {" + String.valueOf(bookmarkActions.getBookmarks().size()) + "}");
+ }
}
- log.debug("ListSize = {"+String.valueOf(bookmarkActions.getBookmarks().size())+"}");
+ request.setAttribute("bookmarkActions", bookmarkActions);
+ request.getRequestDispatcher("search.jsp").forward(request, response);
}
- private void actionRegister(HttpServletRequest request, HttpServletResponse response)
+ protected void actionRegister(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
try {
if (this.checkRegister(request, response)) {
@@ -111,13 +130,12 @@
request.getRequestDispatcher("search.jsp").forward(request, response);
}
}
- }
- catch (Exception eee) {
+ } catch (Exception eee) {
request.getRequestDispatcher("error.jsp").forward(request, response);
}
}
- private void actionLogin(HttpServletRequest request, HttpServletResponse response)
+ protected void actionLogin(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
try {
User user = this.checkLogin(request, response);
@@ -125,6 +143,7 @@
if (user != null) {
log.debug("User exists");
this.user = user;
+ request.setAttribute("bookmarkActions", bookmarkActions);
request.getRequestDispatcher("search.jsp").forward(request, response);
} else {
log.debug("User doesn't exist");
@@ -136,7 +155,7 @@
}
- private User checkLogin(HttpServletRequest request, HttpServletResponse response)
+ protected User checkLogin(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String email = request.getParameter("email");
String password = request.getParameter("password");
@@ -151,12 +170,12 @@
return null;
}
- private boolean checkRegister(HttpServletRequest request, HttpServletResponse response)
+ protected boolean checkRegister(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String email = request.getParameter("email");
String password = request.getParameter("password");
- log.debug("email={"+email+"}");
+ log.debug("email={" + email + "}");
if (!email.isEmpty() && !password.isEmpty()) {
WikittyProxy proxy = model.getProxy();
Modified: trunk/src/main/webapp/search.jsp
===================================================================
--- trunk/src/main/webapp/search.jsp 2010-05-06 09:52:18 UTC (rev 9)
+++ trunk/src/main/webapp/search.jsp 2010-05-06 16:18:00 UTC (rev 10)
@@ -1,3 +1,12 @@
+<%@ page import="org.chorem.bow.BookmarkActions" %>
+<%@ page import="java.util.HashMap" %>
+<%@ page import="java.util.Iterator" %>
+<%@ page import="java.util.Map" %>
+<%@ page import="java.util.Set" %>
+<%@ page import="java.util.ArrayList" %>
+
+<%BookmarkActions bookmarkActions = (BookmarkActions) request.getAttribute("bookmarkActions");%>
+
<html>
<body>
<h1>Search</h1>
@@ -8,9 +17,19 @@
</form>
<form method="POST" action="search?action=check">
- <input type="text" name="words" size="20"><br />
+ <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 font = bookmarkActions.getFont(tagsCloud.get(tag));
+%>
+<FONT SIZE=<%=font%>><%=tag%></FONT>
+<%
+}}
+%>
</body>
</html>
\ No newline at end of file
1
0
06 May '10
Author: bbrossaud
Date: 2010-05-06 11:52:18 +0200 (Thu, 06 May 2010)
New Revision: 9
Url: http://chorem.org/repositories/revision/bow/9
Log:
The URL addition works if the syntax is good
Removed:
trunk/src/main/java/org/chorem/bow/Bookmark.java
trunk/src/main/java/org/chorem/bow/Token.java
trunk/src/main/java/org/chorem/bow/User.java
Modified:
trunk/src/main/java/org/chorem/bow/BookmarkActions.java
trunk/src/main/java/org/chorem/bow/ControllerServlet.java
trunk/src/main/webapp/search.jsp
Deleted: trunk/src/main/java/org/chorem/bow/Bookmark.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/Bookmark.java 2010-05-06 08:58:08 UTC (rev 8)
+++ trunk/src/main/java/org/chorem/bow/Bookmark.java 2010-05-06 09:52:18 UTC (rev 9)
@@ -1,16 +0,0 @@
-import java.util.List;
-import java.util.Date;
-
-public class Bookmark {
-
- public String link;
-
- public String description;
-
- public List tags;
-
- public Date date;
-
- public String email;
-
-}
\ 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-06 08:58:08 UTC (rev 8)
+++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-06 09:52:18 UTC (rev 9)
@@ -6,7 +6,9 @@
import java.util.ArrayList;
import java.util.Date;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
*
@@ -16,6 +18,7 @@
public class BookmarkActions {
List<Bookmark> bookmarks = new ArrayList<Bookmark>();
+ Map<String, Integer> tagsCloud = new HashMap<String, Integer>();
public Bookmark createBookmark(String query, User user) {
Bookmark bookmark = (Bookmark) new BookmarkImpl();
@@ -44,4 +47,16 @@
public List<Bookmark> getBookmarks() {
return bookmarks;
}
+
+ public void createTagsCloud() {
+ ;
+ }
+
+ public Map<String, Integer> getTagsCloud() {
+ return tagsCloud;
+ }
+
+ public void setBookmarks(List<Bookmark> bookmarksList) {
+ bookmarks = bookmarksList;
+ }
}
Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-06 08:58:08 UTC (rev 8)
+++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-06 09:52:18 UTC (rev 9)
@@ -17,7 +17,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sharengo.wikitty.Criteria;
-import org.sharengo.wikitty.WikittyException;
import org.sharengo.wikitty.WikittyProxy;
import org.sharengo.wikitty.search.Search;
@@ -28,6 +27,7 @@
private BookmarkActions bookmarkActions = new BookmarkActions();
private User user = null;
+ @Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String action = request.getParameter("action");
@@ -44,6 +44,7 @@
}
}
+ @Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String action = request.getParameter("action");
@@ -59,11 +60,11 @@
} else if (action.equals("addUrl")) {
log.debug("Going to actionAddUrl");
this.actionAddUrl(request, response);
- } else if (action.equals("addUrl")) {
+ } else if (action.equals("check")) {
log.debug("Going to actionSearch");
this.actionSearch(request, response);
} else {
- log.debug("Default");
+ log.debug("Going to home");
request.getRequestDispatcher("home.jsp").forward(request, response);
}
} else {
@@ -75,17 +76,21 @@
throws IOException, ServletException {
if (request.getParameter("url") != null) {
+ bookmarkActions.getBookmarks().clear();
Bookmark bookmark = bookmarkActions.createBookmark(request.getParameter("url"), user);
model.getProxy().store(bookmark);
- request.getRequestDispatcher("error.jsp").forward(request, response);
+ log.debug("Adding URL");
+ request.getRequestDispatcher("search.jsp").forward(request, response);
}
}
private void actionSearch(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
if (bookmarkActions.getBookmarks().isEmpty()) {
-
+ bookmarkActions.setBookmarks(model.getProxy().findAllByCriteria(Bookmark.class, null).getAll());
+
}
+ log.debug("ListSize = {"+String.valueOf(bookmarkActions.getBookmarks().size())+"}");
}
private void actionRegister(HttpServletRequest request, HttpServletResponse response)
@@ -118,11 +123,11 @@
User user = this.checkLogin(request, response);
if (user != null) {
- log.debug("User is different from null");
+ log.debug("User exists");
this.user = user;
request.getRequestDispatcher("search.jsp").forward(request, response);
} else {
- log.debug("The user doesn't exist");
+ log.debug("User doesn't exist");
request.getRequestDispatcher("home.jsp").forward(request, response);
}
} catch (Exception eee) {
@@ -139,8 +144,6 @@
if (!email.isEmpty() && !password.isEmpty()) {
WikittyProxy proxy = model.getProxy();
- log.debug("email={"+email+"}");
- log.debug("password={"+password+"}");
Criteria criteria = Search.query().eq(User.FQ_FIELD_EMAIL, email).eq(User.FQ_FIELD_PASSWORD, password).criteria();
return proxy.findByCriteria(User.class, criteria);
}
Deleted: trunk/src/main/java/org/chorem/bow/Token.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/Token.java 2010-05-06 08:58:08 UTC (rev 8)
+++ trunk/src/main/java/org/chorem/bow/Token.java 2010-05-06 09:52:18 UTC (rev 9)
@@ -1,7 +0,0 @@
-public class Token {
-
- public String token;
-
- public String email;
-
-}
\ No newline at end of file
Deleted: trunk/src/main/java/org/chorem/bow/User.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/User.java 2010-05-06 08:58:08 UTC (rev 8)
+++ trunk/src/main/java/org/chorem/bow/User.java 2010-05-06 09:52:18 UTC (rev 9)
@@ -1,7 +0,0 @@
-public class User {
-
- public String password;
-
- public String email;
-
-}
\ No newline at end of file
Modified: trunk/src/main/webapp/search.jsp
===================================================================
--- trunk/src/main/webapp/search.jsp 2010-05-06 08:58:08 UTC (rev 8)
+++ trunk/src/main/webapp/search.jsp 2010-05-06 09:52:18 UTC (rev 9)
@@ -9,7 +9,7 @@
<form method="POST" action="search?action=check">
<input type="text" name="words" size="20"><br />
- <input type="submit" value="OK">
+ <input type="submit" value="Find">
</form>
</body>
1
0
r8 - in trunk/src/main: java/org/chorem/bow resources webapp
by bbrossaud@users.chorem.org 06 May '10
by bbrossaud@users.chorem.org 06 May '10
06 May '10
Author: bbrossaud
Date: 2010-05-06 10:58:08 +0200 (Thu, 06 May 2010)
New Revision: 8
Url: http://chorem.org/repositories/revision/bow/8
Log:
Database is now configurated and added BookmarkActions which manages the bookmarkes
Added:
trunk/src/main/java/org/chorem/bow/BookmarkActions.java
trunk/src/main/resources/log4j.properties
trunk/src/main/resources/wikitty-jdbc-config.properties
Modified:
trunk/src/main/java/org/chorem/bow/ControllerServlet.java
trunk/src/main/java/org/chorem/bow/Model.java
trunk/src/main/webapp/search.jsp
Added: trunk/src/main/java/org/chorem/bow/BookmarkActions.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/BookmarkActions.java (rev 0)
+++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-06 08:58:08 UTC (rev 8)
@@ -0,0 +1,47 @@
+/*
+ * 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.Date;
+import java.util.List;
+
+/**
+ *
+ * @author bbrossaud
+ */
+
+public class BookmarkActions {
+
+ List<Bookmark> bookmarks = new ArrayList<Bookmark>();
+
+ public Bookmark createBookmark(String query, User user) {
+ Bookmark bookmark = (Bookmark) new BookmarkImpl();
+
+ if (query.indexOf('|') > 0) {
+ bookmark.setLink(query.substring(0, query.indexOf('|')));
+ query = query.substring(query.indexOf('|') + 1);
+ while (!query.isEmpty()) {
+ if (query.indexOf(',') > 0) {
+ bookmark.addTags(query.substring(0, query.indexOf(',')));
+ query = query.substring(query.indexOf(',') + 1);
+ } else {
+ bookmark.addTags(query.substring(0, query.length()));
+ query = "";
+ }
+ }
+
+ } else {
+ bookmark.setLink(query);
+ }
+ bookmark.setEmail(user.getEmail());
+ bookmark.setDate(new Date());
+ return bookmark;
+ }
+
+ public List<Bookmark> getBookmarks() {
+ return bookmarks;
+ }
+}
Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-05 08:56:11 UTC (rev 7)
+++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-06 08:58:08 UTC (rev 8)
@@ -8,11 +8,14 @@
*
* @author bbrossaud
*/
+
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.sharengo.wikitty.Criteria;
import org.sharengo.wikitty.WikittyException;
import org.sharengo.wikitty.WikittyProxy;
@@ -20,7 +23,9 @@
public class ControllerServlet extends HttpServlet {
+ private static final Log log = LogFactory.getLog(ControllerServlet.class);
private Model model = new Model();
+ private BookmarkActions bookmarkActions = new BookmarkActions();
private User user = null;
public void doGet(HttpServletRequest request, HttpServletResponse response)
@@ -46,10 +51,19 @@
response.setContentType("text/html");
if (action != null) {
if (action.equals("register")) {
+ log.debug("Going to actionRegister");
this.actionRegister(request, response);
} else if (action.equals("login")) {
+ log.debug("Going to actionLogin");
this.actionLogin(request, response);
+ } else if (action.equals("addUrl")) {
+ log.debug("Going to actionAddUrl");
+ this.actionAddUrl(request, response);
+ } else if (action.equals("addUrl")) {
+ log.debug("Going to actionSearch");
+ this.actionSearch(request, response);
} else {
+ log.debug("Default");
request.getRequestDispatcher("home.jsp").forward(request, response);
}
} else {
@@ -57,6 +71,23 @@
}
}
+ private void actionAddUrl(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException {
+
+ if (request.getParameter("url") != null) {
+ Bookmark bookmark = bookmarkActions.createBookmark(request.getParameter("url"), user);
+ model.getProxy().store(bookmark);
+ request.getRequestDispatcher("error.jsp").forward(request, response);
+ }
+ }
+
+ private void actionSearch(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException {
+ if (bookmarkActions.getBookmarks().isEmpty()) {
+
+ }
+ }
+
private void actionRegister(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
try {
@@ -67,9 +98,16 @@
newUser.setPassword(request.getParameter("password"));
newUser.setEmail(request.getParameter("email"));
this.user = model.getProxy().store((User) newUser);
- request.getRequestDispatcher("search.jsp").forward(request, response);
+ if (user == null) {
+ log.debug("Not put in the Databases");
+ request.getRequestDispatcher("error.jsp").forward(request, response);
+ } else {
+ log.debug("adding to the Databases");
+ request.getRequestDispatcher("search.jsp").forward(request, response);
+ }
}
- } catch (Exception eee) {
+ }
+ catch (Exception eee) {
request.getRequestDispatcher("error.jsp").forward(request, response);
}
}
@@ -80,9 +118,11 @@
User user = this.checkLogin(request, response);
if (user != null) {
+ log.debug("User is different from null");
this.user = user;
request.getRequestDispatcher("search.jsp").forward(request, response);
} else {
+ log.debug("The user doesn't exist");
request.getRequestDispatcher("home.jsp").forward(request, response);
}
} catch (Exception eee) {
@@ -99,9 +139,12 @@
if (!email.isEmpty() && !password.isEmpty()) {
WikittyProxy proxy = model.getProxy();
+ log.debug("email={"+email+"}");
+ log.debug("password={"+password+"}");
Criteria criteria = Search.query().eq(User.FQ_FIELD_EMAIL, email).eq(User.FQ_FIELD_PASSWORD, password).criteria();
return proxy.findByCriteria(User.class, criteria);
}
+ log.debug("Empty password or email");
return null;
}
@@ -110,11 +153,13 @@
String email = request.getParameter("email");
String password = request.getParameter("password");
+ log.debug("email={"+email+"}");
if (!email.isEmpty() && !password.isEmpty()) {
WikittyProxy proxy = model.getProxy();
Criteria criteria = Search.query().eq(User.FQ_FIELD_EMAIL, email).criteria();
if (proxy.findByCriteria(User.class, criteria) == null) {
+ log.debug("No user with this email");
return false;
}
}
Modified: trunk/src/main/java/org/chorem/bow/Model.java
===================================================================
--- trunk/src/main/java/org/chorem/bow/Model.java 2010-05-05 08:56:11 UTC (rev 7)
+++ trunk/src/main/java/org/chorem/bow/Model.java 2010-05-06 08:58:08 UTC (rev 8)
@@ -24,11 +24,11 @@
protected WikittyProxy proxy = null;
Model() {
+ System.setProperty("solr.data.dir", System.getProperty("user.home") + "/databases/bow/solr");
this.init();
}
public void init() {
-
MultiStorageConfiguration config = new BasicConfiguration();
this.configureJDBC(config);
Added: trunk/src/main/resources/log4j.properties
===================================================================
--- trunk/src/main/resources/log4j.properties (rev 0)
+++ trunk/src/main/resources/log4j.properties 2010-05-06 08:58:08 UTC (rev 8)
@@ -0,0 +1,10 @@
+# Global logging configuration
+log4j.rootLogger=WARN, stdout
+
+# Console output...
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d %5p [%t] (%F:%L) %M - %m%n
+
+# package level
+log4j.logger.org.chorem.bow=DEBUG
Added: trunk/src/main/resources/wikitty-jdbc-config.properties
===================================================================
--- trunk/src/main/resources/wikitty-jdbc-config.properties (rev 0)
+++ trunk/src/main/resources/wikitty-jdbc-config.properties 2010-05-06 08:58:08 UTC (rev 8)
@@ -0,0 +1,5 @@
+#Connection parameters
+jdbc.con.driver=org.h2.Driver
+jdbc.con.host=jdbc:h2:file:/home/bbrossaud/projets/bow/solr
+jdbc.con.userName=sa
+jdbc.con.password=
Modified: trunk/src/main/webapp/search.jsp
===================================================================
--- trunk/src/main/webapp/search.jsp 2010-05-05 08:56:11 UTC (rev 7)
+++ trunk/src/main/webapp/search.jsp 2010-05-06 08:58:08 UTC (rev 8)
@@ -3,7 +3,7 @@
<h1>Search</h1>
<form method="POST" action="search?action=addUrl">
- URL <input type="text" name="url" size="20"><br />
+ URL <input type="text" name="url" size="20" value="URL|tag1,tag2..."><br />
<input type="submit" value="add">
</form>
1
0