r210 - in trunk/src/main/java/org/chorem/bow: . action interceptor
Author: vbriand Date: 2011-02-18 11:40:36 +0100 (Fri, 18 Feb 2011) New Revision: 210 Url: http://chorem.org/repositories/revision/bow/210 Log: Fixed some code (added comments and removed multiple returns in a single method) Modified: trunk/src/main/java/org/chorem/bow/BowUtils.java trunk/src/main/java/org/chorem/bow/SuggestionsComparator.java trunk/src/main/java/org/chorem/bow/action/BowBaseAction.java trunk/src/main/java/org/chorem/bow/action/DeleteImportAction.java trunk/src/main/java/org/chorem/bow/action/DeleteSearchResultsAction.java trunk/src/main/java/org/chorem/bow/action/DeleteTagAction.java trunk/src/main/java/org/chorem/bow/action/EditBookmarkAction.java trunk/src/main/java/org/chorem/bow/action/ExportBookmarksAction.java trunk/src/main/java/org/chorem/bow/action/ForgotPasswordAction.java trunk/src/main/java/org/chorem/bow/action/FullTextSearchAction.java trunk/src/main/java/org/chorem/bow/action/GenerateTokenAction.java trunk/src/main/java/org/chorem/bow/action/HomeAction.java trunk/src/main/java/org/chorem/bow/action/ImportBookmarksAction.java trunk/src/main/java/org/chorem/bow/action/LoginAction.java trunk/src/main/java/org/chorem/bow/action/ModifyBookmarkAction.java trunk/src/main/java/org/chorem/bow/action/OpenSearchResultAction.java trunk/src/main/java/org/chorem/bow/action/OpenSearchSuggestionAction.java trunk/src/main/java/org/chorem/bow/action/OrderAction.java trunk/src/main/java/org/chorem/bow/action/PreferencesAction.java trunk/src/main/java/org/chorem/bow/action/RegisterAction.java trunk/src/main/java/org/chorem/bow/action/RemoveBookmarkAction.java trunk/src/main/java/org/chorem/bow/action/SearchAction.java trunk/src/main/java/org/chorem/bow/interceptor/AldyLoggedInterceptor.java trunk/src/main/java/org/chorem/bow/interceptor/LoginInterceptor.java Modified: trunk/src/main/java/org/chorem/bow/BowUtils.java =================================================================== --- trunk/src/main/java/org/chorem/bow/BowUtils.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/BowUtils.java 2011-02-18 10:40:36 UTC (rev 210) @@ -43,11 +43,12 @@ static public String redirectTo(String searchLine, String fullTextLine) { + String result = "home.action"; + if (!searchLine.equals("") || !fullTextLine.equals("")) { - return "search.action?searchLine=" + searchLine + "&fullTextLine=" + fullTextLine; - } else { - return "home.action"; + result = "search.action?searchLine=" + searchLine + "&fullTextLine=" + fullTextLine; } + return result; } static public BowUser checkToken(BowSession session, String token) { Modified: trunk/src/main/java/org/chorem/bow/SuggestionsComparator.java =================================================================== --- trunk/src/main/java/org/chorem/bow/SuggestionsComparator.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/SuggestionsComparator.java 2011-02-18 10:40:36 UTC (rev 210) @@ -34,12 +34,14 @@ @Override public int compare(FacetTopic o1, FacetTopic o2) { + int result = 0; + if (o1.getCount() < o2.getCount()) { - return 1; + result = 1; } - if (o1.getCount() > o2.getCount()) { - return -1; + else if (o1.getCount() > o2.getCount()) { + result = -1; } - return 0; + return result; } } Modified: trunk/src/main/java/org/chorem/bow/action/BowBaseAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/BowBaseAction.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/action/BowBaseAction.java 2011-02-18 10:40:36 UTC (rev 210) @@ -34,6 +34,12 @@ import org.chorem.bow.BowProxy; import org.chorem.bow.BowSession; +/** + * Base class which must be extended by every action + * Overrides the Struts2 methods to render text in order to explicitly show + * the missing i18n translations + * Allows access to the session and the proxy + */ public class BowBaseAction extends ActionSupport implements SessionAware { private static final long serialVersionUID = 1L; @@ -90,7 +96,8 @@ } @Override - public String getText(String aTextName, String defaultValue, List<Object> args) { + public String getText(String aTextName, String defaultValue, + List<Object> args) { String value = super.getText(aTextName, defaultValue, args); return getSafeText(aTextName, value); } @@ -102,17 +109,22 @@ } @Override - public String getText(String key, String defaultValue, List<Object> args, ValueStack stack) { + public String getText(String key, String defaultValue, List<Object> args, + ValueStack stack) { String value = super.getText(key, defaultValue, args, stack); return getSafeText(key, value); } @Override - public String getText(String key, String defaultValue, String[] args, ValueStack stack) { + public String getText(String key, String defaultValue, String[] args, + ValueStack stack) { String value = super.getText(key, defaultValue, args, stack); return getSafeText(key, value); } + /** + * Surrounds the non translated keys with a marker to make them visible + */ protected String getSafeText(String key, String value) { if (StringUtils.isEmpty(value)) { if (log.isWarnEnabled()) { Modified: trunk/src/main/java/org/chorem/bow/action/DeleteImportAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/DeleteImportAction.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/action/DeleteImportAction.java 2011-02-18 10:40:36 UTC (rev 210) @@ -57,6 +57,9 @@ this.date = date; } + /** + * Deletes a bookmark import + */ public String execute() { if (date != null && 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")) { Modified: trunk/src/main/java/org/chorem/bow/action/DeleteSearchResultsAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/DeleteSearchResultsAction.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/action/DeleteSearchResultsAction.java 2011-02-18 10:40:36 UTC (rev 210) @@ -74,6 +74,9 @@ this.fullTextLine = fullTextLine; } + /** + * Deletes the search results + */ public String execute() { if (searchLine != null && fullTextLine != null) { WikittyProxy proxy = getBowProxy(); Modified: trunk/src/main/java/org/chorem/bow/action/DeleteTagAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/DeleteTagAction.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/action/DeleteTagAction.java 2011-02-18 10:40:36 UTC (rev 210) @@ -100,6 +100,9 @@ return redirectTo; } + /** + * Deletes a bookmark's tag + */ public String execute() { if (deleteTag != null && bookmarkId != null) { if (!bookmarkId.isEmpty()) { Modified: trunk/src/main/java/org/chorem/bow/action/EditBookmarkAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/EditBookmarkAction.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/action/EditBookmarkAction.java 2011-02-18 10:40:36 UTC (rev 210) @@ -98,6 +98,8 @@ } public String execute() { + String result; + if (bookmarkId != null && !bookmarkId.isEmpty()) { WikittyProxy proxy = getBowProxy(); BowBookmark bookmark = proxy.restore(BowBookmark.class, bookmarkId); @@ -118,7 +120,7 @@ BowPreference user = getBowSession().getPreference(); if (searchLine == null || searchLine.equals("")) { BowInit.initHomePage(request, user); - return "home"; + result = "home"; } else { try { BowSearch.search(request, user); @@ -129,7 +131,8 @@ // TODO Auto-generated catch block e.printStackTrace(); } - return "search"; + result = "search"; } + return result; } } \ No newline at end of file Modified: trunk/src/main/java/org/chorem/bow/action/ExportBookmarksAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/ExportBookmarksAction.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/action/ExportBookmarksAction.java 2011-02-18 10:40:36 UTC (rev 210) @@ -53,6 +53,9 @@ this.response = response; } + /** + * Exports the bookmarks in HTML format + */ public String execute() { WikittyProxy proxy = getBowProxy(); BowUser user = getBowSession().getUser(); Modified: trunk/src/main/java/org/chorem/bow/action/ForgotPasswordAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/ForgotPasswordAction.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/action/ForgotPasswordAction.java 2011-02-18 10:40:36 UTC (rev 210) @@ -74,7 +74,12 @@ // return false; // } + /** + * Generates a new password and sends it to the user + */ public String execute() { + String result = INPUT; + if (email != null) { email = email.trim(); if (!email.isEmpty()) { @@ -109,12 +114,12 @@ // TODO Auto-generated catch block e.printStackTrace(); } - return SUCCESS; + result = SUCCESS; } else { addFieldError("email", getText(n_("bow.forgotPassword.emailDoesntExist"))); } } } - return INPUT; + return result; } } \ No newline at end of file Modified: trunk/src/main/java/org/chorem/bow/action/FullTextSearchAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/FullTextSearchAction.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/action/FullTextSearchAction.java 2011-02-18 10:40:36 UTC (rev 210) @@ -77,6 +77,9 @@ this.fullTextLine = fullTextLine; } + /** + * Fulltext search + */ public String execute() { BowSession session = getBowSession(); BowPreference user = session.getPreference(); Modified: trunk/src/main/java/org/chorem/bow/action/GenerateTokenAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/GenerateTokenAction.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/action/GenerateTokenAction.java 2011-02-18 10:40:36 UTC (rev 210) @@ -36,6 +36,9 @@ private static final long serialVersionUID = 1141019772989666309L; + /** + * Generates a new permanent and temporary token + */ public String execute() { BowUser user = getBowSession().getUser(); WikittyProxy proxy = getBowProxy(); Modified: trunk/src/main/java/org/chorem/bow/action/HomeAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/HomeAction.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/action/HomeAction.java 2011-02-18 10:40:36 UTC (rev 210) @@ -57,6 +57,9 @@ this.request = request; } + /** + * Initializes everything before displaying the home page + */ public String execute() { BowPreference user = getBowSession().getPreference(); Modified: trunk/src/main/java/org/chorem/bow/action/ImportBookmarksAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/ImportBookmarksAction.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/action/ImportBookmarksAction.java 2011-02-18 10:40:36 UTC (rev 210) @@ -57,7 +57,8 @@ * * @author poussin */ -public class ImportBookmarksAction extends BowBaseAction implements ServletRequestAware { +public class ImportBookmarksAction extends BowBaseAction implements + ServletRequestAware { private static final long serialVersionUID = -5962680416570797028L; protected File upfile; protected String upfileContentType; @@ -75,7 +76,8 @@ } /** - * @param upfile the upfile to set + * @param upfile + * the upfile to set */ public void setUpfile(File upfile) { this.upfile = upfile; @@ -89,7 +91,8 @@ } /** - * @param upfileContentType the upfileContentType to set + * @param upfileContentType + * the upfileContentType to set */ public void setUpfileContentType(String upfileContentType) { this.upfileContentType = upfileContentType; @@ -103,7 +106,8 @@ } /** - * @param upfileFileName the upfileFileName to set + * @param upfileFileName + * the upfileFileName to set */ public void setUpfileFileName(String upfileFileName) { this.upfileFileName = upfileFileName; @@ -117,7 +121,8 @@ } /** - * @param searchLine the searchLine to set + * @param searchLine + * the searchLine to set */ public void setSearchLine(String searchLine) { this.searchLine = searchLine; @@ -131,7 +136,8 @@ } /** - * @param fullTextLine the fullTextLine to set + * @param fullTextLine + * the fullTextLine to set */ public void setFullTextLine(String fullTextLine) { this.fullTextLine = fullTextLine; @@ -146,135 +152,142 @@ @Override public void setServletRequest(HttpServletRequest request) { - this.request = request; + this.request = request; } -// protected void createImportExtension(List<Bookmark> bookmarks) { -// if (bookmarks != null && !bookmarks.isEmpty()) { -// WikittyProxy proxy = getBowProxy(); -// 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 createImportExtension(List<Bookmark> bookmarks) { + // if (bookmarks != null && !bookmarks.isEmpty()) { + // WikittyProxy proxy = getBowProxy(); + // 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 parseHtmlToBookmarks(NodeList list, BowUser user, Date date, List<BowBookmark> bookmarks, List<String> tagList) - throws ParserException { - if (list != null) { - boolean isFolder = false; - SimpleNodeIterator it = list.elements(); + 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> + 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); //Adds the folder name to the tagList - isFolder = true; - } - } else if (text != null && text.startsWith("A HREF")) { // HREF = new bookmarks - BowBookmark bookmark = BookmarkUtils.createBookmarkFromHtml(text, plainText, user); - Wikitty w = getBowProxy().getWikitty(bookmark); - BowImportHelper.addExtension(w); - BowImportHelper.setImportDate(w, date); - BookmarkUtils.addTagsToBookmark(tagList, bookmark); + if (text != null && text.startsWith("H3")) { // H3 = folder + if (plainText != null && !plainText.isEmpty()) { + tagList.add(plainText); // Adds the folder name to the + // tagList + isFolder = true; + } + } else if (text != null && text.startsWith("A HREF")) { // HREF + // = new + // bookmarks + BowBookmark bookmark = BookmarkUtils + .createBookmarkFromHtml(text, plainText, user); + Wikitty w = getBowProxy().getWikitty(bookmark); + BowImportHelper.addExtension(w); + BowImportHelper.setImportDate(w, date); + BookmarkUtils.addTagsToBookmark(tagList, bookmark); - if (bookmark != null) { - bookmarks.add(bookmark); - } - } - NodeList children = node.getChildren(); + if (bookmark != null) { + bookmarks.add(bookmark); + } + } + NodeList children = node.getChildren(); - if (children != null) { - parseHtmlToBookmarks(children, user, date, 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 (children != null) { + parseHtmlToBookmarks(children, user, date, 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); - } - } - } + if (index > -1) { + tagList.remove(index); + } + } + } } public String execute() { - BowPreference user = getBowSession().getPreference(); - - if (upfile != null) { -// try { -// List<?> lines = FileUtils.readLines(upfile); -// String content = ""; -// -// for (Object line : lines) { -// content += (String)line; -// } - WikittyProxy proxy = getBowProxy(); + BowPreference user = getBowSession().getPreference(); + String result = SUCCESS; - try { - URL url = upfile.toURI().toURL(); - Parser parser = new Parser(url.openConnection()); - NodeList list = parser.parse(null); - List<BowBookmark> bookmarks = new ArrayList<BowBookmark>(); - parseHtmlToBookmarks(list, user, new Date(), bookmarks, new ArrayList<String>()); - bookmarks = proxy.store(bookmarks); -// createImportExtension(bookmarks); - redirectTo = BowUtils.redirectTo(searchLine, fullTextLine); - if (searchLine == null || searchLine.isEmpty()) { - BowInit.initHomePage(request, user); - return SUCCESS; - } else { - try { - BowSearch.search(request, user); - } catch (IOException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } catch (ServletException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - return SUCCESS; - } - } catch (ParserException e) { - request.setAttribute("errorMsgUser", getText(n_("bow.bookmark.badFileFormat"))); - request.setAttribute("errorMsgTech", e.getMessage()); - redirectTo = BowUtils.redirectTo(searchLine, fullTextLine); + if (upfile != null) { + // try { + // List<?> lines = FileUtils.readLines(upfile); + // String content = ""; + // + // for (Object line : lines) { + // content += (String)line; + // } + WikittyProxy proxy = getBowProxy(); - if (searchLine == null || searchLine.isEmpty()) { - BowInit.initHomePage(request, user); - return SUCCESS; - } else { - try { - BowSearch.search(request, user); - } catch (IOException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } catch (ServletException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - return SUCCESS; - } - } catch (IOException e2) { - // TODO Auto-generated catch block - e2.printStackTrace(); - return ERROR; - } - } - return SUCCESS; + try { + URL url = upfile.toURI().toURL(); + Parser parser = new Parser(url.openConnection()); + NodeList list = parser.parse(null); + List<BowBookmark> bookmarks = new ArrayList<BowBookmark>(); + parseHtmlToBookmarks(list, user, new Date(), bookmarks, + new ArrayList<String>()); + bookmarks = proxy.store(bookmarks); + // createImportExtension(bookmarks); + redirectTo = BowUtils.redirectTo(searchLine, fullTextLine); + if (searchLine == null || searchLine.isEmpty()) { + BowInit.initHomePage(request, user); + } else { + try { + BowSearch.search(request, user); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (ServletException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + } catch (ParserException e) { + request.setAttribute("errorMsgUser", + getText(n_("bow.bookmark.badFileFormat"))); + request.setAttribute("errorMsgTech", e.getMessage()); + redirectTo = BowUtils.redirectTo(searchLine, fullTextLine); + + if (searchLine == null || searchLine.isEmpty()) { + BowInit.initHomePage(request, user); + } else { + try { + BowSearch.search(request, user); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (ServletException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + } catch (IOException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + result = ERROR; + } + } + return result; } -} \ 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-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/action/LoginAction.java 2011-02-18 10:40:36 UTC (rev 210) @@ -109,7 +109,12 @@ return result; } + /** + * Authenticates the user if his email and password are valid + */ public String execute() { + String result = INPUT; + if (email != null) { email = email.trim(); @@ -122,10 +127,10 @@ getBowSession().setUser(user); BowPreference pref = getBowSession().getPreference(); BowInit.initHomePage(servletRequest, pref); - return SUCCESS; + result = SUCCESS; } } } - return INPUT; + return result; } } \ No newline at end of file Modified: trunk/src/main/java/org/chorem/bow/action/ModifyBookmarkAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/ModifyBookmarkAction.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/action/ModifyBookmarkAction.java 2011-02-18 10:40:36 UTC (rev 210) @@ -142,6 +142,9 @@ this.fullTextLine = fullTextLine; } + /** + * Modifies a bookmark + */ public String execute() { WikittyProxy proxy = getBowProxy(); BowBookmark bookmark = proxy.restore(BowBookmark.class, bookmarkId); Modified: trunk/src/main/java/org/chorem/bow/action/OpenSearchResultAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/OpenSearchResultAction.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/action/OpenSearchResultAction.java 2011-02-18 10:40:36 UTC (rev 210) @@ -45,7 +45,8 @@ * * @author poussin */ -public class OpenSearchResultAction extends BowBaseAction implements ServletRequestAware, ServletResponseAware { +public class OpenSearchResultAction extends BowBaseAction implements ServletRequestAware, +ServletResponseAware { private static final long serialVersionUID = -1691325797986483856L; protected String searchLine; protected String token; @@ -104,7 +105,7 @@ redirectTo = BowUtils.redirectTo(searchLine, null); } else if (searchLine != null && (searchLine.startsWith(":") || searchLine.startsWith("t:"))) { - //On fait une recherche sur les tags + //Search on tags int index = searchLine.indexOf(":"); searchLine = searchLine.substring(index + 1); //Suppresses first ":" @@ -118,7 +119,7 @@ request.setAttribute("token", token); redirectTo = BowUtils.redirectTo(searchLine, null); } else if (searchLine != null && searchLine.startsWith("f:")) { - // recherche fulltext dans bow + //Fulltext search in bow String fullText = searchLine.substring(2); WikittyProxy proxy = getBowProxy(); Criteria criteria; @@ -135,11 +136,11 @@ request.setAttribute("token", token); redirectTo = BowUtils.redirectTo(searchLine, null); } else if (searchLine != null && searchLine.startsWith("a:")) { - // on redirige vers l'alias demande + //Redirects to the requested alias searchLine = searchLine.substring(2); redirectTo = BowConfig.getInstance().getAliasUrl() + searchLine; } else { - // on fait une recherche sur le moteur de recherche configure + //Search on the chosen search engine BowPreference pref = getBowSession().getPreference(); String searchEngineURL = pref.getSearchEngineUrlResults(); Modified: trunk/src/main/java/org/chorem/bow/action/OpenSearchSuggestionAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/OpenSearchSuggestionAction.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/action/OpenSearchSuggestionAction.java 2011-02-18 10:40:36 UTC (rev 210) @@ -41,7 +41,7 @@ /** * Retourne les suggestions pour l'opensearch en fonction de ce qui a ete deja - * saisie + * saisi * * @author poussin */ Modified: trunk/src/main/java/org/chorem/bow/action/OrderAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/OrderAction.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/action/OrderAction.java 2011-02-18 10:40:36 UTC (rev 210) @@ -80,6 +80,9 @@ this.request = request; } + /** + * Orders the bookmarks according to a criteria + */ public String execute() { BowPreference user = getBowSession().getPreference(); Criteria baseCriteria = BookmarkUtils.getBookmarkListCriteriaByUser(user, searchLine); Modified: trunk/src/main/java/org/chorem/bow/action/PreferencesAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/PreferencesAction.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/action/PreferencesAction.java 2011-02-18 10:40:36 UTC (rev 210) @@ -41,7 +41,7 @@ import static org.nuiton.i18n.I18n.n_; /** - * Change les preferences de l'utilisateur (coleur, password, email, ...) + * Change les preferences de l'utilisateur (couleur, password, email, ...) * * @author poussin */ @@ -254,10 +254,14 @@ return newUser; } + /** + * Changes the user preferences + */ public String execute() { BowProxy proxy = getBowSession().getProxy(); - // BowPreference etends BowUser, donc on l'utilise pour tout + // BowPreference extends BowUser, donc on l'utilise pour tout BowPreference preference = getBowSession().getPreference(); + String result = SUCCESS; setBookmarksImportDate(BookmarkUtils.getBookmarksByImportDate(request, preference)); if (update != null) { //If the user submitted the form @@ -268,20 +272,21 @@ Criteria criteria = Search.query().eq(BowUser.FQ_FIELD_WIKITTYUSER_LOGIN, email).criteria(); BowUser find = proxy.findByCriteria(BowUser.class, criteria); + //If this email address isn't already used (or if it hasn't changed) if (find == null || find.getLogin().equals(preference.getLogin())) { BowUser newUser = changeUser(preference); if (newUser == null) { - return ERROR; + result = ERROR; + } else { + newUser = proxy.store(newUser); + getBowSession().setUser(newUser); + result = "update"; } - newUser = proxy.store(newUser); - getBowSession().setUser(newUser); - - return "update"; } else { // this email address is already used by someone else setEmail(preference.getLogin()); addActionError(getText("bow.preferences.emailAldyExists")); - return ERROR; + result = ERROR; } } else { // If the user didn't submit the form, the fields are filled with @@ -296,6 +301,6 @@ // retrieve last reference preference = getBowSession().getPreference(); BowInit.initHomePage(request, preference); - return SUCCESS; + return result; } } Modified: trunk/src/main/java/org/chorem/bow/action/RegisterAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/RegisterAction.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/action/RegisterAction.java 2011-02-18 10:40:36 UTC (rev 210) @@ -100,67 +100,80 @@ this.request = request; } - protected boolean checkRegister(String passwordMD5) { + /** + * + * @param passwordMD5 the user password hashed in md5 + * @return false if the email address isn't already registered, true + * otherwise + */ + protected boolean alreadyRegistered(String passwordMD5) { + boolean result = true; + if (email != null && passwordMD5 != null) { if (!email.isEmpty() && !passwordMD5.equals(StringUtil.encodeMD5(""))) { WikittyProxy proxy = getBowProxy(); Criteria criteria = Search.query().eq(BowUser.FQ_FIELD_WIKITTYUSER_LOGIN, email).criteria(); //Retrieves user by user name (email) + //If the user doesn't already exist if (proxy.findByCriteria(BowUser.class, criteria) == null) { - return false; + result = false; + } else { //The email address is already used by someone + addFieldError("email", getText(n_("bow.register.emailAldyUsed"))); } - //FIXME : message d'erreur mais return true ??? - addFieldError("email", getText(n_("bow.register.emailAldyUsed"))); - return true; } } - //FIXME : message d'erreur mais return true ??? - //request.setAttribute("errorMsgUser", "Email and password must be correctly filled"); - return true; + return result; } + /** + * Registers the new user and sends an email to confirm registration + */ public String execute() { + String result = INPUT; + if (email != null) { email = email.trim(); if (password != null) { if (!password.equals(repeatPassword)) { addActionError(getText(n_("bow.register.pwdDontMatch"))); - return INPUT; - } - String md5 = StringUtil.encodeMD5(password); + } else { + String md5 = StringUtil.encodeMD5(password); - if (!checkRegister(md5)) { - WikittyProxy proxy = getBowProxy(); - BowUserImpl newUser = new BowUserImpl(); - newUser.setPassword(md5); - newUser.setLogin(email); - String permanentToken = BowUtils.generateToken(); - newUser.setPermanentToken(permanentToken); - BowUser login = proxy.store(newUser); //Stores the new user + //If the email address isn't already used + if (!alreadyRegistered(md5)) { + WikittyProxy proxy = getBowProxy(); + BowUserImpl newUser = new BowUserImpl(); + newUser.setPassword(md5); + newUser.setLogin(email); + String permanentToken = BowUtils.generateToken(); + newUser.setPermanentToken(permanentToken); + BowUser login = proxy.store(newUser); //Stores the new user - if (login == null) { - addFieldError("email", getText(n_("bow.register.invalidLogin"))); - } else { - getBowSession().setUser(login); - BowPreference pref = getBowSession().getPreference(); - BowInit.initHomePage(request, pref); - try { - String mailContent; + //If there was an error when storing the user + if (login == null) { + addFieldError("email", getText(n_("bow.register.invalidLogin"))); + } else { + getBowSession().setUser(login); + BowPreference pref = getBowSession().getPreference(); + BowInit.initHomePage(request, pref); + try { + String mailContent; - mailContent = getText(n_("bow.register.mailHi")) + ",\n\n" + getText(n_("bow.register.mailPwd")) + ": " + password + "\n\n" + getText(n_("bow.register.mailEmail")) + ": " + email + "\n\n"; - BowMail.sendMail(email, getText(n_("bow.register.mailSubject")), mailContent); - } catch (AddressException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (MessagingException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + mailContent = getText(n_("bow.register.mailHi")) + ",\n\n" + getText(n_("bow.register.mailPwd")) + ": " + password + "\n\n" + getText(n_("bow.register.mailEmail")) + ": " + email + "\n\n"; + BowMail.sendMail(email, getText(n_("bow.register.mailSubject")), mailContent); + } catch (AddressException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (MessagingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + result = SUCCESS; } - return SUCCESS; } } } } - return INPUT; + return result; } } Modified: trunk/src/main/java/org/chorem/bow/action/RemoveBookmarkAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/RemoveBookmarkAction.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/action/RemoveBookmarkAction.java 2011-02-18 10:40:36 UTC (rev 210) @@ -88,6 +88,9 @@ return redirectTo; } + /** + * Removes a bookmark + */ public String execute() { if (bookmarkId != null && !bookmarkId.isEmpty()) { try { Modified: trunk/src/main/java/org/chorem/bow/action/SearchAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/SearchAction.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/action/SearchAction.java 2011-02-18 10:40:36 UTC (rev 210) @@ -91,6 +91,9 @@ this.request = request; } + /** + * Searches a bookmark + */ public String execute() { try { BowPreference user = getBowSession().getPreference(); Modified: trunk/src/main/java/org/chorem/bow/interceptor/AldyLoggedInterceptor.java =================================================================== --- trunk/src/main/java/org/chorem/bow/interceptor/AldyLoggedInterceptor.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/interceptor/AldyLoggedInterceptor.java 2011-02-18 10:40:36 UTC (rev 210) @@ -33,6 +33,10 @@ import com.opensymphony.xwork2.interceptor.AbstractInterceptor; import org.chorem.bow.BowSession; +/** + * Interceptor used to redirect a logged user if he tries to access a page on + * which you mustn't be logged (example : login / register page) + */ public class AldyLoggedInterceptor extends AbstractInterceptor { private static final long serialVersionUID = -2411549996072421471L; protected String redirect; @@ -50,11 +54,14 @@ BowSession bowSession = BowSession.getBowSession(session); BowUser user = bowSession.getUser(); + String result = invocation.invoke(); + + //If the user is logged if (user != null) { ServletActionContext.getResponse().sendRedirect(redirect); - return null; + result = null; } - return invocation.invoke(); + return result; } } Modified: trunk/src/main/java/org/chorem/bow/interceptor/LoginInterceptor.java =================================================================== --- trunk/src/main/java/org/chorem/bow/interceptor/LoginInterceptor.java 2011-02-18 09:10:34 UTC (rev 209) +++ trunk/src/main/java/org/chorem/bow/interceptor/LoginInterceptor.java 2011-02-18 10:40:36 UTC (rev 210) @@ -34,6 +34,10 @@ import com.opensymphony.xwork2.interceptor.AbstractInterceptor; import org.chorem.bow.BowSession; +/** + * Interceptor used to redirect a non-logged user if he tries to access a page + * where logging is mandatory + */ public class LoginInterceptor extends AbstractInterceptor { private static final long serialVersionUID = -7520186185205372272L; protected String redirect; @@ -51,22 +55,28 @@ BowSession bowSession = BowSession.getBowSession(session); BowUser user = bowSession.getUser(); + String result = invocation.invoke(); + //If the user isn't logged in if (user == null) { Map<String, Object> params = ActionContext.getContext().getParameters(); + //Retrieves the token value in URL String[] token = (String[]) params.get("token"); if (token != null && !token[0].isEmpty()) { + //Retrieves the user by token user = BowUtils.checkToken(bowSession, token[0]); + //If the token is valid if (user != null) { + //Authenticates the user bowSession.setUser(user); - return invocation.invoke(); } + } else { //If the token is empty + ServletActionContext.getResponse().sendRedirect(redirect); + result = null; } - ServletActionContext.getResponse().sendRedirect(redirect); - return null; } - return invocation.invoke(); + return result; } }
participants (1)
-
vbriand@users.chorem.org