Author: vbriand Date: 2011-01-06 18:33:35 +0100 (Thu, 06 Jan 2011) New Revision: 165 Url: http://chorem.org/repositories/revision/bow/165 Log: The preferences page works again. On the home page, the link now redirects to the bookmark page. Added: trunk/src/main/java/org/chorem/bow/action/PreferencesAction.java Removed: trunk/src/main/java/org/chorem/bow/action/ChangePreferencesAction.java Modified: trunk/src/main/java/org/chorem/bow/action/AddClickAction.java trunk/src/main/java/org/chorem/bow/action/GenerateTokenAction.java trunk/src/main/resources/struts.xml trunk/src/main/webapp/index.jsp trunk/src/main/webapp/jsp/preferences.jsp Modified: trunk/src/main/java/org/chorem/bow/action/AddClickAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/AddClickAction.java 2011-01-06 14:22:41 UTC (rev 164) +++ trunk/src/main/java/org/chorem/bow/action/AddClickAction.java 2011-01-06 17:33:35 UTC (rev 165) @@ -7,6 +7,7 @@ public class AddClickAction extends BowBaseAction { private static final long serialVersionUID = 8579081104294143087L; protected String bookmarkId; + protected String link; /** * @return the bookmarkId @@ -21,6 +22,18 @@ this.bookmarkId = bookmarkId; } + /** + * @return the link + */ + public String getLink() { + return link; + } + /** + * @param link the link to set + */ + public void setLink(String link) { + this.link = link; + } public String execute() { if (bookmarkId != null && !bookmarkId.isEmpty()) { WikittyProxy proxy = BowProxy.getInstance(); @@ -28,6 +41,7 @@ if (bookmark != null) { bookmark.setClick(bookmark.getClick() + 1); proxy.store(bookmark); + link = bookmark.getLink(); return SUCCESS; } } Deleted: trunk/src/main/java/org/chorem/bow/action/ChangePreferencesAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/ChangePreferencesAction.java 2011-01-06 14:22:41 UTC (rev 164) +++ trunk/src/main/java/org/chorem/bow/action/ChangePreferencesAction.java 2011-01-06 17:33:35 UTC (rev 165) @@ -1,207 +0,0 @@ -package org.chorem.bow.action; - -import java.security.NoSuchAlgorithmException; -import java.util.Map; - -import org.apache.struts2.interceptor.SessionAware; -import org.chorem.bow.BowProxy; -import org.chorem.bow.Preference; -import org.chorem.bow.User; -import org.nuiton.util.StringUtil; -import org.nuiton.wikitty.WikittyProxy; - -public class ChangePreferencesAction extends BowBaseAction implements SessionAware { - private static final long serialVersionUID = -1923646256914239581L; - protected String colors; - protected String tagsNb; - protected String bookmarks; - protected String searchEngineUrlSuggestions; - protected String searchEngineUrlResults; - protected String email; - protected String newPassword; - protected String currentPassword; - protected String confirmNewPassword; - protected Map<String, Object> session; - - /** - * @return the colors - */ - public String getColors() { - return colors; - } - - /** - * @param colors the colors to set - */ - public void setColors(String colors) { - this.colors = colors; - } - - /** - * @return the tagsNb - */ - public String getTagsNb() { - return tagsNb; - } - - /** - * @param tagsNb the tagsNb to set - */ - public void setTagsNb(String tagsNb) { - this.tagsNb = tagsNb; - } - - /** - * @return the bookmarks - */ - public String getBookmarks() { - return bookmarks; - } - - /** - * @param bookmarks the bookmarks to set - */ - public void setBookmarks(String bookmarks) { - this.bookmarks = bookmarks; - } - - /** - * @return the searchEngineUrlSuggestions - */ - public String getSearchEngineUrlSuggestions() { - return searchEngineUrlSuggestions; - } - - /** - * @param searchEngineUrlSuggestions the searchEngineUrlSuggestions to set - */ - public void setSearchEngineUrlSuggestions(String searchEngineUrlSuggestions) { - this.searchEngineUrlSuggestions = searchEngineUrlSuggestions; - } - - /** - * @return the searchEngineUrlResults - */ - public String getSearchEngineUrlResults() { - return searchEngineUrlResults; - } - - /** - * @param searchEngineUrlResults the searchEngineUrlResults to set - */ - public void setSearchEngineUrlResults(String searchEngineUrlResults) { - this.searchEngineUrlResults = searchEngineUrlResults; - } - - /** - * @return the email - */ - public String getEmail() { - return email; - } - - /** - * @param email the email to set - */ - public void setEmail(String email) { - this.email = email; - } - - /** - * @return the newPassword - */ - public String getNewPassword() { - return newPassword; - } - - /** - * @param newPassword the newPassword to set - */ - public void setNewPassword(String newPassword) { - this.newPassword = newPassword; - } - - /** - * @return the currentPassword - */ - public String getCurrentPassword() { - return currentPassword; - } - - /** - * @param currentPassword the currentPassword to set - */ - public void setCurrentPassword(String currentPassword) { - this.currentPassword = currentPassword; - } - - /** - * @return the confirmNewPassword - */ - public String getConfirmNewPassword() { - return confirmNewPassword; - } - - /** - * @param confirmNewPassword the confirmNewPassword to set - */ - public void setConfirmNewPassword(String confirmNewPassword) { - this.confirmNewPassword = confirmNewPassword; - } - - @Override - public void setSession(Map<String, Object> session) { - this.session = session; - } - - protected Preference changePreference() { - Preference preference = (Preference)session.get("preference"); - - preference.setColors(colors); - preference.setTags(Integer.valueOf(tagsNb)); - preference.setBookmarks(Integer.valueOf(bookmarks)); - preference.setSearchEngineUrlSuggestions(searchEngineUrlSuggestions); - preference.setSearchEngineUrlResults(searchEngineUrlResults); - - return preference; - } - - protected User changeUser(User newUser) - throws NoSuchAlgorithmException { - 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; - } - - public String execute() { - WikittyProxy proxy = BowProxy.getInstance(); - Preference preference = changePreference(); - proxy.store(preference); - - User newUser = proxy.restore(User.class, ((User)session.get("user")).getWikittyId()); - try { - newUser = changeUser(newUser); - } catch (NoSuchAlgorithmException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - newUser = proxy.store(newUser); - session.put("user", newUser); - - preference = proxy.restore(Preference.class, newUser.getWikittyId()); - session.put("preference", preference); - return SUCCESS; - } -} \ No newline at end of file Modified: trunk/src/main/java/org/chorem/bow/action/GenerateTokenAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/GenerateTokenAction.java 2011-01-06 14:22:41 UTC (rev 164) +++ trunk/src/main/java/org/chorem/bow/action/GenerateTokenAction.java 2011-01-06 17:33:35 UTC (rev 165) @@ -23,37 +23,41 @@ } public String execute() { - WikittyProxy proxy = BowProxy.getInstance(); User user = (User)session.get("user"); - 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.get("tokenActions"); - - if (tokenActions != null) { - String token; - try { - token = tokenActions.generateToken(); //Generates an encoding MD5 token - criteria = Search.query().eq(Token.FQ_FIELD_TOKEN, token).criteria(); - Token oldToken = proxy.findByCriteria(Token.class, criteria); - - if (oldToken == null) { //Checks 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(""); + + if (user != null) { + 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.get("tokenActions"); + + if (tokenActions != null) { + String token; + try { + token = tokenActions.generateToken(); //Generates an encoding MD5 token + criteria = Search.query().eq(Token.FQ_FIELD_TOKEN, token).criteria(); + Token oldToken = proxy.findByCriteria(Token.class, criteria); + + if (oldToken == null) { //Checks 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(""); + } + } catch (NoSuchAlgorithmException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } - } catch (NoSuchAlgorithmException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } + return SUCCESS; } - return SUCCESS; + return LOGIN; } } \ No newline at end of file Added: trunk/src/main/java/org/chorem/bow/action/PreferencesAction.java =================================================================== --- trunk/src/main/java/org/chorem/bow/action/PreferencesAction.java (rev 0) +++ trunk/src/main/java/org/chorem/bow/action/PreferencesAction.java 2011-01-06 17:33:35 UTC (rev 165) @@ -0,0 +1,245 @@ +package org.chorem.bow.action; + +import java.security.NoSuchAlgorithmException; +import java.util.Map; + +import org.apache.struts2.interceptor.SessionAware; +import org.chorem.bow.BowProxy; +import org.chorem.bow.Preference; +import org.chorem.bow.User; +import org.nuiton.util.StringUtil; +import org.nuiton.wikitty.WikittyProxy; + +public class PreferencesAction extends BowBaseAction implements SessionAware { + private static final long serialVersionUID = -58341106356599721L; + protected String colors; + protected String tagsNb; + protected String bookmarksHomePage; + protected String searchEngineUrlSuggestions; + protected String searchEngineUrlResults; + protected String email; + protected String newPassword; + protected String currentPassword; + protected String confirmNewPassword; + protected String update; + protected Map<String, Object> session; + + /** + * @return the colors + */ + public String getColors() { + return colors; + } + + /** + * @param colors the colors to set + */ + public void setColors(String colors) { + this.colors = colors; + } + + /** + * @return the tagsNb + */ + public String getTagsNb() { + return tagsNb; + } + + /** + * @param tagsNb the tagsNb to set + */ + public void setTagsNb(String tagsNb) { + this.tagsNb = tagsNb; + } + + /** + * @return the bookmarksHomePage + */ + public String getBookmarksHomePage() { + return bookmarksHomePage; + } + + /** + * @param bookmarksHomePage the bookmarksHomePage to set + */ + public void setBookmarksHomePage(String bookmarksHomePage) { + this.bookmarksHomePage = bookmarksHomePage; + } + + /** + * @return the searchEngineUrlSuggestions + */ + public String getSearchEngineUrlSuggestions() { + return searchEngineUrlSuggestions; + } + + /** + * @param searchEngineUrlSuggestions the searchEngineUrlSuggestions to set + */ + public void setSearchEngineUrlSuggestions(String searchEngineUrlSuggestions) { + this.searchEngineUrlSuggestions = searchEngineUrlSuggestions; + } + + /** + * @return the searchEngineUrlResults + */ + public String getSearchEngineUrlResults() { + return searchEngineUrlResults; + } + + /** + * @param searchEngineUrlResults the searchEngineUrlResults to set + */ + public void setSearchEngineUrlResults(String searchEngineUrlResults) { + this.searchEngineUrlResults = searchEngineUrlResults; + } + + /** + * @return the email + */ + public String getEmail() { + return email; + } + + /** + * @param email the email to set + */ + public void setEmail(String email) { + this.email = email; + } + + /** + * @return the newPassword + */ + public String getNewPassword() { + return newPassword; + } + + /** + * @param newPassword the newPassword to set + */ + public void setNewPassword(String newPassword) { + this.newPassword = newPassword; + } + + /** + * @return the currentPassword + */ + public String getCurrentPassword() { + return currentPassword; + } + + /** + * @param currentPassword the currentPassword to set + */ + public void setCurrentPassword(String currentPassword) { + this.currentPassword = currentPassword; + } + + /** + * @return the confirmNewPassword + */ + public String getConfirmNewPassword() { + return confirmNewPassword; + } + + /** + * @param confirmNewPassword the confirmNewPassword to set + */ + public void setConfirmNewPassword(String confirmNewPassword) { + this.confirmNewPassword = confirmNewPassword; + } + + /** + * @return the update + */ + public String getUpdate() { + return update; + } + + /** + * @param update the update to set + */ + public void setUpdate(String update) { + this.update = update; + } + + @Override + public void setSession(Map<String, Object> session) { + this.session = session; + } + + protected Preference changePreference() { + Preference preference = (Preference)session.get("preference"); + + preference.setColors(colors); + if ((tagsNb != null && !tagsNb.isEmpty())) { + preference.setTags(Integer.valueOf(tagsNb)); + } + if (bookmarksHomePage != null && !bookmarksHomePage.isEmpty()) + preference.setBookmarks(Integer.valueOf(bookmarksHomePage)); + preference.setSearchEngineUrlSuggestions(searchEngineUrlSuggestions); + preference.setSearchEngineUrlResults(searchEngineUrlResults); + + return preference; + } + + protected User changeUser(User newUser) + throws NoSuchAlgorithmException { + 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())) { + newUser.setPassword(StringUtil.encodeMD5(newPassword)); + } + } + } + } + return newUser; + } + + public String execute() { + if ((User)session.get("user") != null) { + if (update != null) { + WikittyProxy proxy = BowProxy.getInstance(); + Preference preference = changePreference(); + proxy.store(preference); + + User newUser = proxy.restore(User.class, ((User)session.get("user")).getWikittyId()); + + try { + newUser = changeUser(newUser); + } catch (NoSuchAlgorithmException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + newUser = proxy.store(newUser); + session.put("user", newUser); + + preference = proxy.restore(Preference.class, newUser.getWikittyId()); + session.put("preference", preference); + return "update"; + } else { + Preference preference = (Preference)session.get("preference"); + User user = (User)session.get("user"); + + if (user != null) { + setEmail(user.getEmail()); + } + if (preference != null) { + setColors(preference.getColors()); + setTagsNb(String.valueOf(preference.getTags())); + setBookmarksHomePage(String.valueOf(preference.getBookmarks())); + setSearchEngineUrlSuggestions(preference.getSearchEngineUrlSuggestions()); + setSearchEngineUrlResults(preference.getSearchEngineUrlResults()); + } + } + return SUCCESS; + } + return LOGIN; + } +} Property changes on: trunk/src/main/java/org/chorem/bow/action/PreferencesAction.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/src/main/resources/struts.xml =================================================================== --- trunk/src/main/resources/struts.xml 2011-01-06 14:22:41 UTC (rev 164) +++ trunk/src/main/resources/struts.xml 2011-01-06 17:33:35 UTC (rev 165) @@ -41,7 +41,6 @@ <result name="search">/jsp/search.jsp</result> <result>/jsp/home.jsp</result> </action> - <!-- modify, remove, edit --> <action name="modifyBookmark" class="org.chorem.bow.action.ModifyBookmarkAction"> <result name="home">/jsp/home.jsp</result> <result name="search">/jsp/search.jsp</result> @@ -64,7 +63,8 @@ <result>/jsp/search.jsp</result> </action> <action name="generateToken" class="org.chorem.bow.action.GenerateTokenAction"> - <result>/jsp/preferences.jsp</result> + <result name="login" type="redirectAction">login_input</result> + <result type="redirectAction">preferences</result> </action> <action name="deleteTag" class="org.chorem.bow.action.DeleteTagAction"> <!-- La redirection change selon le type de page sur laquelle on est, donc je ne vois pas trop comment faire ça pour le moment--> @@ -76,8 +76,8 @@ <result>/jsp/search.jsp</result> </action> <action name="addClick" class="org.chorem.bow.action.AddClickAction"> - <result name="error" type="redirect">/home.action</result> - <result type="redirect">${link}<!--???--></result> + <result name="error" type="redirectAction">home</result> + <result type="redirect">${link}</result> </action> <!-- temporary, permanent --> <action name="*Xml"> @@ -88,17 +88,16 @@ <!-- Plein de types de redirections différentes, et un .forward(..., ...); que je ne sais pas comment changer --> <result>/jsp/suggestions.jsp</result> </action> - <action name="preferences"> - <!-- Cas du getBookmarksByImportDate qu'il faudrait caller quelque part --> + <action name="preferences" class="org.chorem.bow.action.PreferencesAction"> + <!-- Cas du getBookmarksByImportDate qu'il faudrait caler quelque part --> + <result name="login" type="redirectAction">login_input</result> + <result name="update" type="redirectAction">preferences</result> <result>/jsp/preferences.jsp</result> </action> <action name="admin"> <result name="error">/jsp/login.jsp</result> <result>/jsp/admin.jsp</result> </action> - <action name="changePreferences" class="org.chorem.bow.action.ChangePreferencesAction"> - <result>/jsp/preferences.jsp</result> - </action> <action name="deleteImport" class="org.chorem.bow.action.DeleteImportAction"> <result>/jsp/preferences.jsp</result> </action> Modified: trunk/src/main/webapp/index.jsp =================================================================== --- trunk/src/main/webapp/index.jsp 2011-01-06 14:22:41 UTC (rev 164) +++ trunk/src/main/webapp/index.jsp 2011-01-06 17:33:35 UTC (rev 165) @@ -1 +1,8 @@ -<% response.sendRedirect("login_input.action"); %> \ No newline at end of file +<%@page import="org.chorem.bow.User"%> +<% +if ((User)session.getAttribute("user") == null) { + response.sendRedirect("login_input.action"); +} else { + response.sendRedirect("home.action"); +} +%> \ No newline at end of file Modified: trunk/src/main/webapp/jsp/preferences.jsp =================================================================== --- trunk/src/main/webapp/jsp/preferences.jsp 2011-01-06 14:22:41 UTC (rev 164) +++ trunk/src/main/webapp/jsp/preferences.jsp 2011-01-06 17:33:35 UTC (rev 165) @@ -66,6 +66,7 @@ preference.setSearchEngineUrlSuggestions(""); } %> + [[[[[<%=preference.getTags() %>]]]]] <html xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" xmlns:jsp="http://java.sun.com/JSP/Page" @@ -81,7 +82,10 @@ <div class="menu clearfix"> <h2><s:text name="bow.preferences.title" /></h2> </div> - <s:form action="changePreferences"> + <s:url id="changePreferences" action="preferences"> + <s:param name="update">1</s:param> + </s:url> + <s:form action="%{changePreferences}"> <div class="formFrame"> <h3><s:text name="bow.preferences.userInfo" /></h3> <p> @@ -104,7 +108,7 @@ <s:submit key="bow.preferences.submit" /> <br /><br /> <s:url id="home" action="home" /> - <a href="%{home}" id="homePage"><s:text name="bow.home.title" /></a> + <s:a href="%{home}" id="homePage"><s:text name="bow.home.title" /></s:a> </p> </div> </s:form> @@ -113,6 +117,7 @@ </div> <% List<FacetTopic> bookmarkImportList = (List<FacetTopic>)request.getAttribute("bookmarksImportDate"); + if (bookmarkImportList != null) { if (bookmarkImportList.size() > 0) { String bgColors[] = {"Pink", "White"}; @@ -134,16 +139,16 @@ i++; } } else { - %> + %> <div class="deleteImport deleteImportWhite"> <span><s:text name="bow.preferences.noImportedBookmarks" /></span> </div> - <% + <% } } %> </div> - <jsp:include page="/jsp/inc/rightMenu.jsp" flush="true" /> + <jsp:include page="inc/rightMenu.jsp" flush="true" /> </body> </html> <% } %> \ No newline at end of file