Author: vbriand Date: 2011-01-07 20:02:06 +0100 (Fri, 07 Jan 2011) New Revision: 167 Url: http://chorem.org/repositories/revision/bow/167 Log: Deleted ControllerServlet.java. The bookmark modification works again but not perfectly. Removed: trunk/src/main/java/org/chorem/bow/ControllerServlet.java Modified: trunk/src/main/java/org/chorem/bow/action/AddAliasAction.java trunk/src/main/java/org/chorem/bow/action/AddUrlAction.java trunk/src/main/java/org/chorem/bow/action/EditBookmarkAction.java trunk/src/main/java/org/chorem/bow/action/LoginAction.java trunk/src/main/resources/i18n/bow_en_GB.properties trunk/src/main/resources/i18n/bow_fr_FR.properties trunk/src/main/resources/struts.xml trunk/src/main/webapp/js/bookmark.js trunk/src/main/webapp/jsp/inc/bookmark.jsp trunk/src/main/webapp/jsp/inc/rightMenu.jsp trunk/src/main/webapp/jsp/preferences.jsp Deleted: trunk/src/main/java/org/chorem/bow/ControllerServlet.java =================================================================== --- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2011-01-07 11:19:18 UTC (rev 166) +++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2011-01-07 19:02:06 UTC (rev 167) @@ -1,1431 +0,0 @@ -/* - * #%L - * bow - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package org.chorem.bow; - -/** - * - * @author bbrossaud - */ -import java.io.IOException; -import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.Properties; -import javax.mail.Message; -import javax.mail.MessagingException; -import javax.mail.Session; -import javax.mail.Transport; -import javax.mail.internet.AddressException; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeMessage; -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import org.apache.commons.fileupload.FileItem; -import org.apache.commons.fileupload.FileUploadException; -import org.apache.commons.fileupload.disk.DiskFileItemFactory; -import org.apache.commons.fileupload.servlet.ServletFileUpload; -import org.apache.commons.lang.RandomStringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.htmlparser.Node; -import org.htmlparser.Parser; -import org.htmlparser.util.NodeList; -import org.htmlparser.util.ParserException; -import org.htmlparser.util.SimpleNodeIterator; -import org.nuiton.util.StringUtil; -import org.nuiton.wikitty.Criteria; -import org.nuiton.wikitty.FacetTopic; -import org.nuiton.wikitty.PagedResult; -import org.nuiton.wikitty.WikittyProxy; -import org.nuiton.wikitty.search.Element; -import org.nuiton.wikitty.search.Search; - -/** - * - * @author bbrossaud - */ -public class ControllerServlet extends HttpServlet { - private static final long serialVersionUID = 1L; - private static final Log log = LogFactory.getLog(ControllerServlet.class); - protected String version = ""; - protected String bowServletUrl = ""; - - public ControllerServlet() throws Exception { - BowConfig config = BowConfig.getInstance(); - version = config.getVersion(); - bowServletUrl = config.getBowUrl(); - if (bowServletUrl == null) { - throw new Exception("No bow.url=\"SERVER URL\" in bow.properties"); - } - bowServletUrl += config.getServletBow(); - } - - @Override - public void doGet(HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException { - 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 { - try { - request.setCharacterEncoding("UTF8"); - request.setAttribute("version", version); - request.setAttribute("bowUrl", bowServletUrl); - HttpSession session = request.getSession(true); - User user = (User) session.getAttribute("user"); - - String token = request.getParameter("token"); // token or not - if (token != null && !token.isEmpty()) { - user = checkToken(token, session); // retrieve user by token - } - - String action = request.getParameter("action"); - if (action != null) { - if (action.equals("register")) { - if (log.isDebugEnabled()) { - log.debug("Going to actionRegister"); - } - actionRegister(request, response, session); - } else if (action.equals("registration")) { - if (log.isDebugEnabled()) { - log.debug("Going to Register"); - } - request.getRequestDispatcher("register.jsp").forward(request, response); - } else if (action.equals("forgotPassword")) { - if (log.isDebugEnabled()) { - log.debug("Going to forgotPassword"); - } - request.getRequestDispatcher("forgotPassword.jsp").forward(request, response); - } else if (action.equals("login")) { - if (log.isDebugEnabled()) { - log.debug("Going to actionLogin"); - } - actionLogin(request, response, session); - } else if (action.equals("logout")) { - if (log.isDebugEnabled()) { - log.debug("Going to actionLogout"); - } - actionLogout(request, response, session); - } else if (action.equals("home")) { - if (log.isDebugEnabled()) { - log.debug("Going to actionHome.jsp"); - } - actionHome(request, response, session); - } else if (action.equals("addUrl") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionAddUrl"); - } - actionAddUrl(request, response, user); - } else if (action.equals("sendPassword")) { - if (log.isDebugEnabled()) { - log.debug("Going to actionSendPassword"); - } - actionSendPassword(request, response); - } else if (action.equals("modifyBookmark") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionModif"); - } - actionModifyBookmark(request, response, user); - } else if (action.equals("importBookmarks") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionImportBookmarks"); - } - actionImportBookmarks(request, response, user); - } else if (action.equals("exportBookmarks") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionExportBookmarks"); - } - actionExportBookmarks(response, user); - } else if (action.equals("search") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionSearch"); - } - actionSearch(request, user); - request.getRequestDispatcher("search.jsp").forward(request, response); - } else if (action.equals("generateToken") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionGenerateToken"); - } - actionGenerateToken(request, response, user, session); - request.getRequestDispatcher("preferences.jsp").forward(request, response); - } else if (action.equals("deleteTag") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionDeleteTag"); - } - actionDeleteTag(request, response, user); - } else if (action.equals("addAlias") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionAddAlias"); - } - actionAddAlias(request, response); - } else if (action.equals("removeBookmark") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionRemoveBookmark"); - } - actionRemoveBookmark(request, response, user); - } else if (action.equals("editBookmark") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionEditBookmark"); - } - actionEditBookmark(request, response, user); - } else if (action.equals("order") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionOrder"); - } - actionOrder(request, response, user); - request.getRequestDispatcher("search.jsp").forward(request, response); - } else if (action.equals("addClick") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionAddClic"); - } - actionAddClick(request, response); - } else if (action.equals("temporaryXml")) { - if (log.isDebugEnabled()) { - log.debug("Going to temporaryXml.jsp"); - } - request.getRequestDispatcher("temporaryXml.jsp").forward(request, response); - } else if (action.equals("permanentXml")) { - if (log.isDebugEnabled()) { - log.debug("Going to permanentXml.jsp"); - } - request.getRequestDispatcher("permanentXml.jsp").forward(request, response); - } else if (action.equals("openSearchSuggestion") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionOpenSearchSuggestion"); - } - actionOpenSearchSuggestion(request, response, user); - request.getRequestDispatcher("suggestions.jsp").forward(request, response); - } else if (action.equals("openSearchResult") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionOpenSearchResult"); - } - actionOpenSearchResult(request, response, session, user, token); - } else if (action.equals("fullText") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionFullText"); - } - actionFullText(request, user); - request.getRequestDispatcher("search.jsp").forward(request, response); - } else if (action.equals("preferences") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionPreferences"); - } - getBookmarksByImportDate(request, user); - request.getRequestDispatcher("preferences.jsp").forward(request, response); - } else if (action.equals("admin") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionAdmin"); - } - if ((Boolean) session.getAttribute("admin")) { - request.getRequestDispatcher("admin.jsp").forward(request, response); - } else { - request.getRequestDispatcher("login.jsp").forward(request, response); - } - } else if (action.equals("changePreferences") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionChangePreferences"); - } - actionChangePreferences(request, session, user); - request.getRequestDispatcher("preferences.jsp").forward(request, response); - } else if (action.equals("deleteImport") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionDeleteImport"); - } - actionDeleteImport(request, response, user); - //request.getRequestDispatcher("preferences.jsp").forward(request, response); - } else if (action.equals("reIndexation") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionReIndexation"); - } - actionReIndexation(request, session, user); - request.getRequestDispatcher("admin.jsp").forward(request, response); - } else if (action.equals("deleteSearchResults") && user != null) { - if (log.isDebugEnabled()) { - log.debug("Going to actionDeleteSearchResults"); - } - actionDeleteSearchResults(request, response, user); - } - else { - if (user != null) { - request.getRequestDispatcher("error.jsp").forward(request, response); - } else { - request.getRequestDispatcher("login.jsp").forward(request, response); - } - } - } else { - request.getRequestDispatcher("login.jsp").forward(request, response); - } - } catch (Exception eee) { - log.error("Can't do action", eee); - request.setAttribute("errorMsgUser", eee.getMessage()); - request.setAttribute("errorMsgTech", eee.toString()); - request.getRequestDispatcher("error.jsp").forward(request, response); - } - } - - /* @param request servlet request - * @param user user information - * @throws IOException If the redirection fails - * @description Deletes every bookmark imported at a given date - */ - protected void actionDeleteImport(HttpServletRequest request, - HttpServletResponse response, - User user) throws IOException { - String date = request.getParameter("date"); - - if (date != null) { - WikittyProxy proxy = BowProxy.getInstance(); - - if (date.matches("[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{1,3}Z")) { - Criteria criteria = Search.query().eq(Element.ELT_EXTENSION, Import.EXT_IMPORT).eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()). - eq(Import.FQ_FIELD_DATE, date).criteria(); - List<Import> bookmarks = proxy.findAllByCriteria(Import.class, criteria).getAll(); - List<String> ids = new ArrayList<String>(); - - for (Import bookmark : bookmarks) { - ids.add(bookmark.getWikittyId()); - } - proxy.delete(ids); - } - response.sendRedirect("bow?action=preferences"); - } - } - - /* @param request servlet request - * @param response servlet response - * @param user user information - * @throws IOException If the redirection fails - * @description Deletes the bookmarks returned after a research - */ - protected void actionDeleteSearchResults(HttpServletRequest request, HttpServletResponse response, User user) throws IOException { - String searchLine = request.getParameter("searchLine"); - String fullText = request.getParameter("fullTextLine"); - - if (searchLine != null && fullText != null) { - WikittyProxy proxy = BowProxy.getInstance(); - Criteria criteria; - if (fullText.isEmpty()) { - criteria = getBookmarkListCriteriaByUser(user, searchLine); - } else { - criteria = Search.query().keyword(fullText).eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria().addFacetField(Bookmark.FQ_FIELD_TAGS); - } - List<Bookmark> bookmarks = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); - List<String> ids = new ArrayList<String>(); - - for (Bookmark bookmark : bookmarks) { - if (searchLine.isEmpty() && bookmark.getTags() == null || !searchLine.isEmpty() || - fullText.isEmpty() && bookmark.getTags() == null || !fullText.isEmpty()) { - ids.add(bookmark.getWikittyId()); - } - } - proxy.delete(ids); - } - response.sendRedirect("bow?action=home"); - } - - /* @param request servlet request - * @param response servlet response - * @param user the user - * @param token the permanent or temporary token - * @throws ServletException if a servlet error occurs - * @description set the openSearch result - */ - protected void actionOpenSearchResult(HttpServletRequest request, - HttpServletResponse response, HttpSession session, User user, String token) - throws IOException, ServletException, NoSuchAlgorithmException { - String searchLine = request.getParameter("searchLine"); - if (searchLine != null && searchLine.matches("^http://[^ ]*")) { - response.sendRedirect(searchLine); - } else if (searchLine != null - && (searchLine.startsWith(":") || searchLine.startsWith("t:")) ) { - // on fait une recherche sur les tags - - int index = searchLine.indexOf(":"); - searchLine = searchLine.substring(index+1); // suppress first ":" - - session.setAttribute("user", user); - initializeToken(session, user); - WikittyProxy proxy = BowProxy.getInstance(); - Criteria criteria = getBookmarkListCriteriaByUser(user, searchLine); - criteria = criteria.addSortDescending(Bookmark.FQ_FIELD_CLICK); - PagedResult<Bookmark> result = proxy.findAllByCriteria(Bookmark.class, criteria);// retrieve bookmarks by search - BookmarkActions bookmarkActions = createBookmarkActions(request, result, searchLine); - request.setAttribute("bookmarkActions", bookmarkActions); - request.setAttribute("token", token); - request.getRequestDispatcher("search.jsp").forward(request, response); - } else if (searchLine != null && searchLine.startsWith("f:")) { - // recherche fulltext dans bow - String fullText = searchLine.substring(2); - - session.setAttribute("user", user); - initializeToken(session, user); - WikittyProxy proxy = BowProxy.getInstance(); - Criteria criteria; - if (!fullText.isEmpty()) { - criteria = Search.query().keyword(fullText). - eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(). - addFacetField(Bookmark.FQ_FIELD_TAGS); - - } else { - criteria = getBookmarkListCriteriaByUser(user, null); - } - PagedResult<Bookmark> result = proxy.findAllByCriteria(Bookmark.class, criteria); - BookmarkActions bookmarkActions = createBookmarkActions(request, result, null); - request.setAttribute("bookmarkActions", bookmarkActions); - request.setAttribute("token", token); - request.getRequestDispatcher("search.jsp").forward(request, response); - } else if (searchLine != null && searchLine.startsWith("a:")) { - // on redirige vers l'alias demande - searchLine = searchLine.substring(2); - response.sendRedirect(BowConfig.getInstance().getAliasUrl() + searchLine); - } else { - // on fait une recherche sur le moteur de recherche configurer - WikittyProxy proxy = BowProxy.getInstance(); - Preference pref = proxy.restore(Preference.class, user.getWikittyId()); - - String searchEngineURL = pref.getSearchEngineUrlResults(); - if (searchEngineURL == null || "".equals(searchEngineURL)) { - BowConfig config = BowConfig.getInstance(); - searchEngineURL = config.getSearchEngine(); - } - searchEngineURL = searchEngineURL.replace("{searchTerms}", searchLine); - searchEngineURL = response.encodeRedirectURL(searchEngineURL); - - response.sendRedirect(searchEngineURL); - } - } - - /* @param request servlet request - * @param response servlet response - * @param user the user - * @throws ServletException if a servlet error occurs - * @description set the openSearch suggestions - */ - protected void actionOpenSearchSuggestion(HttpServletRequest request, - HttpServletResponse response, - User user) - throws IOException, ServletException { - if (user != null) { - String search = request.getParameter("searchLine"); - if (search != null) { - OpenSearchActions openSearchActions = new OpenSearchActions(); - WikittyProxy proxy = BowProxy.getInstance(); - String[] words = search.split("\\s+"); - List<String> searchLine = new ArrayList<String>(Arrays.asList(words)); - if (search.charAt(search.length() - 1) == ' ') { - searchLine.add(""); // if the user types nothing we have to propose suggestions - } - Criteria criteria; - if (searchLine.size() > 1) { - List<String> cpy = new ArrayList<String>(searchLine); - cpy.remove(cpy.size() - 1); - criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()). - eq(Bookmark.FQ_FIELD_TAGS, cpy).criteria().addFacetField(Bookmark.FQ_FIELD_TAGS); - } else { - criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()). - criteria().addFacetField(Bookmark.FQ_FIELD_TAGS); - } - PagedResult<Bookmark> result = proxy.findAllByCriteria(Bookmark.class, criteria); - List<Bookmark> bookList = result.getAll(); - List<FacetTopic> topics = result.getTopic(Bookmark.FQ_FIELD_TAGS); - openSearchActions.setBookmarkList(bookList); - openSearchActions.setSuggestionList(topics); - openSearchActions.findSuggestions(searchLine); - request.setAttribute("openSearchAction", openSearchActions); - } - } - } - - /* @param request servlet request - * @param response servlet response - * @param session current session - * @throws ServletException if a servlet error occurs - * @description delete the session - */ - protected void actionLogout(HttpServletRequest request, - HttpServletResponse response, - HttpSession session) - throws IOException, ServletException { - session.invalidate(); - request.getRequestDispatcher("login.jsp").forward(request, response); - } - - /* @param request servlet request - * @param response servlet response - * @throws ServletException if a servlet error occurs - * @description when the user click on the bookmark bowServletUrl, we - * increment the number of click - */ - protected void actionAddClick(HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException { - String bookmarkId = request.getParameter("bookmarkId"); - if (bookmarkId != null && !bookmarkId.isEmpty()) { - WikittyProxy proxy = BowProxy.getInstance(); - Bookmark bookmark = proxy.restore(Bookmark.class, bookmarkId); - if (bookmark != null) { - int click = bookmark.getClick(); - ++click; - bookmark.setClick(click); - proxy.store(bookmark); - String link = bookmark.getLink(); - response.sendRedirect(link); - } - } - } - - /* @param request servlet request - * @param response servlet response - * @param user the user - * @throws ServletException if a servlet error occurs - * @description order the bookmarks by type - */ - protected void actionOrder(HttpServletRequest request, - HttpServletResponse response, - User user) - throws IOException, ServletException { - String type = request.getParameter("type"); - String searchLine = request.getParameter("searchLine"); - Criteria baseCriteria = getBookmarkListCriteriaByUser(user, searchLine); - if (type != null && baseCriteria != null && !type.isEmpty()) { - WikittyProxy proxy = BowProxy.getInstance(); - PagedResult<Bookmark> result = null; - if (type.equals("ascName")) { - Criteria criteria = baseCriteria.addSortAscending(Bookmark.FQ_FIELD_DESCRIPTION); - result = proxy.findAllByCriteria(Bookmark.class, criteria); - } else if (type.equals("ascDate")) { - Criteria criteria = baseCriteria.addSortAscending(Bookmark.FQ_FIELD_DATE); - result = proxy.findAllByCriteria(Bookmark.class, criteria); - } else if (type.equals("ascClick")) { - Criteria criteria = baseCriteria.addSortAscending(Bookmark.FQ_FIELD_CLICK); - result = proxy.findAllByCriteria(Bookmark.class, criteria); - } else if (type.equals("descName")) { - Criteria criteria = baseCriteria.addSortDescending(Bookmark.FQ_FIELD_DESCRIPTION); - result = proxy.findAllByCriteria(Bookmark.class, criteria); - } else if (type.equals("descDate")) { - Criteria criteria = baseCriteria.addSortDescending(Bookmark.FQ_FIELD_DATE); - result = proxy.findAllByCriteria(Bookmark.class, criteria); - } else if (type.equals("descClick")) { - Criteria criteria = baseCriteria.addSortDescending(Bookmark.FQ_FIELD_CLICK); - result = proxy.findAllByCriteria(Bookmark.class, criteria); - } - BookmarkActions bookmarkActions = createBookmarkActions(request, result, searchLine); - request.setAttribute("bookmarkActions", bookmarkActions); - } - } - - /* @param request servlet request - * @param response servlet response - * @param user the user - * @throws ServletException if a servlet error occurs - * @description edit the bookmark - */ - protected void actionEditBookmark(HttpServletRequest request, - HttpServletResponse response, - User user) - throws IOException, ServletException { - String bookmarkId = request.getParameter("bookmarkId"); - if (bookmarkId != null && !bookmarkId.isEmpty()) { - WikittyProxy proxy = BowProxy.getInstance(); - Bookmark bookmark = proxy.restore(Bookmark.class, bookmarkId); - if (bookmark != null) { - request.setAttribute("link", bookmark.getLink()); - request.setAttribute("name", bookmark.getDescription()); - request.setAttribute("alias", bookmark.getAlias()); - request.setAttribute("tags", BookmarkActions.getBookmarkTagsString(bookmark)); - request.setAttribute("action", "bow?action=modifyBookmark"); - request.setAttribute("bookmarkId", bookmarkId); - } - } - String searchLine = request.getParameter("searchLine"); - if (searchLine == null) { - initHomePage(request, user); - request.getRequestDispatcher("home.jsp").forward(request, response); - } else { - actionSearch(request, user); - request.getRequestDispatcher("search.jsp").forward(request, response); - } - } - - /* @param request servlet request - * @param response servlet response - * @param user the user - * @throws ServletException if a servlet error occurs - * @description remove the bookmark - */ - protected void actionRemoveBookmark(HttpServletRequest request, - HttpServletResponse response, - User user) - throws IOException, ServletException { - String bookmarkId = request.getParameter("bookmarkId"); - if (bookmarkId != null && !bookmarkId.isEmpty()) { - try { - WikittyProxy proxy = BowProxy.getInstance(); - Bookmark bookmark = proxy.restore(Bookmark.class, bookmarkId); - if (bookmark != null) { - proxy.delete(bookmarkId); - } - } catch (Exception eee) { - log.error("Can't do action", eee); - } - } - redirectToTheGoodPage(request, response); - } - - /* @param request servlet request - * @param response servlet response - * @param user the user - * @throws ServletException if a servlet error occurs - * @description delete the bookmark tag - */ - protected void actionDeleteTag(HttpServletRequest request, - HttpServletResponse response, - User user) - throws IOException, ServletException { - String bookmarkId = request.getParameter("bookmarkId"); - String tag = request.getParameter("deleteTag"); - if (tag != null && bookmarkId != null) { - if (!bookmarkId.isEmpty()) { - WikittyProxy proxy = BowProxy.getInstance(); - Bookmark bookmark = proxy.restore(Bookmark.class, bookmarkId); - if (bookmark != null) { - bookmark.removeTags(tag); - proxy.store(bookmark); - } - } - } - redirectToTheGoodPage(request, response); - } - - - /* @param request servlet request - * @param response servlet response - * @param user User user - * @param session HttpSession session - * @throws ServletException if a servlet error occurs - * @description delete the current token and generate an another - */ - protected void actionGenerateToken(HttpServletRequest request, - HttpServletResponse response, - User user, - HttpSession session) - throws IOException, ServletException, NoSuchAlgorithmException { - - WikittyProxy proxy = BowProxy.getInstance(); - Criteria criteria = Search.query().eq(Token.FQ_FIELD_EMAIL, user.getEmail()).criteria(); - Token currentToken = proxy.findByCriteria(Token.class, criteria); - if (currentToken != null) { - String id = currentToken.getWikittyId(); - proxy.delete(id); - } - TokenActions tokenActions = (TokenActions) session.getAttribute("tokenActions"); - if (tokenActions != null) { - String token = tokenActions.generateToken(); // Generate an encoding MD5 token - criteria = Search.query().eq(Token.FQ_FIELD_TOKEN, token).criteria(); - Token oldToken = proxy.findByCriteria(Token.class, criteria); - if (oldToken == null) { // Check if the token already exists - TokenImpl newToken = new TokenImpl(); - newToken.setToken(token); - newToken.setEmail(user.getEmail()); - proxy.store((Token) newToken); // If the token doesn't exist, it is stored - tokenActions.setPermanentToken(token); - } else { - tokenActions.setPermanentToken(""); - } - } - } - - protected void actionModifyBookmark(HttpServletRequest request, - HttpServletResponse response, - User user) - throws IOException { - String link = request.getParameter("url"); // bowServletUrl of the website - String name = request.getParameter("name"); // website name - String alias = request.getParameter("alias"); - String tags = request.getParameter("tags"); - String id = request.getParameter("bookmarkId"); - WikittyProxy proxy = BowProxy.getInstance(); - Bookmark bookmark = proxy.restore(Bookmark.class, id); - if (bookmark != null) { - if (alias != null && !alias.isEmpty()) { - Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_ALIAS, alias).criteria(); - if (proxy.findByCriteria(Bookmark.class, criteria) != null) { - alias = bookmark.getAlias(); - } - } - BookmarkActions.updateBookmark(bookmark, name, link, tags, alias); - proxy.store(bookmark); - } - redirectToTheGoodPage(request, response); - } - - /* @param request servlet request - * @param response servlet response - * @param user User user - * @throws ServletException if a servlet error occurs - * @description add a new bookmark - */ - protected void actionAddUrl(HttpServletRequest request, - HttpServletResponse response, - User user) - throws IOException, ServletException { - addUrl(request, user); - redirectToTheGoodPage(request, response); - } - - protected void addUrl(HttpServletRequest request, User user) { - String link = request.getParameter("url"); // bowServletUrl of the website - String name = request.getParameter("name"); // website name - String alias = request.getParameter("alias"); - WikittyProxy proxy = BowProxy.getInstance(); - Bookmark bookmark = null; - if (name != null) { - String tags = request.getParameter("tags"); // tags - if (alias != null && !alias.isEmpty()) { - Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_ALIAS, alias).criteria(); - if (proxy.findByCriteria(Bookmark.class, criteria) != null) { - alias = ""; - } - } - bookmark = BookmarkActions.createBookmark(link, name, tags, user, alias, null); - } else { // this part is for the bookmark addition by script - String nameAndTags = request.getParameter("nameAndTags"); - if (nameAndTags != null) { - bookmark = BookmarkActions.createBookmark(link, nameAndTags, user); - } - } - if (bookmark != null && !bookmark.getDescription().isEmpty() && !bookmark.getEmail().isEmpty()) { - proxy.store(bookmark); // store the bookmark if everything is ok - if (log.isDebugEnabled()) { - log.debug("Adding URL"); - } - } - } - /* @param token String token - * @param session HttpSession session - * @return User - * @description check if the token is valid and return the - * token owner - */ - protected User checkToken(String token, HttpSession session) { - if (checkTemporaryToken(token, session)) { - User user = (User) session.getAttribute("user"); - return user; - } - User user = checkPermanentToken(token); - return user; - } - - /* @param token String which contains the MD5 encoding token - * @return null the token doesn't exist - * @return User the token owner - */ - protected User checkPermanentToken(String token) { - if (token != null) { - WikittyProxy proxy = BowProxy.getInstance(); - Criteria criteria = Search.query().eq(Token.FQ_FIELD_TOKEN, token).criteria(); - Token DbToken = proxy.findByCriteria(Token.class, 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 token String which contains the MD5 encoding token - * @return null the token doesn't exist - * @return User the token owner - */ - protected boolean checkTemporaryToken(String token, HttpSession session) { - TokenActions tokenActions = (TokenActions) session.getAttribute("tokenActions"); - if (tokenActions != null) { - String temporaryToken = tokenActions.getTemporaryToken(); - if (temporaryToken != null) { - if (temporaryToken.equals(token)) { - return true; - } - } - } - return false; - } - - /* @param request servlet request - * @param response servlet response - * @param user User user - * @throws ServletException if a servlet error occurs - * @description set the bookmarks and the tagCloud by search - * or tag addition - */ - protected void actionSearch(HttpServletRequest request, User user) - throws IOException, ServletException { - String searchLine = request.getParameter("searchLine"); - if (searchLine == null) { - searchLine = ""; - } - String fulltext = request.getParameter("fullTextLine"); - if (fulltext != null && !fulltext.isEmpty() && searchLine.isEmpty()) { - actionFullText(request, user); - } else { - String tag = request.getParameter("addTag"); - if (tag != null && !tag.isEmpty()) { - if (searchLine.isEmpty()) { - searchLine = tag; - } else { - searchLine += " " + tag; - } - } - WikittyProxy proxy = BowProxy.getInstance(); - Criteria criteria = getBookmarkListCriteriaByUser(user, searchLine); - criteria = criteria.addSortDescending(Bookmark.FQ_FIELD_CLICK); - PagedResult<Bookmark> result = proxy.findAllByCriteria(Bookmark.class, criteria); // select all bookmarks by user - BookmarkActions bookmarkActions = createBookmarkActions(request, result, searchLine); - request.setAttribute("bookmarkActions", bookmarkActions); - } - } - - /* @param request servlet request - * @param result PageResult result - * @param searchLine String searchLine - * @return bookmarkActions the bookmarkAction - * @description create the tagCLoud by research type - */ - protected BookmarkActions createBookmarkActions(HttpServletRequest request, - PagedResult<Bookmark> result, - String searchLine) { - String fullText = request.getParameter("fullTextLine"); - BookmarkActions bookmarkActions = new BookmarkActions(); - bookmarkActions.setFullTextLine(fullText); - List<Bookmark> bookList = result.getAll(); - if (bookList != null) { - bookmarkActions.setBookmarks(bookList); - } - if (fullText == null || fullText.isEmpty()) { - if (searchLine != null && searchLine.isEmpty()) { - bookmarkActions.emptySearchline(); - } else { - bookmarkActions.addTags(searchLine); // add the new tags - } - } - List<FacetTopic> topics = result.getTopic(Bookmark.FQ_FIELD_TAGS); - bookmarkActions.createTagCloud(topics); - return bookmarkActions; - } - - /* @param request servlet request - * @param response servlet response - * @param session HttpSessiorn session - * @throws ServletException if a servlet error occurs - * @description check if the registration is correct or not - */ - protected void actionRegister(HttpServletRequest request, HttpServletResponse response, HttpSession session) - throws IOException, ServletException, NoSuchAlgorithmException, MessagingException { - String email = request.getParameter("email"); - if (email != null) { - email = email.trim(); - String password = request.getParameter("password"); - String repeatPassword = request.getParameter("repeatPassword"); - String md5; - - if (password == null) { - request.setAttribute("errorMsgUser", "Invalid password, password must not be null "); - - } else if (!password.equals(repeatPassword)) { - request.setAttribute("errorMsgUser", "Invalid password, you have not type twice the same password."); - - } else { - md5 = StringUtil.encodeMD5(password); - if (!checkRegister(email, md5, request)) { // check if all is well - WikittyProxy proxy = BowProxy.getInstance(); - UserImpl newUser = new UserImpl(); - newUser.setPassword(md5); - newUser.setEmail(email); - User login = proxy.store((User) newUser); // store the new user - - if (login != null) { - initSession(session, login); - initHomePage(request, login); - sendMail(email, password); - request.getRequestDispatcher("home.jsp").forward(request, response); - - } else { - request.setAttribute("errorMsgUser", "Invalid login, please choose another one"); - } - } - } - request.getRequestDispatcher("register.jsp").forward(request, response); - } - } - - /* @param request servlet request - * @param response servlet response - * @param session HttpSession session - * @throws ServletException if a servlet error occurs - * @description check if the authentication is correct or not - */ - protected void actionLogin(HttpServletRequest request, - HttpServletResponse response, - HttpSession session) - throws IOException, ServletException, NoSuchAlgorithmException { - String email = request.getParameter("email"); - if (email != null) { - email = email.trim(); - String password = request.getParameter("password"); - String md5; - if (password != null) { - md5 = StringUtil.encodeMD5(password); - User login = checkLogin(email, md5, request); // check if the user exists - if (login != null) { - initSession(session, login); - initHomePage(request, login); - request.getRequestDispatcher("home.jsp").forward(request, response); - return; - } - } - } - request.getRequestDispatcher("login.jsp").forward(request, response); - } - - protected void checkAdmin(String login, HttpSession session) { - String[] admins = BowConfig.getInstance().getAdmins(); - if (admins != null) { - for (String admin : admins) { - if (login.equals(admin)) { - session.setAttribute("admin", true); - return; - } - } - } - session.setAttribute("admin", false); - } - - /* @param session HttpSession session - * @throws ServletException if a servlet error occurs - * @description retrieve tokens or create there if the user are just - * registered - */ - protected void initializeToken(HttpSession session, User login) - throws NoSuchAlgorithmException { - WikittyProxy proxy = BowProxy.getInstance(); - Criteria criteria = Search.query().eq(Token.FQ_FIELD_EMAIL, login.getEmail()).criteria(); - Token token = proxy.findByCriteria(Token.class, criteria); - TokenActions tokenActions = new TokenActions(); - if (token == null) { - token = new TokenImpl(); - String newToken = tokenActions.generateToken(); - token.setToken(newToken); - token.setEmail(login.getEmail()); - proxy.store(token); - } - tokenActions.setPermanentToken(token.getToken()); - String temporaryToken = tokenActions.generateToken(); - tokenActions.setTemporaryToken(temporaryToken); - session.setAttribute("tokenActions", tokenActions); - } - - - /* @param email String which contains the user name (email) - * @param password String which contains the user password - * @return null the user doesn't exist - * @return User the user exists - */ - protected User checkLogin(String email, - String password, - HttpServletRequest request) throws NoSuchAlgorithmException { - if (email != null && password != null) { - if (!email.isEmpty() && !password.equals(StringUtil.encodeMD5(""))) { - WikittyProxy proxy = BowProxy.getInstance(); - Criteria criteria = Search.query().eq(User.FQ_FIELD_EMAIL, email). - eq(User.FQ_FIELD_PASSWORD, password).criteria(); - User user = proxy.findByCriteria(User.class, criteria); - - if (user == null) { - request.setAttribute("errorMsgUser", "Unknown email or incorrect password"); - } - return user; // retrieve user by user name (email) and password - } - } - request.setAttribute("errorMsgUser", "Please enter your email address and your password"); - return null; - } - - - /* @param email String which contains the user name (email) - * @param password String which contains the user password - * @return boolean false if the user doesn't exist or true - */ - protected boolean checkRegister(String email, - String password, - HttpServletRequest request) throws NoSuchAlgorithmException { - if (email != null && password != null) { - if (!email.isEmpty() && !password.equals(StringUtil.encodeMD5(""))) { - WikittyProxy proxy = BowProxy.getInstance(); - - 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; - } - request.setAttribute("errorMsgUser", "This email address is already used"); - return true; - } - } - request.setAttribute("errorMsgUser", "Email and password must be correctly filled"); - return true; - } - - protected void initHomePage(HttpServletRequest request, User user) { - WikittyProxy proxy = BowProxy.getInstance(); - Criteria criteria = getBookmarkListCriteriaByUser(user, null); - if (criteria != null) { - Criteria sortCriteria = criteria.addSortDescending(Bookmark.FQ_FIELD_CLICK); - PagedResult<Bookmark> result = proxy.findAllByCriteria(Bookmark.class, sortCriteria); // select all bookmarks by user - sortCriteria = criteria.addSortDescending(Bookmark.FQ_FIELD_DATE).setEndIndex(10); - List<Bookmark> lastBookmarks = proxy.findAllByCriteria(Bookmark.class, sortCriteria).getAll(); - BookmarkActions bookmarkActions = createBookmarkActions(request, result, null); - bookmarkActions.setTagSearch(null); - List<Bookmark> bookList = bookmarkActions.getBookmarks(); - if (bookList.size() > 10) { - bookList = bookmarkActions.getBookmarks().subList(0, 10); - bookmarkActions.setBookmarks(bookList); - } - if (lastBookmarks != null) { - bookmarkActions.setLastBookmarks(lastBookmarks); - } - request.setAttribute("bookmarkActions", bookmarkActions); - } - } - - protected void initSession(HttpSession session, User user) throws NoSuchAlgorithmException { - WikittyProxy proxy = BowProxy.getInstance(); - session.setAttribute("user", user); - Preference preference = proxy.restore(Preference.class, user.getWikittyId()); - session.setAttribute("preference", preference); - initializeToken(session, user); - checkAdmin(user.getEmail(), session); - } - - /* @param request servlet request - * @param user User user - * @description initialize all for the home page - */ - protected void actionHome(HttpServletRequest request, - HttpServletResponse response, - HttpSession session) - throws ServletException, IOException, NoSuchAlgorithmException { - User user = (User) session.getAttribute("user"); - if (user == null) { - String token = request.getParameter("token"); - user = checkPermanentToken(token); - if (user != null) { - initSession(session, user); - } - } - if (user != null) { - initHomePage(request, user); - request.getRequestDispatcher("home.jsp").forward(request, response); - } else { - request.getRequestDispatcher("login.jsp").forward(request, response); - } - } - - protected void createImportExtension(List<Bookmark> bookmarks) { - if (bookmarks != null && !bookmarks.isEmpty()) { - WikittyProxy proxy = BowProxy.getInstance(); - List<String> ids = new ArrayList<String>(); - for (Bookmark bookmark : bookmarks) { - String id = bookmark.getWikittyId(); - ids.add(id); - } - Date date = new Date(); - List<Import> imports = proxy.restore(Import.class, ids); - for (Import imp : imports) { - imp.setDate(date); - } - proxy.store(imports); - } - } - - protected void getBookmarksByImportDate(HttpServletRequest request, User user) { - WikittyProxy proxy = BowProxy.getInstance(); - Criteria criteria = Search.query().eq(Element.ELT_EXTENSION, Import.EXT_IMPORT).eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(). - addFacetField(Import.FQ_FIELD_DATE); - List<FacetTopic> bookmarksImportDate = proxy.findAllByCriteria(Import.class, criteria).getTopic(Import.FQ_FIELD_DATE); - request.setAttribute("bookmarksImportDate", bookmarksImportDate); - } - - /* @param request servlet request - * @param response servlet response - * @param user User user - * @throws ServletException if a servlet error occurs - * @description import bookmark for an user - */ - protected void actionImportBookmarks(HttpServletRequest request, HttpServletResponse response, User user) - throws IOException, FileUploadException, ServletException { - // Check that we have a file upload request - boolean isMultipart = ServletFileUpload.isMultipartContent(request); - if (isMultipart) { - // Create a factory for disk-based file items - DiskFileItemFactory factory = new DiskFileItemFactory(); - // Create a new file upload handler - ServletFileUpload upload = new ServletFileUpload(factory); - // Process the uploaded items - // Parse the request - List<?> items = upload.parseRequest(request); - for (Object obj : items) { - FileItem item = (FileItem) obj; - if (!item.isFormField()) { - WikittyProxy proxy = BowProxy.getInstance(); - String content = item.getString(); - try { - Parser parser = new Parser(content); - NodeList list = parser.parse(null); - List<Bookmark> bookmarks = new ArrayList<Bookmark>(); - parseHtmlToBookmarks(list, user, bookmarks, new ArrayList<String>()); - bookmarks = proxy.store(bookmarks); - createImportExtension(bookmarks); - initHomePage(request, user); - request.getRequestDispatcher("home.jsp").forward(request, response); - } - catch (ParserException e) { - request.setAttribute("errorMsgUser", "Bad bookmarks file format, expected Netscape-like bookmarks file"); - request.setAttribute("errorMsgTech", e.getMessage()); - - String searchLine = request.getParameter("searchLine"); - if (searchLine == null) { - initHomePage(request, user); - request.getRequestDispatcher("home.jsp").forward(request, response); - } else { - actionSearch(request, user); - request.getRequestDispatcher("search.jsp").forward(request, response); - } - } - } - } - } - } - - /* @param list NodeList list - * @param bookmarks List<Bookmark> bookmarks - * @param tagList List<String> tagList - * @throws ParserException if a parser error occurs - * @description parse the html by recursion and retrieve bookmarks - */ - protected void parseHtmlToBookmarks(NodeList list, User user, List<Bookmark> bookmarks, List<String> tagList) - throws ParserException { - if (list != null) { - boolean isFolder = false; - SimpleNodeIterator it = list.elements(); - while (it.hasMoreNodes()) { - Node node = it.nextNode(); - String plainText = node.toPlainTextString(); // the text between two heads ==> <toto>plainText</toto> - String text = node.getText(); // the text in the head ==> <text></toto> - if (text != null && text.startsWith("H3")) { // H3 = folder - if (plainText != null && !plainText.isEmpty()) { - tagList.add(plainText); // add the folder name to the tagList - isFolder = true; - } - } else if (text != null && text.startsWith("A HREF")) { // HREF = new bookmarks - Bookmark bookmark = BookmarkActions.createBookmarkFromHtml(text, plainText, user); - BookmarkActions.addTagsToBookmark(tagList, bookmark); - if (bookmark != null) { - bookmarks.add(bookmark); - } - } - NodeList children = node.getChildren(); - if (children != null) { - parseHtmlToBookmarks(children, user, bookmarks, tagList); // if there is an under node = recursion - } - } - if (isFolder) { // if we find a folder, we have to remove it - int index = tagList.size() - 1; - if (index > -1) { - tagList.remove(index); - } - } - } - } - - /* @param response servlet response - * @param user User user - * @description export bookmarks - */ - protected void actionExportBookmarks(HttpServletResponse response, User user) - throws IOException { - WikittyProxy proxy = BowProxy.getInstance(); - Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(); - List<Bookmark> bookmarks = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); - String export = BookmarkActions.getExportHtmlBookmark(bookmarks); - byte[] buff = export.getBytes(); - ServletOutputStream op = response.getOutputStream(); - response.setContentType("application/octet-stream"); - response.setHeader("Content-Disposition", "attachment; filename=\"bookmarks.html\""); - response.setContentLength(buff.length); - op.write(buff, 0, buff.length); - op.flush(); - op.close(); - } - - /* @param request servlet request - * @param response servlet response - * @throws ServletException if a servlet error occurs - * @description add an alias for one bookmark - */ - protected void actionAddAlias(HttpServletRequest request, HttpServletResponse response) - throws IOException { - String alias = request.getParameter("alias"); - if (alias != null && !alias.isEmpty()) { - WikittyProxy proxy = BowProxy.getInstance(); - 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); - } - } - } - } - redirectToTheGoodPage(request, response); - } - - /* @param request servlet request - * @param user User user - * @throws ServletException if a servlet error occurs - * @description retrieve bookmark for the full text research - */ - protected void actionFullText(HttpServletRequest request, User user) throws IOException, ServletException { - String fullText = request.getParameter("fullTextLine"); - if (fullText == null || fullText.isEmpty()) { - actionSearch(request, user); - } else { - WikittyProxy proxy = BowProxy.getInstance(); - Criteria criteria; - if (!fullText.isEmpty()) { - criteria = Search.query().keyword(fullText). - eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(). - addFacetField(Bookmark.FQ_FIELD_TAGS); - - } else { - criteria = getBookmarkListCriteriaByUser(user, null); - } - PagedResult<Bookmark> result = proxy.findAllByCriteria(Bookmark.class, criteria); - BookmarkActions bookmarkActions = createBookmarkActions(request, result, null); - request.setAttribute("bookmarkActions", bookmarkActions); - } - } - - /* @param request servlet request - * @param response servlet response - * @throws ServletException if a servlet error occurs - * @description choose the good page - */ - protected void redirectToTheGoodPage(HttpServletRequest request, HttpServletResponse response) - throws IOException { - String searchLine = request.getParameter("searchLine"); - String fullText = request.getParameter("fullTextLine"); - if (fullText == null) { - fullText = ""; - } - if (searchLine != null) { - response.sendRedirect("bow?action=search&searchLine=" + searchLine + "&fullTextLine=" + fullText); - } else { - response.sendRedirect("bow?action=home"); - } - } - - /* @param user User user - * @param searchLine String searchLine - * @description return the bookmark criteria by search - */ - protected Criteria getBookmarkListCriteriaByUser(User user, String searchLine) { - Criteria criteria = null; - if (user != null) { - if (searchLine != null && !searchLine.isEmpty()) { - String[] words = searchLine.split("\\s+"); // put the tags in an array - List<String> tags = new ArrayList<String>(Arrays.asList(words)); - criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()). - eq(Bookmark.FQ_FIELD_TAGS, tags).criteria().addFacetField(Bookmark.FQ_FIELD_TAGS); - } else { - criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()). - criteria().addFacetField(Bookmark.FQ_FIELD_TAGS); - } - } - return criteria; - } - - protected Preference changePreference(HttpServletRequest request, HttpSession session) { - - Preference preference = (Preference) session.getAttribute("preference"); - // Retrieve Preference fields - String colors = request.getParameter("colors"); - String tags = request.getParameter("tagsNb"); - String bookmarks = request.getParameter("bookmarks"); - String searchEngineSuggestions = request.getParameter("searchEngineUrlSuggestions"); - String searchEngineResults = request.getParameter("searchEngineUrlResults"); - - preference.setColors(colors); - preference.setTags(Integer.valueOf(tags)); - preference.setBookmarks(Integer.valueOf(bookmarks)); - preference.setSearchEngineUrlSuggestions(searchEngineSuggestions); - preference.setSearchEngineUrlResults(searchEngineResults); - - return preference; - } - - protected User changeUser(HttpServletRequest request, User newUser) - throws NoSuchAlgorithmException { - String email = request.getParameter("email"); - String newPassword = request.getParameter("newPassword"); - String currentPassword = request.getParameter("currentPassword"); - String confirmNewPassword = request.getParameter("confirmNewPassword"); - - if (email != null && !email.isEmpty()) { - newUser.setEmail(email); - } - if (newPassword != null && confirmNewPassword != null && currentPassword != null) { - if (!newPassword.isEmpty() && !confirmNewPassword.isEmpty() && !currentPassword.isEmpty()) { - if (newPassword.equals(confirmNewPassword)) { - currentPassword = StringUtil.encodeMD5(currentPassword); - if (currentPassword.equals(newUser.getPassword())) { - String md5 = StringUtil.encodeMD5(newPassword); - newUser.setPassword(md5); - } - } - } - } - return newUser; - } - - protected void actionChangePreferences(HttpServletRequest request, HttpSession session, User user) - throws NoSuchAlgorithmException, AddressException, MessagingException { - - WikittyProxy proxy = BowProxy.getInstance(); - - Preference preference = changePreference(request, session); - proxy.store(preference); - - User newUser = proxy.restore(User.class, user.getWikittyId()); - newUser = changeUser(request, newUser); - newUser = proxy.store(newUser); - session.setAttribute("user", newUser); - - preference = proxy.restore(Preference.class, newUser.getWikittyId()); - session.setAttribute("preference", preference); - } - - protected void sendMail(String email, String password) - throws AddressException, MessagingException { - - BowConfig config = BowConfig.getInstance(); - String smtpServer = config.getSmtpServer(); - Properties properties = new Properties(); - properties.put("mail.smtp.host", smtpServer); - - Session session = Session.getDefaultInstance(properties, null); - session.setDebug(true); - - Message msg = new MimeMessage(session); - - InternetAddress toAddress = new InternetAddress(email); - msg.addRecipient(Message.RecipientType.TO, toAddress); - - String addressFrom = config.getAddressFrom(); - InternetAddress fromAddress = new InternetAddress(addressFrom); - msg.setFrom(fromAddress); - - String messageSubject = "[Bow] New Password"; - msg.setSubject(messageSubject); - - String messageBody = "Hi,\n\n"; - messageBody += "Your new password: " + password + "\n"; - messageBody += "Your email: " + email + "\n\n"; - msg.setContent(messageBody, "text/plain"); - - Transport.send(msg); - } - - protected boolean passwordExists(String password) { - WikittyProxy proxy = BowProxy.getInstance(); - Criteria criteria = Search.query().eq(User.FQ_FIELD_PASSWORD, password).criteria(); - List<User> users = proxy.findAllByCriteria(User.class, criteria).getAll(); - if (users != null && users.size() > 0) { - return true; - } - return false; - } - - protected void actionSendPassword(HttpServletRequest request, HttpServletResponse response) - throws NoSuchAlgorithmException, AddressException, MessagingException, ServletException, IOException { - String email = request.getParameter("email"); - if (email != null) { - email = email.trim(); - if (!email.isEmpty()) { - WikittyProxy proxy = BowProxy.getInstance(); - Criteria criteria = Search.query().eq(User.FQ_FIELD_EMAIL, email).criteria(); - User user = proxy.findByCriteria(User.class, criteria); - if (user != null) { - boolean bool = true; - String password = ""; - String md5 = ""; - while (bool) { - password = RandomStringUtils.randomAlphanumeric(20); - md5 = StringUtil.encodeMD5(password); - bool = passwordExists(md5); - } - sendMail(email, password); - user.setPassword(md5); - proxy.store(user); - request.getRequestDispatcher("login.jsp").forward(request, response); - } else { - request.setAttribute("errorMsgUser", "This email address doesn't exist"); - } - } else { - request.setAttribute("errorMsgUser", "Please enter an email address"); - } - } - request.getRequestDispatcher("forgotPassword.jsp").forward(request, response); - } - - protected void actionReIndexation(HttpServletRequest request, HttpSession session, User user) { - if ((Boolean) session.getAttribute("admin")) { - WikittyProxy proxy = BowProxy.getInstance(); - proxy.getWikittyService().syncEngin(proxy.getSecurityToken()); - } - } -} Modified: trunk/src/main/java/org/chorem/bow/action/AddAliasAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/AddAliasAction.java 2011-01-07 11:19:18 UTC (rev 166) +++ trunk/src/main/java/org/chorem/bow/action/AddAliasAction.java 2011-01-07 19:02:06 UTC (rev 167) @@ -46,6 +46,7 @@ WikittyProxy proxy = BowProxy.getInstance(); 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()) { if (bookmarkId != null && !bookmarkId.isEmpty()) { Bookmark bookmark = proxy.restore(Bookmark.class, bookmarkId); Modified: trunk/src/main/java/org/chorem/bow/action/AddUrlAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/AddUrlAction.java 2011-01-07 11:19:18 UTC (rev 166) +++ trunk/src/main/java/org/chorem/bow/action/AddUrlAction.java 2011-01-07 19:02:06 UTC (rev 167) @@ -20,6 +20,7 @@ protected String nameAndTags; protected Map<String, Object> session; + /** * @return the link */ Modified: trunk/src/main/java/org/chorem/bow/action/EditBookmarkAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/EditBookmarkAction.java 2011-01-07 11:19:18 UTC (rev 166) +++ trunk/src/main/java/org/chorem/bow/action/EditBookmarkAction.java 2011-01-07 19:02:06 UTC (rev 167) @@ -71,13 +71,12 @@ request.setAttribute("name", bookmark.getDescription()); request.setAttribute("alias", bookmark.getAlias()); request.setAttribute("tags", BookmarkActions.getBookmarkTagsString(bookmark)); - request.setAttribute("action", "bow/modifyBookmark.action"); - request.setAttribute("bookmarkId", bookmarkId); + request.setAttribute("formAction", "/bow/modifyBookmark.action?bookmarkId=" + bookmarkId); } } if (searchLine == null) { BowInit.initHomePage(request, (User)session.get("user")); - return NONE; + return "home"; } else { try { BowSearch.search(request, (User)session.get("user")); @@ -88,7 +87,7 @@ // TODO Auto-generated catch block e.printStackTrace(); } - return SUCCESS; + return "search"; } } } \ No newline at end of file Modified: trunk/src/main/java/org/chorem/bow/action/LoginAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/LoginAction.java 2011-01-07 11:19:18 UTC (rev 166) +++ trunk/src/main/java/org/chorem/bow/action/LoginAction.java 2011-01-07 19:02:06 UTC (rev 167) @@ -68,20 +68,12 @@ public void setSession(Map<String, Object> session) { this.session = session; } - - public Map<String, Object> getSession() { - return this.session; - } @Override public void setServletRequest(HttpServletRequest request) { this.servletRequest = request; } - public HttpServletRequest getServletRequest() { - return this.servletRequest; - } - protected User checkLogin(String email, String password) throws NoSuchAlgorithmException { if (email != null && password != null) { if (!email.isEmpty() && !password.equals(StringUtil.encodeMD5(""))) { Modified: trunk/src/main/resources/i18n/bow_en_GB.properties =================================================================== --- trunk/src/main/resources/i18n/bow_en_GB.properties 2011-01-07 11:19:18 UTC (rev 166) +++ trunk/src/main/resources/i18n/bow_en_GB.properties 2011-01-07 19:02:06 UTC (rev 167) @@ -1,4 +1,3 @@ -bookmarksHomePage= bow.action.locale.english=English bow.action.locale.french=French bow.bookmark.badFileFormat= @@ -44,7 +43,7 @@ bow.preferences.siteLook= bow.preferences.submit= bow.preferences.tagsNb= -bow.preferences.title= +bow.preferences.title=Preferences bow.preferences.userInfo= bow.register.emailAldyUsed=This email address is already used bow.register.invalidLogin= @@ -56,11 +55,3 @@ bow.register.submit=Register bow.register.title=Register bow.requiredstring=${getText(fieldKey)} is required -colors= -confirmNewPassword= -currentPassword= -email= -newPassword= -searchEngineUrlResults= -searchEngineUrlSuggestions= -tagsNb= Modified: trunk/src/main/resources/i18n/bow_fr_FR.properties =================================================================== --- trunk/src/main/resources/i18n/bow_fr_FR.properties 2011-01-07 11:19:18 UTC (rev 166) +++ trunk/src/main/resources/i18n/bow_fr_FR.properties 2011-01-07 19:02:06 UTC (rev 167) @@ -1,4 +1,3 @@ -bookmarksHomePage= bow.action.locale.english=Anglais bow.action.locale.french=Fran\u00E7ais bow.bookmark.badFileFormat= @@ -44,7 +43,7 @@ bow.preferences.siteLook= bow.preferences.submit= bow.preferences.tagsNb= -bow.preferences.title= +bow.preferences.title=Pr\u00E9f\u00E9rences bow.preferences.userInfo= bow.register.emailAldyUsed=Cette adresse email est d\u00E9j\u00E0 utilis\u00E9e bow.register.invalidLogin= @@ -56,11 +55,3 @@ bow.register.submit=S''enregistrer bow.register.title=S''enregistrer bow.requiredstring=${getText(fieldKey)} est obligatoire -colors= -confirmNewPassword= -currentPassword= -email= -newPassword= -searchEngineUrlResults= -searchEngineUrlSuggestions= -tagsNb= Modified: trunk/src/main/resources/struts.xml =================================================================== --- trunk/src/main/resources/struts.xml 2011-01-07 11:19:18 UTC (rev 166) +++ trunk/src/main/resources/struts.xml 2011-01-07 19:02:06 UTC (rev 167) @@ -46,15 +46,15 @@ <result type="redirectAction">home</result> </action> <action name="modifyBookmark" class="org.chorem.bow.action.ModifyBookmarkAction"> - <result name="home">/jsp/home.jsp</result> <result name="search">/jsp/search.jsp</result> + <result type="redirectAction">home</result> </action> <action name="removeBookmark" class="org.chorem.bow.action.RemoveBookmarkAction"> <result type="redirectAction">home</result> <result name="search">/jsp/search.jsp</result> </action> <action name="editBookmark" class="org.chorem.bow.action.EditBookmarkAction"> - <result name="home">/jsp/home.jsp</result> + <result name="home" type="redirectAction">home</result> <result name="search">/jsp/search.jsp</result> </action> </package> @@ -75,6 +75,7 @@ </action> <action name="addAlias" class="org.chorem.bow.action.AddAliasAction"> <!-- La redirection change selon le type de page sur laquelle on est, donc je ne vois pas trop comment faire ça pour le moment--> + <result type="redirectAction">home</result> </action> <action name="order" class="org.chorem.bow.action.OrderAction"> <result>/jsp/search.jsp</result> Modified: trunk/src/main/webapp/js/bookmark.js =================================================================== --- trunk/src/main/webapp/js/bookmark.js 2011-01-07 11:19:18 UTC (rev 166) +++ trunk/src/main/webapp/js/bookmark.js 2011-01-07 19:02:06 UTC (rev 167) @@ -1,6 +1,6 @@ function modify(name, alias, tags, link, action, id) { var form = document.getElementById("bookmarkForm"); - form.elements["url"].value = link; + form.elements["link"].value = link; form.elements["name"].value = name; form.elements["tags"].value = tags; form.elements["alias"].value = alias; Modified: trunk/src/main/webapp/jsp/inc/bookmark.jsp =================================================================== --- trunk/src/main/webapp/jsp/inc/bookmark.jsp 2011-01-07 11:19:18 UTC (rev 166) +++ trunk/src/main/webapp/jsp/inc/bookmark.jsp 2011-01-07 19:02:06 UTC (rev 167) @@ -56,10 +56,10 @@ <%=bookmark.getAlias()%> </a> <p class="date"> (<%=sdf.format(bookmark.getDate())%>)</p> - <s:url id="editBookmark" action="editBookmark"> + <s:url id="editBookmark" action="modifyBookmark"> <s:param name="bookmarkId"><%=bookmark.getWikittyId()%><%=search%></s:param> </s:url> - <s:a cssClass="edit" href="%{editBookmark}" onclick="return modify('<%=bookmark.getDescription()%>', '<%=bookmark.getAlias()%>', '<%=BookmarkActions.getBookmarkTagsString(bookmark)%>', '<%=link%>', %{editBookmark}, '<%=bookmark.getWikittyId()%>');"></s:a> + <s:a cssClass="edit" href="%{editBookmark}" onclick="return modify('%{#request.bookmark.getDescription()}', '%{#request.bookmark.getAlias()}', '%{#request.bookmark.getTags()}', '%{#request.bookmark.getLink()}', '%{editBookmark}', '%{#request.bookmark.getWikittyId()}');"></s:a> <s:url id="removeBookmark" action="removeBookmark"> <s:param name="bookmarkId"><%=bookmark.getWikittyId()%><%=search%></s:param> </s:url> @@ -81,6 +81,7 @@ <strong>Tags :</strong> <% Set<String> tagList = bookmark.getTags(); + if (tagList != null && !tagList.isEmpty()) { for (String tag : tagList) { %> Modified: trunk/src/main/webapp/jsp/inc/rightMenu.jsp =================================================================== --- trunk/src/main/webapp/jsp/inc/rightMenu.jsp 2011-01-07 11:19:18 UTC (rev 166) +++ trunk/src/main/webapp/jsp/inc/rightMenu.jsp 2011-01-07 19:02:06 UTC (rev 167) @@ -75,7 +75,8 @@ if (formAlias == null) formAlias = "alias"; if (formAction == null) - formAction = "/bow/addUrl.action"; + request.setAttribute("formAction", "/bow/addUrl.action"); + //formAction = "/bow/addUrl.action"; %> <div id="logout" xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" @@ -93,24 +94,24 @@ <li><s:a action="admin"><s:text name="bow.rightMenu.admin" /></s:a></li> <% } %> <li><s:a action="preferences"><s:text name="bow.preferences.title" /></s:a></li> - <li><a title="%{getText('temporaryLinkDescription')}" 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+'|');if%20(nameAndTags!=(document.title+'|')){var%20link='<%=url%>/addUrl.action&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);"><s:text name="bow.rightMenu.bookmark.temporaryLink" /></a></li> - <li><a title="%{getText('permanentLinkDescription')}" 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+'|');if%20(nameAndTags!=(document.title+'|')){var%20link='<%=url%>/addUrl.action&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);"><s:text name="bow.rightMenu.bookmark.permanentLink" /></a></li> + <li><s:a title="%{getText('bow.rightMenu.bookmark.temporaryLinkDescription')}" 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+'|');if%20(nameAndTags!=(document.title+'|')){var%20link='<%=url%>/addUrl.action&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);"><s:text name="bow.rightMenu.bookmark.temporaryLink" /></s:a></li> + <li><s:a title="%{getText('bow.rightMenu.bookmark.permanentLinkDescription')}" 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+'|');if%20(nameAndTags!=(document.title+'|')){var%20link='<%=url%>/addUrl.action&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);"><s:text name="bow.rightMenu.bookmark.permanentLink" /></s:a></li> </ul> <div id="extensions"> <h2><s:text name="bow.rightMenu.extensions" /></h2> <ul class="droite"> <li><a href="extensions/bow4chromium.crx"><img src="img/chromium.png" alt="Chromium" class="extensionIcon" />Extension pour Chromium</a></li> - <li><strong><s:text name="bow.rightMenu.token.permanent" /></strong> <%= permanentToken %></li> - <li><strong><s:text name="bow.rightMenu.token.temporary" /></strong> <%= temporaryToken %></li> + <li><strong><s:text name="bow.rightMenu.token.permanent" /></strong> <%=permanentToken%></li> + <li><strong><s:text name="bow.rightMenu.token.temporary" /></strong> <%=temporaryToken%></li> </ul> </div> <div id="add" class="clearfix"> <h2><s:text name="bow.rightMenu.bookmark.addModify" /></h2> - <s:form id="bookmarkForm" action="addUrl"> - <s:textfield key="bow.rightMenu.bookmark.link" name="link" /><!-- <%=formLink%> --> - <s:textfield key="bow.rightMenu.bookmark.alias" name="alias" /><!-- <%=formAlias%> --> - <s:textfield key="bow.rightMenu.bookmark.name" name="name" /><!-- <%=formName%> --> - <s:textfield key="bow.rightMenu.bookmark.tags" name="tags" /><!-- <%=formTags%> --> + <s:form id="bookmarkForm" action="%{#request.formAction}"> + <s:textfield key="bow.rightMenu.bookmark.link" name="link" value="%{#request.link}" /> + <s:textfield key="bow.rightMenu.bookmark.alias" name="alias" value="%{#request.alias}" /> + <s:textfield key="bow.rightMenu.bookmark.name" name="name" value="%{#request.name}" /> + <s:textfield key="bow.rightMenu.bookmark.tags" name="tags" value="%{#request.tags}" /> <s:submit key="bow.rightMenu.bookmark.submit" /> </s:form> </div> Modified: trunk/src/main/webapp/jsp/preferences.jsp =================================================================== --- trunk/src/main/webapp/jsp/preferences.jsp 2011-01-07 11:19:18 UTC (rev 166) +++ trunk/src/main/webapp/jsp/preferences.jsp 2011-01-07 19:02:06 UTC (rev 167) @@ -95,7 +95,10 @@ %> <div class="deleteImport deleteImport<%=bgColors[i % colorsNb]%>"> <span><%= date + " (" + bookmarkImport.getCount() + " bookmarks)" %></span> - <a class="deleteImportButton" href="" onclick="deleteConfirmation('/bow/deleteImport.action&date=<%=dateSave%>',<%=bookmarkImport.getCount()%>,'<%=date%>'); return(false);"></a> + <s:url id="deleteImport" action="deleteImport"> + <s:param name="date"><%=dateSave%></s:param> + </s:url> + <s:a cssClass="deleteImportButton" href="" onclick="deleteConfirmation('%{deleteImport}','%{#bookmarkImport!getCount}','<%=date%>'); return(false);"></s:a> </div> <% i++; @@ -109,19 +112,6 @@ } } %> - <s:if test="%{#bookmarksImportDate != null && #bookmarksImportDate.size() > 0}"> - <s:iterator value="bookmarksImportDate"> - <div class="deleteImport"> - <span>(<s:property value="topicName" /> bookmarks)</span> - <a class="deleteImportButton" href="" onclick="deleteConfirmation('/bow/deleteImport.action&date=',,''); return(false);"></a> - </div> - </s:iterator> - </s:if> - <s:else> - <div class="deleteImport deleteImportWhite"> - <span><s:text name="bow.preferences.noImportedBookmarks" /></span> - </div> - </s:else> </div> <jsp:include page="inc/rightMenu.jsp" flush="true" /> </body>