Author: amarkhel
Date: 2009-05-13 07:53:15 -0400 (Wed, 13 May 2009)
New Revision: 14151
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/Authenticator.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/Controller.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/DnDManager.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/FileManager.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/FileUploadManager.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/ImageManager.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/Model.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/NavigationEnum.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/SlideshowManager.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/UserManager.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/DirectLinkHelper.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/EditorBean.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/ErrorHandlerBean.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/Help.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/ImageLoader.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/ImageSizeHelper.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/UserPrefsHelper.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/Environment.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/FileUtils.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/HashUtils.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/ImageDimension.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/SessionListener.java
trunk/examples/photoalbum/source/web/src/main/webapp/includes/help/errorHelp.xhtml
trunk/examples/photoalbum/source/web/src/main/webapp/includes/image/imageInfo.xhtml
trunk/examples/photoalbum/source/web/src/main/webapp/includes/misc/errorPanel.xhtml
trunk/examples/photoalbum/source/web/src/main/webapp/includes/misc/modalPanels.xhtml
trunk/examples/photoalbum/source/web/src/main/webapp/index.xhtml
Log:
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/Authenticator.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/Authenticator.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/Authenticator.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -19,7 +19,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.richfaces.photoalbum.manager;
-
+/**
+ * Class encapsulated all functionality, related to working with
authenticating/registering users.
+ *
+ * @author Andrey Markhel
+ */
import java.io.File;
import java.io.Serializable;
@@ -33,7 +37,6 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.web.RequestParameter;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.core.Events;
import org.jboss.seam.faces.FacesMessages;
@@ -51,11 +54,7 @@
private static final long serialVersionUID = -4585673256547342140L;
- @RequestParameter
- protected Long startConversation;
-
- @In
- @Out
+ @In @Out
User user;
@In
@@ -74,18 +73,27 @@
private boolean conversationStarted = false;
+ /**
+ * Method, that invoked when user try to login to the application.
+ * @return boolean indicator, that denotative is user succesfully loginned to the
system.
+ *
+ */
public boolean authenticate() {
try {
- user = userAction.login(credentials.getUsername(), HashUtils
- .hash(credentials.getPassword()));
+ //If user with this login and password exist, the user object will be returned
+ user = userAction.login(credentials.getUsername(),
HashUtils.hash(credentials.getPassword()));
if (user != null) {
+ //This check is actual only on livedemo server to prevent hacks.
+ //Check if pre-defined user login.
if (Environment.isInProduction() && user.isPreDefined()) {
+ //If true assume that login failed
loginFailed();
return false;
}
identity.addRole(Constants.ADMIN_ROLE);
- Events.instance().raiseEvent(Constants.AUTHENTICATED_EVENT,
- user);
+ //Raise event to controller to update Model
+ Events.instance().raiseEvent(Constants.AUTHENTICATED_EVENT, user);
+ //Login was succesfull
setLoginFailed(false);
return true;
}
@@ -96,70 +104,95 @@
return false;
}
+ /**
+ * Method, that invoked when user logout from application.
+ * @return outcome string to redirect.
+ *
+ */
public String logout() {
identity.logout();
setConversationStarted(false);
return Constants.LOGOUT_OUTCOME;
}
+ /**
+ * Method, that invoked when user try to register in the application.
+ * If registration was successfull, user immediately will be loginned to the system.
+ * @param user - user object, that will be passed to registration procedure.
+ *
+ */
public void register(User user) {
+ //Checks
if (checkPassword(user) || checkUserExist(user)
|| checkEmailExist(user.getEmail())) {
return;
}
user.setPasswordHash(HashUtils.hash(user.getPassword()));
+ //This check is actual only on livedemo server to prevent hacks.
+ //Only admins can mark user as pre-defined
user.setPreDefined(false);
- File avatarData = (File) Contexts.getConversationContext().get(
- Constants.AVATAR_DATA_COMPONENT);
- if (avatarData != null) {
- user.setHasAvatar(true);
- FileManager fileManager = (FileManager) Contexts
- .getApplicationContext().get(
- Constants.FILE_MANAGER_COMPONENT);
- if (fileManager == null
- || !fileManager.saveAvatar(avatarData, user)) {
- Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT,
- Constants.AVATAR_SAVING_ERROR);
- return;
- }
+ if(!handleAvatar(user)){
+ return;
}
try {
userAction.register(user);
} catch (Exception e) {
- Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT,
- Constants.REGISTRATION_ERROR);
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT,
Constants.REGISTRATION_ERROR);
return;
}
+ //Registration was successfull, so we can login this user.
credentials.setPassword(user.getPassword());
credentials.setUsername(user.getLogin());
try {
identity.authenticate();
} catch (LoginException e) {
- Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT,
- Constants.LOGIN_ERROR);
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, Constants.LOGIN_ERROR);
}
}
+ /**
+ * Method, that invoked when user want to go to the registration screen
+ *
+ */
public void goToRegister() {
+ //create new User object
user = new User();
- Contexts.getConversationContext().set(Constants.AVATAR_DATA_COMPONENT,
- null);
+ //Clear avatarData component in conversation scope
+ Contexts.getConversationContext().set(Constants.AVATAR_DATA_COMPONENT, null);
setLoginFailed(false);
+ //raise event to controller to prepare Model.
Events.instance().raiseEvent(Constants.START_REGISTER_EVENT);
}
+ /**
+ * Method, that invoked when new conversation is started.
+ * This method prevent instantiation of couples of conversations when user refresh the
whole page.
+ *
+ * @return string outcome to properly redirect on the current page(to assign to page
parameters conversationId.
+ */
public String startConversation() {
- Events.instance().raiseEvent(Constants.UPDATE_MAIN_AREA_EVENT,
- NavigationEnum.ANONYM);
+ Events.instance().raiseEvent(Constants.UPDATE_MAIN_AREA_EVENT, NavigationEnum.ANONYM);
setConversationStarted(true);
return "";
}
+ private boolean handleAvatar(User user) {
+ File avatarData = (File)
Contexts.getConversationContext().get(Constants.AVATAR_DATA_COMPONENT);
+ if (avatarData != null) {
+ user.setHasAvatar(true);
+ FileManager fileManager = (FileManager)
Contexts.getApplicationContext().get(Constants.FILE_MANAGER_COMPONENT);
+ if (fileManager == null || !fileManager.saveAvatar(avatarData, user)) {
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT,
Constants.AVATAR_SAVING_ERROR);
+ return false;
+ }
+ }
+ return true;
+ }
+
private boolean checkUserExist(User user) {
if (userAction.isUserExist(user.getLogin())) {
- addFacesMessage(Constants.REGISTER_LOGIN_NAME_ID,
- Constants.USER_WITH_THIS_LOGIN_ALREADY_EXIST);
+ addFacesMessage(Constants.REGISTER_LOGIN_NAME_ID,
Constants.USER_WITH_THIS_LOGIN_ALREADY_EXIST);
return true;
}
return false;
@@ -167,8 +200,7 @@
private boolean checkEmailExist(String email) {
if (userAction.isEmailExist(email)) {
- addFacesMessage(Constants.REGISTER_EMAIL_ID,
- Constants.USER_WITH_THIS_EMAIL_ALREADY_EXIST);
+ addFacesMessage(Constants.REGISTER_EMAIL_ID,
Constants.USER_WITH_THIS_EMAIL_ALREADY_EXIST);
return true;
}
return false;
@@ -177,19 +209,13 @@
private void addFacesMessage(String componentId, String message) {
UIComponent root = FacesContext.getCurrentInstance().getViewRoot();
UIComponent component = root.findComponent(componentId);
- FacesContext
- .getCurrentInstance()
- .addMessage(
- component
- .getClientId(FacesContext.getCurrentInstance()),
- new FacesMessage(FacesMessage.SEVERITY_ERROR, message,
- message));
+ FacesContext.getCurrentInstance().addMessage(component
+ .getClientId(FacesContext.getCurrentInstance()),new
FacesMessage(FacesMessage.SEVERITY_ERROR, message, message));
}
private boolean checkPassword(User user) {
if (!user.getPassword().equals(user.getConfirmPassword())) {
- addFacesMessage(Constants.REGISTER_CONFIRM_PASSWORD_ID,
- Constants.CONFIRM_PASSWORD_NOT_EQUALS_PASSWORD);
+ addFacesMessage(Constants.REGISTER_CONFIRM_PASSWORD_ID,
Constants.CONFIRM_PASSWORD_NOT_EQUALS_PASSWORD);
return true;
}
return false;
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/Controller.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/Controller.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/Controller.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -38,7 +38,12 @@
import org.richfaces.photoalbum.domain.Shelf;
import org.richfaces.photoalbum.domain.User;
import org.richfaces.photoalbum.service.Constants;
-
+/**
+ * This class represent 'C' in MVC pattern. It is logic that determine what
actions invoked and what next page need to be showed.
+ * Typically on almost all user actions, this class populates the model and determine new
view to show.
+ * Also contain utility logic, such as checking is the given shelf belongs to the
specified user etc..
+ * @author Andrey Markhel
+ */
@Name("controller")
@Scope(ScopeType.EVENT)
public class Controller implements Serializable{
@@ -49,22 +54,38 @@
@In(scope = ScopeType.SESSION) User user;
+ /**
+ * This method invoked after the user want to see all predefined shelves, existed in
application
+ */
public void selectPublicShelves(){
model.resetModel(NavigationEnum.ANONYM, user, null, null, null, null);
}
+ /**
+ * This method invoked after the user want to see all her shelves.
+ */
public void selectShelves(){
model.resetModel(NavigationEnum.ALL_SHELFS, user, null, null, null, null);
}
+ /**
+ * This method invoked after the user want to see all her albums.
+ */
public void selectAlbums(){
model.resetModel(NavigationEnum.ALL_ALBUMS, user, null, null, null, null);
}
+ /**
+ * This method invoked after the user want to see all her images.
+ */
public void selectImages(){
model.resetModel(NavigationEnum.ALL_IMAGES, user, null, null, null, user.getImages()
);
}
+ /**
+ * This method invoked after the user want to edit specified shelf.
+ * @param shelf - shelf to edit
+ */
@Restrict("#{s:hasRole('admin')}")
public void startEditShelf(Shelf shelf){
if(!canViewShelf(shelf)){
@@ -74,16 +95,25 @@
model.resetModel(NavigationEnum.SHELF_EDIT, shelf.getOwner(), shelf, null, null,
null);
}
+ /**
+ * This method invoked after the user want to interrupt edit shelf process
+ *
+ */
public void cancelEditShelf(){
model.resetModel(NavigationEnum.SHELF_PREVIEW, model.getSelectedShelf().getOwner(),
model.getSelectedShelf(), null, null, null);
}
+ /**
+ * This method invoked after the user want to see specified album independently is it
her album or not.
+ * @param album - album to show
+ */
public void showAlbum(Album album){
if(!canViewAlbum(album)){
pushEvent(Constants.ADD_ERROR_EVENT, Constants.HAVENT_ACCESS);
return;
}
FileManager fileManager =
(FileManager)Contexts.getApplicationContext().get(Constants.FILE_MANAGER_COMPONENT);
+ //Check, that album was not deleted recently.
if(!fileManager.isDirectoryPresent(album.getPath())){
pushEvent(Constants.ADD_ERROR_EVENT, Constants.ALBUM_RECENTLY_DELETED_ERROR);
model.resetModel(NavigationEnum.SHELF_PREVIEW, album.getOwner(), album.getShelf(),
null, null, null);
@@ -92,16 +122,26 @@
model.resetModel(NavigationEnum.ALBUM_PREVIEW, album.getOwner(), album.getShelf(),
album, null, album.getImages());
}
+ /**
+ * This method invoked in cases, when it is need to clear fileUpload component
+ *
+ */
public void resetFileUpload(){
pushEvent(Constants.CLEAR_FILE_UPLOAD_EVENT);
}
+ /**
+ * This method invoked after the user want to see specified image independently is it
her image or not.
+ * @param album - album to show
+ */
public void showImage(Image image){
+ //Clear not-saved comment in editor
pushEvent(Constants.CLEAR_EDITOR_EVENT, "");
if(!canViewImage(image)){
pushEvent(Constants.ADD_ERROR_EVENT, Constants.HAVENT_ACCESS);
return;
}
+ //Check, that image was not deleted recently
final FileManager fileManager =
(FileManager)Contexts.getApplicationContext().get(Constants.FILE_MANAGER_COMPONENT);
if(!fileManager.isFilePresent(image.getFullPath())){
pushEvent(Constants.ADD_ERROR_EVENT, Constants.IMAGE_RECENTLY_DELETED_ERROR);
@@ -112,6 +152,10 @@
image.setVisited(true);
}
+ /**
+ * This method invoked after the user want to edit specified image.
+ * @param image - image to edit
+ */
@Restrict("#{s:hasRole('admin')}")
public void startEditImage(Image image){
if(!canViewImage(image)){
@@ -121,21 +165,37 @@
model.resetModel(NavigationEnum.ALBUM_IMAGE_EDIT, image.getOwner(),
image.getAlbum().getShelf(), image.getAlbum(), image, image.getAlbum().getImages());
}
+ /**
+ * This method invoked after the user want to save just edited user to database.
+ *
+ */
@Restrict("#{s:hasRole('admin')}")
public void editUser(){
pushEvent(Constants.EDIT_USER_EVENT);
model.resetModel(NavigationEnum.ALL_SHELFS, user, model.getSelectedShelf(),
model.getSelectedAlbum(), model.getSelectedImage(), model.getImages());
}
+ /**
+ * This method invoked after the user want to interrupt edit user process
+ *
+ */
public void cancelEditUser(){
pushEvent(Constants.CANCEL_EDIT_USER_EVENT);
model.resetModel(NavigationEnum.ANONYM, user, null, null, null, null);
}
+ /**
+ * This method invoked after the user want to interrupt edit image process
+ *
+ */
public void cancelEditImage(){
model.resetModel(NavigationEnum.ALBUM_IMAGE_PREVIEW,
model.getSelectedImage().getAlbum().getShelf().getOwner(),
model.getSelectedImage().getAlbum().getShelf(), model.getSelectedImage().getAlbum(),
model.getSelectedImage(), model.getSelectedImage().getAlbum().getImages() );
}
+ /**
+ * This method invoked after the user want to see specified shelf independently is it
her shelf or not.
+ * @param album - album to show
+ */
public void showShelf(Shelf shelf){
final FileManager fileManager =
(FileManager)Contexts.getApplicationContext().get(Constants.FILE_MANAGER_COMPONENT);
if(!fileManager.isDirectoryPresent(shelf.getPath())){
@@ -146,6 +206,10 @@
model.resetModel(NavigationEnum.SHELF_PREVIEW, shelf.getOwner(), shelf, null, null,
null);
}
+ /**
+ * This method invoked after the user want to edit specified album.
+ * @param album - album to edit
+ */
@Restrict("#{s:hasRole('admin')}")
public void startEditAlbum(Album album){
if(!album.isOwner(user)) {
@@ -155,71 +219,110 @@
model.resetModel(NavigationEnum.ALBUM_EDIT, album.getOwner(), album.getShelf(), album,
null, album.getImages());
}
+ /**
+ * This method invoked after the user want to interrupt edit album process
+ *
+ */
public void cancelEditAlbum(){
model.resetModel(NavigationEnum.ALBUM_PREVIEW, model.getSelectedAlbum().getOwner(),
model.getSelectedAlbum().getShelf(), model.getSelectedAlbum(), null,
model.getSelectedAlbum().getImages());
}
+ /**
+ * This method observes <code>Constants.ALBUM_ADDED_EVENT</code> and invoked
after the user add new album
+ * @param album - added album
+ */
@Observer(Constants.ALBUM_ADDED_EVENT)
public void onAlbumAdded(Album album){
model.resetModel(NavigationEnum.ALBUM_PREVIEW, album.getOwner(), album.getShelf(),
album, null, album.getImages());
}
+ /**
+ * This method observes <code>Constants.ALBUM_EDITED_EVENT</code> and
invoked after the user edit her album
+ * @param album - edited album
+ */
@Observer(Constants.ALBUM_EDITED_EVENT)
public void onAlbumEdited(Album album){
model.resetModel(NavigationEnum.ALBUM_PREVIEW, model.getSelectedUser(),
model.getSelectedShelf(), album, null, album.getImages());
}
+ /**
+ * This method observes <code>Constants.ALBUM_DELETED_EVENT</code> and
invoked after the user delete her album
+ * @param album - deleted album
+ * @param path - relative path of the album directory
+ */
@Observer(Constants.ALBUM_DELETED_EVENT)
public void onAlbumDeleted(Album album, String path){
model.resetModel(NavigationEnum.ALL_ALBUMS, model.getSelectedUser(),
model.getSelectedShelf(), null, null, null);
}
+ /**
+ * This method observes <code>Constants.SHELF_DELETED_EVENT</code> and
invoked after the user delete her shelf
+ * @param shelf - deleted shelf
+ * @param path - relative path of the shelf directory
+ */
@Observer(Constants.SHELF_DELETED_EVENT)
public void onShelfDeleted(Shelf shelf, String path){
model.resetModel(NavigationEnum.ALL_SHELFS, model.getSelectedUser(), null, null, null,
null);
}
+ /**
+ * This method observes <code>Constants.SHELF_ADDED_EVENT</code> and invoked
after the user add new shelf
+ * @param shelf - added shelf
+ */
@Observer(Constants.SHELF_ADDED_EVENT)
public void onShelfAdded(Shelf shelf){
model.resetModel(NavigationEnum.SHELF_PREVIEW, shelf.getOwner(), shelf, null, null,
null);
}
+ /**
+ * This method observes <code>Constants.SHELF_EDITED_EVENT</code> and
invoked after the user edit her shelf
+ * @param shelf - edited shelf
+ */
@Observer(Constants.SHELF_EDITED_EVENT)
public void onShelfEdited(Shelf shelf){
model.resetModel(NavigationEnum.SHELF_PREVIEW, shelf.getOwner(), shelf, null, null,
null);
}
+ /**
+ * This method observes <code>Constants.IMAGE_DELETED_EVENT</code> and
invoked after the user delete her image
+ * @param image - deleted image
+ * @param path - relative path of the image file
+ */
@Observer(Constants.IMAGE_DELETED_EVENT)
public void onImageDeleted(Image image, String path){
model.resetModel(NavigationEnum.ALBUM_PREVIEW, model.getSelectedUser(),
model.getSelectedShelf(), model.getSelectedAlbum(), null,
model.getSelectedAlbum().getImages());
}
+ /**
+ * This method observes <code>Constants.AUTHENTICATED_EVENT</code> and
invoked after the user successfully authenticate to the system
+ * @param u - authenticated user
+ */
@Observer(Constants.AUTHENTICATED_EVENT)
public void onAuthenticate(User u){
model.resetModel(NavigationEnum.ALL_SHELFS, u, null, null, null, null);
}
+ /**
+ * This method invoked after the user want to go to the file-upload page
+ *
+ */
public void showFileUpload(){
if(!(user.getShelves().size() > 0)){
+ //If user have no shelves, that can start fileupload process
pushEvent(Constants.ADD_ERROR_EVENT, Constants.FILE_UPLOAD_SHOW_ERROR);
return;
}
Album alb = null;
- if(isUserAlbum(model.getSelectedAlbum())){
- alb = model.getSelectedAlbum();
- }
- if(alb == null){
- if(user != null && user.getShelves().size() > 0 &&
user.getShelves().get(0).getAlbums().size() > 0)
- for(Shelf s : user.getShelves()){
- if(s.getAlbums().size() > 0){
- alb = s.getAlbums().get(0);
- break;
- }
- }
- }
+ //If selected album belongs to user
+ alb = setDefaultAlbumToUpload(alb);
model.resetModel(NavigationEnum.FILE_UPLOAD, user, alb.getShelf(), alb, null,
alb.getImages());
- }
+ }
+ /**
+ * This method invoked after the user want to go to the file-upload page and download
images to the specified album
+ * @param album - selected album
+ *
+ */
public void showFileUpload(Album album){
if(!isUserAlbum(album)){
showError(Constants.YOU_CAN_T_ADD_IMAGES_TO_THAT_ALBUM_ERROR);
@@ -228,45 +331,92 @@
model.resetModel(NavigationEnum.FILE_UPLOAD, album.getShelf().getOwner(),
album.getShelf(), album, null, album.getImages());
}
+ /**
+ * This method invoked after the user want to see all shared albums of the specified
user
+ * @param user - user to see
+ *
+ */
public void showSharedAlbums(User user){
model.resetModel(NavigationEnum.USER_SHARED_ALBUMS, user, null, null, null,
user.getSharedImages());
}
+ /**
+ * This method invoked after the user want to see all shared images of the specified
user
+ * @param user - user to see
+ *
+ */
public void showSharedImages(User user){
model.resetModel(NavigationEnum.USER_SHARED_IMAGES, user, null, null, null,
user.getSharedImages());
}
+ /**
+ * This method invoked after the user want to see profile of the specified user
+ * @param user - user to see
+ *
+ */
public void showUser(User user){
model.resetModel(NavigationEnum.USER_PREFS, user, null, null, null, null);
Contexts.getConversationContext().set(Constants.AVATAR_DATA_COMPONENT, null);
}
+ /**
+ * This method invoked after the user want to see all unvisited images, belongs to the
of specified shelf
+ * @param shelf - shelf to see
+ *
+ */
public void showUnvisitedImages(Shelf shelf){
model.resetModel(NavigationEnum.SHELF_UNVISITED, shelf.getOwner(), shelf, null, null,
shelf.getUnvisitedImages());
}
+ /**
+ * This method invoked after the user want to see all unvisited images, belongs to the
of specified album
+ * @param album - album to see
+ *
+ */
public void showUnvisitedImages(Album album){
model.resetModel(NavigationEnum.ALBUM_UNVISITED, album.getOwner(), album.getShelf(),
album, null, album.getUnvisitedImages());
}
+ /**
+ * This method invoked after the user want to see all images, related to the of
specified album
+ * @param metatag - tag to see
+ *
+ */
public void showTag(MetaTag metatag){
model.resetModel(NavigationEnum.TAGS, model.getSelectedUser(),
model.getSelectedShelf(), model.getSelectedAlbum(), model.getSelectedImage(),
metatag.getImages());
model.setSelectedTag(metatag);
}
+ /**
+ * This utility method invoked in case if you want to show to the user specified error
in popup
+ * @param error - error to show
+ *
+ */
public void showError(String error){
pushEvent(Constants.ADD_ERROR_EVENT, error);
}
+ /**
+ * This method observes <code>Constants.START_REGISTER_EVENT</code> and
invoked after the user want to start registration process.
+ *
+ */
@Observer(Constants.START_REGISTER_EVENT)
public void startRegistration(){
model.resetModel(NavigationEnum.REGISTER, user, null, null, null, null);
}
+ /**
+ * This method invoked after the user want to interrupt registration process
+ *
+ */
public void cancelRegistration(){
model.resetModel(NavigationEnum.ANONYM, user, null, null, null, null);
}
+ /**
+ * This utility method determine if the specified node should be marked as selected.
+ * Used in internal rich:tree mechanism
+ */
@SuppressWarnings("unchecked")
public Boolean adviseNodeSelected(UITree tree) {
Object currentNode = tree.getRowData();
@@ -276,11 +426,19 @@
return false;
}
+ /**
+ * This utility method used by custom datascroller to determine images to show.
+ * Used in internal rich:tree mechanism
+ */
public Integer getPage(){
final Integer index = model.getSelectedAlbum().getIndex(model.getSelectedImage());
return index / 5 + 1;
}
+ /**
+ * This utility method used to determine if the specified image belongs to the logged
user
+ * @param image - image to check
+ */
public boolean isUserImage(Image image){
if(image == null || image.getOwner() == null) {
return false;
@@ -288,22 +446,46 @@
return image.isOwner(user);
}
+ /**
+ * This utility method used to determine if the logged user have any shelves.
+ *
+ */
public boolean isUserHaveShelves(){
return user.getShelves().size() > 0 ;
}
+ /**
+ * This utility method used to determine if the logged user have any albums.
+ *
+ */
public boolean isUserHaveAlbums(){
return user.getAlbums().size() > 0 ;
}
+ /**
+ * This utility method used to determine if the specified shelf belongs to the logged
user
+ * @param shelf - shelf to check
+ */
public boolean isUserShelf(Shelf shelf){
return shelf != null && shelf.isOwner(user);
}
+ /**
+ * This utility method used to determine if the specified album belongs to the logged
user
+ * @param album - album to check
+ */
public boolean isUserAlbum(Album album){
return album != null && album.isOwner(user);
}
+ /**
+ * This utility method used to determine if the specified user can be edited
+ * @param user - user to check
+ */
+ public boolean isProfileEditable(User selectedUser){
+ return selectedUser != null && selectedUser.equals(user);
+ }
+
private boolean canViewShelf(Shelf shelf) {
return shelf != null && shelf.isOwner(user);
}
@@ -320,7 +502,19 @@
Events.instance().raiseEvent(type, parameters);
}
- public boolean isProfileEditable(User selectedUser){
- return selectedUser != null && selectedUser.equals(user);
- }
+ private Album setDefaultAlbumToUpload(Album alb) {
+ if(isUserAlbum(model.getSelectedAlbum())){
+ alb = model.getSelectedAlbum();
+ }
+ if(alb == null){
+ if(user != null && user.getShelves().size() > 0 &&
user.getShelves().get(0).getAlbums().size() > 0)
+ for(Shelf s : user.getShelves()){
+ if(s.getAlbums().size() > 0){
+ alb = s.getAlbums().get(0);
+ break;
+ }
+ }
+ }
+ return alb;
+ }
}
\ No newline at end of file
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/DnDManager.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/DnDManager.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/DnDManager.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -64,6 +64,7 @@
if(dragValue instanceof Image){
//If user drag image
if(!((Album)dropValue).getOwner().getLogin().equals(user.getLogin())){
+ //Drag in the album, that not belongs to user
Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, Constants.DND_PHOTO_ERROR);
return;
}
@@ -71,6 +72,7 @@
}else if(dragValue instanceof Album){
//If user drag album
if(!((Shelf)dropValue).getOwner().getLogin().equals(user.getLogin())){
+ //Drag in the shelf, that not belongs to user
Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, Constants.DND_ALBUM_ERROR);
return;
}
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/FileManager.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/FileManager.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/FileManager.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -19,7 +19,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.richfaces.photoalbum.manager;
-
+/**
+ * Class encapsulated all functionality, related to working with the file system.
+ *
+ * @author Andrey Markhel
+ */
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
@@ -50,29 +54,21 @@
private String uploadRootPath;
+ /**
+ * Method, that invoked at startup application. Used to determine where application
will be write new images.
+ * This method set uploadRoot field - it is reference to the file where images will be
copied.
+ */
@Create
public void create() {
uploadRoot = (File)Component.getInstance(Constants.UPLOAD_ROOT_COMPONENT_NAME,
ScopeType.APPLICATION);
uploadRootPath =
(String)Component.getInstance(Constants.UPLOAD_ROOT_PATH_COMPONENT_NAME,
ScopeType.APPLICATION);
}
-
- public void setUploadRoot(String uploadRootPath) throws IOException {
- if (uploadRootPath != null) {
- this.uploadRoot = new File(uploadRootPath);
- for (String f : uploadRoot.list()) {
- File temp = new File(uploadRoot, f);
- temp.delete();
- }
- uploadRoot.delete();
- uploadRoot.mkdirs();
- this.uploadRootPath = this.uploadRoot.getCanonicalPath()
- + File.separator;
- } else {
- this.uploadRoot = null;
- this.uploadRootPath = null;
- }
- }
+ /**
+ * This method used to get reference to the file with the specified relative path to the
uploadRoot field
+ * @param path - relative path of file
+ * @return File reference
+ */
public File getFileByPath(String path) {
if (this.uploadRoot != null) {
File result = new File(this.uploadRoot, path);
@@ -90,41 +86,81 @@
return null;
}
+ /**
+ * This method observes <code>Constants.ALBUM_DELETED_EVENT</code> and
invoked after the user delete album.
+ * This method delete album directory from the disk
+ * @param album - deleted album
+ * @param path - relative path of the album directory
+ *
+ */
@Restrict("#{s:hasRole('admin')}")
@Observer(Constants.ALBUM_DELETED_EVENT)
public void onAlbumDeleted(Album album, String path) {
deleteDirectory(path);
}
+ /**
+ * This method observes <code>Constants.SHELF_DELETED_EVENT</code> and
invoked after the user delete her shelf
+ * This method delete shelf directory from the disk
+ * @param shelf - deleted shelf
+ * @param path - relative path of the shelf directory
+ */
@Restrict("#{s:hasRole('admin')}")
@Observer(Constants.SHELF_DELETED_EVENT)
public void onShelfDeleted(Shelf shelf, String path) {
deleteDirectory(path);
}
+ /**
+ * This method observes <code>Constants.USER_DELETED_EVENT</code> and
invoked after the user was deleted(used in livedemo to prevent flooding)
+ * This method delete user directory from the disk
+ * @param user - deleted user
+ * @param path - relative path of the user directory
+ */
@Observer(Constants.USER_DELETED_EVENT)
public void onUserDeleted(User user){
deleteDirectory(user.getPath());
}
+ /**
+ * This method observes <code>SHELF_ADDED_EVENT</code> and invoked after the
user add new shelf
+ * This method add shelf directory to the disk
+ * @param shelf - added shelf
+ */
@Observer(Constants.SHELF_ADDED_EVENT)
public void onShelfAdded(Shelf shelf){
File directory = getFileByPath(shelf.getPath());
FileUtils.addDirectory(directory);
}
+ /**
+ * This method observes <code>ALBUM_ADDED_EVENT</code> and invoked after the
user add new album
+ * This method add album directory to the disk
+ * @param album - added album
+ */
@Observer(Constants.ALBUM_ADDED_EVENT)
- public void onShelfAdded(Album album){
+ public void onAlbumAdded(Album album){
File directory = getFileByPath(album.getPath());
FileUtils.addDirectory(directory);
}
+ /**
+ * This method invoked after user set new avatar icon
+ * @param avatarData - avatar file
+ * @param user - user, that add avatar
+ */
public boolean saveAvatar(File avatarData, User user) {
String avatarPath = File.separator + user.getLogin() + File.separator +
Constants.AVATAR_JPG;
createDirectoryIfNotExist(avatarPath);
return writeFile(avatarPath, avatarData.getPath(), "", Constants.AVATAR_SIZE,
true);
}
+ /**
+ * This method observes <code>Constants.IMAGE_DELETED_EVENT</code> and
invoked after the user delete her image
+ * This method delete image and all thumbnails of this image from the disk
+ * @param image - deleted image
+ * @param path - relative path of the image file
+ */
@Restrict("#{s:hasRole('admin')}")
@Observer(Constants.IMAGE_DELETED_EVENT)
public void deleteImage(Image image, String path) {
@@ -133,6 +169,11 @@
}
}
+ /**
+ * This method invoked after user upload new image
+ * @param fileName - new relative path to the image file
+ * @param tempFilePath - absolute path to uploaded image
+ */
@Restrict("#{s:hasRole('admin')}")
public boolean addImage(String fileName, String tempFilePath) {
createDirectoryIfNotExist(fileName);
@@ -144,39 +185,12 @@
return true;
}
- @Restrict("#{s:hasRole('admin')}")
- public boolean writeFile(String newFileName, String fileName,
- String pattern, int size, boolean includeUploadRoot) {
- BufferedImage bsrc = null;
- try {
- bsrc = FileUtils.bitmapToImage(fileName, Constants.JPG);
- } catch (IOException e1) {
- return false;
- }
- int i = bsrc.getWidth() > bsrc.getHeight() ? bsrc.getWidth() : bsrc.getHeight();
- double d = (double) size / i;
- Double yy = ((Double) d * bsrc.getWidth());
- int width = yy.intValue();
- yy = ((Double) d * bsrc.getHeight());
- int height = yy.intValue();
- // Too small picture or original size
- if (width > bsrc.getWidth() || height > bsrc.getHeight() || size == 0) {
- width = bsrc.getWidth();
- height = bsrc.getHeight();
- }
- BufferedImage bdest = FileUtils.getScaledInstance(bsrc, width, height,
- RenderingHints.VALUE_INTERPOLATION_BICUBIC, true);
- String dest = includeUploadRoot ? this.uploadRootPath
- + transformPath(newFileName, pattern) : transformPath(
- newFileName, pattern);
- try {
- FileUtils.imageToBitmap(bdest, dest, Constants.JPG);
- } catch (IOException ex) {
- return false;
- }
- return true;
- }
-
+ /**
+ * This method used to transform one path to another.
+ * For example you want get path of the file with dimensioms 80 of image with path
/user/1/2/image.jpg, this method return /user/1/2/image_substitute.jpg
+ * @param target - path to transform
+ * @param substitute - new 'addon' to the path
+ */
public String transformPath(String target, String substitute) {
if(target.length()<2 || target.lastIndexOf(Constants.DOT) == -1){
return "";
@@ -186,20 +200,41 @@
return begin + substitute + end;
}
+ /**
+ * This method used to get reference to the file with the absolute path
+ * @param path - absolute path of file
+ * @return File reference
+ */
public File getFileByAbsolutePath(String path) {
return new File(path);
}
+ /**
+ * This utility method used to determine if the directory with specified relative path
exist
+ * @param path - absolute path of directory
+ * @return File reference
+ */
public boolean isDirectoryPresent(String path){
final File file = getFileByPath(path);
return file.exists() && file.isDirectory();
}
+ /**
+ * This utility method used to determine if the file with specified relative path exist
+ * @param path - absolute path of file
+ * @return File reference
+ */
public boolean isFilePresent(String path){
final File file = getFileByPath(path);
return file.exists();
}
+ /**
+ * This method observes <code>Constants.ALBUM_DRAGGED_EVENT</code> and
invoked after the user dragged album form one shelf to the another.
+ * This method rename album directory to the new directory
+ * @param album - dragged album
+ * @param pathOld - old path of album directory
+ */
@Observer(Constants.ALBUM_DRAGGED_EVENT)
public void renameAlbumDirectory(Album album, String pathOld){
File file = getFileByPath(pathOld);
@@ -214,6 +249,12 @@
file.renameTo(file2);
}
+ /**
+ * This method observes <code>Constants.IMAGE_DRAGGED_EVENT</code> and
invoked after the user dragged image form one album to the another.
+ * This method rename image file and all thumbnails to the new name
+ * @param image - dragged image
+ * @param pathOld - old path of image file
+ */
@Observer(Constants.IMAGE_DRAGGED_EVENT)
public void renameImageFile(Image image, String pathOld){
File file = null;
@@ -232,6 +273,42 @@
}
}
+ private boolean writeFile(String newFileName, String fileName,
+ String pattern, int size, boolean includeUploadRoot) {
+ BufferedImage bsrc = null;
+ try {
+ //Read file form disk
+ bsrc = FileUtils.bitmapToImage(fileName, Constants.JPG);
+ } catch (IOException e1) {
+ return false;
+ }
+ int resizedParam = bsrc.getWidth() > bsrc.getHeight() ? bsrc.getWidth() :
bsrc.getHeight();
+ double scale = (double) size / resizedParam;
+ Double widthInDouble = ((Double) scale * bsrc.getWidth());
+ int width = widthInDouble.intValue();
+ Double heightInDouble = ((Double) scale * bsrc.getHeight());
+ int height = heightInDouble.intValue();
+ // Too small picture or original size
+ if (width > bsrc.getWidth() || height > bsrc.getHeight() || size == 0) {
+ width = bsrc.getWidth();
+ height = bsrc.getHeight();
+ }
+ //scale image if need
+ BufferedImage bdest = FileUtils.getScaledInstance(bsrc, width, height,
+ RenderingHints.VALUE_INTERPOLATION_BICUBIC, true);
+ //Determine new path of image file
+ String dest = includeUploadRoot ? this.uploadRootPath
+ + transformPath(newFileName, pattern) : transformPath(
+ newFileName, pattern);
+ try {
+ //save to disk
+ FileUtils.imageToBitmap(bdest, dest, Constants.JPG);
+ } catch (IOException ex) {
+ return false;
+ }
+ return true;
+ }
+
private void deleteDirectory(String directory){
final File file = getFileByPath(directory);
FileUtils.deleteDirectory(file, false);
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/FileUploadManager.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/FileUploadManager.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/FileUploadManager.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -49,8 +49,9 @@
import com.drew.metadata.jpeg.JpegDirectory;
/**
- * @author $Autor$
- *
+ * Class encapsulated all functionality, related to file-upload process.
+ *
+ * @author Andrey Markhel
*/
@Name("fileUploadManager")
@Scope(ScopeType.EVENT)
@@ -73,7 +74,7 @@
* @param event - event, indicated that file upload started
*/
@Restrict("#{s:hasRole('admin')}")
- public void listener(UploadEvent event) throws Exception {
+ public void listener(UploadEvent event){
UploadItem item = event.getUploadItem();
//Construct image from item
Image image = constructImage(item);
@@ -109,7 +110,7 @@
//Prepare to show in UI
fileWrapper.getFiles().add(image);
Events.instance().raiseEvent(Constants.IMAGE_ADDED_EVENT, image);
- //Delete temporary fule
+ //Delete temporary file
item.getFile().delete();
}
@@ -121,6 +122,10 @@
fileWrapper.onFileUploadError(image, error);
item.getFile().delete();
}
+
+ private void addError(Image image, String error) {
+ fileWrapper.onFileUploadError(image, error);
+ }
private Image constructImage(UploadItem item) {
Image image = new Image();
@@ -133,21 +138,24 @@
return image;
}
- private void extractMetadata(UploadItem item, Image image)
- throws RuntimeException, IOException {
- InputStream in =null;
+ private void extractMetadata(UploadItem item, Image image){
+ InputStream in = null;
try{
- in = new FileInputStream(item.getFile());
- Metadata metadata = JpegMetadataReader.readMetadata(in);
- Directory exifDirectory = metadata.getDirectory(ExifDirectory.class);
- Directory jpgDirectory = metadata.getDirectory(JpegDirectory.class);
- setupCameraModel(image, exifDirectory);
- setupDimensions(image, exifDirectory, jpgDirectory);
- setupCreatedDate(image, exifDirectory);
+ in = new FileInputStream(item.getFile());
+ Metadata metadata = JpegMetadataReader.readMetadata(in);
+ Directory exifDirectory = metadata.getDirectory(ExifDirectory.class);
+ Directory jpgDirectory = metadata.getDirectory(JpegDirectory.class);
+ setupCameraModel(image, exifDirectory);
+ setupDimensions(image, exifDirectory, jpgDirectory);
+ setupCreatedDate(image, exifDirectory);
}catch(Exception e){
- throw new RuntimeException();
+ addError(item, image, Constants.IMAGE_SAVING_ERROR);
}finally{
- in.close();
+ try {
+ in.close();
+ } catch (IOException e) {
+ addError(item, image, Constants.IMAGE_SAVING_ERROR);
+ }
}
}
@@ -159,20 +167,23 @@
}
}
- private void setupDimensions(Image image, Directory exifDirectory,
- Directory jpgDirectory) throws MetadataException {
- if (exifDirectory.containsTag(ExifDirectory.TAG_EXIF_IMAGE_WIDTH) &&
exifDirectory.containsTag(ExifDirectory.TAG_EXIF_IMAGE_HEIGHT)) {
- int width = exifDirectory.getInt(ExifDirectory.TAG_EXIF_IMAGE_WIDTH);
- image.setWidth(width);
- int height = exifDirectory.getInt(ExifDirectory.TAG_EXIF_IMAGE_HEIGHT);
- image.setHeight(height);
- } else {
- if (jpgDirectory.containsTag(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT)) {
- int width = jpgDirectory.getInt(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
+ private void setupDimensions(Image image, Directory exifDirectory, Directory
jpgDirectory){
+ try{
+ if (exifDirectory.containsTag(ExifDirectory.TAG_EXIF_IMAGE_WIDTH) &&
exifDirectory.containsTag(ExifDirectory.TAG_EXIF_IMAGE_HEIGHT)) {
+ int width = exifDirectory.getInt(ExifDirectory.TAG_EXIF_IMAGE_WIDTH);
image.setWidth(width);
- int height = jpgDirectory.getInt(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
+ int height = exifDirectory.getInt(ExifDirectory.TAG_EXIF_IMAGE_HEIGHT);
image.setHeight(height);
+ } else {
+ if (jpgDirectory.containsTag(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT)) {
+ int width = jpgDirectory.getInt(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
+ image.setWidth(width);
+ int height = jpgDirectory.getInt(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
+ image.setHeight(height);
+ }
}
+ }catch(MetadataException e){
+ addError(image, Constants.IMAGE_SAVING_ERROR);
}
}
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/ImageManager.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/ImageManager.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/ImageManager.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -103,7 +103,7 @@
return;
}
}
- imageAction.editImage(image, editFromInplace);
+ imageAction.editImage(image, !editFromInplace);
}catch(Exception e){
Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT,
Constants.IMAGE_SAVING_ERROR);
imageAction.resetImage(image);
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/Model.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/Model.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/Model.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -15,7 +15,11 @@
import org.richfaces.photoalbum.domain.Shelf;
import org.richfaces.photoalbum.domain.User;
import org.richfaces.photoalbum.service.Constants;
-
+/**
+ * This class represent 'M' in MVC pattern. It is storage to application flow
related data such as selectedAlbum, image, mainArea to preview etc..
+ *
+ * @author Andrey Markhel
+ */
@Name("model")
@Scope(ScopeType.CONVERSATION)
@AutoCreate
@@ -37,6 +41,15 @@
private List<Image> images;
+ /**
+ * This method invoked after the almost user actions, to prepare properly data to show
in the UI.
+ * @param mainArea - next Area to show(determined in controller)
+ * @param selectedUser - user, that was selected(determined in controller)
+ * @param selectedShelf - shelf, that was selected(determined in controller)
+ * @param selectedAlbum - album, that was selected(determined in controller)
+ * @param selectedImage - image, that was selected(determined in controller)
+ * @param images - list of images, to show during slideshow process(determined in
controller)
+ */
public void resetModel(NavigationEnum mainArea, User selectedUser, Shelf selectedShelf,
Album selectedAlbum, Image selectedImage, List<Image> images){
this.setSelectedAlbum(selectedAlbum);
this.setSelectedImage(selectedImage);
@@ -46,6 +59,11 @@
this.images = images;
}
+ /**
+ * This method observes <code> Constants.UPDATE_MAIN_AREA_EVENT </code>event
and invoked after the user actions, that not change model, but change area to preview
+ * @param mainArea - next Area to show
+ *
+ */
@Observer(Constants.UPDATE_MAIN_AREA_EVENT)
public void setMainArea(NavigationEnum mainArea) {
if(this.mainArea != null && this.mainArea.equals(NavigationEnum.FILE_UPLOAD)){
@@ -54,6 +72,16 @@
this.mainArea = mainArea;
}
+ /**
+ * This method observes <code> Constants.UPDATE_SELECTED_TAG_EVENT
</code>event and invoked after the user click on any metatag.
+ * @param selectedTag - clicked tag
+ *
+ */
+ @Observer(Constants.UPDATE_SELECTED_TAG_EVENT)
+ public void setSelectedTag(MetaTag selectedTag) {
+ this.selectedTag = selectedTag;
+ }
+
public NavigationEnum getMainArea() {
return mainArea;
}
@@ -93,11 +121,6 @@
public MetaTag getSelectedTag() {
return selectedTag;
}
-
- @Observer(Constants.UPDATE_SELECTED_TAG_EVENT)
- public void setSelectedTag(MetaTag selectedTag) {
- this.selectedTag = selectedTag;
- }
public List<Image> getImages() {
return images;
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/NavigationEnum.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/NavigationEnum.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/NavigationEnum.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -22,7 +22,8 @@
/**
* Class encapsulated all possible states, that can be applied to so called
'mainArea' area on the page.
- *
+ * This ensured that properly template will be applied, and user will be redirected to
desired page.
+ * Next template to show obviously determined in Controller and pushes to Model.
* @author Andrey Markhel
*/
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/SlideshowManager.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/SlideshowManager.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/SlideshowManager.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -89,7 +89,7 @@
this.selectedImage = model.getImages().get(this.slideshowIndex);
//mark image as 'visited'
this.selectedImage.setVisited(true);
- //Check if that image was recently deleted. If yes, immediately stop slideshow
+ //Check if that image was recently deleted. If yes, immediately stop slideshow process
FileManager fileManager =
(FileManager)Contexts.getApplicationContext().get(Constants.FILE_MANAGER_COMPONENT);
if(!fileManager.isFilePresent(this.selectedImage.getFullPath())){
Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT,
Constants.IMAGE_RECENTLY_DELETED_ERROR);
@@ -172,6 +172,7 @@
slideshowIndex = -1;
}
slideshowIndex++;
+ //To prevent slideshow mechanism working in cycle.
if(slideshowIndex == startSlideshowIndex){
stopSlideshow();
errorDetected = true;
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/UserManager.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/UserManager.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/UserManager.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -71,6 +71,8 @@
avatarData = null;
user.setHasAvatar(true);
}try{
+ //This check is actual only on livedemo server to prevent hacks.
+ //Prevent hackers to mark user as pre-defined
user.setPreDefined(false);
user.setPasswordHash(HashUtils.hash(user.getPassword()));
user = userAction.updateUser();
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/DirectLinkHelper.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/DirectLinkHelper.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/DirectLinkHelper.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -14,7 +14,11 @@
import org.jboss.seam.security.Identity;
import org.richfaces.photoalbum.domain.Image;
import org.richfaces.photoalbum.service.Constants;
-
+/**
+ * Convenience UI class for 'directLink' functionality.
+ *
+ * @author Andrey Markhel
+ */
@Name("directLink")
@Scope(ScopeType.EVENT)
@AutoCreate
@@ -27,7 +31,12 @@
@In Identity identity;
@In Credentials credentials;
-
+ /**
+ * Convenience method to paint full-sized image in new tab or window
+ *
+ * @param out - OutputStream to write image
+ * @param data - relative path of the image
+ */
public void paintImage(OutputStream out, Object data)
throws IOException {
Long id = Long.valueOf(data.toString());
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/EditorBean.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/EditorBean.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/EditorBean.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -23,7 +23,11 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Observer;
import org.richfaces.photoalbum.service.Constants;
-
+/**
+ * Convenience UI class for rich:editor component
+ *
+ * @author Andrey Markhel
+ */
@Name("editorBean")
public class EditorBean {
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/ErrorHandlerBean.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/ErrorHandlerBean.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/ErrorHandlerBean.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -29,7 +29,11 @@
import org.jboss.seam.annotations.Observer;
import org.jboss.seam.annotations.Scope;
import org.richfaces.photoalbum.service.Constants;
-
+/**
+ * Convenience UI class for global eeror-checking mechanism
+ *
+ * @author Andrey Markhel
+ */
@Name("errorHandlerBean")
@Scope(ScopeType.EVENT)
@AutoCreate
@@ -44,6 +48,11 @@
return errors.size() > 0 ;
}
+ /**
+ * Convenience method that observes <code>Constants.ADD_ERROR_EVENT</code>.
After error occured add error to the list of erors andon rerendering modal panel with all
errors will be showed.
+ *
+ * @param e - string representation of error.
+ */
@Observer(Constants.ADD_ERROR_EVENT)
public void addToErrors(String e){
errors.add(e);
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/Help.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/Help.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/Help.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -5,7 +5,11 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.richfaces.photoalbum.util.Environment;
-
+/**
+ * Convenience UI class for application help system
+ *
+ * @author Andrey Markhel
+ */
@Name("help")
@Scope(ScopeType.EVENT)
@AutoCreate
@@ -21,10 +25,20 @@
this.page = page;
}
+ /**
+ * Convenience method to show specified page with help info in modal panel
+ *
+ * @param src - page to show
+ */
public void navigateTo(String src){
this.setPage(src);
}
+ /**
+ * Convenience method to determine is there need to render application help system.
+ *
+ * @param src - page to show
+ */
public boolean isShowHelp(){
return Environment.isShowHelp();
}
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/ImageLoader.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/ImageLoader.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/ImageLoader.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -31,8 +31,6 @@
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.contexts.Contexts;
-import org.richfaces.photoalbum.domain.User;
import org.richfaces.photoalbum.manager.FileManager;
import org.richfaces.photoalbum.service.Constants;
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/ImageSizeHelper.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/ImageSizeHelper.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/ImageSizeHelper.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -10,8 +10,10 @@
import org.richfaces.photoalbum.util.ImageDimension;
/**
- * @author Andrey Markavtsov
*
+ * Convenience UI class for image resizing
+ *
+ * @author Andrey Markhel
*/
@Name("imageSizeHelper")
@Scope(ScopeType.PAGE)
@@ -28,7 +30,13 @@
public int getValue() {
return value;
}
-
+
+ /**
+ *
+ * Convenience method invoked after user want to change image dimensions
+ *
+ * @param value - new image dimension value
+ */
public void setValue(int value) {
currentDimension = ImageDimension.getInstance(value);
this.value = currentDimension.getX();
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/UserPrefsHelper.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/UserPrefsHelper.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/ui/UserPrefsHelper.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -5,9 +5,6 @@
import java.io.File;
import java.io.Serializable;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
import javax.faces.model.SelectItem;
@@ -23,14 +20,15 @@
import org.richfaces.photoalbum.service.IUserAction;
/**
- * @author Andrey Markavtsov
+ * Convenience UI class for userPrefs page
*
+ * @author Andrey Markhel
*/
+
@Name("userPrefsBean")
@Scope(ScopeType.EVENT)
public class UserPrefsHelper implements Serializable{
private static final long serialVersionUID = -1767281809514660171L;
- private Calendar calendar;
@In IUserAction userAction;
@In(required=false, scope=ScopeType.CONVERSATION) @Out(required=false,
scope=ScopeType.CONVERSATION) private File avatarData;
@@ -43,17 +41,15 @@
return sexs;
}
+ /**
+ * Convenience method invoked after user add avatar and outject avatar to conversation
+ *
+ * param event - upload event
+ */
public void uploadAvatar(UploadEvent event) {
UploadItem item = event.getUploadItem();
avatarData = item.getFile();
}
-
- /*public Date getDefaultDate(){
- if(calendar == null){
- calendar = new GregorianCalendar(1980, Calendar.DECEMBER, 25);
- }
- return calendar.getTime();
- }*/
public File getAvatarData() {
return avatarData;
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/Environment.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/Environment.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/Environment.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -1,5 +1,9 @@
package org.richfaces.photoalbum.util;
-
+/**
+ * Convenience class to determine in which environment application running.
+ *
+ * @author Andrey Markhel
+ */
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -49,6 +53,11 @@
return null;
}
+ /**
+ * Convenience method to determine is the application running in production mode.
+ *
+ * @return true if application running in production mode
+ */
public static boolean isInProduction(){
final String environment = getEnvironment();
if (DEVELOPMENT.equals(environment)) {
@@ -57,6 +66,11 @@
return true;
}
+ /**
+ * Convenience method to determine is the application help system will be rendered
+ *
+ * @return true if the application help system need to be rendered
+ */
public static boolean isShowHelp(){
final String environment = getShowHelpIconsStrategy();
if (SHOW.equals(environment)) {
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/FileUtils.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/FileUtils.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/FileUtils.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -27,7 +27,8 @@
/**
* Utility method for copying file
- *
+ * @param srcFile - source file
+ * @param destFile - destination file
*/
public static void copyFile(File srcFile, File destFile) throws IOException {
if (!srcFile.getPath().toLowerCase().endsWith(JPG) &&
!srcFile.getPath().toLowerCase().endsWith(JPEG)) {
@@ -65,7 +66,8 @@
/**
* Utility method for copying directory
- *
+ * @param srcDir - source directory
+ * @param dstDir - destination directory
*/
public static void copyDirectory(File srcDir, File dstDir)
throws IOException {
@@ -89,7 +91,9 @@
/**
* Utility method for delete directory
- *
+ * @param dir - directory to delete
+ * @param isInitialDelete - determine if the deleting process running at startup or
on destroy of application
+ * @return true if directory succesfully deleted
*/
public static boolean deleteDirectory(File dir , boolean isInitialDelete){
if (dir.isDirectory()) {
@@ -119,7 +123,8 @@
/**
* Utility method for concatenation names of collection of files
- *
+ * @param files - array of strings to concatenate
+ * @return concatenated string
*/
public static String joinFiles(String... files) {
final StringBuilder res = new StringBuilder();
@@ -132,7 +137,7 @@
/**
* Utility method for delete file
- *
+ * @param file - file to delete
*/
public static void deleteFile(File file) {
if (file.exists()) {
@@ -140,6 +145,13 @@
}
}
+ /**
+ * Utility method to read image from disk and transform image to BufferedImage
object
+ * @param data - relative path to the image
+ * @param format - file prefix of the image
+ * @return BufferedImage representation of the image
+ *
+ */
public static BufferedImage bitmapToImage(String data, String format) throws
IOException {
final InputStream inb = new FileInputStream(data);
final ImageReader rdr = ImageIO.getImageReadersByFormatName(format).next();
@@ -150,6 +162,14 @@
return image;
}
+ /**
+ * Utility method to write BufferedImage object to disk
+ * @param image - BufferedImage object to save.
+ * @param data - relative path to the image
+ * @param format - file prefix of the image
+ * @return BufferedImage representation of the image
+ *
+ */
public static void imageToBitmap(BufferedImage image, String data, String format)
throws IOException {
final OutputStream inb = new FileOutputStream(data);
final ImageWriter wrt = ImageIO.getImageWritersByFormatName(format).next();
@@ -233,6 +253,7 @@
/**
* Utility method for creation of directory
+ * @param directory - directory to create
*
*/
public static void addDirectory(File directory) {
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/HashUtils.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/HashUtils.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/HashUtils.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -1,5 +1,9 @@
package org.richfaces.photoalbum.util;
-
+/**
+ * Convenience class to hash user passwords.
+ *
+ * @author Andrey Markhel
+ */
import java.security.MessageDigest;
import org.jboss.seam.util.Hex;
@@ -8,7 +12,11 @@
private static String digestAlgorithm = "SHA-1";
private static String charset = "UTF-8";
-
+ /**
+ * Convenience method to hash user passwords.
+ *
+ * @param plainTextPassword - password to hash
+ */
public static String hash(String plainTextPassword) {
try {
MessageDigest digest = MessageDigest.getInstance(digestAlgorithm);
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/ImageDimension.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/ImageDimension.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/ImageDimension.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -1,5 +1,10 @@
package org.richfaces.photoalbum.util;
-
+/**
+ * Convenience UI class for represent image object in different dimensions. Each image
have 5 thumbnails with different
+ * size, background style, file prefix, css class and background image. CurrentDimension
field will be used to determine rendering parameters used during page rendering process
+ *
+ * @author Andrey Markhel
+ */
import org.richfaces.photoalbum.service.Constants;
public enum ImageDimension {
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/SessionListener.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/SessionListener.java 2009-05-13
08:55:07 UTC (rev 14150)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/SessionListener.java 2009-05-13
11:53:15 UTC (rev 14151)
@@ -1,5 +1,10 @@
package org.richfaces.photoalbum.util;
-
+/**
+ * This class is session listener that observes
<code>"org.jboss.seam.sessionExpired"</code> event to delete in
production systems users when it's session is expired
+ * to prevent flood. Used only on livedemo server. If you don't want this
functionality simply delete this class from distributive.
+ *
+ * @author Andrey Markhel
+ */
import java.util.List;
import javax.persistence.EntityManager;
Modified:
trunk/examples/photoalbum/source/web/src/main/webapp/includes/help/errorHelp.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/examples/photoalbum/source/web/src/main/webapp/includes/image/imageInfo.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/examples/photoalbum/source/web/src/main/webapp/includes/misc/errorPanel.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/examples/photoalbum/source/web/src/main/webapp/includes/misc/modalPanels.xhtml
===================================================================
(Binary files differ)
Modified: trunk/examples/photoalbum/source/web/src/main/webapp/index.xhtml
===================================================================
(Binary files differ)