Author: bbrossaud Date: 2010-05-28 14:47:46 +0200 (Fri, 28 May 2010) New Revision: 37 Url: http://chorem.org/repositories/revision/bow/37 Log: addtion alias for url Modified: trunk/pom.xml trunk/src/main/java/org/chorem/bow/BookmarkActions.java trunk/src/main/java/org/chorem/bow/ControllerServlet.java trunk/src/main/java/org/chorem/bow/Model.java trunk/src/main/java/org/chorem/bow/TokenActions.java trunk/src/main/webapp/WEB-INF/web.xml trunk/src/main/webapp/home.jsp trunk/src/main/webapp/login.jsp trunk/src/main/webapp/openSearchResult.jsp trunk/src/main/webapp/register.jsp trunk/src/main/webapp/search.jsp trunk/src/main/xmi/bow.zargo Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-05-27 15:21:05 UTC (rev 36) +++ trunk/pom.xml 2010-05-28 12:47:46 UTC (rev 37) @@ -132,6 +132,16 @@ <build> + <resources> + <resource> + <directory>src/main/resources</directory> + <includes> + <include>**/*</include> + </includes> + <filtering>true</filtering> + </resource> + </resources> + <pluginManagement> <plugins> <plugin> Modified: trunk/src/main/java/org/chorem/bow/BookmarkActions.java =================================================================== --- trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-27 15:21:05 UTC (rev 36) +++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-05-28 12:47:46 UTC (rev 37) @@ -4,7 +4,6 @@ */ package org.chorem.bow; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -58,9 +57,9 @@ export += bookmark.getLink() + "\" "; Date date = bookmark.getDate(); if (date != null) { - SimpleDateFormat sdf = new SimpleDateFormat("ss"); - String time = sdf.format(date); - export += "ADD_DATE=\"" + time + "\" LAST_MODIFIED=\"" + time + "\""; + long milli = date.getTime(); + String time = String.valueOf(milli / 1000); + export += "ADD_DATE=\"" + time + "\" LAST_MODIFIED=\"" + time + "\" "; } export += "LAST_CHARSET=\"UTF-8\" "; Set<String> tags = bookmark.getTags(); @@ -126,13 +125,14 @@ bookmark.setClick(0); bookmark.setEmail(user.getEmail()); // set the email (user name) bookmark.setDate(new Date()); // set the date + bookmark.setAlias(""); return bookmark; } public static void addUrlToBookmark(String url, Bookmark bookmark) { if (url != null && !url.isEmpty()) { String link = url.trim(); - if (!link.contains("http://")) { + if (!link.contains("://")) { link = "http://" + link; } bookmark.setLink(link); @@ -179,6 +179,7 @@ date = new Date(); } bookmark.setDate(date); // set the date + bookmark.setAlias(""); return bookmark; } Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java =================================================================== --- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-27 15:21:05 UTC (rev 36) +++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-28 12:47:46 UTC (rev 37) @@ -32,6 +32,8 @@ import org.htmlparser.util.NodeList; import org.htmlparser.util.ParserException; import org.htmlparser.util.SimpleNodeIterator; +import org.nuiton.util.ApplicationConfig; +import org.nuiton.util.ArgumentsParserException; import org.nuiton.wikitty.Criteria; import org.nuiton.wikitty.WikittyProxy; import org.nuiton.wikitty.search.Search; @@ -44,7 +46,16 @@ private static final Log log = LogFactory.getLog(ControllerServlet.class); protected Model model = new Model(); + protected String version = ""; + + public ControllerServlet() throws ArgumentsParserException { + ApplicationConfig config = new ApplicationConfig(); + config.setConfigFileName("bow.properties"); + config.parse(new String[]{}); + version = config.getOption("application.version"); + } + @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { @@ -59,6 +70,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { try { + request.setAttribute("version", version); HttpSession session = request.getSession(true); User user = (User) session.getAttribute("user"); String token = request.getParameter("token"); // token or not @@ -84,7 +96,7 @@ this.actionLogin(request, response, session); } else if (action.equals("logout")) { if (log.isDebugEnabled()) { - log.debug("Going to actionLogin"); + log.debug("Going to actionLogout"); } this.actionLogout(request, response, session); } else if (action.equals("home") && user != null) { @@ -124,6 +136,11 @@ log.debug("Going to actionDeleteTag"); } this.actionDeleteTag(request, response, user); + } else if (action.equals("addAlias") && user != null) { + if (log.isDebugEnabled()) { + log.debug("Going to actionAddAlias"); + } + this.actionAddAlias(request, response); } else if (action.equals("removeBookmark") && user != null) { if (log.isDebugEnabled()) { log.debug("Going to actionRemoveBookmark"); @@ -186,20 +203,13 @@ this.actionOpenSearchResult(request, response, user, token); request.getRequestDispatcher("openSearchResult.jsp").forward(request, response); } else { - if (log.isDebugEnabled()) { - log.debug("Going to home"); - } - request.getRequestDispatcher("login.jsp").forward(request, response); + request.getRequestDispatcher("error.jsp").forward(request, response); } } else { - if (log.isDebugEnabled()) { - log.debug("Going to home"); - } request.getRequestDispatcher("login.jsp").forward(request, response); } } catch (Exception eee) { - //request.getRequestDispatcher("error.jsp").forward(request, response); - throw new ServletException("DO GET ERROR", eee); + request.getRequestDispatcher("error.jsp").forward(request, response); } } @@ -713,4 +723,30 @@ op.flush(); op.close(); } + + private void actionAddAlias(HttpServletRequest request, HttpServletResponse response) + throws IOException { + String alias = request.getParameter("alias"); + if (alias != null && !alias.isEmpty()) { + WikittyProxy proxy = model.getProxy(); + Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_ALIAS, alias).criteria(); + List<Bookmark> bookmarks = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); + if (bookmarks == null || bookmarks.isEmpty()) { + String id = request.getParameter("bookmarkId"); + if (id != null && !id.isEmpty()) { + Bookmark bookmark = proxy.restore(Bookmark.class, id); + if (bookmark != null) { + bookmark.setAlias(alias); + proxy.store(bookmark); + } + } + } + } + String searchLine = request.getParameter("searchLine"); + if (searchLine != null) { + response.sendRedirect("bow?action=search&searchLine=" + searchLine); + } else { + response.sendRedirect("bow?action=home"); + } + } } Modified: trunk/src/main/java/org/chorem/bow/Model.java =================================================================== --- trunk/src/main/java/org/chorem/bow/Model.java 2010-05-27 15:21:05 UTC (rev 36) +++ trunk/src/main/java/org/chorem/bow/Model.java 2010-05-28 12:47:46 UTC (rev 37) @@ -30,7 +30,7 @@ public void init() { MultiStorageConfiguration config = new BasicConfiguration(); - this.configureJDBC(config); + Model.configureJDBC(config); WikittyService jdbcStorage = new WikittyServiceMultiStorage(config); proxy = new WikittyProxy(); Modified: trunk/src/main/java/org/chorem/bow/TokenActions.java =================================================================== --- trunk/src/main/java/org/chorem/bow/TokenActions.java 2010-05-27 15:21:05 UTC (rev 36) +++ trunk/src/main/java/org/chorem/bow/TokenActions.java 2010-05-28 12:47:46 UTC (rev 37) @@ -27,8 +27,8 @@ public String generateToken() throws NoSuchAlgorithmException { - Double rand = Math.random() * 1000000; - int res = (int) Math.abs(rand); // generate a token between 0 and 1 000 000 + Double rand = Math.random() * 100000000; + int res = (int) Math.abs(rand); // generate a token between 0 and 100 000 000 String tokenGenerated = String.valueOf(res); tokenGenerated = StringUtil.encodeMD5(tokenGenerated); // encode the token in MD5 return tokenGenerated; // return the generate token Modified: trunk/src/main/webapp/WEB-INF/web.xml =================================================================== --- trunk/src/main/webapp/WEB-INF/web.xml 2010-05-27 15:21:05 UTC (rev 36) +++ trunk/src/main/webapp/WEB-INF/web.xml 2010-05-28 12:47:46 UTC (rev 37) @@ -8,11 +8,20 @@ <servlet-name>Controller</servlet-name> </servlet> - <welcome-file-list> - <welcome-file>login.jsp</welcome-file> - </welcome-file-list> + <servlet> + <servlet-class>org.chorem.bow.AliasServlet</servlet-class> + <servlet-name>Alias</servlet-name> + </servlet> + <welcome-file-list> + <welcome-file>bow</welcome-file> + </welcome-file-list> + <listener> + <listener-class>org.chorem.bow.ControllerServlet</listener-class> + </listener> + + <!-- SERVLET MAPPING --> <servlet-mapping> @@ -20,4 +29,9 @@ <url-pattern>/bow</url-pattern> </servlet-mapping> + <servlet-mapping> + <servlet-name>Alias</servlet-name> + <url-pattern>/alias/*</url-pattern> + </servlet-mapping> + </web-app> \ No newline at end of file Modified: trunk/src/main/webapp/home.jsp =================================================================== --- trunk/src/main/webapp/home.jsp 2010-05-27 15:21:05 UTC (rev 36) +++ trunk/src/main/webapp/home.jsp 2010-05-28 12:47:46 UTC (rev 37) @@ -15,13 +15,10 @@ String temporaryToken = tokenActions.getTemporaryToken(); String permanentToken = tokenActions.getPermanentToken(); BookmarkActions bookmarkActions = (BookmarkActions) request.getAttribute("bookmarkActions"); - String searchLine = ""; - if (bookmarkActions != null) { - searchLine = bookmarkActions.getSearchLine(); - } String url = request.getRequestURL().toString(); int index = url.indexOf("home.jsp"); url = url.substring(0, index); + String version = (String) request.getAttribute("version"); %> <html> @@ -68,8 +65,12 @@ <td class="result"> <%=sdf.format(bookmark.getDate())%> </td> - <td class="result"> - <a href="bow?action=addClick&bookmarkId=<%=bookmark.getWikittyId()%>" target="_blank"><%=bookmark.getDescription()%></a> + <td class="result" style="text-align: left"> + <a href="bow?action=addAlias&bookmarkId=<%=bookmark.getWikittyId()%>" target="_blank"><%=bookmark.getDescription()%></a> + <form method="POST" action="bow?action=addAlias&bookmarkId=<%=bookmark.getWikittyId()%>" style="display: inline"> + <input type="text" name="alias" size="10" value="<%=bookmark.getAlias()%>" /> + <input style="display: inline;" type="submit" value="Add alias" /> + </form> <form method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>"> <input type="text" name="name" size="35" value="<%=bookmark.getDescription()%>" /> <input type="image" src="img/edit.png" title="Edit"/> @@ -139,9 +140,13 @@ <td class="result"> <%=sdf.format(bookmark.getDate())%> </td> - <td class="result"> + <td class="result" style="text-align: left"> <a href="bow?action=addClick&bookmarkId=<%=bookmark.getWikittyId()%>" target="_blank"><%=bookmark.getDescription()%></a> - <form method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>&searchLine=<%=searchLine%>"> + <form method="POST" action="bow?action=addAlias&bookmarkId=<%=bookmark.getWikittyId()%>" style="display: inline"> + <input type="text" name="alias" size="10" value="<%=bookmark.getAlias()%>" /> + <input style="display: inline;" type="submit" value="Add alias" /> + </form> + <form method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>"> <input type="text" name="name" size="35" value="<%=bookmark.getDescription()%>" /> <input type="image" src="img/edit.png" title="Edit"/> </form> @@ -154,7 +159,7 @@ %> <div style="display: inline"> <a style="text-decoration:none" href="bow?action=deleteTag&bookmarkId=<%=bookmark.getWikittyId()%>&deleteTag=<%=tag%>"> - <IMG style="border:none" SRC="img/delete.png" ALT="Delete tag" TITLE="Delete" /> + <IMG style="border:none;" SRC="img/delete.png" ALT="Delete tag" TITLE="Delete" /> </a> <%=tag%> </div> @@ -164,7 +169,7 @@ %> <form method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>"> <input type="text" name="tags" size="35" value="<%=BookmarkActions.getBookmarkTagsString(bookmark)%>" /> - <input type="image" src="img/edit.png" title="Edit"/> + <input style="display: inline" type="image" src="img/edit.png" title="Edit"/> </form> </td> <td class="result"> @@ -190,7 +195,7 @@ <li><a href="bow?action=logout">Logout</a></li> <li><a href="javascript:var%20url=location.href;var%20nameAndTags=prompt('Entrez%20le%20nom%20du%20lien%20et%20la%20liste%20des%20tags%20sous%20la%20forme:%20name|tag1%20tag2%20tag3',%20document.title+'|');var%20link='<%=url%>bow?action=addUrl&token=<%=temporaryToken%>&url='+encodeURIComponent(url)+'&nameAndTags='+encodeURIComponent(nameAndTags);var%20script=document.createElement('script');script.src=link;script.type='text/javascript';document.body.appendChild(script);void(0);">Temporary token</a></li> <li><a href="javascript:var%20url=location.href;var%20nameAndTags=prompt('Entrez%20le%20nom%20du%20lien%20et%20la%20liste%20des%20tags%20sous%20la%20forme:%20name|tag1%20tag2%20tag3',%20document.title+'|');var%20link='<%=url%>bow?action=addUrl&token=<%=permanentToken%>&url='+encodeURIComponent(url)+'&nameAndTags='+encodeURIComponent(nameAndTags);var%20script=document.createElement('script');script.src=link;script.type='text/javascript';document.body.appendChild(script);void(0);">Current permanent token</a></li> - <li><a href="bow?action=generateToken&searchLine=<%=searchLine%>">Regenerate permanent token</a></li> + <li><a href="bow?action=generateToken">Regenerate permanent token</a></li> </ul> </div> <div class="menu"> @@ -214,13 +219,13 @@ int value = tagsCloud.get(tag); int font = bookmarkActions.getFont(value); %> - <a href="bow?action=search&addTag=<%=tag%>&searchLine=<%=searchLine%>" title="<%=value%> results" class="tag" style="font-size: <%=font%>px;"><%=tag%></a> + <a href="bow?action=search&addTag=<%=tag%>" title="<%=value%> results" class="tag" style="font-size: <%=font%>px;"><%=tag%></a> <% } } %> <form method="POST" action="bow?action=search" style="text-align: center;margin-left: 20px;"> - <input style="float: left" type="text" name="searchLine" size="15" value="<%=searchLine%>" /> + <input style="float: left" type="text" name="searchLine" size="15" /> <input style="float: left;" type="submit" value="Find" /> </form> </div> @@ -235,5 +240,14 @@ <a href="bow?action=exportBookmarks">Export bookmarks</a> </div> </div> + <div class="Index" id="footer"> + <a shape="rect" href="<%=url%>">bow</a> + <a shape="rect" href="http://www.chorem.org/projects/list_files/bow"><%=version%></a> - + <a shape="rect" href="http://www.gnu.org/licenses/agpl.html">Licence AGPL</a> - + <span title="Copyright">©2010</span> + <a shape="rect" href="http://www.codelutin.com">Code Lutin</a> - + <a shape="rect" href="http://www.chorem.org/projects/bow/issues">Rapport de bug</a> - + <a shape="rect" href="http://list.chorem.org/cgi-bin/mailman/listinfo/bow-users">Support utilisateur</a> + </div> </body> </html> \ No newline at end of file Modified: trunk/src/main/webapp/login.jsp =================================================================== --- trunk/src/main/webapp/login.jsp 2010-05-27 15:21:05 UTC (rev 36) +++ trunk/src/main/webapp/login.jsp 2010-05-28 12:47:46 UTC (rev 37) @@ -1,6 +1,8 @@ <%@page contentType="text/html" pageEncoding="UTF-8"%> <% String error = (String) request.getAttribute("msgError"); + String url = request.getRequestURL().toString(); + String version = (String) request.getAttribute("version"); %> <html> @@ -19,5 +21,14 @@ <%if (error != null) {%> <font color="red"><%=error%></font> <%}%> + <div class="Index" id="footer"> + <a shape="rect" href="<%=url%>">bow</a> + <a shape="rect" href="http://www.chorem.org/projects/list_files/bow"><%=version%></a> - + <a shape="rect" href="http://www.gnu.org/licenses/agpl.html">Licence AGPL</a> - + <span title="Copyright">©2010</span> + <a shape="rect" href="http://www.codelutin.com">Code Lutin</a> - + <a shape="rect" href="http://www.chorem.org/projects/bow/issues">Rapport de bug</a> - + <a shape="rect" href="http://list.chorem.org/cgi-bin/mailman/listinfo/bow-users">Support utilisateur</a> + </div> </body> </html> \ No newline at end of file Modified: trunk/src/main/webapp/openSearchResult.jsp =================================================================== --- trunk/src/main/webapp/openSearchResult.jsp 2010-05-27 15:21:05 UTC (rev 36) +++ trunk/src/main/webapp/openSearchResult.jsp 2010-05-28 12:47:46 UTC (rev 37) @@ -74,9 +74,9 @@ </td> <td class="result"> <% - Set<String> tagList = bookmark.getTags(); - if (tagList != null && !tagList.isEmpty()) { - for (String tag : tagList) { + Set<String> tagList = bookmark.getTags(); + if (tagList != null && !tagList.isEmpty()) { + for (String tag : tagList) { %> <%=tag%> <% @@ -84,7 +84,7 @@ %> </td> <% - } + } %> <td class="result"> <%=bookmark.getClick()%> @@ -101,5 +101,14 @@ <% } } %> + <div class="Index" id="footer"> + <a shape="rect" href="<%=url%>">bow</a> + <a shape="rect" href="http://www.chorem.org/projects/list_files/bow"></a> - + <a shape="rect" href="http://www.gnu.org/licenses/agpl.html">Licence AGPL</a> - + <span title="Copyright">©2009-2010</span> + <a shape="rect" href="http://www.codelutin.com">Code Lutin</a> - + <a shape="rect" href="http://www.chorem.org/projects/bow/issues">Rapport de bug</a> - + <a shape="rect" href="http://list.chorem.org/cgi-bin/mailman/listinfo/bow-users">Support utilisateur</a> + </div> </body> </html> \ No newline at end of file Modified: trunk/src/main/webapp/register.jsp =================================================================== --- trunk/src/main/webapp/register.jsp 2010-05-27 15:21:05 UTC (rev 36) +++ trunk/src/main/webapp/register.jsp 2010-05-28 12:47:46 UTC (rev 37) @@ -1,5 +1,11 @@ <%@page contentType="text/html" pageEncoding="UTF-8"%> -<%String error = (String) request.getAttribute("msgError");%> +<% + String error = (String) request.getAttribute("msgError"); + String url = request.getRequestURL().toString(); + int index = url.indexOf("register.jsp"); + url = url.substring(0, index); + String version = (String) request.getAttribute("version"); +%> <html> <link rel="stylesheet" type="text/css" href="./css/styles.css" /> <body> @@ -12,11 +18,19 @@ <br /> <input type="submit" value="Register"> </form> - <a href="bow?action=login">Return to the login page</a> + <a href="bow">Return to the login page</a> <br /> <%if (error != null && error.isEmpty() == false) {%> <font color="red"><%=error%></font> <%}%> - + <div class="Index" id="footer"> + <a shape="rect" href="<%=url%>">bow</a> + <a shape="rect" href="http://www.chorem.org/projects/list_files/bow"><%=version%></a> - + <a shape="rect" href="http://www.gnu.org/licenses/agpl.html">Licence AGPL</a> - + <span title="Copyright">©2010</span> + <a shape="rect" href="http://www.codelutin.com">Code Lutin</a> - + <a shape="rect" href="http://www.chorem.org/projects/bow/issues">Rapport de bug</a> - + <a shape="rect" href="http://list.chorem.org/cgi-bin/mailman/listinfo/bow-users">Support utilisateur</a> + </div> </body> </html> \ No newline at end of file Modified: trunk/src/main/webapp/search.jsp =================================================================== --- trunk/src/main/webapp/search.jsp 2010-05-27 15:21:05 UTC (rev 36) +++ trunk/src/main/webapp/search.jsp 2010-05-28 12:47:46 UTC (rev 37) @@ -22,6 +22,7 @@ String url = request.getRequestURL().toString(); int index = url.indexOf("search.jsp"); url = url.substring(0, index); + String version = (String) request.getAttribute("version"); %> <html> @@ -83,7 +84,11 @@ </td> <td class="result"> <a href="bow?action=addClick&bookmarkId=<%=bookmark.getWikittyId()%>" target="_blank"><%=bookmark.getDescription()%></a> - <form method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>&searchLine=<%=searchLine%>"> + <form method="POST" action="bow?action=addAlias&bookmarkId=<%=bookmark.getWikittyId()%>&searchLine=<%=searchLine%>" style="display: inline"> + <input type="text" name="alias" size="10" value="<%=bookmark.getAlias()%>" /> + <input style="display: inline;" type="submit" value="Add alias" /> + </form> + <form method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>&searchLine=<%=searchLine%>"> <input type="text" name="name" size="35" value="<%=bookmark.getDescription()%>" /> <input type="image" src="img/edit.png" title="Edit"/> </form> @@ -104,7 +109,7 @@ } } %> - <form method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>&searchLine=<%=searchLine%>"> + <form method="POST" action="bow?action=editBookmark&bookmarkId=<%=bookmark.getWikittyId()%>&searchLine=<%=searchLine%>"> <input type="text" name="tags" size="35" value="<%=BookmarkActions.getBookmarkTagsString(bookmark)%>" /> <input type="image" src="img/edit.png" title="Edit"/> </form> @@ -167,5 +172,14 @@ </div> </div> </div> + <div class="Index" id="footer"> + <a shape="rect" href="<%=url%>">bow</a> + <a shape="rect" href="http://www.chorem.org/projects/list_files/bow"><%=version%></a> - + <a shape="rect" href="http://www.gnu.org/licenses/agpl.html">Licence AGPL</a> - + <span title="Copyright">©2010</span> + <a shape="rect" href="http://www.codelutin.com">Code Lutin</a> - + <a shape="rect" href="http://www.chorem.org/projects/bow/issues">Rapport de bug</a> - + <a shape="rect" href="http://list.chorem.org/cgi-bin/mailman/listinfo/bow-users">Support utilisateur</a> + </div> </body> </html> \ No newline at end of file Modified: trunk/src/main/xmi/bow.zargo =================================================================== (Binary files differ)