Author: amarkhel
Date: 2009-01-26 14:30:57 -0500 (Mon, 26 Jan 2009)
New Revision: 12432
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileManager.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/Authenticator.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/UserManager.java
trunk/test-applications/realworld/web/src/main/webapp/includes/image/breadCrumb.xhtml
Log:
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileManager.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileManager.java 2009-01-26
19:28:18 UTC (rev 12431)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileManager.java 2009-01-26
19:30:57 UTC (rev 12432)
@@ -186,6 +186,11 @@
}
}
+ public String getPathOfImage(String path){
+ int i = path.lastIndexOf(Constants.SLASH);
+ return path.substring(i);
+ }
+
public void renameImage(String fileNameOld, String fileNameNew) {
createDirectoryIfNotExist(fileNameNew);
String fullPath = getAbsolutePath(fileNameOld);
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/Authenticator.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/Authenticator.java 2009-01-26
19:28:18 UTC (rev 12431)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/Authenticator.java 2009-01-26
19:30:57 UTC (rev 12432)
@@ -96,16 +96,6 @@
}
return false;
}
-
- private void setupCatalogForUser() {
- if (!fileManager.isDirectoryPresent(credentials.getUsername())) {
- fileManager.addDirectory(credentials.getUsername());
- }
- }
-
- private boolean wantLoginAnonymous() {
- return null == credentials.getUsername() ||
credentials.getUsername().equals("");
- }
@End
public String register(User user){
@@ -117,6 +107,23 @@
return Constants.INDEX_OUTCOME;
}
+ public String loginAnonymous(){
+ credentials.setUsername(null);
+ credentials.setPassword(null);
+ this.authenticate();
+ return Constants.MAIN_OUTCOME;
+ }
+
+ private void setupCatalogForUser() {
+ if (!fileManager.isDirectoryPresent(credentials.getUsername())) {
+ fileManager.addDirectory(credentials.getUsername());
+ }
+ }
+
+ private boolean wantLoginAnonymous() {
+ return null == credentials.getUsername() ||
credentials.getUsername().equals("");
+ }
+
private boolean checkUserExist(User user) {
if(userAction.isUserExist(user.getLogin())){
UIComponent root = FacesContext.getCurrentInstance().getViewRoot();
@@ -138,11 +145,4 @@
}
return false;
}
-
- public String loginAnonymous(){
- credentials.setUsername(null);
- credentials.setPassword(null);
- this.authenticate();
- return Constants.MAIN_OUTCOME;
- }
}
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java 2009-01-26
19:28:18 UTC (rev 12431)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java 2009-01-26
19:30:57 UTC (rev 12432)
@@ -68,30 +68,48 @@
}
private void handleRoot(Album dragValue) {
- TreeAlbumItem itemParent = null;
- if(!dragValue.getOwner().equals(user)){
- Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new
Exception(Constants.WRONG_DND));
+ TreeAlbumItem itemParent = removeAlbumFromParentAlbum(dragValue);
+ if(null == itemParent){
+ //Tree root contain this album
return;
}
+ if(!renameDirectory(dragValue)){
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT,
Constants.ALBUM_WITH_THIS_NAME_ALREADY_PRESENT);
+ return;
+ }
+ renameImagesFromAlbum(dragValue);
+ updateRootTreeNode(dragValue, itemParent);
+ addTreeToRerender();
+ }
+
+ private TreeAlbumItem removeAlbumFromParentAlbum(Album dragValue) {
+ TreeAlbumItem itemParent = null;
if(dragValue.getParent() != null ){
itemParent =
(TreeAlbumItem)treeMyAlbumsItem.getNode(dragValue.getParent().getName());
dragValue.getParent().removeChildAlbum(dragValue);
}else{
- return;
+ //Tree root contain this album
+ return null;
}
- String directoryOld = user.getLogin() + fileManager.getFileSeparator() +
dragValue.getAlbumPathFromParents(dragValue, fileManager.getFileSeparator(), true );
- String directoryNew = user.getLogin() + fileManager.getFileSeparator() +
dragValue.getName();
- if(!fileManager.renameDirectory(directoryOld, directoryNew)){
- Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT,
Constants.ALBUM_WITH_THIS_NAME_ALREADY_PRESENT);
- return;
- }
- String albumOld = user.getLogin() + Constants.SLASH +
dragValue.getAlbumPathFromParents(dragValue, Constants.SLASH, false );
+ return itemParent;
+ }
+
+ private boolean renameDirectory(Album dragValue) {
+ String directoryOld = fileManager.concat(user.getLogin(),
dragValue.getAlbumPathFromParents(dragValue, fileManager.getFileSeparator(), true ));
+ String directoryNew = fileManager.concat(user.getLogin(), dragValue.getName());
+ return fileManager.renameDirectory(directoryOld, directoryNew);
+ }
+
+ private void renameImagesFromAlbum(Album dragValue) {
+ String albumOld = fileManager.concatwithSlash(user.getLogin(),
dragValue.getAlbumPathFromParents(dragValue, Constants.SLASH, false ));
String albumNew = user.getLogin() + Constants.SLASH;
+ albumAction.renameAllImagesFromAlbumAndChilds(dragValue, albumOld, albumNew);
+ }
+
+ private void updateRootTreeNode(Album dragValue, TreeAlbumItem itemParent) {
TreeAlbumItem item = (TreeAlbumItem)treeMyAlbumsItem.getNode(dragValue.getName());
itemParent.removeChild(item.getId());
treeMyAlbumsItem.addChild(item.getId(), item);
- albumAction.renameAllImagesFromAlbumAndChilds(dragValue, albumOld, albumNew);
- addTreeToRerender();
}
private void addTreeToRerender() {
@@ -107,47 +125,60 @@
private void handleAlbum(Album dragValue, Album dropValue) {
TreeNode<Object> itemParent = null;
- if(!dragValue.getOwner().equals(user)){
- Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new
Exception(Constants.WRONG_DND));
- return;
- }
if(dragValue.getParent() != null ){
itemParent = treeMyAlbumsItem.getNode(dragValue.getParent().getName());
if(dragValue.getParent().equals(dropValue)){
+ //Parent album contain this album
return;
}
}else{
itemParent = treeMyAlbumsItem;
}
- String directoryOld = user.getLogin() + fileManager.getFileSeparator() +
dragValue.getAlbumPathFromParents(dragValue, fileManager.getFileSeparator(), true );
- String directoryNew = user.getLogin() + fileManager.getFileSeparator() +
dropValue.getAlbumPathFromParents(dropValue, fileManager.getFileSeparator(), false) +
dragValue.getName();
- String albumOld = user.getLogin() + Constants.SLASH +
dragValue.getAlbumPathFromParents(dragValue, Constants.SLASH, false );
- String albumNew = user.getLogin() + Constants.SLASH +
dropValue.getAlbumPathFromParents(dropValue, Constants.SLASH, false);
- dropValue.addChildAlbum(dragValue);
- TreeAlbumItem itemParentNew =
(TreeAlbumItem)treeMyAlbumsItem.getNode(dropValue.getName());
- TreeAlbumItem item = (TreeAlbumItem)treeMyAlbumsItem.getNode(dragValue.getName());
- itemParent.removeChild(item.getId());
- itemParentNew.addAlbum(item);
+ String directoryOld = fileManager.concat(user.getLogin(),
dragValue.getAlbumPathFromParents(dragValue, fileManager.getFileSeparator(), true ));
+ String directoryNew = fileManager.concat(user.getLogin()
,dropValue.getAlbumPathFromParents(dropValue, fileManager.getFileSeparator(), false),
dragValue.getName());
if(!fileManager.renameDirectory(directoryOld, directoryNew)){
Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT,
Constants.ALBUM_WITH_THIS_NAME_ALREADY_PRESENT);
return;
}
- albumAction.renameAllImagesFromAlbumAndChilds(dragValue, albumOld, albumNew);
+
+ updateAlbums(dragValue, dropValue, itemParent);
addTreeToRerender();
}
+ private void updateAlbums(Album dragValue, Album dropValue,
+ TreeNode<Object> itemParent) {
+ String albumOld = fileManager.concatwithSlash(user.getLogin(),
dragValue.getAlbumPathFromParents(dragValue, Constants.SLASH, false ));
+ String albumNew = fileManager.concatwithSlash(user.getLogin()
,dropValue.getAlbumPathFromParents(dropValue, Constants.SLASH, false));
+ albumAction.renameAllImagesFromAlbumAndChilds(dragValue, albumOld, albumNew);
+ dropValue.addChildAlbum(dragValue);
+ updateTree(dragValue, dropValue, itemParent);
+ }
+
+ private void updateTree(Album dragValue, Album dropValue,
+ TreeNode<Object> itemParent) {
+ TreeAlbumItem itemParentNew =
(TreeAlbumItem)treeMyAlbumsItem.getNode(dropValue.getName());
+ TreeAlbumItem item = (TreeAlbumItem)treeMyAlbumsItem.getNode(dragValue.getName());
+ itemParent.removeChild(item.getId());
+ itemParentNew.addAlbum(item);
+ }
+
private void handleImage(Image dragValue, Album dropValue) {
if(dragValue.getAlbum().equals(dropValue)){
return;
}
+ String newPath = getNewPathOfImage(dragValue, dropValue);
+ dragValue.setPath(newPath);
+ dropValue.addImage(dragValue);
+ albumAction.flush();
+ }
+
+ private String getNewPathOfImage(Image dragValue, Album dropValue) {
String fileNameOld = fileManager.transformToServerPath(dragValue.getPath());
int lastIndexOf = dragValue.getPath().lastIndexOf(Constants.SLASH);
String prevPathEnd = dragValue.getPath().substring(lastIndexOf);
- String fileNameNew = user.getLogin() + fileManager.getFileSeparator() +
dropValue.getAlbumPathFromParents(dropValue, fileManager.getFileSeparator(), true) +
prevPathEnd;
- String newPath = user.getLogin() + Constants.SLASH +
dropValue.getAlbumPathFromParents(dropValue, Constants.SLASH, true) + prevPathEnd;
- dragValue.setPath(newPath);
- dropValue.addImage(dragValue);
+ String fileNameNew = fileManager.concat(user.getLogin(),
dropValue.getAlbumPathFromParents(dropValue, fileManager.getFileSeparator(), true),
prevPathEnd);
+ String newPath = fileManager.concatwithSlash(user.getLogin() ,
dropValue.getAlbumPathFromParents(dropValue, Constants.SLASH, true), prevPathEnd);
fileManager.renameImage(fileNameOld, fileNameNew);
- albumAction.flush();
+ return newPath;
}
}
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java 2009-01-26
19:28:18 UTC (rev 12431)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java 2009-01-26
19:30:57 UTC (rev 12432)
@@ -20,7 +20,6 @@
*/
package org.richfaces.realworld.manager;
-import java.util.ArrayList;
import java.util.Date;
import org.jboss.seam.ScopeType;
@@ -36,12 +35,12 @@
import org.richfaces.realworld.domain.User;
import org.richfaces.realworld.fileupload.FileManager;
import org.richfaces.realworld.navigation.NavigationEnum;
+import org.richfaces.realworld.service.Constants;
import org.richfaces.realworld.service.IImageAction;
import org.richfaces.realworld.tree.TreeAlbumItem;
import org.richfaces.realworld.tree.TreeMyAlbumsItem;
import org.richfaces.realworld.ui.RatingBinder;
import org.richfaces.realworld.util.ConversationState;
-import org.richfaces.realworld.service.Constants;
@Name("imageManager")
@Scope(ScopeType.CONVERSATION)
@@ -72,17 +71,11 @@
public void editImage(Image image){
TreeAlbumItem parent =
(TreeAlbumItem)treeMyAlbumsItem.getNode(image.getAlbum().getName());
- boolean parentChanged = !parent.getAlbum().getName().equals(image.getAlbumName());
+ boolean parentChanged = parentChanged(image, parent);
if(parentChanged){
TreeAlbumItem albumItem =
(TreeAlbumItem)treeMyAlbumsItem.getNode(image.getAlbumName());
- String fileNameOld = fileManager.transformToServerPath(image.getPath());
- int lastIndexOf = image.getPath().lastIndexOf(Constants.SLASH);
- String prevPathEnd = image.getPath().substring(lastIndexOf);
- Album dropValue =
((TreeAlbumItem)treeMyAlbumsItem.getNode(image.getAlbumName())).getAlbum();
- String fileNameNew = user.getLogin() + fileManager.getFileSeparator() +
dropValue.getAlbumPathFromParents(dropValue , fileManager.getFileSeparator(), true) +
prevPathEnd;
- String newPath = user.getLogin() + Constants.SLASH +
albumItem.getAlbum().getAlbumPathFromParents(albumItem.getAlbum(), Constants.SLASH, true)
+ prevPathEnd;
+ String newPath = getNewPathOfImage(image, albumItem);
image.setPath(newPath);
- fileManager.renameImage(fileNameOld, fileNameNew);
conversationState.setSelectedImage(image);
conversationState.setSelectedAlbum(albumItem.getAlbum());
}
@@ -123,4 +116,19 @@
public void vote(Image image){
imageAction.vote(image,
Long.valueOf(ratingBinder.getInputSlider().getValue().toString()));
}
+
+ private boolean parentChanged(Image image, TreeAlbumItem parent) {
+ return !parent.getAlbum().getName().equals(image.getAlbumName());
+ }
+
+ private String getNewPathOfImage(Image image, TreeAlbumItem albumItem) {
+ String fileNameOld = fileManager.transformToServerPath(image.getPath());
+ int lastIndexOf = image.getPath().lastIndexOf(Constants.SLASH);
+ String prevPathEnd = image.getPath().substring(lastIndexOf);
+ Album dropValue =
((TreeAlbumItem)treeMyAlbumsItem.getNode(image.getAlbumName())).getAlbum();
+ String fileNameNew = fileManager.concat(user.getLogin(),
dropValue.getAlbumPathFromParents(dropValue , fileManager.getFileSeparator(), true),
prevPathEnd);
+ String newPath = fileManager.concatwithSlash(user.getLogin(),
albumItem.getAlbum().getAlbumPathFromParents(albumItem.getAlbum(), Constants.SLASH, true),
prevPathEnd);
+ fileManager.renameImage(fileNameOld, fileNameNew);
+ return newPath;
+ }
}
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/UserManager.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/UserManager.java 2009-01-26
19:28:18 UTC (rev 12431)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/UserManager.java 2009-01-26
19:30:57 UTC (rev 12432)
@@ -125,9 +125,4 @@
public List<Album> getRootAlbums(User user2) {
return userAction.getRootAlbums(user2);
}
-
- public String getPathOfImage(String path){
- int i = path.lastIndexOf(Constants.SLASH);
- return path.substring(i);
- }
}
Modified:
trunk/test-applications/realworld/web/src/main/webapp/includes/image/breadCrumb.xhtml
===================================================================
(Binary files differ)