r8 - in trunk/src/main: java/org/chorem/bow resources webapp
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>
participants (1)
-
bbrossaudï¼ users.chorem.org