JBoss Rich Faces SVN: r12388 - in trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld: search and 3 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: amarkhel
Date: 2009-01-23 08:28:09 -0500 (Fri, 23 Jan 2009)
New Revision: 12388
Added:
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/MessageManager.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendItem.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendRootItem.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendsItem.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeManager.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeMyAlbumsItem.java
Removed:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/servlet/FileHelper.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeImageItem.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeSelectionManager.java
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/AlbumManager.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/ImageManager.java
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/search/SearchBean.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/servlet/PictureServlet.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/slideshow/SlideshowBean.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeAlbumItem.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeRootItem.java
Log:
Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/AlbumManager.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/AlbumManager.java 2009-01-23 13:27:29 UTC (rev 12387)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/AlbumManager.java 2009-01-23 13:28:09 UTC (rev 12388)
@@ -20,30 +20,34 @@
*/
package org.richfaces.realworld.manager;
-import javax.faces.model.SelectItem;
+import java.util.ArrayList;
+import java.util.List;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
+import org.richfaces.model.TreeNode;
import org.richfaces.realworld.domain.Album;
+import org.richfaces.realworld.domain.Image;
import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.error.ErrorHandler;
import org.richfaces.realworld.fileupload.FileManager;
import org.richfaces.realworld.service.IAlbumAction;
import org.richfaces.realworld.tree.TreeAlbumItem;
-import org.richfaces.realworld.tree.TreeRootItem;
-import org.richfaces.realworld.util.SelectionHelper;
+import org.richfaces.realworld.tree.TreeMyAlbumsItem;
+import org.richfaces.realworld.ui.ConversationState;
@Name("albumManager")
@Scope(ScopeType.CONVERSATION)
public class AlbumManager {
+ private static final String SLASH = "/";
+
@In(create=true, required=true)
private IAlbumAction albumAction;
- @In(create=true) @Out TreeRootItem treeRoot;
+ @In(create=true) @Out TreeMyAlbumsItem treeMyAlbumsItem;
@In(create=true, required=true) @Out
private Album album;
@@ -55,52 +59,60 @@
FileManager fileManager;
@In @Out
- private SelectionHelper selectionHelper;
+ private ConversationState conversationState;
public void addAlbum(){
albumAction.addAlbum(album);
- treeRoot.getAvailableAlbums().add(new SelectItem(album.getName()));
- TreeAlbumItem albumItem = new TreeAlbumItem(album.getId(), treeRoot, album);
- treeRoot.addAlbumToTree(albumItem);
- fileManager.addDirectory(user.getLogin() + fileManager.getFileSeparator() + album.getName());
- selectionHelper.setSelectedImage(null);
- selectionHelper.setSelectedAlbum(albumItem.getAlbum());
+ TreeNode parent = null;
+ if(null == album.getParent()){
+ parent = treeMyAlbumsItem;
+ }else{
+ parent = treeMyAlbumsItem.getParentItem(album.getParent().getName());
+ }
+ TreeAlbumItem albumItem = new TreeAlbumItem(album.getId(), parent, album, treeMyAlbumsItem);
+ treeMyAlbumsItem.addAlbumToTree(parent, albumItem);
+ List<String> list = new ArrayList<String>();
+ String albumPath = album.getAlbumPathFromParents(album, list, fileManager.getFileSeparator()) + album.getName();
+ fileManager.addDirectory(user.getLogin() + fileManager.getFileSeparator() + albumPath);
+ conversationState.setSelectedImage(null);
+ conversationState.setSelectedAlbum(albumItem.getAlbum());
}
public void editAlbum(Album album){
boolean nameChanged = !album.getName().equals(album.getChangedName());
if(nameChanged){
- String directoryOld = user.getLogin() + fileManager.getFileSeparator() + album.getName();
- String directoryNew = user.getLogin() + fileManager.getFileSeparator() + album.getChangedName();
+ String directoryOld = user.getLogin() + fileManager.getFileSeparator() + album.getAlbumPathFromParents(album, new ArrayList<String>(),fileManager.getFileSeparator() )+album.getName();
+ Album oldAlbum = ((TreeAlbumItem)treeMyAlbumsItem.getParentItem(album.getName())).getAlbum();
+ String directoryNew = user.getLogin() + fileManager.getFileSeparator() + oldAlbum.getAlbumPathFromParents(oldAlbum, new ArrayList<String>(),fileManager.getFileSeparator() )+album.getChangedName();
try {
fileManager.renameDirectory(directoryOld, directoryNew);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
+ String albumOld = user.getLogin() + SLASH + album.getAlbumPathFromParents(album, new ArrayList<String>(),SLASH )+album.getName();
+ String albumNew = user.getLogin() + SLASH + oldAlbum.getAlbumPathFromParents(oldAlbum, new ArrayList<String>(),SLASH )+album.getChangedName();
+ albumAction.renameAllImagesFromAlbumAndChilds(album, albumOld, albumNew);
album.setName(album.getChangedName());
album.setChangedName(null);
+
}
albumAction.editAlbum(album);
- treeRoot.updateChild(album);
+ treeMyAlbumsItem.updateChild(album);
}
public void deleteAlbum(Album album){
String albumName = album.getName();
albumAction.deleteAlbum(album);
- SelectItem item = treeRoot.getSelectItemByName(album.getName());
- treeRoot.getAvailableAlbums().remove(item);
- treeRoot.removeChild(album.getId());
+ TreeAlbumItem oldAlbum = (TreeAlbumItem)treeMyAlbumsItem.getParentItem(album.getName());
+ oldAlbum.getParent().removeChild(album.getId());
fileManager.deleteDirectory(user.getLogin() + fileManager.getFileSeparator() + albumName);
- selectionHelper.setSelectedAlbum(user.getChildAlbums().get(0));
- selectionHelper.setSelectedImage(selectionHelper.getSelectedAlbum().getImages().get(0));
}
public void updateSelectedAlbum(){
- selectionHelper.setSelectedAlbum(user.getAlbumByName(selectionHelper.getSelectedAlbum().getName()));
- selectionHelper.setSelectedImage(selectionHelper.getSelectedAlbum().getImages().get(0));
- selectionHelper.setSelectedImageIndex(1);
- selectionHelper.setUserAlbumSelected(true);
+ conversationState.setSelectedAlbum(user.getAlbumByName(conversationState.getSelectedAlbum().getName()));
}
+
+
}
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-23 13:27:29 UTC (rev 12387)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/Authenticator.java 2009-01-23 13:28:09 UTC (rev 12388)
@@ -20,11 +20,9 @@
*/
package org.richfaces.realworld.manager;
-import java.io.IOException;
import java.io.Serializable;
import javax.faces.application.FacesMessage;
-import javax.faces.application.FacesMessage.Severity;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
@@ -40,17 +38,22 @@
import org.jboss.seam.log.Log;
import org.jboss.seam.security.Identity;
import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.fileupload.AvatarUpload;
import org.richfaces.realworld.fileupload.FileManager;
import org.richfaces.realworld.navigation.NavigationEnum;
import org.richfaces.realworld.service.IUserAction;
-import org.richfaces.realworld.util.SelectionHelper;
+import org.richfaces.realworld.ui.ConversationState;
@Name("authenticator")
@Scope(ScopeType.CONVERSATION)
public class Authenticator implements Serializable
{
+ private static final String INVALID_LOGIN_OR_PASSWORD = "Invalid login or password";
+
+ private static final String MAIN_OUTCOME = "main";
+
+ private static final String LOGIN_SUCCESS = "You are successfully registered.";
+
@In("#{messages['user.exist']}") private String USER_WITH_THIS_LOGIN_ALREADY_EXIST;
@In("#{messages['user.confirm.error']}") private String CONFIRM_PASSWORD_NOT_EQUALS_PASSWORD;
@@ -70,7 +73,7 @@
private static final long serialVersionUID = -4585673256547342140L;
@Logger Log log;
-
+
@In Identity identity;
@In FacesMessages facesMessages;
@@ -81,11 +84,8 @@
@In(create = true)
FileManager fileManager;
- @In(create = true)
- AvatarUpload avatarUpload;
-
@In(create=true) @Out
- private SelectionHelper selectionHelper;
+ private ConversationState conversationState;
/* (non-Javadoc)
* @see org.richfaces.realworld.service.IAuthenticator#authenticate()
@@ -94,8 +94,8 @@
{
if(null == identity.getUsername() || identity.getUsername().equals("")){
identity.addRole(GUEST_ROLE);
+ userAction.loginAnonymous();
Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.SEARCH);
- userAction.loginAnonymous();
return true;
}
try{
@@ -105,17 +105,12 @@
if(!fileManager.isDirectoryPresent(identity.getUsername())){
fileManager.addDirectory(identity.getUsername());
}
- if(user.getChildAlbums().size() > 0){
- selectionHelper.setSelectedAlbum(user.getChildAlbums().get(0));
- //if(selectionHelper.getSelectedAlbum().getImages().size() > 0){
- //selectionHelper.setSelectedImage(selectionHelper.getSelectedAlbum().getImages().get(0));
- //}
- }
+ conversationState.setSelectedUser(user);
Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
return true;
}
}catch(Exception nre){
- facesMessages.add("Invalid login or password");
+ facesMessages.add(INVALID_LOGIN_OR_PASSWORD);
return false;
}
return false;
@@ -142,20 +137,14 @@
return "";
}
userAction.register(user);
- if(avatarUpload.getAvatarItem() != null){
- user.setAvatarPath(avatarUpload.getAvatarItem().getImage().getName());
- fileManager.deleteDirectory(user.getLogin() + fileManager.getFileSeparator() + "avatars");
- fileManager.addDirectory(user.getLogin() + fileManager.getFileSeparator() + "avatars");
- try {
- fileManager.addImage(user.getLogin() + fileManager.getFileSeparator() + "avatars" + fileManager.getFileSeparator() + user.getAvatarPath(), avatarUpload.getAvatarItem().getData());
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- String messageTemplate = "You are successfully registered.";
- facesMessages.add(messageTemplate);
+ facesMessages.add(LOGIN_SUCCESS);
return INDEX_OUTCOME;
}
+
+ public String loginAnonymous(){
+ identity.setUsername(null);
+ identity.setPassword(null);
+ this.authenticate();
+ return MAIN_OUTCOME;
+ }
}
Added: 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 (rev 0)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java 2009-01-23 13:28:09 UTC (rev 12388)
@@ -0,0 +1,133 @@
+package org.richfaces.realworld.manager;
+
+import java.util.ArrayList;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.context.AjaxContext;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Out;
+import org.jboss.seam.core.Events;
+import org.richfaces.component.Dropzone;
+import org.richfaces.event.DropEvent;
+import org.richfaces.event.DropListener;
+import org.richfaces.model.TreeNode;
+import org.richfaces.realworld.domain.Album;
+import org.richfaces.realworld.domain.Image;
+import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.fileupload.FileManager;
+import org.richfaces.realworld.service.IAlbumAction;
+import org.richfaces.realworld.tree.TreeAlbumItem;
+import org.richfaces.realworld.tree.TreeMyAlbumsItem;
+
+@Name("dndManager")
+public class DnDManager implements DropListener {
+
+ private static final String SLASH = "/";
+
+ private static final String WRONG_DND = "That album isn't yours, so you can't change it's location";
+
+ private static final String ADD_ERROR_EVENT = "addErrorEvent";
+
+ @In @Out TreeMyAlbumsItem treeMyAlbumsItem;
+
+ @In User user;
+ @In(create=true)
+ FileManager fileManager;
+ @In(create=true)
+ IAlbumAction albumAction;
+
+ public void processDrop(DropEvent dropEvent) {
+ Dropzone dropzone = (Dropzone) dropEvent.getComponent();
+ Object dragValue = dropEvent.getDragValue();
+ Object dropValue = dropzone.getDropValue();
+ if(dragValue instanceof Image){
+ handleImage((Image)dragValue, (Album)dropValue);
+ }else if(dragValue instanceof Album){
+ if(dropValue instanceof TreeMyAlbumsItem){
+ handleRoot((Album)dragValue);
+ }else{
+ handleAlbum((Album)dragValue, (Album)dropValue);
+ }
+ }
+ }
+
+ private void handleRoot(Album dragValue) {
+ TreeAlbumItem itemParent = null;
+ if(!dragValue.getOwner().equals(user)){
+ Events.instance().raiseEvent(ADD_ERROR_EVENT, new Exception(WRONG_DND));
+ return;
+ }
+ if(dragValue.getParent() != null ){
+ itemParent = treeMyAlbumsItem.getAlbumByName(dragValue.getParent().getName());
+ dragValue.getParent().removeChildAlbum(dragValue);
+ }else{
+ return;
+ }
+ String directoryOld = user.getLogin() + fileManager.getFileSeparator() + dragValue.getAlbumPathFromParents(dragValue, new ArrayList<String>(), fileManager.getFileSeparator() )+ dragValue.getName();
+ String directoryNew = user.getLogin() + fileManager.getFileSeparator() + dragValue.getName();
+ fileManager.renameDirectory(directoryOld, directoryNew);
+ String albumOld = user.getLogin() + SLASH + dragValue.getAlbumPathFromParents(dragValue, new ArrayList<String>(), SLASH );
+ String albumNew = user.getLogin() + SLASH;
+
+ TreeAlbumItem item = treeMyAlbumsItem.getAlbumByName(dragValue.getName());
+ itemParent.removeChild(item.getId());
+ treeMyAlbumsItem.addChild(item.getId(), item);
+ fileManager.renameDirectory(directoryOld, directoryNew);
+ albumAction.renameAllImagesFromAlbumAndChilds(dragValue, albumOld, albumNew);
+
+ }
+
+ private void handleAlbum(Album dragValue, Album dropValue) {
+ TreeNode itemParent = null;
+ if(!dragValue.getOwner().equals(user)){
+ Events.instance().raiseEvent(ADD_ERROR_EVENT, new Exception(WRONG_DND));
+ return;
+ }
+ if(dragValue.getParent() != null ){
+ itemParent = treeMyAlbumsItem.getAlbumByName(dragValue.getParent().getName());
+ if(dragValue.getParent().equals(dropValue)){
+ return;
+ }
+ }else{
+ itemParent = treeMyAlbumsItem;
+ }
+ String directoryOld = user.getLogin() + fileManager.getFileSeparator() + dragValue.getAlbumPathFromParents(dragValue, new ArrayList<String>(), fileManager.getFileSeparator() ) + dragValue.getName();
+ String directoryNew = user.getLogin() + fileManager.getFileSeparator() + dropValue.getAlbumPathFromParents(dropValue, new ArrayList<String>(), fileManager.getFileSeparator()) + dragValue.getName();
+ String albumOld = user.getLogin() + SLASH + dragValue.getAlbumPathFromParents(dragValue, new ArrayList<String>(), SLASH );
+ String albumNew = user.getLogin() + SLASH + dropValue.getAlbumPathFromParents(dropValue, new ArrayList<String>(), SLASH);
+ dropValue.addChildAlbum(dragValue);
+ TreeAlbumItem itemParentNew = treeMyAlbumsItem.getAlbumByName(dropValue.getName());
+ TreeAlbumItem item = treeMyAlbumsItem.getAlbumByName(dragValue.getName());
+ itemParent.removeChild(item.getId());
+ itemParentNew.addAlbum(item);
+ fileManager.renameDirectory(directoryOld, directoryNew);
+ albumAction.renameAllImagesFromAlbumAndChilds(dragValue, albumOld, albumNew);
+ try {
+ FacesContext fc = FacesContext.getCurrentInstance();
+ AjaxContext ac = AjaxContext.getCurrentInstance();
+ UIComponent destTree = fc.getViewRoot().findComponent("tree");
+ ac.addComponentToAjaxRender(destTree);
+ } catch (Exception e) {
+ //System.err.print(e.getMessage());
+ }
+ }
+
+ private void handleImage(Image dragValue, Album dropValue) {
+ if(dragValue.getAlbum().equals(dropValue)){
+ return;
+ }
+ String fileNameOld = fileManager.transformToServerPath(dragValue.getPath());
+ int lastIndexOf = dragValue.getPath().lastIndexOf(SLASH);
+ String prevPathEnd = dragValue.getPath().substring(lastIndexOf);
+ String fileNameNew = user.getLogin() + fileManager.getFileSeparator() + dropValue.getAlbumPathFromParents(dropValue, new ArrayList<String>(), fileManager.getFileSeparator()) + prevPathEnd;
+ String newPath = user.getLogin() + SLASH + dropValue.getAlbumPathFromParents(dropValue, new ArrayList<String>(), SLASH) + prevPathEnd;
+ dragValue.setPath(newPath);
+ dropValue.addImage(dragValue);
+ fileManager.renameImage(fileNameOld, fileNameNew);
+ albumAction.flush();
+ }
+
+}
Property changes on: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
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-23 13:27:29 UTC (rev 12387)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java 2009-01-23 13:28:09 UTC (rev 12388)
@@ -20,6 +20,7 @@
*/
package org.richfaces.realworld.manager;
+import java.util.ArrayList;
import java.util.Date;
import org.jboss.seam.ScopeType;
@@ -28,32 +29,39 @@
import org.jboss.seam.annotations.Observer;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.core.Events;
+import org.richfaces.realworld.domain.Album;
import org.richfaces.realworld.domain.Comment;
import org.richfaces.realworld.domain.Image;
import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.error.ErrorHandler;
import org.richfaces.realworld.fileupload.FileManager;
+import org.richfaces.realworld.navigation.NavigationEnum;
import org.richfaces.realworld.service.IImageAction;
import org.richfaces.realworld.tree.TreeAlbumItem;
-import org.richfaces.realworld.tree.TreeImageItem;
-import org.richfaces.realworld.tree.TreeRootItem;
-import org.richfaces.realworld.util.RatingBinder;
-import org.richfaces.realworld.util.SelectionHelper;
+import org.richfaces.realworld.tree.TreeMyAlbumsItem;
+import org.richfaces.realworld.ui.RatingBinder;
+import org.richfaces.realworld.ui.ConversationState;
@Name("imageManager")
@Scope(ScopeType.CONVERSATION)
public class ImageManager {
+ private static final String META_TAG_WRONG = "Meta-tag length should be great then 2 symbols";
+
+ private static final String ADD_ERROR_EVENT = "addErrorEvent";
+
@In(create=true, required=true)
private IImageAction imageAction;
+ private static final String UPDATE_MAIN_AREA_EVENT = "updateMainArea";
+
@In(create=true)
FileManager fileManager;
- @In(create=true) @Out TreeRootItem treeRoot;
+ @In(create=true) @Out TreeMyAlbumsItem treeMyAlbumsItem;
@In(create=true) @Out
- private SelectionHelper selectionHelper;
+ private ConversationState conversationState;
@In
private User user;
@@ -62,56 +70,43 @@
private RatingBinder ratingBinder;
public void deleteImage(Image image){
- int index = image.getAlbum().getIndex(image);
- String albumName = image.getAlbum().getName();
String imagePath = image.getPath();
- TreeAlbumItem parent = treeRoot.getAlbums().get(image.getAlbum().getId());
imageAction.deleteImage(image);
- parent.removeChild(image.getId());
fileManager.deleteImage(fileManager.transformToServerPath(imagePath));
- if(selectionHelper.getSelectedAlbum().getImages().size() > index){
- selectionHelper.setSelectedImage(selectionHelper.getSelectedAlbum().getImages().get(index));
- }else{
- selectionHelper.setSelectedImage(selectionHelper.getSelectedAlbum().getImages().get(index-1));
- }
}
public void editImage(Image image){
- TreeAlbumItem parent = treeRoot.getAlbums().get(image.getAlbum().getId());
+ TreeAlbumItem parent = treeMyAlbumsItem.getAlbumByName(image.getAlbum().getName());
boolean parentChanged = !parent.getAlbum().getName().equals(image.getAlbumName());
if(parentChanged){
- parent.removeChild(image.getId());
- TreeAlbumItem albumItem = treeRoot.getAlbumByName(image.getAlbumName());
- TreeImageItem imageItem = new TreeImageItem(image.getId(),albumItem,image);
- albumItem.addChild(image.getId(), imageItem);
+ TreeAlbumItem albumItem = treeMyAlbumsItem.getAlbumByName(image.getAlbumName());
String fileNameOld = fileManager.transformToServerPath(image.getPath());
int lastIndexOf = image.getPath().lastIndexOf("/");
String prevPathEnd = image.getPath().substring(lastIndexOf);
- String fileNameNew = user.getLogin() + fileManager.getFileSeparator() + image.getAlbumName() + fileManager.getFileSeparator() + prevPathEnd;
- String newPath = user.getLogin() + "/" + image.getAlbumName() + "/" + prevPathEnd;
+ Album dropValue = treeMyAlbumsItem.getAlbumByName(image.getAlbumName()).getAlbum();
+ String fileNameNew = user.getLogin() + fileManager.getFileSeparator() + dropValue.getAlbumPathFromParents(dropValue , new ArrayList<String>(), fileManager.getFileSeparator()) + prevPathEnd;
+ String newPath = user.getLogin() + "/" + albumItem.getAlbum().getAlbumPathFromParents(albumItem.getAlbum(), new ArrayList<String>(), "/") + prevPathEnd;
image.setPath(newPath);
fileManager.renameImage(fileNameOld, fileNameNew);
- selectionHelper.setSelectedImage(imageItem.getImage());
- selectionHelper.setSelectedAlbum(albumItem.getAlbum());
- }else{
- TreeImageItem imageItem = (TreeImageItem)parent.getChild(image.getId());
- imageItem.setImage(image);
+ conversationState.setSelectedImage(image);
+ conversationState.setSelectedAlbum(albumItem.getAlbum());
}
imageAction.editImage(image, parentChanged);
}
-
+
@Observer("addImage")
public void addImage(Image image) {
+ if(!image.validateTags()){
+ Events.instance().raiseEvent(ADD_ERROR_EVENT, new Exception(META_TAG_WRONG));
+ return;
+ }
imageAction.addImage(image);
- TreeAlbumItem albumItem = treeRoot.getAlbumByName(image.getAlbumName());
- TreeImageItem imageItem = new TreeImageItem(image.getId(),albumItem,image);
- albumItem.addChild(image.getId(), imageItem);
- selectionHelper.setSelectedImage(imageItem.getImage());
- selectionHelper.setSelectedAlbum(albumItem.getAlbum());
+ TreeAlbumItem albumItem = treeMyAlbumsItem.getAlbumByName(image.getAlbumName());
+ conversationState.setSelectedAlbum(albumItem.getAlbum());
+ Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
}
-
public void editComment(Comment comment) {
imageAction.editComment(comment);
}
Added: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/MessageManager.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/MessageManager.java (rev 0)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/MessageManager.java 2009-01-23 13:28:09 UTC (rev 12388)
@@ -0,0 +1,152 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.realworld.manager;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import javax.faces.event.ActionEvent;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Out;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.core.Events;
+import org.richfaces.realworld.domain.Message;
+import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.navigation.NavigationEnum;
+import org.richfaces.realworld.service.IMessageAction;
+import org.richfaces.realworld.service.MessageAction;
+import org.richfaces.realworld.ui.History;
+
+@Name("messageManager")
+(a)Scope(ScopeType.CONVERSATION)
+public class MessageManager implements Serializable{
+
+ private static final long serialVersionUID = 2561824019376412988L;
+
+ private static final String UPDATE_MAIN_AREA_EVENT = "updateMainArea";
+
+ @In
+ private User user;
+
+ private Message message;
+
+ private Message messageForSend;
+
+ private Long countUnreadedMessages;
+
+ @In(create=true) @Out(required=false)
+ private History history;
+
+ @In(create=true) IMessageAction messageAction;
+ public void closeMessage(){
+ this.message = null;
+ this.messageForSend = null;
+ }
+
+ public void showHistory(User u){
+ Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.READ_MESSAGES);
+ history.setSelected(true);
+ history.setHistoryUser(u);
+ }
+
+ public void initMessage(Message message, User owner, String theme, String content, boolean isFrRequest){
+ if(message == null){
+ this.message = null;
+ }else{
+ this.message=message;
+ this.message.setReaded(true);
+ this.setCountUnreadedMessages(null);
+ }
+ if(owner == null){
+ this.messageForSend = null;
+ }else{
+ this.messageForSend = new Message();
+ this.messageForSend.setAuthor(user);
+ if(theme.startsWith("Re:")){
+ this.messageForSend.setTheme(theme + this.message.getTheme());
+ }else{
+ this.messageForSend.setTheme(theme);
+ }
+ this.messageForSend.setOwner(owner);
+ this.messageForSend.setMessage(content);
+ this.messageForSend.setFriendshipRequest(isFrRequest);
+ }
+ Events.instance().raiseEvent("updateMainArea", NavigationEnum.READ_MESSAGES);
+ }
+
+ public void initMessage(){
+ this.message = null;
+ this.messageForSend = new Message();
+ this.messageForSend.setAuthor(user);
+ this.messageForSend.setFriendshipRequest(false);
+ }
+
+ public void sendMessage(){
+ this.messageForSend.setDate(new Date());
+ messageAction.sendMessage(this.message);
+ this.message = null;
+ this.messageForSend = null;
+ }
+
+ public void markAsReaded(Message message){
+ messageAction.markAsReaded(message);
+ this.setCountUnreadedMessages(null);
+ }
+
+ public void deleteMessage(Message message){
+ messageAction.deleteMessage(message);
+ this.setCountUnreadedMessages(null);
+ }
+
+ public Long getCountUnreadedMessages() {
+ if(null == countUnreadedMessages){
+ countUnreadedMessages = messageAction.countNotReadedMessages(user);
+ }
+ return countUnreadedMessages != null ? countUnreadedMessages : 0;
+ }
+
+ public void setCountUnreadedMessages(Long count){
+ countUnreadedMessages = null;
+ }
+
+ public Message getMessage() {
+ return message;
+ }
+
+ public void setMessage(Message message) {
+ this.message = message;
+ }
+
+ public Message getMessageForSend() {
+ return messageForSend;
+ }
+
+ public void setMessageForSend(Message messageForSend) {
+ this.messageForSend = messageForSend;
+ }
+
+ public void sendMessage(Message message) {
+ messageAction.sendMessage(message);
+ }
+}
Property changes on: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/MessageManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
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-23 13:27:29 UTC (rev 12387)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/UserManager.java 2009-01-23 13:28:09 UTC (rev 12388)
@@ -23,28 +23,42 @@
import java.io.Serializable;
import java.util.Date;
import java.util.List;
+import java.util.Map;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.core.Events;
+import org.richfaces.component.UIDatascroller;
import org.richfaces.realworld.domain.Album;
+import org.richfaces.realworld.domain.Comment;
import org.richfaces.realworld.domain.FriendshipRequest;
import org.richfaces.realworld.domain.Image;
import org.richfaces.realworld.domain.Message;
import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.error.ErrorHandler;
import org.richfaces.realworld.navigation.NavigationEnum;
import org.richfaces.realworld.service.IMessageAction;
import org.richfaces.realworld.service.IUserAction;
-import org.richfaces.realworld.util.SelectionHelper;
+import org.richfaces.realworld.tree.TreeFriendItem;
+import org.richfaces.realworld.tree.TreeFriendsItem;
+import org.richfaces.realworld.ui.History;
+import org.richfaces.realworld.ui.ConversationState;
@Name("userManager")
@Scope(ScopeType.CONVERSATION)
public class UserManager implements Serializable{
+ private static final String FRIEND_ERROR_MESSAGE = "This user won't be your friend!";
+ private static final String SLASH = "/";
+ private static final String HAVENT_ACCESS = "You have no rights to view this album";
+ private static final String ADD_ERROR_EVENT = "addErrorEvent";
+ private static final String SEND_MESSAGE = "sendMessage";
+ private static final String CLEAR_EDITOR = "clearEditor";
@In("#{messages['addedtofriends']}") private String ADDED_TO_FRIENDS_MESSAGE_THEME;
@In("#{messages['addedtofriendsby']}") private String ADDED_TO_FRIENDS_MESSAGE;
@In("#{messages['removedfromfriends']}") private String REMOVED_FROM_FRIENDS_MESSAGE_THEME;
@@ -53,43 +67,49 @@
private static final String UPDATE_MAIN_AREA_EVENT = "updateMainArea";
private static final long serialVersionUID = 6027103521084558931L;
+
+ private static final String DATASCROLLER_ID = "mainform:imageScroller";
+ @In(create=true, required=true)
+ private ImageManager imageManager;
+
@In
private User user;
- private Long countUnreadedMessages;
+ @In(required=false) @Out(required=false)
+ TreeFriendsItem treeFriendsItem;
@In(create=true, required=true)
- private IMessageAction messageAction;
-
- @In(create=true, required=true)
private IUserAction userAction;
@In(create=true) @Out
- private SelectionHelper selectionHelper;
+ private ConversationState conversationState;
public List<String> availableUserLogins(Object suggest){
List<String> suggestions = userAction.getUsers((String)suggest);
return suggestions;
}
- public void sendMessage(Message message) {
- messageAction.sendMessage(message);
+ public void showUserProfile(){
+ conversationState.setSelectedUser(user);
+ conversationState.setSecondSelectedUser(null);
+ Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.USER_PREFS);
}
-
- public Long getCountUnreadedMessages() {
- if(null == countUnreadedMessages){
- countUnreadedMessages = userAction.countNotReadedMessages(user);
- }
- return countUnreadedMessages != null ? countUnreadedMessages : 0;
+
+ public void showUserProfile(User user){
+ conversationState.setSelectedUser(user);
+ conversationState.setSecondSelectedUser(null);
+ Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.USER_PREFS);
}
- public void setCountUnreadedMessages(Long count){
- countUnreadedMessages = null;
+ public void showSecondUserProfile(User user){
+ conversationState.setSecondSelectedUser(user);
+ Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.USER_PREFS);
}
-
+
public void removeFromFriends(User owner, User removed){
userAction.removeFromFriends(owner, removed);
+ treeFriendsItem.removeChild(removed.getId());
Message message = new Message();
message.setAuthor(user);
message.setDate(new Date());
@@ -98,7 +118,7 @@
message.setReaded(false);
message.setMessage(YOU_ARE_WERE_REMOVED_FROM_FRIENDS_MESSAGE+ user.getLogin());
message.setTheme(REMOVED_FROM_FRIENDS_MESSAGE_THEME);
- messageAction.sendMessage(message);
+ Events.instance().raiseEvent(SEND_MESSAGE, message);
}
public void addToFriends(User friend){
@@ -106,6 +126,8 @@
if(request != null){
if(!userAction.friendExist(user, friend)){
userAction.addFriend(user, friend, request);
+ TreeFriendItem friendItem = new TreeFriendItem(friend.getId(), treeFriendsItem, friend);
+ treeFriendsItem.addChild(friend.getId(), friendItem );
Message message = new Message();
message.setAuthor(user);
message.setDate(new Date());
@@ -114,36 +136,106 @@
message.setReaded(false);
message.setMessage(ADDED_TO_FRIENDS_MESSAGE+ user.getLogin());
message.setTheme(ADDED_TO_FRIENDS_MESSAGE_THEME);
- messageAction.sendMessage(message);
+ Events.instance().raiseEvent(SEND_MESSAGE, message);
}
- }/*else{
- throw new Exception("This user won't be your friend!");
- }*/
+ }else{
+ Events.instance().raiseEvent(ADD_ERROR_EVENT, new Exception(FRIEND_ERROR_MESSAGE));
+ return;
+ }
}
+ public void addComment(Image image, String message){
+ Comment comment= new Comment();
+ comment.setAuthor(user);
+ comment.setImage(image);
+ comment.setDate(new Date());
+ comment.setMessage(message);
+ imageManager.addComment(comment);
+ Events.instance().raiseEvent(CLEAR_EDITOR, "");
+ }
- public void addToSharedAlbums(Image image){
- userAction.addSharedAlbum(image.getAlbum());
+ public void addToFavoriteAlbums(Album album){
+ userAction.addFavoriteAlbum(album);
}
- public void removeFromSharedAlbums(Album album){
- userAction.removeFromSharedAlbums(user, album);
+ public void removeFromFavoriteAlbums(Album album){
+ userAction.removeFromFavoriteAlbums(user, album);
}
+
+ public void addToFavoriteImages(Image image){
+ userAction.addFavoriteImage(image);
+ }
+
+ public void removeFromFavoriteImages(Image image){
+ userAction.removeFromFavoriteImages(user, image);
+ }
- public void showSharedAlbum(Image image){
+ public void showImage(Image image){
+ if(!image.getAlbum().isShared() && !image.getAlbum().getOwner().equals(user) && !user.getFriends().contains(image.getAlbum().getOwner())){
+ Events.instance().raiseEvent(ADD_ERROR_EVENT, new Exception(HAVENT_ACCESS));
+ return;
+ }
Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
- selectionHelper.setSelectedAlbum(image.getAlbum());
- selectionHelper.setSelectedImage(selectionHelper.getSelectedAlbum().getImages().get(0));
- selectionHelper.setSelectedImageIndex(1);
- selectionHelper.setUserAlbumSelected(false);
+ conversationState.setSelectedAlbum(image.getAlbum());
+ conversationState.setSelectedImage(image);
+ setDataScrollerIndex(image.getAlbum().getIndex(image));
+ conversationState.setSelectedUser(image.getAlbum().getOwner());
}
- public void markAsReaded(Message message){
- messageAction.markAsReaded(message);
- this.setCountUnreadedMessages(null);
+ public void showUser(User u){
+ Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
+ conversationState.setSelectedAlbum(null);
+ conversationState.setSelectedImage(null);
+ conversationState.setSelectedUser(u);
}
- public void deleteMessage(Message message){
- messageAction.deleteMessage(message);
- this.setCountUnreadedMessages(null);
+ private void setDataScrollerIndex(int index) {
+ UIComponent component = FacesContext.getCurrentInstance().getViewRoot();
+ UIDatascroller scroller = (UIDatascroller)component.findComponent(DATASCROLLER_ID);
+ Map<String, Object> attributes = scroller.getDataTable().getAttributes();
+ attributes.put(UIDatascroller.SCROLLER_STATE_ATTRIBUTE, index+1);
+ conversationState.setSelectedImageIndex(index+1);
}
+
+ public void showAlbum(Album album){
+ if(!album.isShared() && !album.getOwner().equals(user) && !user.getFriends().contains(album.getOwner())){
+ Events.instance().raiseEvent(ADD_ERROR_EVENT, new Exception(HAVENT_ACCESS));
+ return;
+ }
+ Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
+ conversationState.setSelectedAlbum(album);
+ conversationState.setSelectedUser(album.getOwner());
+ }
+
+ public List<Album> getRootAlbums(User user2) {
+ return userAction.getRootAlbums(user2);
+ }
+
+ public void selectMyAlbums(){
+ conversationState.setSelectedAlbum(null);
+ conversationState.setSelectedImage(null);
+ conversationState.setSelectedUser(user);
+ }
+
+ public void selectMyFriends(){
+ conversationState.setSelectedAlbum(null);
+ conversationState.setSelectedImage(null);
+ conversationState.setSelectedUser(null);
+ }
+
+ public void selectUser(User u){
+ conversationState.setSelectedAlbum(null);
+ conversationState.setSelectedImage(null);
+ conversationState.setSelectedUser(u);
+ }
+
+ public void selectAlbum(Album a){
+ conversationState.setSelectedAlbum(a);
+ conversationState.setSelectedImage(null);
+ conversationState.setSelectedUser(a.getOwner());
+ }
+
+ public String getPathOfImage(String path){
+ int i = path.lastIndexOf(SLASH);
+ return path.substring(i);
+ }
}
Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/search/SearchBean.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/search/SearchBean.java 2009-01-23 13:27:29 UTC (rev 12387)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/search/SearchBean.java 2009-01-23 13:28:09 UTC (rev 12388)
@@ -28,17 +28,12 @@
import java.util.Map;
import javax.faces.model.SelectItem;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
-import org.richfaces.realworld.domain.Album;
import org.richfaces.realworld.domain.Image;
-import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.error.ErrorHandler;
import org.richfaces.realworld.service.ISearchService;
import org.richfaces.realworld.service.SearchService;
@@ -50,8 +45,6 @@
@In("#{messages['less']}") private String LESS_CHOICE;
@In("#{messages['more']}") private String MORE_CHOICE;
@In("#{messages['nomatter']}") private String NO_MATTER_CHOICE;
-
- private boolean collapsed;
private static final String EQUALS = "= ";
@@ -209,10 +202,6 @@
map.put(SearchService.CASE_SENSITIVE_PARAMETER, caseSensitive);
return map;
}
-
- public void collapse(){
- this.setCollapsed(!collapsed);
- }
private String populateAdditionalParams() {
StringBuilder additionalParams = new StringBuilder("");
@@ -409,14 +398,6 @@
this.heightChoice = heightChoice;
}
- public boolean isCollapsed() {
- return collapsed;
- }
-
- public void setCollapsed(boolean collapsed) {
- this.collapsed = collapsed;
- }
-
public boolean isCaseSensitive() {
return caseSensitive;
}
Deleted: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/servlet/FileHelper.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/servlet/FileHelper.java 2009-01-23 13:27:29 UTC (rev 12387)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/servlet/FileHelper.java 2009-01-23 13:28:09 UTC (rev 12388)
@@ -1,63 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.richfaces.realworld.servlet;
-
-import java.io.File;
-
-public class FileHelper {
-
- private static final String FILE_SEPARATOR = "file.separator";
- private String uploadRoot;
-
- public String getUploadRoot() {
- return uploadRoot;
- }
-
- public void setUploadRoot(String uploadRoot) {
- this.uploadRoot = uploadRoot;
- }
-
- public FileHelper(String uploadRoot){
- this.setUploadRoot(uploadRoot);
- }
-
- public String getFileSeparator() {
- return System.getProperty(FILE_SEPARATOR);
- }
-
- public boolean isImagePresent(String fileName) {
- String fullPath = getAbsolutePath(fileName);
- File file = new File(fullPath);
- return file.exists() && !file.isDirectory();
- }
-
- public File getImage(String fileName){
- if(isImagePresent(fileName)){
- return new File(getAbsolutePath(fileName));
- }
- return null;
- }
-
- private String getAbsolutePath(String fileName) {
- return getUploadRoot() + fileName;
- }
-
-}
Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/servlet/PictureServlet.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/servlet/PictureServlet.java 2009-01-23 13:27:29 UTC (rev 12387)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/servlet/PictureServlet.java 2009-01-23 13:28:09 UTC (rev 12388)
@@ -6,37 +6,59 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.util.Date;
+import java.util.Map;
+import javax.persistence.EntityManager;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import com.drew.imaging.jpeg.JpegMetadataReader;
-import com.drew.imaging.jpeg.JpegProcessingException;
-import com.drew.metadata.Directory;
-import com.drew.metadata.Metadata;
-import com.drew.metadata.MetadataException;
-import com.drew.metadata.exif.ExifDirectory;
+import org.jboss.seam.Component;
+import org.richfaces.realworld.domain.Image;
+import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.fileupload.FileManager;
public class PictureServlet extends javax.servlet.http.HttpServlet {
public static final long serialVersionUID = 596009789004L;
- private static final String UPLOAD_ROOT = "uploadRoot";
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String pathInfo = request.getPathInfo();
String fileName = WebUtil.getFileName(pathInfo);
+ Map req = request.getParameterMap();
+ String userId = request.getParameter("userId");
+ EntityManager em = (EntityManager)Component.getInstance("entityManager", true);
+ FileManager fileManager = (FileManager)Component.getInstance("fileManager", true);
+ User user = null;
+ if(userId != null){
+ user = em.find(User.class, Long.valueOf(userId));
+ }
+ Image i = (Image)em.createQuery("from Image i where i.path=:path").setParameter("path", pathInfo.substring(1)).getSingleResult();
+ if(!i.getAlbum().isShared()){
+ if(user != null){
+ if(i.getAlbum().getOwner().equals(user) || user.getFriends().contains(i.getAlbum().getOwner())){
+ //OK
+ }else{
+ String contextPath = request.getContextPath();
+ response.sendRedirect(contextPath + "/error.seam");
+ return;
+ }
+ }else{
+ String contextPath = request.getContextPath();
+ response.sendRedirect(contextPath + "/error.seam");
+ return;
+ }
+ }
if (fileName == null) {
String contextPath = request.getContextPath();
response.sendRedirect(contextPath + "/error.seam");
return;
}
ServletContext context = getServletContext();
- FileHelper helper = new FileHelper(context.getInitParameter(UPLOAD_ROOT));
- File file = helper.getImage(fileName);
+ //FileHelper helper = new FileHelper(context.getInitParameter(UPLOAD_ROOT));
+ File file = fileManager.getImage(fileName);
/*try {
Metadata metadata = JpegMetadataReader.readMetadata(file);
Directory exifDirectory = metadata.getDirectory(ExifDirectory.class);
Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/slideshow/SlideshowBean.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/slideshow/SlideshowBean.java 2009-01-23 13:27:29 UTC (rev 12387)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/slideshow/SlideshowBean.java 2009-01-23 13:28:09 UTC (rev 12388)
@@ -27,8 +27,7 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
-import org.richfaces.realworld.error.ErrorHandler;
-import org.richfaces.realworld.tree.TreeSelectionManager;
+import org.richfaces.realworld.tree.TreeManager;
@Name("slideshow")
@Scope(ScopeType.CONVERSATION)
@@ -43,9 +42,6 @@
@In(required=false) @Out(required=false)
SlideshowHelper slideshowHelper;
- @In
- TreeSelectionManager treeSelectionManager;
-
private boolean active;
private int interval = INITIAL_DELAY;
@@ -77,8 +73,4 @@
public void updateInterval(){
this.setInterval((int)(DELAY * Long.valueOf(slideshowHelper.getInputSlider().getValue().toString())));
}
- @ErrorHandler
- public void incrementSlide() {
- treeSelectionManager.incrementSlideshowIndex();
- }
}
Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeAlbumItem.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeAlbumItem.java 2009-01-23 13:27:29 UTC (rev 12387)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeAlbumItem.java 2009-01-23 13:28:09 UTC (rev 12388)
@@ -26,52 +26,60 @@
import java.util.List;
import java.util.Map;
+import javax.faces.model.SelectItem;
+
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.core.Events;
import org.richfaces.model.TreeNode;
import org.richfaces.realworld.domain.Album;
import org.richfaces.realworld.domain.Image;
+import org.richfaces.realworld.manager.AlbumManager;
+import org.richfaces.realworld.manager.UserManager;
public class TreeAlbumItem implements TreeNode {
private static final String ALBUM_NODE_TYPE = "album";
-
+ TreeMyAlbumsItem treeMyAlbumsItem;
private static final long serialVersionUID = 6514596192023597908L;
private long id;
- private Map<Object, TreeNode> images = new LinkedHashMap<Object, TreeNode>();
+ private Map<Object, TreeNode> childs = new LinkedHashMap<Object, TreeNode>();
private Album album;
TreeNode parent;
- public TreeAlbumItem(long id, TreeRootItem parent, Album album) {
+ public TreeAlbumItem(long id, TreeNode parent, Album album, TreeMyAlbumsItem treeMyAlbumsItem) {
this.id = id;
this.parent = parent;
this.album = album;
- for(Image image:album.getImages()){
- TreeImageItem node = new TreeImageItem(image.getId(), this, image);
- addImage(node);
+ this.treeMyAlbumsItem = treeMyAlbumsItem;
+ for(Album alb:album.getChildAlbums()){
+ TreeAlbumItem node = new TreeAlbumItem(alb.getId(), this, alb , this.treeMyAlbumsItem);
+ addAlbum(node);
}
}
- public void addImage(TreeImageItem image) {
- addChild(image.getId(), image);
- image.setParent(this);
+ public void addAlbum(TreeAlbumItem alb) {
+ addChild(alb.getId(), alb);
+ alb.setParent(this);
}
public void addChild(Object identifier, TreeNode child) {
- images.put(identifier, child);
+ childs.put(identifier, child);
}
public TreeNode getChild(Object id) {
- return (TreeNode) images.get(id);
+ return (TreeNode) childs.get(id);
}
public Iterator<Map.Entry<Object, TreeNode>> getChildren() {
- return images.entrySet().iterator();
+ return childs.entrySet().iterator();
}
- public List<TreeNode> getImages() {
- List<TreeNode> imageCollection = new ArrayList<TreeNode>();
- imageCollection.addAll(images.values());
- return imageCollection;
+ public List<TreeNode> getAlbums() {
+ List<TreeNode> childCollection = new ArrayList<TreeNode>();
+ childCollection.addAll(childs.values());
+ return childCollection;
}
public Object getData() {
@@ -83,11 +91,11 @@
}
public boolean isLeaf() {
- return images.isEmpty();
+ return childs.isEmpty();
}
public void removeChild(Object id) {
- images.remove(id);
+ childs.remove(id);
}
public void setData(Object data) {
@@ -102,6 +110,9 @@
}
public Album getAlbum() {
+ if(album == null){
+ System.out.println();
+ }
return album;
}
@@ -116,4 +127,42 @@
public String toString(){
return this.getAlbum().getName();
}
+
+ public boolean containAlbum(Album selectedAlbum) {
+ for(TreeNode item : this.childs.values()){
+ TreeAlbumItem node = (TreeAlbumItem)item;
+ if(node.getAlbum().equals(selectedAlbum)){
+ return true;
+ }
+ if(node.getAlbums().size() > 0){
+ for(TreeNode a : node.getAlbums()){
+ TreeAlbumItem temp = (TreeAlbumItem)a;
+ return temp.containAlbum(selectedAlbum);
+ }
+ }
+ }
+ return false;
+ }
+
+ public List<SelectItem> getArrayOfChildsAlbumsNames() {
+ List<SelectItem> items = new ArrayList<SelectItem>();
+ for(TreeNode item: this.getAlbums()){
+ TreeAlbumItem a = (TreeAlbumItem)item;
+ String pathFromParents = a.getAlbum().getAlbumPathFromParents(a.getAlbum(), new ArrayList<String>(), "/");
+ SelectItem e = new SelectItem(pathFromParents);
+ items.add(e);
+ a.getArrayOfChildsAlbumsNames(items);
+ }
+ return items;
+ }
+
+ public void getArrayOfChildsAlbumsNames(List<SelectItem> list) {
+ for(TreeNode item: this.getAlbums()){
+ TreeAlbumItem a = (TreeAlbumItem)item;
+ String pathFromParents = this.getAlbum().getAlbumPathFromParents(this.getAlbum(), new ArrayList<String>(), "/");
+ SelectItem e = new SelectItem(pathFromParents);
+ list.add(e);
+ a.getArrayOfChildsAlbumsNames(list);
+ }
+ }
}
Added: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendItem.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendItem.java (rev 0)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendItem.java 2009-01-23 13:28:09 UTC (rev 12388)
@@ -0,0 +1,116 @@
+package org.richfaces.realworld.tree;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Out;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.contexts.Contexts;
+import org.richfaces.model.TreeNode;
+import org.richfaces.realworld.domain.Album;
+import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.manager.UserManager;
+import org.richfaces.realworld.service.IUserAction;
+
+@Name("treeFriendAlbum")
+(a)Scope(ScopeType.CONVERSATION)
+public class TreeFriendItem implements TreeNode{
+
+ private static final String TYPE = "treeFriendAlbum";
+
+ private long id;
+
+ private User friend;
+
+ public TreeFriendItem(long id, TreeNode parent, User friend){
+ this.id = id;
+ this.parent = parent;
+ this.friend = friend;
+ }
+
+ public UserManager getUserManager() {
+ return (UserManager) Contexts.getConversationContext().get("userManager");
+ }
+
+ private TreeNode parent;
+
+ private static final long serialVersionUID = -3530085227471752526L;
+
+ private Map<Long, TreeAlbumItem> albums = null;
+
+ public Map<Long, TreeAlbumItem> getAlbums() {
+ if (this.albums==null) {
+ initData();
+ }
+ return this.albums;
+ }
+
+ public void addChild(Object identifier, TreeNode child) {
+ getAlbums().put((Long)identifier, (TreeAlbumItem)child);
+ child.setParent(this);
+ }
+
+ public TreeNode getChild(Object id) {
+ return (TreeNode) albums.get(id);
+ }
+
+ public Iterator getChildren() {
+ return getAlbums().entrySet().iterator();
+ }
+
+ public Object getData() {
+ return this;
+ }
+
+ public TreeNode getParent() {
+ return parent;
+ }
+
+ public boolean isLeaf() {
+ return getAlbums().isEmpty();
+ }
+
+ public void removeChild(Object id) {
+ albums.remove(id);
+ }
+
+ public void setData(Object data) {
+ this.friend = (User)data;
+ }
+
+ public void setParent(TreeNode parent) {
+ this.parent = parent;
+ }
+
+ public String getType() {
+ return TYPE;
+ }
+
+ private void initData() {
+ albums = new HashMap<Long, TreeAlbumItem>();
+ for(Album a: getUserManager().getRootAlbums(friend)){
+ TreeAlbumItem item = new TreeAlbumItem(a.getId(), this, a, null);
+ albums.put(item.getId(), item);
+ }
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public User getFriend() {
+ return friend;
+ }
+
+ public void setFriend(User friend) {
+ this.friend = friend;
+ }
+}
Property changes on: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendItem.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendRootItem.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendRootItem.java (rev 0)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendRootItem.java 2009-01-23 13:28:09 UTC (rev 12388)
@@ -0,0 +1,114 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.realworld.tree;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.model.SelectItem;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Out;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.contexts.Contexts;
+import org.richfaces.model.TreeNode;
+import org.richfaces.realworld.domain.Album;
+import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.service.IUserAction;
+
+@Name("treeFriendRoot")
+(a)Scope(ScopeType.CONVERSATION)
+public class TreeFriendRootItem implements TreeNode {
+
+ @In(create=true, required=true)
+ IUserAction userAction;
+
+ private static final String TREE_ROOT_NODE_TYPE = "treeRootFriend";
+
+ private static final long serialVersionUID = -3530085227471752526L;
+
+ private Map<Long, TreeNode> childs;
+
+ public void addChild(Object identifier, TreeNode child) {
+ getChilds().put((Long)identifier, child);
+ child.setParent(this);
+ }
+
+ public TreeNode getChild(Object id) {
+ return getChilds().get(id);
+ }
+
+ public Iterator getChildren() {
+ return getChilds().entrySet().iterator();
+ }
+
+ public Object getData() {
+ return this;
+ }
+
+ public TreeNode getParent() {
+ return null;
+ }
+
+ public boolean isLeaf() {
+ return false;
+ }
+
+ public void removeChild(Object id) {
+ getChilds().remove(id);
+ }
+
+ public void setData(Object data) {
+ }
+
+ public void setParent(TreeNode parent) {
+ }
+
+ public String getType() {
+ return TREE_ROOT_NODE_TYPE;
+ }
+
+ public Map<Long, TreeNode> getChilds() {
+ if (this.childs==null) {
+ initialise();
+ }
+ return this.childs;
+ }
+
+ private void initialise() {
+ childs = new HashMap<Long, TreeNode>();
+ //TreeMyAlbumsItem item = new TreeMyAlbumsItem(1L, this);
+ //childs.put(item.getId(), item);
+ TreeFriendsItem friendsItem = new TreeFriendsItem(2L, this);
+ childs.put(friendsItem.getId(), friendsItem);
+ //Contexts.getConversationContext().set("treeMyAlbumsItem", item);
+ Contexts.getConversationContext().set("treeFriendsItem", friendsItem);
+ }
+
+ public void setChilds(Map<Long, TreeNode> childs) {
+ this.childs = childs;
+ }
+}
Property changes on: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendRootItem.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendsItem.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendsItem.java (rev 0)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendsItem.java 2009-01-23 13:28:09 UTC (rev 12388)
@@ -0,0 +1,115 @@
+package org.richfaces.realworld.tree;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.model.SelectItem;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Out;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.contexts.Contexts;
+import org.richfaces.model.TreeNode;
+import org.richfaces.realworld.domain.Album;
+import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.service.IUserAction;
+@Name("treeFriendsAlbums")
+(a)Scope(ScopeType.CONVERSATION)
+public class TreeFriendsItem implements TreeNode{
+
+ private static final String TYPE = "treeFriendsAlbums";
+
+ private long id;
+
+ private User user;
+
+ public TreeFriendsItem(long id, TreeNode parent){
+ this.id = id;
+ this.parent = parent;
+ }
+
+ private TreeNode parent;
+
+ private static final long serialVersionUID = -3530085227471752526L;
+
+ private Map<Long, TreeFriendItem> friends = null;
+
+ public Map<Long, TreeFriendItem> getFriends() {
+ if (this.friends==null) {
+ initData();
+ }
+ return this.friends;
+ }
+
+ public void addAlbumToTree(TreeFriendItem friend) {
+ addChild(friend.getId(), friend);
+ }
+
+ public void addChild(Object identifier, TreeNode child) {
+ getFriends().put((Long)identifier, (TreeFriendItem)child);
+ child.setParent(this);
+ }
+
+ public TreeNode getChild(Object id) {
+ return (TreeNode) friends.get(id);
+ }
+
+ public Iterator getChildren() {
+ return getFriends().entrySet().iterator();
+ }
+
+ public Object getData() {
+ return this;
+ }
+
+ public TreeNode getParent() {
+ return parent;
+ }
+
+ public boolean isLeaf() {
+ return getFriends().isEmpty();
+ }
+
+ public void removeChild(Object id) {
+ friends.remove(id);
+ }
+
+ public void setData(Object data) {
+ }
+
+ public void setParent(TreeNode parent) {
+ this.parent = parent;
+ }
+
+ public String getType() {
+ return TYPE;
+ }
+
+ private void initData() {
+ friends = new HashMap<Long, TreeFriendItem>();
+ if(null == getUser().getFriends()){
+ return;
+ }
+ for(User u: getUser().getFriends()){
+ TreeFriendItem item = new TreeFriendItem(u.getId(), this, u);
+ friends.put(item.getId(), item);
+ }
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public User getUser() {
+ return (User) Contexts.getConversationContext().get("user");
+ }
+}
Property changes on: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendsItem.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Deleted: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeImageItem.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeImageItem.java 2009-01-23 13:27:29 UTC (rev 12387)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeImageItem.java 2009-01-23 13:28:09 UTC (rev 12388)
@@ -1,94 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.richfaces.realworld.tree;
-
-import java.util.Iterator;
-
-import org.richfaces.model.TreeNode;
-import org.richfaces.realworld.domain.Image;
-
-public class TreeImageItem implements TreeNode {
-
- private static final String IMAGE_NODE_TYPE = "image";
- private static final long serialVersionUID = 6514596192023597908L;
- private long id;
- private Image image;
-
- private TreeAlbumItem album;
-
- public TreeImageItem(long id, TreeAlbumItem album, Image image) {
- this.id = id;
- this.album = album;
- this.image = image;
- }
-
- public void addChild(Object identifier, TreeNode child) {
-
- }
-
- public TreeNode getChild(Object id) {
- return null;
- }
-
- public Iterator getChildren() {
- return null;
- }
-
- public Object getData() {
- return this;
- }
-
- public TreeNode getParent() {
- return album;
- }
-
- public boolean isLeaf() {
- return true;
- }
-
- public void removeChild(Object id) {
-
- }
-
- public void setData(Object data) {
- }
-
- public void setParent(TreeNode parent) {
- this.album = (TreeAlbumItem) parent;
- }
-
- public long getId() {
- return id;
- }
-
- public String getType() {
- return IMAGE_NODE_TYPE;
- }
-
- public Image getImage() {
- return image;
- }
-
- public void setImage(Image image) {
- this.image = image;
- }
-
-}
Added: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeManager.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeManager.java (rev 0)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeManager.java 2009-01-23 13:28:09 UTC (rev 12388)
@@ -0,0 +1,246 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.realworld.tree;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.model.SelectItem;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Observer;
+import org.jboss.seam.annotations.Out;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.Synchronized;
+import org.jboss.seam.core.Events;
+import org.richfaces.component.UIDatascroller;
+import org.richfaces.component.UITree;
+import org.richfaces.component.html.HtmlTree;
+import org.richfaces.event.DataScrollerEvent;
+import org.richfaces.event.NodeSelectedEvent;
+import org.richfaces.model.TreeNode;
+import org.richfaces.model.TreeRowKey;
+import org.richfaces.realworld.domain.Album;
+import org.richfaces.realworld.domain.Image;
+import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.fileupload.FileManager;
+import org.richfaces.realworld.manager.ImageManager;
+import org.richfaces.realworld.navigation.NavigationEnum;
+import org.richfaces.realworld.ui.ConversationState;
+
+@Name("treeManager")
+(a)Scope(ScopeType.CONVERSATION)
+@Synchronized(timeout=200000)
+public class TreeManager implements Serializable{
+
+ private static final String DATASCROLLER_ID = "mainform:imageScroller";
+
+ private static final String IMAGE_DATATABLE_ID = "mainform:mainImage";
+
+ private static final String FIRST = "first";
+
+ private static final String NEXT = "next";
+
+ private static final String LAST = "last";
+
+ private static final String UPDATE_MAIN_AREA_EVENT = "updateMainArea";
+
+ private static final String PREVIOUS = "previous";
+
+ private static final long serialVersionUID = -6072049677194472463L;
+
+ private NavigationEnum mainArea;
+
+ @In(required=false) @Out(required=false)
+ private ConversationState conversationState;
+
+ @In(create=true)
+ FileManager fileManager;
+
+ @In User user;
+
+ @In(required=false)
+ ImageManager imageManager;
+
+ public void showFileUpload(TreeAlbumItem item, boolean singleMode){
+ String i;
+ if(singleMode){
+ i="single";
+ }else{
+ i="multy";
+ }
+ Events.instance().raiseEvent("changeMode", i);
+ Events.instance().raiseEvent("fileUploadClear");
+ conversationState.setSelectedAlbum(item.getAlbum());
+ this.setMainArea(NavigationEnum.FILE_UPLOAD);
+ }
+
+ public void showFileUpload(Album item, boolean singleMode){
+ String i;
+ if(singleMode){
+ i="single";
+ }else{
+ i="multy";
+ }
+ Events.instance().raiseEvent("changeMode", i);
+ Events.instance().raiseEvent("fileUploadClear");
+ conversationState.setSelectedAlbum(item);
+ this.setMainArea(NavigationEnum.FILE_UPLOAD);
+ }
+
+ public void scrollerListener(DataScrollerEvent event) {
+ List<Image> images = conversationState.getSelectedAlbum().getImages();
+ if (event.getNewScrolVal().equals(PREVIOUS)) {
+ for(int index = 0 ; index < images.size(); index++){
+ if(images.get(index) == conversationState.getSelectedImage()){
+ conversationState.setSelectedImage(images.get(index - 1));
+ conversationState.setSelectedImageIndex(index);
+ }
+ }
+ } else if (event.getNewScrolVal().equals(LAST)) {
+ conversationState.setSelectedImage(images.get(images.size() - 1));
+ conversationState.setSelectedImageIndex(images.size());
+ } else if (event.getNewScrolVal().equals(NEXT)) {
+ for(int index = 0 ; index < images.size(); index++){
+ if(images.get(index) == conversationState.getSelectedImage()){
+ conversationState.setSelectedImage(images.get(index + 1));
+ conversationState.setSelectedImageIndex(index + 2);
+ return;
+ }
+ }
+ } else if (event.getNewScrolVal().equals(FIRST)) {
+ conversationState.setSelectedImage(images.get(0));
+ conversationState.setSelectedImageIndex(1);
+ }
+
+ }
+
+ public Boolean adviseNodeSelected(UITree tree) {
+ TreeRowKey treeRowKey = (TreeRowKey) tree.getRowKey();
+ TreeNode treeNode = (TreeNode) tree.getRowData(treeRowKey);
+ if (treeNode instanceof TreeAlbumItem) {
+ TreeAlbumItem currentNode = (TreeAlbumItem) treeNode;
+ boolean selected = currentNode.getAlbum() == conversationState.getSelectedAlbum() || currentNode.containAlbum(conversationState.getSelectedAlbum());
+ return selected;
+ }
+ return null;
+ }
+
+ public Boolean adviseNodeOpened(UITree tree) {
+ TreeRowKey treeRowKey = (TreeRowKey) tree.getRowKey();
+ TreeNode treeNode = (TreeNode) tree.getRowData(treeRowKey);
+ if (treeNode instanceof TreeAlbumItem) {
+ TreeAlbumItem currentNode = (TreeAlbumItem) treeNode;
+ boolean selected = currentNode.getAlbum() == conversationState.getSelectedAlbum() || currentNode.containAlbum(conversationState.getSelectedAlbum());
+ return selected;
+ }
+ return null;
+ }
+
+ public void processSelection(NodeSelectedEvent event) {
+ Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
+ HtmlTree tree = (HtmlTree) event.getComponent();
+ TreeNode<String> currentNode = tree.getModelTreeNode(tree.getRowKey());
+ if(currentNode instanceof TreeAlbumItem){
+ TreeAlbumItem node = (TreeAlbumItem)currentNode;
+ Album album = node.getAlbum();
+ conversationState.setSelectedAlbum(album);
+ }else if(currentNode instanceof TreeMyAlbumsItem){
+ conversationState.setSelectedAlbum(null);
+ }
+ conversationState.setSelectedUser(user);
+ conversationState.setSelectedImage(null);
+ }
+
+ public void processSelectionFriends(NodeSelectedEvent event) {
+ Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
+ HtmlTree tree = (HtmlTree) event.getComponent();
+ TreeNode<String> currentNode = tree.getModelTreeNode(tree.getRowKey());
+ if(currentNode instanceof TreeAlbumItem){
+ TreeAlbumItem node = (TreeAlbumItem)currentNode;
+ conversationState.setSelectedUser(((TreeAlbumItem)currentNode).getAlbum().getOwner());
+ Album album = node.getAlbum();
+ conversationState.setSelectedAlbum(album);
+ }else if(currentNode instanceof TreeFriendsItem){
+ conversationState.setSelectedUser(null);
+ conversationState.setSelectedAlbum(null);
+ }else if(currentNode instanceof TreeFriendItem){
+ conversationState.setSelectedUser(((TreeFriendItem)currentNode).getFriend());
+ conversationState.setSelectedAlbum(null);
+ }
+ conversationState.setSelectedImage(null);
+ }
+
+ private void setDataScrollerIndex(int index) {
+ UIComponent component = FacesContext.getCurrentInstance().getViewRoot();
+ UIDatascroller scroller = (UIDatascroller)component.findComponent(DATASCROLLER_ID);
+ Map<String, Object> attributes = scroller.getDataTable().getAttributes();
+ attributes.put(UIDatascroller.SCROLLER_STATE_ATTRIBUTE, index+1);
+ conversationState.setSelectedImageIndex(index+1);
+ }
+
+
+ public void incrementSlideshowIndex() {
+ int index = conversationState.getSelectedAlbum().getIndex(conversationState.getSelectedImage());
+ if(conversationState.getSelectedAlbum().getImages().size() == index +1){
+ index = -1;
+ }
+ conversationState.setSelectedImage(conversationState.getSelectedAlbum().getImages().get(index +1));
+ UIComponent component = FacesContext.getCurrentInstance().getViewRoot();
+ UIDatascroller scroller = (UIDatascroller)component.findComponent(DATASCROLLER_ID);
+ Map<String, Object> attributes = scroller.getDataTable().getAttributes();
+ attributes.put(UIDatascroller.SCROLLER_STATE_ATTRIBUTE, index+2);
+ conversationState.setSelectedImageIndex(index+2);
+ }
+
+ public NavigationEnum getMainArea() {
+ return mainArea;
+ }
+
+ @Observer("updateMainArea")
+ public void setMainArea(NavigationEnum mainArea) {
+ this.mainArea = mainArea;
+ if(mainArea.equals(NavigationEnum.FILE_UPLOAD)){
+ Events.instance().raiseEvent("showFileUpload", true);
+ }
+ }
+
+ public SelectItem[] getAvailableIndexOfImages(){
+ SelectItem[] group = new SelectItem[conversationState.getSelectedAlbum().getImages().size()];
+ for(int i = 0; i < conversationState.getSelectedAlbum().getImages().size(); i++){
+ group[i] = new SelectItem(i+1);
+ }
+ return group;
+ }
+
+ public void updateSelectedItems(Image image){
+ conversationState.setSelectedImage(image);
+ Integer index = conversationState.getSelectedAlbum().getIndex(conversationState.getSelectedImage());
+ setDataScrollerIndex(index);
+ }
+}
Property changes on: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeMyAlbumsItem.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeMyAlbumsItem.java (rev 0)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeMyAlbumsItem.java 2009-01-23 13:28:09 UTC (rev 12388)
@@ -0,0 +1,231 @@
+package org.richfaces.realworld.tree;
+
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.model.SelectItem;
+import javax.persistence.EntityManager;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.contexts.Contexts;
+import org.richfaces.model.TreeNode;
+import org.richfaces.realworld.domain.Album;
+import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.manager.UserManager;
+
+@Name("treeMyAlbumsItem")
+(a)Scope(ScopeType.CONVERSATION)
+public class TreeMyAlbumsItem implements TreeNode {
+
+ private static final String TYPE = "treeMyAlbums";
+
+ private long id;
+
+ UserManager userManager;
+
+ public TreeMyAlbumsItem(){
+
+ }
+ public TreeMyAlbumsItem(long id, TreeNode parent){
+ this.id = id;
+ this.parent = parent;
+ }
+
+ private List<SelectItem> availableAlbums;
+
+ private TreeNode parent;
+
+ private static final long serialVersionUID = -3530085227471752526L;
+
+ private Map<Long, TreeAlbumItem> albums = null;
+
+ public Map<Long, TreeAlbumItem> getAlbums() {
+ if (this.albums==null) {
+ initData();
+ }
+ return this.albums;
+ }
+
+ public void addAlbumToTree(TreeNode parent, TreeAlbumItem album) {
+ parent.addChild(album.getId(), album);
+ }
+
+ public void addChild(Object identifier, TreeNode child) {
+ getAlbums().put((Long)identifier, (TreeAlbumItem)child);
+ child.setParent(this);
+ }
+
+ public TreeNode getChild(Object id) {
+ return (TreeNode) albums.get(id);
+ }
+
+ public Iterator getChildren() {
+ return getAlbums().entrySet().iterator();
+ }
+
+ public Object getData() {
+ return this;
+ }
+
+ public TreeNode getParent() {
+ return parent;
+ }
+
+ public boolean isLeaf() {
+ return getAlbums().isEmpty();
+ }
+
+ public void removeChild(Object id) {
+ albums.remove(id);
+ }
+
+ public void setData(Object data) {
+ }
+
+ public void setParent(TreeNode parent) {
+ this.parent = parent;
+ }
+
+ public String getType() {
+ return TYPE;
+ }
+
+ private void initData() {
+ transformAlbumsToMap();
+ }
+
+ private void transformAlbumsToMap() {
+ albums = new HashMap<Long, TreeAlbumItem>();
+ availableAlbums = new ArrayList<SelectItem>();
+ for(Album album:getUserManager().getRootAlbums(getUser())){
+ TreeAlbumItem albumNode = new TreeAlbumItem(album.getId(), this, album, this);
+ availableAlbums.add(new SelectItem(album.getName()+"/"));
+ addAlbumToTree(this, albumNode);
+ }
+ }
+
+ public void updateChild(Album album) {
+ TreeAlbumItem albumItem = getAlbums().get(album.getId());
+ albumItem.setAlbum(album);
+ }
+
+ public SelectItem getSelectItemByName(String name) {
+ for(SelectItem item : availableAlbums){
+ if(item.getValue().toString().equals(name)){
+ return item;
+ }
+ }
+ return null;
+ }
+
+ public TreeAlbumItem getAlbumByName(String albumName) {
+ Object album = getParentItem(albumName);
+ return album != null ? (TreeAlbumItem)album : null;
+ }
+
+ public TreeNode getParentItem(String albumName){
+ for(Map.Entry<Long, TreeAlbumItem> entry : getAlbums().entrySet()){
+ if(entry.getValue().getAlbum().getName().equals(albumName)){
+ return entry.getValue();
+ }else{
+ if(entry.getValue() instanceof TreeAlbumItem){
+ TreeAlbumItem value = (TreeAlbumItem)entry.getValue();
+ if(value.getAlbums().size() >0){
+ TreeNode parentItem = getParentItem(value, albumName);
+ if(parentItem != null){
+ return parentItem;
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public TreeNode getParentItem(TreeAlbumItem item, String albumName){
+ for(TreeNode entry : item.getAlbums()){
+ if(((TreeAlbumItem)entry).getAlbum().getName().equals(albumName)){
+ return (TreeAlbumItem)entry;
+ }else{
+ if(((TreeAlbumItem)entry).getAlbums().size() >0){
+ getParentItem((TreeAlbumItem)entry, albumName);
+ }
+ }
+ }
+ return null;
+ }
+
+ public List<SelectItem> getAvailableAlbums() {
+ List<SelectItem> availableAlbums = new ArrayList<SelectItem>();
+ for(TreeAlbumItem item :this.getAlbums().values()){
+ SelectItem e = new SelectItem(item.getAlbum().getName() + "/");
+ availableAlbums.add(e);
+ List<SelectItem> availableChildAlbums = item.getArrayOfChildsAlbumsNames();
+ availableAlbums.addAll(availableChildAlbums);
+ }
+ return availableAlbums;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public User getUser() {
+ return (User) Contexts.getConversationContext().get("user");
+ }
+
+ public String getAlbumPathFromParents(Album album2, List<String> list, String delimiter) {
+ if(album2.getParent() == null){
+ list.add(album2.getName() + delimiter);
+ return "";
+ }else{
+ getAlbumPathFromParents(album2.getParent(), list, delimiter);
+ }
+ list.add(album2.getName()+delimiter);
+ String path = "";
+ for(int i =0; i < list.size(); i++){
+ path += list.get(i);
+ }
+ return path;
+}
+
+ public UserManager getUserManager() {
+ UserManager userManager2 = (UserManager) Contexts.getConversationContext().get("userManager");
+ if(userManager2 != null){
+ return userManager2;
+ }
+ else return (UserManager)Component.getInstance("userManager", true);
+ }
+}
+
Property changes on: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeMyAlbumsItem.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeRootItem.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeRootItem.java 2009-01-23 13:27:29 UTC (rev 12387)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeRootItem.java 2009-01-23 13:28:09 UTC (rev 12388)
@@ -33,47 +33,36 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.contexts.Contexts;
import org.richfaces.model.TreeNode;
import org.richfaces.realworld.domain.Album;
import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.service.IUserAction;
@Name("treeRoot")
@Scope(ScopeType.CONVERSATION)
public class TreeRootItem implements TreeNode {
+ @In(create=true, required=true)
+ IUserAction userAction;
+
private static final String TREE_ROOT_NODE_TYPE = "treeRoot";
-
- @In @Out
- private User user;
- private List<SelectItem> availableAlbums;
-
private static final long serialVersionUID = -3530085227471752526L;
- private Map<Long, TreeAlbumItem> albums = null;
-
- public Map<Long, TreeAlbumItem> getAlbums() {
- if (this.albums==null) {
- initData();
- }
- return this.albums;
- }
+ private Map<Long, TreeNode> childs;
- public void addAlbumToTree(TreeAlbumItem album) {
- addChild(album.getId(), album);
- }
-
public void addChild(Object identifier, TreeNode child) {
- getAlbums().put((Long)identifier, (TreeAlbumItem)child);
+ getChilds().put((Long)identifier, child);
child.setParent(this);
}
public TreeNode getChild(Object id) {
- return (TreeNode) albums.get(id);
+ return getChilds().get(id);
}
public Iterator getChildren() {
- return getAlbums().entrySet().iterator();
+ return getChilds().entrySet().iterator();
}
public Object getData() {
@@ -85,11 +74,11 @@
}
public boolean isLeaf() {
- return getAlbums().isEmpty();
+ return false;
}
public void removeChild(Object id) {
- albums.remove(id);
+ getChilds().remove(id);
}
public void setData(Object data) {
@@ -101,45 +90,22 @@
public String getType() {
return TREE_ROOT_NODE_TYPE;
}
-
- private void initData() {
- transformAlbumsToMap();
- }
- private void transformAlbumsToMap() {
- albums = new HashMap<Long, TreeAlbumItem>();
- availableAlbums = new ArrayList<SelectItem>();
- for(Album album:user.getChildAlbums()){
- TreeAlbumItem albumNode = new TreeAlbumItem(album.getId(), this, album);
- availableAlbums.add(new SelectItem(album.getName()));
- addAlbumToTree(albumNode);
+ public Map<Long, TreeNode> getChilds() {
+ if (this.childs==null) {
+ initialise();
}
+ return this.childs;
}
-
- public void updateChild(Album album) {
- TreeAlbumItem albumItem = getAlbums().get(album.getId());
- albumItem.setAlbum(album);
- }
-
- public SelectItem getSelectItemByName(String name) {
- for(SelectItem item : availableAlbums){
- if(item.getValue().toString().equals(name)){
- return item;
- }
- }
- return null;
+
+ private void initialise() {
+ childs = new HashMap<Long, TreeNode>();
+ TreeMyAlbumsItem item = new TreeMyAlbumsItem(1L, this);
+ childs.put(item.getId(), item);
+ Contexts.getConversationContext().set("treeMyAlbumsItem", item);
}
-
- public TreeAlbumItem getAlbumByName(String albumName) {
- for(Map.Entry<Long, TreeAlbumItem> entry : getAlbums().entrySet()){
- if(entry.getValue().getAlbum().getName().equals(albumName)){
- return entry.getValue();
- }
- }
- return null;
- }
- public List<SelectItem> getAvailableAlbums() {
- return availableAlbums;
+ public void setChilds(Map<Long, TreeNode> childs) {
+ this.childs = childs;
}
}
Deleted: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeSelectionManager.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeSelectionManager.java 2009-01-23 13:27:29 UTC (rev 12387)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeSelectionManager.java 2009-01-23 13:28:09 UTC (rev 12388)
@@ -1,348 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.richfaces.realworld.tree;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.model.SelectItem;
-
-import org.ajax4jsf.context.AjaxContext;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Observer;
-import org.jboss.seam.annotations.Out;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Synchronized;
-import org.jboss.seam.core.Events;
-import org.richfaces.component.UIDatascroller;
-import org.richfaces.component.UIDragSupport;
-import org.richfaces.component.UITree;
-import org.richfaces.component.UITreeNode;
-import org.richfaces.component.html.HtmlTree;
-import org.richfaces.event.DataScrollerEvent;
-import org.richfaces.event.DropEvent;
-import org.richfaces.event.NodeSelectedEvent;
-import org.richfaces.model.TreeNode;
-import org.richfaces.model.TreeRowKey;
-import org.richfaces.realworld.domain.Album;
-import org.richfaces.realworld.domain.Image;
-import org.richfaces.realworld.error.ErrorHandler;
-import org.richfaces.realworld.fileupload.FileManager;
-import org.richfaces.realworld.manager.ImageManager;
-import org.richfaces.realworld.navigation.NavigationEnum;
-import org.richfaces.realworld.util.SelectionHelper;
-
-@Name("treeSelectionManager")
-(a)Scope(ScopeType.CONVERSATION)
-@Synchronized(timeout=200000)
-public class TreeSelectionManager implements Serializable{
-
- private static final String DATASCROLLER_ID = "mainform:imageScroller";
-
- private static final String IMAGE_DATATABLE_ID = "mainform:mainImage";
-
- private static final String FIRST = "first";
-
- private static final String NEXT = "next";
-
- private static final String LAST = "last";
-
- private static final String UPDATE_MAIN_AREA_EVENT = "updateMainArea";
-
- private static final String PREVIOUS = "previous";
-
- private static final long serialVersionUID = -6072049677194472463L;
-
- private NavigationEnum mainArea;
-
- @In(required=false) @Out(required=false)
- private SelectionHelper selectionHelper;
-
- @In(create=true)
- FileManager fileManager;
-
- @In(required=false)
- ImageManager imageManager;
-
- private String nodeTitle;
-
- public void showFileUpload(TreeAlbumItem item){
- selectionHelper.setSelectedAlbum(item.getAlbum());
- if(item.isLeaf()){
- selectionHelper.setSelectedImage(null);
- }else{
- selectionHelper.setSelectedImage(((TreeImageItem)(item.getImages().get(0))).getImage());
- }
- this.setMainArea(NavigationEnum.FILE_UPLOAD);
- }
-
- @Observer("updateMainArea")
- public void updateMainArea(NavigationEnum mainArea) {
- this.setMainArea(mainArea);
- }
-
- public void scrollerListener(DataScrollerEvent event) {
- List<Image> images = selectionHelper.getSelectedAlbum().getImages();
- if (event.getNewScrolVal().equals(PREVIOUS)) {
- for(int index = 0 ; index < images.size(); index++){
- if(images.get(index) == selectionHelper.getSelectedImage()){
- selectionHelper.setSelectedImage(images.get(index - 1));
- selectionHelper.setSelectedImageIndex(index);
- }
- }
- } else if (event.getNewScrolVal().equals(LAST)) {
- selectionHelper.setSelectedImage(images.get(images.size() - 1));
- selectionHelper.setSelectedImageIndex(images.size());
- } else if (event.getNewScrolVal().equals(NEXT)) {
- for(int index = 0 ; index < images.size(); index++){
- if(images.get(index) == selectionHelper.getSelectedImage()){
- selectionHelper.setSelectedImage(images.get(index + 1));
- selectionHelper.setSelectedImageIndex(index + 2);
- return;
- }
- }
- } else if (event.getNewScrolVal().equals(FIRST)) {
- selectionHelper.setSelectedImage(images.get(0));
- selectionHelper.setSelectedImageIndex(1);
- }
-
- }
-
- public void dropListener(DropEvent dropEvent) {
-
- // resolve drag destination attributes
- UITreeNode destNode = (dropEvent.getSource() instanceof UITreeNode) ? (UITreeNode) dropEvent.getSource() : null;
- UITree destTree = destNode != null ? destNode.getUITree() : null;
- TreeRowKey dropNodeKey = (dropEvent.getDropValue() instanceof TreeRowKey) ? (TreeRowKey) dropEvent.getDropValue() : null;
- TreeNode droppedInNode = dropNodeKey != null ? destTree.getTreeNode(dropNodeKey) : null;
-
- // resolve drag source attributes
- UITreeNode srcNode = (dropEvent.getDraggableSource() instanceof UITreeNode) ? (UITreeNode) dropEvent.getDraggableSource() : null;
- UITree srcTree = srcNode != null ? srcNode.getUITree() : null;
- TreeRowKey dragNodeKey = (dropEvent.getDragValue() instanceof TreeRowKey) ? (TreeRowKey) dropEvent.getDragValue() : null;
- TreeNode draggedNode = dragNodeKey != null ? srcTree.getTreeNode(dragNodeKey) : null;
- if (dropEvent.getDraggableSource() instanceof UIDragSupport && srcTree == null && draggedNode == null && dropEvent.getDragValue() instanceof TreeNode) {
- srcTree = destTree;
- draggedNode = (TreeNode) dropEvent.getDragValue();
- dragNodeKey = srcTree.getTreeNodeRowKey(draggedNode) instanceof TreeRowKey ? (TreeRowKey) srcTree.getTreeNodeRowKey(draggedNode) : null;
- }
-
- // Note: check if we dropped node on to itself or to item instead of
- // folder here
- if (droppedInNode != null && (droppedInNode.equals(draggedNode) || droppedInNode.getParent().getParent() != null || draggedNode.getParent().getParent() == null)) {
- //Warning: Can't drop on itself or to pic itself! Also can't move folders
- return;
- }
-
- if (dropNodeKey != null) {
- // add destination node for rerender
- destTree.addRequestKey(dropNodeKey);
-
- Object state = null;
- if (dragNodeKey != null) { // Drag from this or other tree
- TreeNode parentNode = draggedNode.getParent();
- // 1. remove node from tree
- state = srcTree.removeNode(dragNodeKey);
- // 2. add parent for rerender
- Object rowKey = srcTree.getTreeNodeRowKey(parentNode);
- srcTree.addRequestKey(rowKey);
- //TODO refactor this code
- if (dropEvent.getDraggableSource() instanceof UIDragSupport) {
- // if node was gragged in it's parent place dragged node to
- // the end of selected nodes in grid
- if (droppedInNode.equals(parentNode)) {
- }
- }
- } else if (dropEvent.getDragValue() != null) { // Drag from some
- // drag source
- draggedNode.setData(dropEvent.getDragValue().toString());
- }
-
- // generate new node id
- Object id = getNewId(destTree.getTreeNode(dropNodeKey));
- destTree.addNode(dropNodeKey, draggedNode, id, state);
- }
-
- AjaxContext ac = AjaxContext.getCurrentInstance();
- ac.addRenderedArea(IMAGE_DATATABLE_ID);
- Image draggedImage = ((TreeImageItem)draggedNode).getImage();
- draggedImage.setAlbumName(((TreeAlbumItem)droppedInNode).getAlbum().getName());
- imageManager.editImage(draggedImage);
- // Add destination tree to reRender
- try {
- ac.addComponentToAjaxRender(destTree);
- } catch (Exception e) {
- //System.err.print(e.getMessage());
- }
-
- }
-
- private Object getNewId(TreeNode parentNode) {
- Map<Object, TreeNode> childs = new HashMap<Object, TreeNode>();
- Iterator<Map.Entry<Object, TreeNode>> iter = parentNode.getChildren();
- while (iter != null && iter.hasNext()) {
- Map.Entry<Object, TreeNode> entry = iter.next();
- childs.put(entry.getKey(), entry.getValue());
- }
-
- Integer index = 1;
- while (childs.containsKey(index)) {
- index++;
- }
- return index;
- }
-
- public Boolean adviseNodeSelected(UITree tree) {
- TreeRowKey treeRowKey = (TreeRowKey) tree.getRowKey();
- TreeNode treeNode = (TreeNode) tree.getRowData(treeRowKey);
- if (treeNode instanceof TreeAlbumItem) {
- TreeAlbumItem currentNode = (TreeAlbumItem) treeNode;
- return currentNode.getAlbum() == selectionHelper.getSelectedAlbum();
- } else if (treeNode instanceof TreeImageItem) {
- return ((TreeImageItem) treeNode).getImage() == selectionHelper.getSelectedImage();
- }
- return null;
- }
-
- public Boolean adviseNodeOpened(UITree tree) {
- TreeRowKey treeRowKey = (TreeRowKey) tree.getRowKey();
- TreeNode treeNode = (TreeNode) tree.getRowData(treeRowKey);
- if (treeNode instanceof TreeAlbumItem) {
- TreeAlbumItem currentNode = (TreeAlbumItem) treeNode;
- return currentNode.getAlbum() == selectionHelper.getSelectedAlbum();
- }
- return null;
- }
-
- public void processSelection(NodeSelectedEvent event) {
- try{
- HtmlTree tree = (HtmlTree) event.getComponent();
- if (tree.getRowData() instanceof TreeImageItem) {
- nodeTitle = ((TreeImageItem) (tree.getRowData())).getImage()
- .getName();
- } else if (tree.getRowData() instanceof TreeAlbumItem) {
- nodeTitle = ((TreeAlbumItem) (tree.getRowData())).getAlbum()
- .getName();
- }
- Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
- TreeNode<String> currentNode = tree.getModelTreeNode(tree.getRowKey());
- selectionHelper.setUserAlbumSelected(true);
- if(currentNode instanceof TreeImageItem){
- Image image = ((TreeImageItem)currentNode).getImage();
- selectionHelper.setSelectedImage(image);
- Album album = ((TreeAlbumItem)currentNode.getParent()).getAlbum();
- if(album != selectionHelper.getSelectedAlbum()){
- selectionHelper.setSelectedAlbum(album);
- }
- int index = album.getIndex(image);
- setDataScrollerIndex(index);
- return;
- }else if(currentNode instanceof TreeAlbumItem){
- TreeAlbumItem node = (TreeAlbumItem)currentNode;
- selectionHelper.setSelectedImage(null);
- setDataScrollerIndex(0);
- if (node.isLeaf()) {
- //selectionHelper.setSelectedImage(null);
- Album album = node.getAlbum();
- selectionHelper.setSelectedAlbum(album);
- }else{
- if(node.getAlbum() == selectionHelper.getSelectedAlbum()){
- return;
- }else{
- selectionHelper.setSelectedAlbum(node.getAlbum());
- //selectionHelper.setSelectedImage(node.getAlbum().getImages().get(0));
- }
- }
- }
- }
- catch(Exception e){
- //Bla-bla-bla
- }
- }
-
- //public void updateScroller(ActionEvent event){
- //this.setDataScrollerIndex(selectionHelper.getSelectedImageIndex()- 1);
- //}
-
- private void setDataScrollerIndex(int index) {
- UIComponent component = FacesContext.getCurrentInstance().getViewRoot();
- UIDatascroller scroller = (UIDatascroller)component.findComponent(DATASCROLLER_ID);
- Map<String, Object> attributes = scroller.getDataTable().getAttributes();
- attributes.put(UIDatascroller.SCROLLER_STATE_ATTRIBUTE, index+1);
- selectionHelper.setSelectedImageIndex(index+1);
- }
-
-
- public void incrementSlideshowIndex() {
- if(null == selectionHelper.getSelectedAlbum()){
- //Events.instance().raiseEvent("addErrorEvent", new RealworldException("You have no albums and images"));
- return;
- }
- int index = selectionHelper.getSelectedAlbum().getIndex(selectionHelper.getSelectedImage());
- if(selectionHelper.getSelectedAlbum().getImages().size() == index +1){
- index = -1;
- }
- selectionHelper.setSelectedImage(selectionHelper.getSelectedAlbum().getImages().get(index +1));
- UIComponent component = FacesContext.getCurrentInstance().getViewRoot();
- UIDatascroller scroller = (UIDatascroller)component.findComponent(DATASCROLLER_ID);
- Map<String, Object> attributes = scroller.getDataTable().getAttributes();
- attributes.put(UIDatascroller.SCROLLER_STATE_ATTRIBUTE, index+2);
- selectionHelper.setSelectedImageIndex(index+2);
- }
-
- public String getNodeTitle() {
- return nodeTitle;
- }
-
- public void setNodeTitle(String nodeTitle) {
- this.nodeTitle = nodeTitle;
- }
-
- public NavigationEnum getMainArea() {
- return mainArea;
- }
-
- public void setMainArea(NavigationEnum mainArea) {
- this.mainArea = mainArea;
- }
-
- public SelectItem[] getAvailableIndexOfImages(){
- SelectItem[] group = new SelectItem[selectionHelper.getSelectedAlbum().getImages().size()];
- for(int i = 0; i < selectionHelper.getSelectedAlbum().getImages().size(); i++){
- group[i] = new SelectItem(i+1);
- }
- return group;
- }
-
- @ErrorHandler
- public void updateSelectedItems(Image image){
- selectionHelper.setSelectedImage(image);
- Integer index = selectionHelper.getSelectedAlbum().getIndex(selectionHelper.getSelectedImage());
- setDataScrollerIndex(index);
- }
-}
15 years, 12 months
JBoss Rich Faces SVN: r12387 - in trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld: fileupload and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: amarkhel
Date: 2009-01-23 08:27:29 -0500 (Fri, 23 Jan 2009)
New Revision: 12387
Removed:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandler.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandlerInterceptor.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/RealworldException.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/AvatarUpload.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileLoader.java
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandlerBean.java
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/FileUploadBean.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileWrapper.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/ImageLoader.java
Log:
Deleted: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandler.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandler.java 2009-01-23 13:23:32 UTC (rev 12386)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandler.java 2009-01-23 13:27:29 UTC (rev 12387)
@@ -1,13 +0,0 @@
-package org.richfaces.realworld.error;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import org.jboss.seam.annotations.intercept.Interceptors;
-
-(a)Target({ElementType.TYPE ,ElementType.METHOD })
-(a)Retention(RetentionPolicy.RUNTIME)
-(a)Interceptors(ErrorHandlerInterceptor.class)
-public @interface ErrorHandler {}
Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandlerBean.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandlerBean.java 2009-01-23 13:23:32 UTC (rev 12386)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandlerBean.java 2009-01-23 13:27:29 UTC (rev 12387)
@@ -1,3 +1,23 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
package org.richfaces.realworld.error;
import java.util.ArrayList;
@@ -11,13 +31,15 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Observer;
import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Startup;
@Name("errorHandlerBean")
@Scope(ScopeType.EVENT)
@AutoCreate
public class ErrorHandlerBean {
+ private static final String ERROR_ID = "mainform:error";
+ private static final String CLEAR_ERROR_EVENT = "clearErrorEvent";
+ private static final String ADD_ERROR_EVENT = "addErrorEvent";
private List<Exception> errors = new ArrayList<Exception>();
public List<Exception> getErrors() {
@@ -32,16 +54,16 @@
return errors.size() > 0 ;
}
- @Observer("clearErrorEvent")
+ @Observer(CLEAR_ERROR_EVENT)
public void clearEvents(){
errors.clear();
}
- @Observer("addErrorEvent")
+ @Observer(ADD_ERROR_EVENT)
public void addToErrors(Exception e){
FacesContext context = FacesContext.getCurrentInstance();
AjaxContext ac = AjaxContext.getCurrentInstance(context);
- ac.addRenderedArea("mainform:error");
+ ac.addRenderedArea(ERROR_ID);
errors.add(e);
}
}
Deleted: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandlerInterceptor.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandlerInterceptor.java 2009-01-23 13:23:32 UTC (rev 12386)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandlerInterceptor.java 2009-01-23 13:27:29 UTC (rev 12387)
@@ -1,18 +0,0 @@
-package org.richfaces.realworld.error;
-
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.intercept.AroundInvoke;
-import org.jboss.seam.annotations.intercept.Interceptor;
-import org.jboss.seam.core.BijectionInterceptor;
-import org.jboss.seam.core.Events;
-import org.jboss.seam.intercept.InvocationContext;
-
-@Name("interceptor")
-public class ErrorHandlerInterceptor {
-
- @AroundInvoke
- public Object process(InvocationContext invocation) throws Exception {
- Events.instance().raiseEvent("clearErrorEvent");
- return invocation.proceed();
- }
-}
Deleted: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/RealworldException.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/RealworldException.java 2009-01-23 13:23:32 UTC (rev 12386)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/RealworldException.java 2009-01-23 13:27:29 UTC (rev 12387)
@@ -1,21 +0,0 @@
-package org.richfaces.realworld.error;
-
-import javax.ejb.ApplicationException;
-
-@ApplicationException
-public class RealworldException extends Exception{
-
- private static final long serialVersionUID = -5514996140663854304L;
-
- public RealworldException(String message) {
- super(message);
- }
-
- public RealworldException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public RealworldException(Throwable cause) {
- super(cause);
- }
-}
Deleted: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/AvatarUpload.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/AvatarUpload.java 2009-01-23 13:23:32 UTC (rev 12386)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/AvatarUpload.java 2009-01-23 13:27:29 UTC (rev 12387)
@@ -1,64 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.richfaces.realworld.fileupload;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.Serializable;
-
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.richfaces.event.UploadEvent;
-import org.richfaces.model.UploadItem;
-import org.richfaces.realworld.domain.Image;
-
-@Name("avatarUpload")
-(a)Scope(ScopeType.CONVERSATION)
-public class AvatarUpload implements Serializable{
-
- private static final long serialVersionUID = -3653686566159143678L;
-
- private FileItem avatarItem;
-
- public void avatarListener(UploadEvent event){
- UploadItem item = event.getUploadItem();
- FileItem file = new FileItem();
- file.setLength(item.getData().length);
- Image image = new Image();
- image.setName(item.getFileName());
- file.setImage(image);
- file.setData(item.getData());
- this.setAvatarItem(file);
- }
-
- public synchronized void paintAvatar(OutputStream stream, Object object) throws IOException {
- stream.write(this.getAvatarItem().getData());
- }
-
- public FileItem getAvatarItem() {
- return avatarItem;
- }
-
- public void setAvatarItem(FileItem avatarItem) {
- this.avatarItem = avatarItem;
- }
-}
Deleted: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileLoader.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileLoader.java 2009-01-23 13:23:32 UTC (rev 12386)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileLoader.java 2009-01-23 13:27:29 UTC (rev 12387)
@@ -1,40 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.richfaces.realworld.fileupload;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-
-@Name("fileLoader")
-(a)Scope(ScopeType.CONVERSATION)
-public class FileLoader {
-
- @In
- FileWrapper fileWrapper;
- public synchronized void paint(OutputStream stream, Object object) throws IOException {
- stream.write(fileWrapper.getFiles().get((Integer)object).getData());
- }
-}
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-23 13:23:32 UTC (rev 12386)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileManager.java 2009-01-23 13:27:29 UTC (rev 12387)
@@ -54,6 +54,10 @@
this.uploadRoot = uploadRoot;
}
+ public String getAvatarFriendsPath(String path, String avatarPath){
+ return getUploadRoot() + path + getFileSeparator() + "avatars" + getFileSeparator() + avatarPath;
+ }
+
public FileManager(){
FacesContext fc = FacesContext.getCurrentInstance();
this.setUploadRoot(fc.getExternalContext().getInitParameter(UPLOAD_ROOT));
@@ -106,35 +110,6 @@
writeFileTodisk(data, fileName, 0, 0, "" );
writeFileTodisk(data, fileName, 50, 50, "_mini" );
writeFileTodisk(data, fileName, 600, 400, "_medium" );
- //FileOutputStream b = new FileOutputStream(getUploadRoot() + fileName);
- //b.write(data);
- //b.close();
- /*InputStream inputStream = new ByteArrayInputStream(data);
- BufferedImage bsrc = ImageIO.read(inputStream);
- inputStream = new ByteArrayInputStream(data);
- bsrc = ImageIO.read(inputStream);
- ImageIO.write(bsrc, "JPG", new File(getUploadRoot() + fileName));
- int width = 50;
- int height = 50;
- BufferedImage bdest = new BufferedImage(width, height,
- BufferedImage.TYPE_INT_RGB);
- Graphics2D g = bdest.createGraphics();
- AffineTransform at = AffineTransform.getScaleInstance((double) width
- / bsrc.getWidth(), (double) height / bsrc.getHeight());
- g.drawRenderedImage(bsrc, at);
- String dest = getUploadRoot() + transformPath(fileName, "_mini");
- ImageIO.write(bdest, "JPG", new File(dest));
- width = 600;
- height = 400;
- bdest = new BufferedImage(width, height,
- BufferedImage.TYPE_INT_RGB);
- g = bdest.createGraphics();
- at = AffineTransform.getScaleInstance((double) width
- / bsrc.getWidth(), (double) height / bsrc.getHeight());
- g.drawRenderedImage(bsrc, at);
- dest = getUploadRoot() + transformPath(fileName, "_medium");
- ImageIO.write(bdest, "JPG", new File(dest));
- inputStream.close();*/
}
private void writeFileTodisk(byte[] data, String fileName, int width, int height, String format) throws IOException{
Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileUploadBean.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileUploadBean.java 2009-01-23 13:23:32 UTC (rev 12386)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileUploadBean.java 2009-01-23 13:27:29 UTC (rev 12387)
@@ -29,17 +29,22 @@
import java.util.Date;
import java.util.List;
+import javax.faces.model.SelectItem;
+
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Observer;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.core.Events;
import org.richfaces.event.UploadEvent;
import org.richfaces.model.UploadItem;
import org.richfaces.realworld.domain.Image;
+import org.richfaces.realworld.domain.MetaTag;
+import org.richfaces.realworld.domain.Rank;
import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.util.SelectionHelper;
+import org.richfaces.realworld.ui.ConversationState;
import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.imaging.jpeg.JpegProcessingException;
@@ -51,133 +56,222 @@
/**
* @author $Autor$
- *
+ *
*/
@Name("fileUploadBean")
@Scope(ScopeType.CONVERSATION)
+public class FileUploadBean implements Serializable {
-public class FileUploadBean implements Serializable{
-
- @In("#{messages['samplename']}") private String SAMPLE_NAME;
+ private static final int MULTY_MODE_FILE_QUANTITY = 100;
- @In("#{messages['sampledesc']}") private String SAMPLE_DESCRIPTION;
+ private static final int SINGLE_MODE_FILE_QUANTITY = 1;
+ private static final String MULTY = "multy";
+
+ private static final String SINGLE = "single";
+
+ private static final String SLASH = "/";
+
+ @In("#{messages['samplename']}")
+ private String SAMPLE_NAME;
+
+ @In("#{messages['sampledesc']}")
+ private String SAMPLE_DESCRIPTION;
+
private static final String ADD_IMAGE_EVENT = "addImage";
private static final long serialVersionUID = 4969087557225414955L;
@In
private User user;
-
- @In(create=true) @Out
+
+ private int fileQuantity = 1;
+
+ private boolean fileUploadRendered;
+
+ @In(create = true)
+ @Out
FileWrapper fileWrapper;
-
- @In(create=true)
+
+ @In(create = true)
private FileManager fileManager;
-
- @In @Out
- private SelectionHelper selectionHelper;
- public synchronized void listener(UploadEvent event) throws Exception{
- UploadItem item = event.getUploadItem();
- FileItem file = new FileItem();
- file.setLength(item.getData().length);
- file.setData(item.getData());
- file.setSelected(false);
- Image image = new Image();
- image.setUploaded(new Date());
- image.setDescription(SAMPLE_DESCRIPTION);
- image.setName(SAMPLE_NAME);
- image.setSize(file.getLength() / 1024);
- image.setPath(user.getLogin() + "/" + selectionHelper.getSelectedAlbum().getName() + "/" + item.getFileName());
- image.setAlbumName(selectionHelper.getSelectedAlbum().getName());
- image.setAlbum(selectionHelper.getSelectedAlbum());
- try {
+ private String selectedMode;
+
+ @In
+ @Out
+ private ConversationState conversationState;
+
+ public synchronized void listener(UploadEvent event) throws Exception {
+ UploadItem item = event.getUploadItem();
+ FileItem file = new FileItem();
+ file.setLength(item.getData().length);
+ file.setData(item.getData());
+ file.setSelected(false);
+ Image image = new Image();
+ image.setUploaded(new Date());
+ image.setDescription(SAMPLE_DESCRIPTION);
+ image.setName(SAMPLE_NAME);
+ image.setSize(file.getLength() / 1024);
+ String albumPath = conversationState.getSelectedAlbum()
+ .getAlbumPathFromParents(conversationState.getSelectedAlbum(),
+ new ArrayList<String>(), SLASH)
+ + conversationState.getSelectedAlbum().getName() + SLASH;
+ image.setPath(user.getLogin() + SLASH + albumPath + item.getFileName());
+ image.setAlbumName(conversationState.getSelectedAlbum().getName());
+ image.setAlbum(conversationState.getSelectedAlbum());
+ Rank rank = new Rank();
+ rank.setHits(0L);
+ rank.setTotal(0L);
+ image.setRank(rank);
+ List<MetaTag> tags = new ArrayList<MetaTag>();
+ image.setTags(tags);
+ image.setMeta(new ArrayList<MetaTag>(tags));
+
+ try {
InputStream in = new ByteArrayInputStream(file.getData());
Metadata metadata = JpegMetadataReader.readMetadata(in);
- Directory exifDirectory = metadata.getDirectory(ExifDirectory.class);
+ Directory exifDirectory = metadata
+ .getDirectory(ExifDirectory.class);
Directory jpgDirectory = metadata.getDirectory(JpegDirectory.class);
-
- if(exifDirectory.containsTag(ExifDirectory.TAG_MODEL)){
- String cameraModel = exifDirectory.getString(ExifDirectory.TAG_MODEL);
+
+ if (exifDirectory.containsTag(ExifDirectory.TAG_MODEL)) {
+ String cameraModel = exifDirectory
+ .getString(ExifDirectory.TAG_MODEL);
image.setCameraModel(cameraModel);
}
- if(exifDirectory.containsTag(ExifDirectory.TAG_EXIF_IMAGE_WIDTH) && exifDirectory.containsTag(ExifDirectory.TAG_EXIF_IMAGE_HEIGHT)){
- int width = exifDirectory.getInt(ExifDirectory.TAG_EXIF_IMAGE_WIDTH);
+ 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);
+ 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);
+ } 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);
+ int height = jpgDirectory
+ .getInt(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
image.setHeight(height);
}
}
- if(exifDirectory.containsTag(ExifDirectory.TAG_DATETIME_ORIGINAL)){
- Date time = exifDirectory.getDate(ExifDirectory.TAG_DATETIME_ORIGINAL);
+ if (exifDirectory.containsTag(ExifDirectory.TAG_DATETIME_ORIGINAL)) {
+ Date time = exifDirectory
+ .getDate(ExifDirectory.TAG_DATETIME_ORIGINAL);
image.setCreated(time);
}
- }
- catch (JpegProcessingException e1) {
+ } catch (JpegProcessingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
- } catch (MetadataException e) {
+ } catch (MetadataException me) {
// TODO Auto-generated catch block
- e.printStackTrace();
+ me.printStackTrace();
}
file.setImage(image);
- fileWrapper.getFiles().add(file);
+ fileWrapper.getFiles().add(file);
}
-
+
+ @Observer("fileUploadClear")
public void clearUploadData() {
fileWrapper.getFiles().clear();
}
-
+
public void clearSelectedData() {
- for(int i = 0; i < fileWrapper.getFiles().size(); i++){
- if(fileWrapper.getFiles().get(i).isSelected()){
+ for (int i = 0; i < fileWrapper.getFiles().size(); i++) {
+ if (fileWrapper.getFiles().get(i).isSelected()) {
fileWrapper.getFiles().remove(i);
}
}
}
-
+
public void storeSelectedData() {
List<FileItem> temp = new ArrayList<FileItem>();
- for(FileItem file:fileWrapper.getFiles()){
- if(file.isSelected()){
- //Save file to disk
- String fileName = fileManager.transformToServerPath(file.getImage().getPath());
+ for (FileItem file : fileWrapper.getFiles()) {
+ if (file.isSelected()) {
+ // Save file to disk
+ String fileName = fileManager.transformToServerPath(file
+ .getImage().getPath());
try {
- fileManager.addImage(fileName , file.getData());
+ fileManager.addImage(fileName, file.getData());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Events.instance().raiseEvent(ADD_IMAGE_EVENT, file.getImage());
- }else{
+ } else {
temp.add(file);
}
}
fileWrapper.getFiles().clear();
fileWrapper.getFiles().addAll(temp);
}
-
+
public void storeAll() {
- for(FileItem file:fileWrapper.getFiles()){
- //Save file to disk
- String fileName = fileManager.transformToServerPath(file.getImage().getPath());
+ for (FileItem file : fileWrapper.getFiles()) {
+ // Save file to disk
+ String fileName = fileManager.transformToServerPath(file.getImage()
+ .getPath());
try {
- fileManager.addImage(fileName , file.getData());
+ fileManager.addImage(fileName, file.getData());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
- //Update domain model
+ // Update domain model
Events.instance().raiseEvent(ADD_IMAGE_EVENT, file.getImage());
}
fileWrapper.getFiles().clear();
}
-
+
+ public boolean isFileUploadRendered() {
+ return fileUploadRendered;
+ }
+
+ public void setFileUploadRendered(boolean fileUploadRendered) {
+ this.fileUploadRendered = fileUploadRendered;
+ }
+
+ @Observer("showFileUpload")
+ public void showFileUpload(boolean result) {
+ this.setFileUploadRendered(result);
+ clearUploadData();
+ }
+
+ public void changeMode() {
+ if (this.getSelectedMode().equals(SINGLE)) {
+ this.setFileQuantity(SINGLE_MODE_FILE_QUANTITY);
+ } else if (this.getSelectedMode().equals(MULTY)) {
+ this.setFileQuantity(MULTY_MODE_FILE_QUANTITY);
+ }
+ }
+
+ public int getFileQuantity() {
+ return fileQuantity;
+ }
+
+ public void setFileQuantity(int fileQuantity) {
+ this.fileQuantity = fileQuantity;
+ }
+
+ public List<SelectItem> getItems() {
+ List<SelectItem> list = new ArrayList<SelectItem>(2);
+ list.add(new SelectItem(SINGLE, SINGLE));
+ list.add(new SelectItem(MULTY, MULTY));
+ return list;
+ }
+
+ public String getSelectedMode() {
+ return selectedMode;
+ }
+
+ @Observer("changeMode")
+ public void setSelectedMode(String selectedMode) {
+ this.selectedMode = selectedMode;
+ }
+
}
\ No newline at end of file
Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileWrapper.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileWrapper.java 2009-01-23 13:23:32 UTC (rev 12386)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileWrapper.java 2009-01-23 13:27:29 UTC (rev 12387)
@@ -32,12 +32,7 @@
private ArrayList<FileItem> files = new ArrayList<FileItem>();
public int getSize() {
- if (getFiles().size()>0){
- return getFiles().size();
- }else
- {
- return 0;
- }
+ return getFiles().size();
}
public ArrayList<FileItem> getFiles() {
Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/ImageLoader.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/ImageLoader.java 2009-01-23 13:23:32 UTC (rev 12386)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/ImageLoader.java 2009-01-23 13:27:29 UTC (rev 12387)
@@ -36,14 +36,11 @@
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
-import org.richfaces.realworld.domain.User;
@Name("imageLoader")
@Scope(ScopeType.CONVERSATION)
public class ImageLoader implements Serializable{
- private static final String DELIMITER = ":";
-
private static final String JPEG = "jpeg";
private static final long serialVersionUID = -1572789608594870285L;
@@ -51,6 +48,16 @@
@In(create=true)
FileManager fileManager;
+ @In(create=true)
+ FileWrapper fileWrapper;
+ public synchronized void paintImageFromByteArray(OutputStream stream, Object object) throws IOException {
+ stream.write(fileWrapper.getFiles().get(((Long)object).intValue()).getData());
+ }
+
+ public synchronized void paintImageFromByteArray2(OutputStream stream, Object object) throws IOException {
+ stream.write(fileWrapper.getFiles().get(((Integer)object)).getData());
+ }
+
public synchronized void paintSearchImage(OutputStream stream, Object object) throws IOException {
File image = fileManager.getImage(fileManager.transformToServerPath(object.toString()));
InputStream paintData = null;
@@ -94,7 +101,7 @@
stream.write(data);
}
- public synchronized void paint(OutputStream out, Object data) throws IOException{
+ public synchronized void paintImage(OutputStream out, Object data) throws IOException{
if (null == data) {
return;
}
@@ -119,86 +126,4 @@
}
}
}
-
- public synchronized void paintGalleryImage(OutputStream out, Object data) throws IOException{
- if (null == data) {
- return;
- }
- String fileName = fileManager.getFileSeparator() + "galleries" + fileManager.getFileSeparator() + fileManager.transformToServerPath(data.toString());
- File imageResource = fileManager.getImage(fileName);
- if (imageResource != null) {
- FileInputStream fileInputStream = new FileInputStream(imageResource);
- BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
- InputStream paintData = bufferedInputStream;
- if (null == paintData) {
- // throw new Exception("");
- // TODO
- }
- try{
- BufferedImage images = ImageIO.read(paintData);
- ImageIO.write(images, JPEG, out);
- }catch(Exception e){
-
- }finally{
- fileInputStream.close();
- bufferedInputStream.close();
- paintData.close();
- }
- }
- }
-
- public synchronized void paintAvatar(OutputStream out, Object data) throws IOException{
- if (null == data) {
- return;
- }
- User user = (User)data;
- File imageResource = fileManager.getImage(user.getLogin() + fileManager.getFileSeparator() + "avatars" + fileManager.getFileSeparator() + user.getAvatarPath());
- if (imageResource != null) {
- FileInputStream fileInputStream = new FileInputStream(imageResource);
- BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
- InputStream paintData = bufferedInputStream;
- if (null == paintData) {
- // throw new Exception("");
- // TODO
- }
- try{
- BufferedImage image = ImageIO.read(paintData);
- ImageIO.write(image, JPEG, out);
- }catch(Exception e){
-
- }finally{
- fileInputStream.close();
- bufferedInputStream.close();
- paintData.close();
- }
- }
- }
-
- public synchronized void paintFriendAvatar(OutputStream out, Object data) throws IOException{
- if (null == data) {
- return;
- }
- String temp = data.toString();
- String[] array = temp.split(DELIMITER);
- File imageResource = fileManager.getImage(array[0] + fileManager.getFileSeparator() + "avatars" + fileManager.getFileSeparator() + array[1]);
- if (imageResource != null) {
- FileInputStream fileInputStream = new FileInputStream(imageResource);
- BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
- InputStream paintData = bufferedInputStream;
- if (null == paintData) {
- // throw new Exception("");
- // TODO
- }
- try{
- BufferedImage image = ImageIO.read(paintData);
- ImageIO.write(image, JPEG, out);
- }catch(Exception e){
-
- }finally{
- fileInputStream.close();
- bufferedInputStream.close();
- paintData.close();
- }
- }
- }
}
15 years, 12 months
JBoss Rich Faces SVN: r12386 - in trunk/test-applications/realworld/ejb/src/main: java/org/richfaces/realworld/service and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: amarkhel
Date: 2009-01-23 08:23:32 -0500 (Fri, 23 Jan 2009)
New Revision: 12386
Added:
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/MessageComparator.java
Removed:
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Gallery.java
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/GalleryImage.java
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/GalleryAction.java
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/IGalleryAction.java
Modified:
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Album.java
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Image.java
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Message.java
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Rank.java
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/User.java
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/AlbumAction.java
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/IAlbumAction.java
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/IMessageAction.java
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/IUserAction.java
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/MessageAction.java
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/SearchService.java
trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/UserAction.java
trunk/test-applications/realworld/ejb/src/main/resources/import.sql
Log:
Modified: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Album.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Album.java 2009-01-23 13:11:28 UTC (rev 12385)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Album.java 2009-01-23 13:23:32 UTC (rev 12386)
@@ -7,11 +7,13 @@
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
@@ -92,6 +94,14 @@
)
private List<User> sharedOwners = new ArrayList<User>();
+ @OneToMany(mappedBy = "parent", cascade = {CascadeType.ALL})
+ @org.hibernate.annotations.OrderBy(clause = "NAME asc")
+ private List<Album> childAlbums = new ArrayList<Album>();
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "PARENT_ALBUM_ID", nullable = true)
+ @org.hibernate.annotations.ForeignKey(name = "FK_ALBUM_PARENT_ID")
+ private Album parent;
/**
* No-arg constructor for JavaBean tools
*/
@@ -100,6 +110,53 @@
// ********************** Accessor Methods ********************** //
+ public List<Album> getChildAlbums() { return childAlbums; }
+
+ public void addChildAlbum(Album album) {
+ if (album == null) throw new IllegalArgumentException("Null child category!");
+ if (album.getParent() != null)
+ album.getParent().getChildAlbums().remove(album);
+ album.setParent(this);
+ childAlbums.add(album);
+ }
+ public void removeChildAlbum(Album album) {
+ if (album == null) throw new IllegalArgumentException("Null child category!");
+ album.setParent(null);
+ childAlbums.remove(album);
+ }
+
+ public Album getParent() { return parent; }
+ public void setParent(Album parent) { this.parent = parent; }
+
+ public String getAlbumPathFromParents(Album album, List<String> list, String delimiter) {
+ if(album.getParent() == null){
+ list.add(album.getName() + delimiter);
+ return "";
+ }else{
+ album.getParent().getAlbumPathFromParents(album.getParent(), list, delimiter);
+ }
+ list.add(this.getName()+delimiter);
+ String path = "";
+ for(int i =0; i < list.size(); i++){
+ path += list.get(i);
+ }
+ return path;
+}
+ public List<Album> getArrayOfParents(){
+ return getArrayOfParents(new ArrayList<Album>());
+ }
+
+ public List<Album> getArrayOfParents(List<Album> albums){
+ if(this.getParent() == null){
+ Collections.reverse(albums);
+ return albums;
+ }else{
+ albums.add(this.getParent());
+ this.getParent().getArrayOfParents(albums);
+ }
+ return albums;
+ }
+
/**
* Getter for property id
*
Deleted: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Gallery.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Gallery.java 2009-01-23 13:11:28 UTC (rev 12385)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Gallery.java 2009-01-23 13:23:32 UTC (rev 12386)
@@ -1,113 +0,0 @@
-package org.richfaces.realworld.domain;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.OneToMany;
-import javax.persistence.Table;
-
-import org.hibernate.validator.Length;
-import org.hibernate.validator.NotEmpty;
-import org.hibernate.validator.NotNull;
-import org.jboss.seam.annotations.Name;
-
-@Entity
-@Name("gallery")
-@Table(name = "galleries")
-public class Gallery implements Serializable {
-
- private static final long serialVersionUID = -7042878411608396483L;
-
- @Id
- @GeneratedValue
- @Column(name = "GALLERY_ID")
- private Long id = null;
-
- @Column(length = 255, nullable = false)
- @NotNull
- @NotEmpty
- @Length(min=3)
- private String name;
-
- @OneToMany(cascade = CascadeType.ALL, mappedBy = "gallery")
- @org.hibernate.annotations.OrderBy(clause = "uploaded desc")
- @org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.SUBSELECT)
- private List<GalleryImage> images = new ArrayList<GalleryImage>();
-
- /**
- * Getter for property id
- *
- * @return id of album
- */
- public Long getId() {
- return id;
- }
-
- /**
- * Getter for property name
- *
- * @return name of album
- */
- public String getName() {
- return name;
- }
-
- /**
- * Setter for property name
- *
- * @param name - name of album
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * This method add image to collection of images of current album
- *
- * @param image - image to add
- */
- public void addImage(GalleryImage image) {
- if (image == null) {
- throw new IllegalArgumentException("Null image!");
- }
- if (image.getGallery() != null && !this.equals(image.getGallery())) {
- image.getGallery().getImages().remove(image);
- }
- image.setGallery(this);
- images.add(image);
- }
-
- /**
- * This method remove image from collection of images of album
- *
- * @param image - image to remove
- */
- public void removeImage(GalleryImage image) {
- if (image == null) {
- throw new IllegalArgumentException("Null image");
- }
- image.setGallery(null);
- images.remove(image);
- }
-
- /**
- * This method return count of images of current album
- *
- * @return count of images of this album
- */
- public int getCountImages() {
- return this.getImages()!= null ? this.getImages().size() : 0;
-
- }
-
- public List<GalleryImage> getImages() {
- return images;
- }
-
-}
Deleted: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/GalleryImage.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/GalleryImage.java 2009-01-23 13:11:28 UTC (rev 12385)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/GalleryImage.java 2009-01-23 13:23:32 UTC (rev 12386)
@@ -1,157 +0,0 @@
-package org.richfaces.realworld.domain;
-
-import java.io.Serializable;
-import java.util.Date;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.Table;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
-
-import org.hibernate.validator.Length;
-import org.hibernate.validator.NotEmpty;
-import org.hibernate.validator.NotNull;
-import org.jboss.seam.annotations.Name;
-
-@Entity
-@Name("galleryImage")
-@Table(name = "galleryImages")
-public class GalleryImage implements Serializable {
-
- private static final long serialVersionUID = -7042878411608396483L;
-
- @Id
- @GeneratedValue
- @Column(name = "GALLERY_IMAGE_ID")
- private Long id = null;
-
- @Column(length = 255)
- private String name;
-
- @Column(length = 1024)
- private String path;
-
- @Column(length = 255)
- private String cameraModel;
-
- @Column(length = 255)
- private String author;
-
- private int height;
-
- private double size;
-
- private int width;
-
- @Column(length = 1024)
- private String description;
-
- @Temporal(TemporalType.TIMESTAMP)
- private Date created;
-
- @Temporal(TemporalType.TIMESTAMP)
- private Date uploaded;
-
- @ManyToOne(fetch = FetchType.LAZY)
- @JoinColumn(name="IMG_GALLERY_ID",
- referencedColumnName="GALLERY_ID")
- private Gallery gallery;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getCameraModel() {
- return cameraModel;
- }
-
- public void setCameraModel(String cameraModel) {
- this.cameraModel = cameraModel;
- }
-
- public String getAuthor() {
- return author;
- }
-
- public void setAuthor(String author) {
- this.author = author;
- }
-
- public int getHeight() {
- return height;
- }
-
- public void setHeight(int height) {
- this.height = height;
- }
-
- public int getWidth() {
- return width;
- }
-
- public void setWidth(int width) {
- this.width = width;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public Date getCreated() {
- return created;
- }
-
- public void setCreated(Date created) {
- this.created = created;
- }
-
- public Gallery getGallery() {
- return gallery;
- }
-
- public void setGallery(Gallery gallery) {
- this.gallery = gallery;
- }
-
- public Long getId() {
- return id;
- }
-
- public String getPath() {
- return path;
- }
-
- public void setPath(String path) {
- this.path = path;
- }
-
- public Date getUploaded() {
- return uploaded;
- }
-
- public void setUploaded(Date uploaded) {
- this.uploaded = uploaded;
- }
-
- public double getSize() {
- return size;
- }
-
- public void setSize(double size) {
- this.size = size;
- }
-}
Modified: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Image.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Image.java 2009-01-23 13:11:28 UTC (rev 12385)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Image.java 2009-01-23 13:23:32 UTC (rev 12386)
@@ -17,6 +17,8 @@
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
@@ -76,7 +78,7 @@
@Temporal(TemporalType.TIMESTAMP)
private Date uploaded;
- @OneToOne
+ @OneToOne(optional=false, cascade = { CascadeType.ALL })
@JoinColumn(name="RANK_ID")
private Rank rank;
@@ -109,6 +111,14 @@
@JoinColumn(name="IMG_ALBUM_ID",
referencedColumnName="ALBUM_ID")
private Album album;
+
+ @ManyToMany
+ @JoinTable(
+ name = "SHARED_IMAGES",
+ joinColumns = @JoinColumn(name = "IMAGE_ID"),
+ inverseJoinColumns = @JoinColumn(name = "USER_ID")
+ )
+ private List<User> sharedOwners = new ArrayList<User>();
/**
* No-arg constructor for JavaBean tools
@@ -155,6 +165,14 @@
this.name = name;
}
+ public List<User> getSharedOwners() {
+ return sharedOwners;
+ }
+
+ public void setSharedOwners(List<User> sharedOwners) {
+ this.sharedOwners = sharedOwners;
+ }
+
/**
* Getter for property description
*
@@ -204,6 +222,15 @@
return albumName;
}
+ public String getMetatagString(Image image){
+ StringBuilder s = new StringBuilder();
+ for(MetaTag t: image.getTags()){
+ s.append(t.getTag());
+ s.append(", ");
+ }
+ return s.toString();
+ }
+
public void setAlbumName(String albumName) {
this.albumName = albumName;
}
@@ -273,7 +300,7 @@
}
public List<MetaTag> getMeta() {
- return meta;
+ return meta;
}
public void setMeta(List<MetaTag> meta) {
@@ -319,4 +346,22 @@
public void setUploaded(Date uploaded) {
this.uploaded = uploaded;
}
+
+ public boolean containTag(String a) {
+ for(MetaTag t :this.getTags()){
+ if(t.getTag().equals(a)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean validateTags() {
+ for(MetaTag t : this.getTags()){
+ if(t.getTag().length()<3){
+ return false;
+ }
+ }
+ return true;
+ }
}
Modified: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Message.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Message.java 2009-01-23 13:11:28 UTC (rev 12385)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Message.java 2009-01-23 13:23:32 UTC (rev 12386)
@@ -18,7 +18,9 @@
import org.hibernate.validator.Length;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.NotNull;
+import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Role;
@Entity
@Name("message")
@Table(name = "messages")
@@ -124,6 +126,11 @@
}
public String getOwnerLogin() {
+ if(ownerLogin == null){
+ if(getOwner()!=null){
+ ownerLogin = getOwner().getLogin();
+ }
+ }
return ownerLogin;
}
Modified: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Rank.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Rank.java 2009-01-23 13:11:28 UTC (rev 12385)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Rank.java 2009-01-23 13:23:32 UTC (rev 12386)
@@ -61,10 +61,13 @@
public double getRating() {
double total2 = (double)total;
- double result = total2/hits;
- BigDecimal x = new BigDecimal(result);
- x = x.setScale(2, BigDecimal.ROUND_HALF_UP);
- return x.doubleValue();
+ if(total2 >0 && hits>0){
+ double result = total2/hits;
+ BigDecimal x = new BigDecimal(result);
+ x = x.setScale(2, BigDecimal.ROUND_HALF_UP);
+ return x.doubleValue();
+ }
+ return 0;
}
}
Modified: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/User.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/User.java 2009-01-23 13:11:28 UTC (rev 12385)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/User.java 2009-01-23 13:23:32 UTC (rev 12386)
@@ -28,6 +28,7 @@
import org.hibernate.validator.Pattern;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Role;
import org.jboss.seam.annotations.Scope;
@NamedQueries({
@@ -50,12 +51,21 @@
@NamedQuery(
name = "user-friendExist",
query = "SELECT count(u) FROM User u JOIN u.friendshipRequests fr WHERE u.login=:login and fr.friend.login=:friend"
- )
+ ),
+ @NamedQuery(
+ name = "user-rootAlbums",
+ query = "from Album a WHERE a.owner.login=:login and a.parent is null"
+ ),
+ @NamedQuery(
+ name = "user-outcomeMessages",
+ query = "from Message m WHERE m.author.login=:login"
+ )
})
@Entity
@Scope(ScopeType.CONVERSATION)
@Name("user")
+@Role(name="selectedUser", scope=ScopeType.CONVERSATION)
@Table(name = "Users")
public class User implements Serializable {
@@ -84,9 +94,6 @@
@Pattern(regex=".+@.+\\.[a-z]+", message="Not valid e-mail")
private String email;
- @Column(length = 255)
- private String avatarPath;
-
@Column(length = 255, nullable = false)
@NotNull
@NotEmpty
@@ -103,8 +110,11 @@
private String confirmPassword;
@ManyToMany(mappedBy = "sharedOwners")
- private List<Album> sharedAlbums = new ArrayList<Album>();
+ private List<Album> favoriteAlbums = new ArrayList<Album>();
+ @ManyToMany(mappedBy = "sharedOwners")
+ private List<Image> favoriteImages = new ArrayList<Image>();
+
@ManyToMany
@JoinTable(
name = "USER_FRIENDS",
@@ -159,14 +169,6 @@
this.email = email;
}
- public String getAvatarPath() {
- return avatarPath;
- }
-
- public void setAvatarPath(String avatarPath) {
- this.avatarPath = avatarPath;
- }
-
public String getLogin() {
return login;
}
@@ -276,12 +278,12 @@
this.friends = friends;
}
- public List<Album> getSharedAlbums() {
- return sharedAlbums;
+ public List<Album> getFavoriteAlbums() {
+ return favoriteAlbums;
}
- public void setSharedAlbums(List<Album> sharedAlbums) {
- this.sharedAlbums = sharedAlbums;
+ public void setFavoriteAlbums(List<Album> favoriteAlbums) {
+ this.favoriteAlbums = favoriteAlbums;
}
public List<Message> getMessages() {
@@ -301,6 +303,9 @@
}
public void addFriendshipRequest(User owner) {
+ if (getFriendshipRequest(owner, this) != null) {
+ return;
+ }
FriendshipRequest request = new FriendshipRequest();
request.setUser(this);
request.setFriend(owner);
@@ -333,17 +338,39 @@
return null;
}
- public void removeFromSharedAlbums(Album album) {
- sharedAlbums.remove(album);
+ public void removeFromFavoriteAlbums(Album album) {
+ favoriteAlbums.remove(album);
}
- public void addSharedAlbum(Album album) {
+ public void addFavoriteAlbum(Album album) {
if (album == null) {
throw new IllegalArgumentException("Null album!");
}
- if(sharedAlbums.contains(album)){
+ if(favoriteAlbums.contains(album)){
return;
}
- sharedAlbums.add(album);
+ favoriteAlbums.add(album);
}
+
+ public void removeFromFavoriteImages(Image image) {
+ favoriteImages.remove(image);
+ }
+
+ public void addFavoriteImage(Image image) {
+ if (image == null) {
+ throw new IllegalArgumentException("Null image!");
+ }
+ if(favoriteAlbums.contains(image)){
+ return;
+ }
+ favoriteImages.add(image);
+ }
+
+ public List<Image> getFavoriteImages() {
+ return favoriteImages;
+ }
+
+ public void setFavoriteImages(List<Image> favoriteImages) {
+ this.favoriteImages = favoriteImages;
+ }
}
\ No newline at end of file
Modified: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/AlbumAction.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/AlbumAction.java 2009-01-23 13:11:28 UTC (rev 12385)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/AlbumAction.java 2009-01-23 13:23:32 UTC (rev 12386)
@@ -7,6 +7,7 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.richfaces.realworld.domain.Album;
+import org.richfaces.realworld.domain.Image;
import org.richfaces.realworld.domain.User;
@Name("albumAction")
@@ -16,6 +17,8 @@
@In(value="entityManager")
EntityManager em;
+ private static final String SLASH = "/";
+
@In @Out
private User user;
@@ -29,11 +32,34 @@
}
public void deleteAlbum(Album album){
- user.removeAlbum(album);
+ if(album.getParent()!=null){
+ album.getParent().removeChildAlbum(album);
+ }else{
+ user.removeAlbum(album);
+ }
em.flush();
}
public void editAlbum(Album album){
em.flush();
}
+
+ public void flush(){
+ em.flush();
+ }
+
+ public void renameAllImagesFromAlbumAndChilds(Album album, String replace,
+ String forReplace) {
+ for (Image image : album.getImages()) {
+ image.setPath(image.getPath().replaceAll(replace, forReplace));
+ }
+
+ for (Album a : album.getChildAlbums()) {
+ String replace2 = replace + SLASH + a.getName();
+ String forReplace2 = forReplace + SLASH + a.getName();
+ renameAllImagesFromAlbumAndChilds(a, replace2, forReplace2);
+ }
+ em.flush();
+ }
+
}
Deleted: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/GalleryAction.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/GalleryAction.java 2009-01-23 13:11:28 UTC (rev 12385)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/GalleryAction.java 2009-01-23 13:23:32 UTC (rev 12386)
@@ -1,45 +0,0 @@
-package org.richfaces.realworld.service;
-
-import java.util.List;
-
-import javax.ejb.Stateless;
-import javax.persistence.EntityManager;
-
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.Name;
-import org.richfaces.realworld.domain.Gallery;
-import org.richfaces.realworld.domain.GalleryImage;
-
-@Name("galleryAction")
-@Stateless
-public class GalleryAction implements IGalleryAction {
-
- @In(value="entityManager")
- EntityManager em;
- /* (non-Javadoc)
- * @see org.richfaces.realworld.service.IGalleryAction#addGallery(java.lang.String)
- */
- public void addGallery(String name){
- Gallery gal = new Gallery();
- gal.setName(name);
- em.persist(gal);
- em.flush();
- }
-
- /* (non-Javadoc)
- * @see org.richfaces.realworld.service.IGalleryAction#addmage(org.richfaces.realworld.domain.Gallery, org.richfaces.realworld.domain.GalleryImage)
- */
- public void addImage(Gallery gallery, GalleryImage image){
- gallery.addImage(image);
- em.flush();
- }
-
- /* (non-Javadoc)
- * @see org.richfaces.realworld.service.IGalleryAction#getGalleries()
- */
- public List<Gallery> getGalleries(){
- List<Gallery> galleries = em.createQuery("from Gallery")
- .getResultList();
- return galleries;
- }
-}
Modified: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/IAlbumAction.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/IAlbumAction.java 2009-01-23 13:11:28 UTC (rev 12385)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/IAlbumAction.java 2009-01-23 13:23:32 UTC (rev 12386)
@@ -13,4 +13,9 @@
public void editAlbum(Album album);
+ public abstract void flush();
+
+ public abstract void renameAllImagesFromAlbumAndChilds(Album dragValue,
+ String albumOld, String albumNew);
+
}
\ No newline at end of file
Deleted: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/IGalleryAction.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/IGalleryAction.java 2009-01-23 13:11:28 UTC (rev 12385)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/IGalleryAction.java 2009-01-23 13:23:32 UTC (rev 12386)
@@ -1,19 +0,0 @@
-package org.richfaces.realworld.service;
-
-import java.util.List;
-
-import javax.ejb.Local;
-
-import org.richfaces.realworld.domain.Gallery;
-import org.richfaces.realworld.domain.GalleryImage;
-
-@Local
-public interface IGalleryAction {
-
- public abstract void addGallery(String name);
-
- public abstract void addImage(Gallery gallery, GalleryImage image);
-
- public abstract List<Gallery> getGalleries();
-
-}
\ No newline at end of file
Modified: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/IMessageAction.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/IMessageAction.java 2009-01-23 13:11:28 UTC (rev 12385)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/IMessageAction.java 2009-01-23 13:23:32 UTC (rev 12386)
@@ -3,6 +3,7 @@
import javax.ejb.Local;
import org.richfaces.realworld.domain.Message;
+import org.richfaces.realworld.domain.User;
@Local
public interface IMessageAction {
@@ -12,4 +13,6 @@
public abstract void deleteMessage(Message message);
public void markAsReaded(Message message);
+
+ public long countNotReadedMessages(User user);
}
\ No newline at end of file
Modified: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/IUserAction.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/IUserAction.java 2009-01-23 13:11:28 UTC (rev 12385)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/IUserAction.java 2009-01-23 13:23:32 UTC (rev 12386)
@@ -6,6 +6,8 @@
import org.richfaces.realworld.domain.Album;
import org.richfaces.realworld.domain.FriendshipRequest;
+import org.richfaces.realworld.domain.Image;
+import org.richfaces.realworld.domain.Message;
import org.richfaces.realworld.domain.User;
@Local
@@ -16,11 +18,15 @@
public void updateUser(User user);
public void resetUser(User user);
public List<String> getUsers(String suggest);
- public long countNotReadedMessages(User user);
public void removeFromFriends(User owner, User removed);
public boolean friendExist(User user, User friend);
public void addFriend(User user, User friend, FriendshipRequest request);
- public void removeFromSharedAlbums(User user, Album album);
- public void addSharedAlbum(Album album);
+ public void removeFromFavoriteAlbums(User user, Album album);
+ public void addFavoriteAlbum(Album album);
public void loginAnonymous();
+ public List<Album> getRootAlbums(User user);
+ public List<Message> getHistory(User historyUser);
+ public List<Message> getOutgoingMessages();
+ public void addFavoriteImage(Image image);
+ public void removeFromFavoriteImages(User user, Image image);
}
\ No newline at end of file
Modified: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/MessageAction.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/MessageAction.java 2009-01-23 13:11:28 UTC (rev 12385)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/MessageAction.java 2009-01-23 13:23:32 UTC (rev 12386)
@@ -5,6 +5,7 @@
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Observer;
import org.richfaces.realworld.domain.Message;
import org.richfaces.realworld.domain.User;
@@ -13,9 +14,13 @@
public class MessageAction implements IMessageAction {
private static final String LOGIN_PARAMETER = "login";
+
+ private static final String USER_COUNT_MESSAGES_QUERY = "user-countMessages";
+
@In(value="entityManager")
EntityManager em;
+ @Observer("sendMessage")
public void sendMessage(Message message){
if(message.getOwnerLogin() != null){
User user = (User)em.createQuery("from User u where u.login = :login")
@@ -31,6 +36,13 @@
em.flush();
}
+ public long countNotReadedMessages(User user){
+ Long result = (Long)em.createNamedQuery(USER_COUNT_MESSAGES_QUERY)
+ .setParameter(LOGIN_PARAMETER, user.getLogin())
+ .getSingleResult();
+ return result;
+ }
+
public void deleteMessage(Message message){
em.remove(message);
message.getOwner().removeMessage(message);
Added: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/MessageComparator.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/MessageComparator.java (rev 0)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/MessageComparator.java 2009-01-23 13:23:32 UTC (rev 12386)
@@ -0,0 +1,14 @@
+package org.richfaces.realworld.service;
+
+import java.util.Comparator;
+
+import org.richfaces.realworld.domain.Message;
+
+public class MessageComparator implements Comparator {
+
+ public int compare(Object obj1, Object obj2) {
+ Message mes1 = (Message) obj1;
+ Message mes2 = (Message) obj2;
+ return mes1.getDate().after(mes2.getDate())?-1:1;
+ }
+}
Property changes on: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/MessageComparator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/SearchService.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/SearchService.java 2009-01-23 13:11:28 UTC (rev 12385)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/SearchService.java 2009-01-23 13:23:32 UTC (rev 12386)
@@ -1,6 +1,7 @@
package org.richfaces.realworld.service;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -10,7 +11,9 @@
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
+import org.jboss.seam.core.Events;
import org.richfaces.realworld.domain.Image;
+import org.richfaces.realworld.domain.MetaTag;
@Name("searchService")
@Stateless
@@ -48,6 +51,11 @@
EntityManager em;
public List<Image> searchImages(String searchPattern, String additionalParams, Map<String, Object> paramMap){
+ List<String> additions = new ArrayList<String>();
+ List<String> removals = new ArrayList<String>();
+ if(!parse(searchPattern, additions, removals)){
+ return null;
+ }
String fullQuery = null;
if(paramMap != null && paramMap.get(CASE_SENSITIVE_PARAMETER) != null){
boolean sensitive = (Boolean)paramMap.get(CASE_SENSITIVE_PARAMETER);
@@ -57,10 +65,37 @@
fullQuery = SEARCH_QUERY_BEGIN + additionalParams + SEARCH_QUERY_END;
}
}
- Query prepared = prepareQuery(fullQuery, searchPattern, additionalParams, paramMap);
- return prepared.getResultList();
+ Query prepared = prepareQuery(fullQuery, additions.get(0), additionalParams, paramMap);
+ List<Image> tempResult = prepared.getResultList();
+ additions.remove(0);
+ return filter(tempResult, additions, removals);
}
+ private List<Image> filter(List<Image> tempResult, List<String> additions,
+ List<String> removals) {
+ List<Image> result = new ArrayList<Image>();
+ result.addAll(tempResult);
+ for(Image i : tempResult){
+ for(String a:additions){
+ if(!i.containTag(a)){
+ result.remove(i);
+ break;
+ }
+ }
+ }
+ tempResult.clear();
+ tempResult.addAll(result);
+ for(Image i : result){
+ for(String a:removals){
+ if(i.containTag(a)){
+ tempResult.remove(i);
+ break;
+ }
+ }
+ }
+ return tempResult;
+ }
+
public List<Image> popularImages(String additionalParams, Map<String, Object> paramMap){
String fullQuery = SEARCH_RELEVANT_QUERY_BEGIN + additionalParams + SEARCH_POPULAR_QUERY_END;
Query prepared = prepareQuery(fullQuery, null, additionalParams, paramMap);
@@ -129,4 +164,74 @@
Query query = em.createQuery("select distinct t.tag from Image i join i.tags t");
return (List<String>)query.getResultList();
}
+
+ private boolean parse(String str, List<String> adds, List<String> removes){
+ str = str.trim();
+ if(str.startsWith("+") || str.startsWith("-") || str.endsWith("+") || str.endsWith("-") || str.length() == 0){
+ Events.instance().raiseEvent("addErrorEvent", new Exception("Invalid syntax"));
+ return false;
+ }
+ if(str.lastIndexOf('+')==-1 && str.lastIndexOf('-')==-1){
+ adds.add(str);
+ return true;
+ }
+ int curIndex=0;
+ int prevIndex=0;
+ boolean prevSignplus =true;
+ boolean signedPreviousChar = false;
+ for(int i =0; i< str.length(); i++){
+ char c = str.charAt(i);
+ if(c == '+' ){
+ if(signedPreviousChar == false){
+
+ curIndex = i;
+ if(prevSignplus){
+ if(prevIndex ==0){
+ adds.add(str.substring(prevIndex, curIndex));
+ }else{
+ adds.add(str.substring(prevIndex+1, curIndex));
+ }
+ }else{
+ removes.add(str.substring(prevIndex+1, curIndex));
+ }
+ prevSignplus=true;
+ signedPreviousChar=true;
+ prevIndex =i;
+ }else {
+ Events.instance().raiseEvent("addErrorEvent", new Exception("Invalid syntax"));
+ return false;
+ }
+
+ }else if(c == '-'){
+ if(signedPreviousChar == false){
+ curIndex = i;
+ signedPreviousChar=true;
+ if(prevSignplus){
+ if(prevIndex ==0){
+ adds.add(str.substring(prevIndex, curIndex));
+ }else{
+ adds.add(str.substring(prevIndex+1, curIndex));
+ }
+ }else{
+ removes.add(str.substring(prevIndex+1, curIndex));
+ }
+ prevSignplus=false;
+
+ prevIndex =i;
+ }else {
+ Events.instance().raiseEvent("addErrorEvent", new Exception("Invalid syntax"));
+ return false;
+ }
+ }else{
+ signedPreviousChar=false;
+ }
+ }
+ char c2 = str.charAt(prevIndex);
+ if(c2 == '+'){
+ adds.add(str.substring(prevIndex+1));
+ }else if(c2 == '-'){
+ removes.add(str.substring(prevIndex+1));
+ }
+ return true;
+ }
}
Modified: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/UserAction.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/UserAction.java 2009-01-23 13:11:28 UTC (rev 12385)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/UserAction.java 2009-01-23 13:23:32 UTC (rev 12386)
@@ -20,26 +20,29 @@
*/
package org.richfaces.realworld.service;
+import java.util.Collections;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
+import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.richfaces.realworld.domain.Album;
import org.richfaces.realworld.domain.FriendshipRequest;
+import org.richfaces.realworld.domain.Image;
+import org.richfaces.realworld.domain.Message;
import org.richfaces.realworld.domain.User;
@Name("userAction")
@Stateless
+@AutoCreate
public class UserAction implements IUserAction {
private static final String USER_FRIEND_EXIST_QUERY = "user-friendExist";
- private static final String USER_COUNT_MESSAGES_QUERY = "user-countMessages";
-
private static final String USER_AVAILABLE_USERS_QUERY = "user-availableUsers";
private static final String USER_EXIST_QUERY = "user-exist";
@@ -56,6 +59,8 @@
private static final String USERNAME_PARAMETER = "username";
+ private static final String USER_OUTCOMING_MESSAGES = "user-outcomeMessages";
+
@In(value="entityManager")
EntityManager em;
@@ -79,12 +84,26 @@
this.user = user;
}
+ public List<Album> getRootAlbums(User user) {
+ List<Album> albums = em.createNamedQuery("user-rootAlbums")
+ .setParameter("login", user.getLogin())
+ .getResultList();
+ return albums;
+ }
+
public void resetUser(User user) {
em.refresh(user);
em.flush();
this.user = user;
}
+ public List<Message> getOutgoingMessages(){
+ List<Message> messages = em.createNamedQuery(USER_OUTCOMING_MESSAGES)
+ .setParameter("login", user.getLogin())
+ .getResultList();
+ return messages;
+ }
+
public boolean isUserExist(String login) {
return em.createNamedQuery(USER_EXIST_QUERY)
.setParameter(LOGIN_PARAMETER, login)
@@ -99,12 +118,7 @@
return users;
}
- public long countNotReadedMessages(User user){
- Long result = (Long)em.createNamedQuery(USER_COUNT_MESSAGES_QUERY)
- .setParameter(LOGIN_PARAMETER, user.getLogin())
- .getSingleResult();
- return result;
- }
+
public void removeFromFriends(User owner, User removed) {
owner.removeFriend(removed);
@@ -127,13 +141,13 @@
em.flush();
}
- public void removeFromSharedAlbums(User user, Album album) {
- user.removeFromSharedAlbums(album);
+ public void removeFromFavoriteAlbums(User user, Album album) {
+ user.removeFromFavoriteAlbums(album);
em.flush();
}
- public void addSharedAlbum(Album album) {
- user.addSharedAlbum(album);
+ public void addFavoriteAlbum(Album album) {
+ user.addFavoriteAlbum(album);
album.getSharedOwners().add(user);
em.flush();
}
@@ -141,4 +155,32 @@
public void loginAnonymous() {
user = new User();
}
+
+ public List<Message> getHistory(User historyUser) {
+ List<Message> userMessages = getUserMessages(historyUser);
+ List<Message> userSecondMessages = getUserSecondMessages(historyUser);
+ userMessages.addAll(userSecondMessages);
+ MessageComparator c = new MessageComparator();
+ Collections.sort(userMessages, c );
+ return userMessages;
+ }
+
+ private List<Message> getUserSecondMessages(User historyUser) {
+ return em.createQuery("from Message m where m.author =:author and m.owner=:owner").setParameter("author", historyUser).setParameter("owner", user).getResultList();
+ }
+
+ private List<Message> getUserMessages(User historyUser) {
+ return em.createQuery("from Message m where m.author =:author and m.owner=:owner").setParameter("author", user).setParameter("owner", historyUser).getResultList();
+ }
+
+ public void addFavoriteImage(Image image) {
+ user.addFavoriteImage(image);
+ image.getSharedOwners().add(user);
+ em.flush();
+ }
+
+ public void removeFromFavoriteImages(User user, Image image) {
+ user.removeFromFavoriteImages(image);
+ em.flush();
+ }
}
\ No newline at end of file
Modified: trunk/test-applications/realworld/ejb/src/main/resources/import.sql
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/resources/import.sql 2009-01-23 13:11:28 UTC (rev 12385)
+++ trunk/test-applications/realworld/ejb/src/main/resources/import.sql 2009-01-23 13:23:32 UTC (rev 12386)
@@ -1,12 +1,14 @@
-INSERT INTO Users(user_id, firstname, secondname, email, avatarpath, login, password, birthdate) VALUES (1, 'Andrey', 'Markhel', 'amarkhel(a)exadel.com', 'avatar.jpg', 'amarkhel', '12345', '1985-01-08');
-INSERT INTO Users(user_id, firstname, secondname, email, avatarpath, login, password, birthdate) VALUES (2, 'Andrey', 'Markhel', 'amarkhel(a)exadel.com', 'avatar.jpg', 'root', '12345', '1985-01-08');
-INSERT INTO Users(user_id, firstname, secondname, email, avatarpath, login, password, birthdate) VALUES (3, 'Andrey', 'Markhel', 'amarkhel(a)exadel.com', 'avatar.jpg', 'qqqq', '12345', '1985-01-08');
-INSERT INTO Users(user_id, firstname, secondname, email, avatarpath, login, password, birthdate) VALUES (4, 'Andrey', 'Markhel', 'amarkhel(a)exadel.com', 'avatar.jpg', 'sss', '12345', '1985-01-08');
-INSERT INTO albums(album_id, name, description, shared, album_user_id) VALUES (1, 'Cars', 'Photo of my dog', true, 1);
-INSERT INTO albums(album_id, name, description, shared, album_user_id) VALUES (2, 'Tetki', 'Simple Album 2', true, 1);
-INSERT INTO albums(album_id, name, description, shared, album_user_id) VALUES (3, 'Football', 'Simple Album 3', true, 2);
-INSERT INTO albums(album_id, name, description, shared, album_user_id) VALUES (4, 'Japan', 'Simple Album', true, 3);
-INSERT INTO albums(album_id, name, description, shared, album_user_id) VALUES (5, 'Music', 'Simple Album 2', true, 3);
+INSERT INTO Users(user_id, firstname, secondname, email, login, password, birthdate) VALUES (1, 'Andrey', 'Markhel', 'amarkhel(a)exadel.com', 'amarkhel', '12345', '1985-01-08');
+INSERT INTO Users(user_id, firstname, secondname, email, login, password, birthdate) VALUES (2, 'Andrey', 'Markhel', 'amarkhel(a)exadel.com', 'root', '12345', '1985-01-08');
+INSERT INTO Users(user_id, firstname, secondname, email, login, password, birthdate) VALUES (3, 'Andrey', 'Markhel', 'amarkhel(a)exadel.com', 'qqqq', '12345', '1985-01-08');
+INSERT INTO Users(user_id, firstname, secondname, email, login, password, birthdate) VALUES (4, 'Andrey', 'Markhel', 'amarkhel(a)exadel.com', 'sss', '12345', '1985-01-08');
+INSERT INTO albums(album_id, name, description, shared, album_user_id, parent_album_id) VALUES (1, 'Cars', 'Photo of my dog', true, 1, null);
+INSERT INTO albums(album_id, name, description, shared, album_user_id, parent_album_id) VALUES (2, 'Tetki', 'Simple Album 2', true, 1, null);
+INSERT INTO albums(album_id, name, description, shared, album_user_id, parent_album_id) VALUES (3, 'Football', 'Simple Album 3', true, 2, null);
+INSERT INTO albums(album_id, name, description, shared, album_user_id, parent_album_id) VALUES (4, 'Japan', 'Simple Album', true, 3, null);
+INSERT INTO albums(album_id, name, description, shared, album_user_id, parent_album_id) VALUES (5, 'Music', 'Simple Album 2', false, 3, null);
+INSERT INTO albums(album_id, name, description, shared, album_user_id, parent_album_id) VALUES (6, 'Child1', 'Simple Album 2', true, 1, 1);
+INSERT INTO albums(album_id, name, description, shared, album_user_id, parent_album_id) VALUES (7, 'Child2', 'Simple Album 2', true, 1, 1);
INSERT INTO Ranks(rank_id, total, hits) VALUES (1, 100, 21);
INSERT INTO Ranks(rank_id, total, hits) VALUES (2, 200, 21);
INSERT INTO Ranks(rank_id, total, hits) VALUES (3, 100, 31);
@@ -70,9 +72,14 @@
INSERT INTO images(image_id, name, path, description, created, img_album_id, rank_id, cameraModel, height, size, width, uploaded) VALUES (29, 'Street musician', 'qqqq/Music/StreetMusician.jpg', 'unknown musician', '2008-12-18', 5, 29,'Canon S3', 336, 60.5, 500, '2008-12-01');
INSERT INTO images(image_id, name, path, description, created, img_album_id, rank_id, cameraModel, height, size, width, uploaded) VALUES (30, 'SOAD', 'qqqq/Music/system-of-a-down.jpg', 'Try not to loose your innervision!', '2008-12-18', 5, 30,'Canon S3', 500, 39.5, 323, '2008-12-01');
INSERT INTO images(image_id, name, path, description, created, img_album_id, rank_id, cameraModel, height, size, width, uploaded) VALUES (31, 'Amon Tobin', 'qqqq/Music/tobin.jpg', 'Brasilian, works in London. Try his "Supermodified2000" album', '2008-12-18', 5, 31,'Canon S3', 450, 37, 302, '2008-12-01');
-INSERT INTO metatags(metatag_id, tag, image_metatag_id) VALUES (1, 'Cool', 1);
-INSERT INTO metatags(metatag_id, tag, image_metatag_id) VALUES (2, 'Cool2', 1);
+INSERT INTO metatags(metatag_id, tag, image_metatag_id) VALUES (1, 'Beach', 1);
+INSERT INTO metatags(metatag_id, tag, image_metatag_id) VALUES (22, 'Sun', 1);
+INSERT INTO metatags(metatag_id, tag, image_metatag_id) VALUES (23, 'Summer', 1);
+INSERT INTO metatags(metatag_id, tag, image_metatag_id) VALUES (2, 'Cool', 1);
INSERT INTO metatags(metatag_id, tag, image_metatag_id) VALUES (3, 'richfaces', 2);
+INSERT INTO metatags(metatag_id, tag, image_metatag_id) VALUES (24, 'Beach', 2);
+INSERT INTO metatags(metatag_id, tag, image_metatag_id) VALUES (25, 'Sun', 2);
+INSERT INTO metatags(metatag_id, tag, image_metatag_id) VALUES (26, 'amarkhel', 2);
INSERT INTO metatags(metatag_id, tag, image_metatag_id) VALUES (4, 'Cool', 3);
INSERT INTO metatags(metatag_id, tag, image_metatag_id) VALUES (5, 'theCool', 4);
INSERT INTO metatags(metatag_id, tag, image_metatag_id) VALUES (6, 'Cool', 5);
@@ -95,45 +102,10 @@
INSERT INTO comments(comment_id, date, message, image_comment_id, from_user_id) VALUES (2, '1985-01-08', 'Hello I am user2', 1, 3);
INSERT INTO messages(message_id, date, message, author_id, owner_id, readed, theme, friendshipRequest) VALUES (1, '1985-01-08', 'Hello I am user', 2, 1, false, 'Hello, amarkhel', false);
INSERT INTO messages(message_id, date, message, author_id, owner_id, readed, theme, friendshipRequest) VALUES (2, '1985-01-08', 'Please, add meto your friends', 3, 1, false, 'Request for friendship', true);
+INSERT INTO messages(message_id, date, message, author_id, owner_id, readed, theme, friendshipRequest) VALUES (3, '1985-01-09', 'Hello ', 1, 2, false, 'Hello, amarkhel', false);
INSERT INTO shared_albums(album_id, user_id) VALUES(4, 1);
INSERT INTO shared_albums(album_id, user_id) VALUES(5, 1);
+INSERT INTO shared_images(image_id, user_id) VALUES(30, 1);
+INSERT INTO shared_images(image_id, user_id) VALUES(31, 1);
INSERT INTO user_friends(user1_id, user2_id) VALUES(1, 2);
-INSERT INTO friendship_requests(REQUEST_ID, USER_ID, FRIEND_ID) VALUES(1, 3, 1);
-INSERT INTO galleries(GALLERY_ID, name) VALUES (1, 'Fun');
-INSERT INTO galleries(GALLERY_ID, name) VALUES (2, 'Sport');
-INSERT INTO galleries(GALLERY_ID, name) VALUES (3, 'Nature');
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (1, 'Picture1','Fun/img-2e015.jpg' ,'Canon ES3', 'Nick', 1280, 145, 1024, 'Description', '1985-01-08', '2008-21-11', 1 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (2, 'Picture2', 'Fun/img-9b1c2.jpg','Canon ES3', 'Nick', 1024, 129, 768, 'Description', '1985-01-08', '2008-22-11', 1 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (3, 'Picture3', 'Fun/img-20d46.jpg','Canon ES3', 'Andrey', 1600, 260, 1200, 'Description', '1985-01-08', '2008-23-11', 1 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (4, 'Picture4','Fun/img-31c2e.jpg' ,'Canon ES3', 'Ilya', 1280, 169, 1024, 'Description', '1985-01-08', '2008-24-11', 1 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (5, 'Picture5','Fun/img-69fe6.jpg' ,'Canon ES3', 'Nick', 1280, 102, 1024, 'Description', '1985-01-08', '2008-25-11', 1 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (6, 'Picture6', 'Fun/img-334ee.jpg','Canon ES3', 'aaa', 1024, 90.9, 768, 'Description', '1985-01-08', '2008-21-11', 1 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (7, 'Picture7','Fun/img-828dd.jpg' ,'Canon ES3', 'qwazar', 1280, 276, 1024, 'Description', '1985-01-08', '2008-27-11', 1 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (8, 'Picture8','Fun/img-6537e.jpg' ,'Canon ES3', '', 1600, 338, 1200, 'Description', '1985-01-08', '2008-21-11', 1 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (9, 'Picture9','Fun/img-7141c.jpg' ,'Canon FS', 'Pit', 1024, 159, 768, 'Description', '1985-01-08', '2008-22-11', 1 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (10, 'Picture10','Fun/img-25386.jpg' ,'Canon ES3', 'Nick', 1600, 217, 1200, 'Description', '1985-01-08', '2008-21-11', 1 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (11, 'Picture11','Fun/img-99215.jpg' ,'Canon ES3', 'Andrey', 1024, 74, 768, 'Description', '1985-01-08', '2008-24-11', 1 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (12, 'Picture12', 'Fun/img-a9307.jpg','Canon ES3', 'aaa', 1680, 197, 1050, 'Description', '1985-01-08', '2008-21-11', 1 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (13, 'Picture13','Fun/img-b8d37.jpg' ,'Canon ES3-2', 'x-files', 1280, 275, 1024, 'Description', '1985-01-08', '2008-11-11', 1 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (14, 'Picture14','Fun/img-be1c0.jpg' ,'Canon ES3', 'Nk', 1024, 90.4, 768, 'Description', '1985-01-08', '2008-12-11', 1 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (15, 'Picture15','Fun/img-cf3ee.jpg' ,'Canon ES3', 'Nickolas', 1024, 97.6, 768, 'Description', '1985-01-08', '2008-22-11', 1 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (16, 'Picture16','Fun/img-d5ada.jpg' ,'Canon ES3', 'Andr', 1024, 192, 768, 'Description', '1985-01-08', '2008-22-11', 1 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (17, 'Picture17','Fun/img-d5ed3.jpg' ,'Canon ES3', 'adc', 1024, 213, 768, 'Description', '1985-01-08', '2008-23-11', 1 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (18, 'Picture18','Fun/img-d966e.jpg' ,'Canon ES3', 'Neeek', 1600, 128, 1200, 'Description', '1985-01-08', '2008-24-11', 1 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (19, 'Picture19','Sport/1.jpg' ,'Canon ES3', 'Potk', 1600, 736, 1200, 'Description', '1985-01-08', '2008-25-11', 2 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (20, 'Picture20','Sport/2.jpg' ,'Canon ES3', 'aqw', 1280, 229, 1024, 'Description', '1985-01-08', '2008-21-11', 2 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (21, 'Picture100','Sport/3.jpg' ,'Canon ES3', 'ass', 1600, 310, 1200, 'Description', '1985-01-08', '2008-27-11', 2 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (22, 'Picture101','Sport/4.jpg' ,'Canon ES3', 'www', 1600, 728, 1200, 'Description', '1985-01-08', '2008-29-11', 2 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (23, 'Picture111','Sport/5.jpg' ,'Canon ES3', 'Nwww', 1280, 251, 1024, 'Description', '1985-01-08', '2008-30-11', 2 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (24, 'Picture1111','Sport/6.jpg' ,'Canon ES3', 'www', 1280, 278, 1024, 'Description', '1985-01-08', '2008-11-11', 2 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (25, 'Picture113','Sport/7.jpg' ,'Canon ES3-2', 'Nick', 1600, 689, 1200, 'Description', '1985-01-08', '2008-21-11', 2 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (26, 'Picture1s','Sport/8.jpg' ,'Canon ES3', 'Nick', 1280, 285, 1024, 'Description', '1985-01-08', '2008-14-11', 2 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (27, 'Picture1sd','Sport/9.jpg' ,'Canon ES3', 'Nick', 1600, 468, 1200, 'Description', '1985-01-08', '2008-21-11', 2 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (28, 'Picture1ssd','Sport/10.jpg' ,'Canon ES3', 'Nick', 1600, 313, 1200, 'Description', '1985-01-08', '2008-21-11', 2 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (29, 'Picture1xd','Sport/11.jpg' ,'Canon ES3', 'Nick', 1600, 214, 1200, 'Description', '1985-01-08', '2008-21-11', 2 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (30, 'Picture1dfd','Sport/12.jpg' ,'Canon ES3', 'Nick', 1280, 336, 1024, 'Description', '1985-01-08', '2008-21-11', 2 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (31, 'Picture1ww','Sport/13.jpg' ,'Canon ES3', 'Nick', 1600, 287, 1200, 'Description', '1985-01-08', '2008-21-11', 2 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (32, 'Picture1weqw','Sport/14.jpg' ,'Canon ES3', 'Nick', 1600, 400,1200, 'Description', '1985-01-08', '2008-21-11', 2 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (33, 'Picture1wdfeqw','Sport/15.jpg' ,'Canon ES3', 'Nick', 1280, 194, 1024, 'Description', '1985-01-08', '2008-21-11', 2 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (34, 'Picture1wseqw','Sport/16.jpg' ,'Canon ES3', 'Nick', 1600, 197, 1200, 'Description', '1985-01-08', '2008-21-11', 2 );
-INSERT INTO galleryImages(GALLERY_IMAGE_ID, name, path, cameraModel, author, height, size, width, description, created, uploaded, IMG_GALLERY_ID) VALUES (35, 'Picture1wddeqw','Sport/17.jpg' ,'Canon ES3', 'Nick', 1280, 87.9, 1024, 'Description', '1985-01-08', '2008-21-11', 2 );
\ No newline at end of file
+INSERT INTO friendship_requests(REQUEST_ID, USER_ID, FRIEND_ID) VALUES(1, 3, 1);
\ No newline at end of file
15 years, 12 months
JBoss Rich Faces SVN: r12385 - in trunk/test-applications/seleniumTest/richfaces/src: main/webapp/pages/toolBar and 2 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alevkovsky
Date: 2009-01-23 08:11:28 -0500 (Fri, 23 Jan 2009)
New Revision: 12385
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/toolBar/toolBarGroupTest.xhtml
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/ToolBarTestBean.java
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/toolBar/toolBarTest.xhtml
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/ToolBarTest.java
Log:
Tool bar selenium tests
Modified: trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/ToolBarTestBean.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/ToolBarTestBean.java 2009-01-23 13:03:54 UTC (rev 12384)
+++ trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/ToolBarTestBean.java 2009-01-23 13:11:28 UTC (rev 12385)
@@ -25,6 +25,18 @@
private String groupSeparator = "";
private String groupItemSeparator = "";
+
+ private String location = "left";
+
+ private boolean toolBarGroupRendered = true;
+
+ public void reset(){
+ toolBarGroupRendered = true;
+ groupSeparator = "";
+ groupItemSeparator = "";
+ location = "left";
+ }
+
/**
* Gets value of groupSeparator field.
@@ -63,4 +75,38 @@
public void setGroupItemSeparator(String groupItemSeparator) {
this.groupItemSeparator = groupItemSeparator;
}
+
+
+ /**
+ * @return the toolBarGroupRendered
+ */
+ public boolean isToolBarGroupRendered() {
+ return toolBarGroupRendered;
+ }
+
+
+ /**
+ * @param toolBarGroupRendered the toolBarGroupRendered to set
+ */
+ public void setToolBarGroupRendered(boolean toolBarGroupRendered) {
+ this.toolBarGroupRendered = toolBarGroupRendered;
+ }
+
+
+ /**
+ * @return the location
+ */
+ public String getLocation() {
+ return location;
+ }
+
+
+ /**
+ * @param location the location to set
+ */
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+
}
Added: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/toolBar/toolBarGroupTest.xhtml
===================================================================
(Binary files differ)
Property changes on: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/toolBar/toolBarGroupTest.xhtml
___________________________________________________________________
Name: svn:mime-type
+ application/xhtml+xml
Modified: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/toolBar/toolBarTest.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java 2009-01-23 13:03:54 UTC (rev 12384)
+++ trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java 2009-01-23 13:11:28 UTC (rev 12385)
@@ -1146,7 +1146,7 @@
* @param message - error message to insert in log
*/
public void assertColumnsCount(int i, String tableId, String mesage) {
- StringBuffer script = new StringBuffer("$('");
+ StringBuffer script = new StringBuffer("document.getElementById('");
script.append(tableId);
script.append("').rows[0].cells.length");
Modified: trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/ToolBarTest.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/ToolBarTest.java 2009-01-23 13:03:54 UTC (rev 12384)
+++ trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/ToolBarTest.java 2009-01-23 13:11:28 UTC (rev 12385)
@@ -29,13 +29,15 @@
import org.testng.annotations.Test;
public class ToolBarTest extends SeleniumTestBase {
+
+ private final static String TOOL_BAR_GROUP_TEST_URL = "pages/toolBar/toolBarGroupTest.xhtml";
static final Map<String, String> TOOL_BAR_STYLES = new HashMap<String, String>();
static {
TOOL_BAR_STYLES.put("font-size", "16px");
}
- private static final String TOOLBAR = "toolbar";
+
/* Tab panel group/item separator constants */
private final static String LINE_SEPARATOR = "line";
@@ -47,33 +49,99 @@
private final static String SQUARE_SEPARATOR = "square";
private final static String NONE_SEPARATOR = "none";
+
+ private final static String RESET_METHOD = "#{toolBarBean.reset}";
+ private String formId;
+ private String toolBarId;
+ private String groupContentPrefix;
+ private String renderedControl;
+ private String submitControl;
+
+ private void initIds(String parentId){
+ formId = parentId + "_form:";
+ toolBarId = formId + "toolBar";
+ groupContentPrefix = formId + "groupContent";
+ renderedControl = formId + "rendered";
+ submitControl = formId + "submit";
+ }
+
@Test
public void testToolBarComponentLayout(Template template) {
renderPage(template);
writeStatus("Check component layout");
- String id = getParentId() + "_form:";
+ initIds(getParentId());
- writeStatus("Switch toolbar group separator");
+ AssertPresent(toolBarId, "Tool bar component not present on the page");
+ AssertVisible(toolBarId, "Tool bar component not visible on the page");
+ assertClassNames(toolBarId, new String[]{"rich-toolbar"}, "Tool bar component not have valid style class", true);
+
+ assertColumnsCount(8, toolBarId, "Tool bar should contains 8 elements");
+ }
+
+ @Test
+ public void testSeparators(Template template) {
+ renderPage(template, RESET_METHOD);
+ initIds(getParentId());
- clickAjaxCommandAndWait(id + "gs_" + LINE_SEPARATOR);
- clickAjaxCommandAndWait(id + "gs_" + DISC_SEPARATOR);
- clickAjaxCommandAndWait(id + "gs_" + GRID_SEPARATOR);
- clickAjaxCommandAndWait(id + "gs_" + SQUARE_SEPARATOR);
- clickAjaxCommandAndWait(id + "gs_" + NONE_SEPARATOR);
+ //test group separators
+ assertColumnsCount(8, toolBarId, "Tool bar should contains 8 elements");
- writeStatus("Switch toolbar group item separator");
+ clickAjaxCommandAndWait(formId + "gs_" + LINE_SEPARATOR);
+ assertColumnsCount(9, toolBarId, "Tool bar should contains 9 elements");
+
+ clickAjaxCommandAndWait(formId + "gs_" + DISC_SEPARATOR);
+ assertColumnsCount(9, toolBarId, "Tool bar should contains 9 elements");
+
+ clickAjaxCommandAndWait(formId + "gs_" + GRID_SEPARATOR);
+ assertColumnsCount(9, toolBarId, "Tool bar should contains 9 elements");
+
+ clickAjaxCommandAndWait(formId + "gs_" + SQUARE_SEPARATOR);
+ assertColumnsCount(9, toolBarId, "Tool bar should contains 9 elements");
+
+ clickAjaxCommandAndWait(formId + "gs_" + NONE_SEPARATOR);
+ assertColumnsCount(8, toolBarId, "Tool bar should contains 8 elements");
- clickAjaxCommandAndWait(id + "gis_" + LINE_SEPARATOR);
- clickAjaxCommandAndWait(id + "gis_" + DISC_SEPARATOR);
- clickAjaxCommandAndWait(id + "gis_" + GRID_SEPARATOR);
- clickAjaxCommandAndWait(id + "gis_" + SQUARE_SEPARATOR);
- clickAjaxCommandAndWait(id + "gis_" + NONE_SEPARATOR);
- }
+ //test items separators
+
+ clickAjaxCommandAndWait(formId + "gis_" + LINE_SEPARATOR);
+ assertColumnsCount(12, toolBarId, "Tool bar should contains 12 elements");
+
+ clickAjaxCommandAndWait(formId + "gis_" + DISC_SEPARATOR);
+ assertColumnsCount(12, toolBarId, "Tool bar should contains 12 elements");
+
+ clickAjaxCommandAndWait(formId + "gis_" + GRID_SEPARATOR);
+ assertColumnsCount(12, toolBarId, "Tool bar should contains 12 elements");
+
+ clickAjaxCommandAndWait(formId + "gis_" + SQUARE_SEPARATOR);
+ assertColumnsCount(12, toolBarId, "Tool bar should contains 12 elements");
+
+ clickAjaxCommandAndWait(formId + "gis_" + NONE_SEPARATOR);
+ assertColumnsCount(8, toolBarId, "Tool bar should contains 8 elements");
+ }
@Test
+ public void testItemsAlignment(Template template) {
+ renderPage(TOOL_BAR_GROUP_TEST_URL, template, RESET_METHOD);
+ initIds(getParentId());
+
+ AssertTextEquals(groupContentPrefix + "1", "Group1", "Toolbar group should present on page");
+ AssertTextEquals(groupContentPrefix + "2", "Group1", "Toolbar group should present on page");
+ AssertTextEquals(groupContentPrefix + "3", "Group1", "Toolbar group should present on page");
+ assertAttributeContains(getToolBarTdXpath(toolBarId, 4), "style", "width: 100%", null);
+
+ clickAjaxCommandAndWait(formId + "location");
+
+ assertAttributeContains(getToolBarTdXpath(toolBarId, 1), "style", "width: 100%", null);
+ AssertTextEquals(groupContentPrefix + "1", "Group1", "Toolbar group should present on page");
+ AssertTextEquals(groupContentPrefix + "2", "Group1", "Toolbar group should present on page");
+ AssertTextEquals(groupContentPrefix + "3", "Group1", "Toolbar group should present on page");
+
+ }
+
+ @Test
public void testRendered(Template template){
AutoTester tester = getAutoTester(this);
tester.renderPage(template, null);
@@ -89,7 +157,46 @@
tester.testStyleAndClasses(new String [] {"rich-toolbar", "styleClass"}, TOOL_BAR_STYLES);
tester.testHTMLEvents();
}
+
+ @Test
+ public void testToolBarGroupRendered(Template template){
+ renderPage(TOOL_BAR_GROUP_TEST_URL, template, RESET_METHOD);
+ initIds(getParentId());
+ AssertPresent(groupContentPrefix + "1", "Toolbar group should present on page");
+ AssertPresent(groupContentPrefix + "2", "Toolbar group should present on page");
+ AssertPresent(groupContentPrefix + "3", "Toolbar group should present on page");
+ AssertTextEquals(groupContentPrefix + "1", "Group1", "Toolbar group should present on page");
+ AssertTextEquals(groupContentPrefix + "2", "Group1", "Toolbar group should present on page");
+ AssertTextEquals(groupContentPrefix + "3", "Group1", "Toolbar group should present on page");
+ clickById(renderedControl);
+ clickCommandAndWait(submitControl);
+ AssertNotPresent(groupContentPrefix + "1", "Toolbar group should not present on page");
+ AssertNotPresent(groupContentPrefix + "2", "Toolbar group should not present on page");
+ AssertNotPresent(groupContentPrefix + "3", "Toolbar group should not present on page");
+
+ }
+
+ @Test
+ public void testToolBarGroupStylesAndClassesAndHtmlAttributes(Template template){
+ renderPage(TOOL_BAR_GROUP_TEST_URL, template, RESET_METHOD);
+ initIds(getParentId());
+ AssertPresent(groupContentPrefix + "1", "Toolbar group should present on page");
+ AssertPresent(groupContentPrefix + "2", "Toolbar group should present on page");
+ AssertPresent(groupContentPrefix + "3", "Toolbar group should present on page");
+
+ assertClassNames(getToolBarTdXpath(toolBarId, 1), new String[]{"styleClass"}, "styleClass attribute not work for Tool bar group", false);
+ assertClassNames(getToolBarTdXpath(toolBarId, 2), new String[]{"styleClass"}, "styleClass attribute not work for Tool bar group", false);
+ assertClassNames(getToolBarTdXpath(toolBarId, 3), new String[]{"styleClass"}, "styleClass attribute not work for Tool bar group", false);
+
+ assertAttributeContains(getToolBarTdXpath(toolBarId, 1), "style", "font-size: 16px", null);
+ assertAttributeContains(getToolBarTdXpath(toolBarId, 2), "style", "font-size: 16px", null);
+ assertAttributeContains(getToolBarTdXpath(toolBarId, 3), "style", "font-size: 16px", null);
+
+ }
+ private String getToolBarTdXpath(String toolBarId, int item){
+ return "//*[@id='" + toolBarId + "']/tbody/tr/td[" + item + "]";
+ }
@Override
public String getTestUrl() {
15 years, 12 months
JBoss Rich Faces SVN: r12384 - in trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd: generator and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2009-01-23 08:03:54 -0500 (Fri, 23 Jan 2009)
New Revision: 12384
Modified:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Component.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Components.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/JarResourceScanner.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/StyleAssembler.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java
Log:
missed license added
Modified: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Component.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Component.java 2009-01-23 13:02:28 UTC (rev 12383)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Component.java 2009-01-23 13:03:54 UTC (rev 12384)
@@ -1,3 +1,23 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
package org.richfaces.cdk.rd;
import java.util.ArrayList;
Modified: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Components.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Components.java 2009-01-23 13:02:28 UTC (rev 12383)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Components.java 2009-01-23 13:03:54 UTC (rev 12384)
@@ -1,3 +1,23 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
package org.richfaces.cdk.rd;
import java.util.ArrayList;
Modified: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/JarResourceScanner.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/JarResourceScanner.java 2009-01-23 13:02:28 UTC (rev 12383)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/JarResourceScanner.java 2009-01-23 13:03:54 UTC (rev 12384)
@@ -1,3 +1,23 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
package org.richfaces.cdk.rd;
import java.io.IOException;
Modified: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/StyleAssembler.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/StyleAssembler.java 2009-01-23 13:02:28 UTC (rev 12383)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/StyleAssembler.java 2009-01-23 13:03:54 UTC (rev 12384)
@@ -1,3 +1,23 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
package org.richfaces.cdk.rd.generator;
import java.io.File;
Modified: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java 2009-01-23 13:02:28 UTC (rev 12383)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java 2009-01-23 13:03:54 UTC (rev 12384)
@@ -1,3 +1,23 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
package org.richfaces.cdk.rd.mojo;
import java.io.File;
15 years, 12 months
JBoss Rich Faces SVN: r12383 - in trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd: utils and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2009-01-23 08:02:28 -0500 (Fri, 23 Jan 2009)
New Revision: 12383
Modified:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/utils/PluginUtils.java
Log:
Modified: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java 2009-01-23 12:53:14 UTC (rev 12382)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java 2009-01-23 13:02:28 UTC (rev 12383)
@@ -13,7 +13,6 @@
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
-import org.ajax4jsf.builder.mojo.Library;
import org.apache.commons.digester.Digester;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemException;
@@ -59,7 +58,6 @@
*/
MavenProject project;
-
/**
* Used to look up Artifacts in the remote repository.
*
@@ -67,7 +65,6 @@
*/
private org.apache.maven.artifact.factory.ArtifactFactory factory;
-
/**
* Used to look up Artifacts in the remote repository.
*
@@ -75,15 +72,13 @@
*/
private org.apache.maven.artifact.resolver.ArtifactResolver resolver;
-
/**
* The local repository.
*
* @parameter expression="${localRepository}"
*/
private ArtifactRepository localRepository;
-
-
+
/**
* webSourceDirectory
* @parameter expression="${basedir}/src/main/webapp"
@@ -96,7 +91,6 @@
*/
private ArtifactMetadataSource metadataSource;
-
/**
* outputScriptDirectory
* @parameter expression = "${basedir}/src/main/webapp"
@@ -121,8 +115,7 @@
* @parameter expression="custom-dependencies"
*/
private String stylePackName;
-
-
+
/**
* beforeIncludes
* @parameter
@@ -148,12 +141,6 @@
private List afterStyleIncludes;
/**
- *
- * @parameter
- */
- protected Library library;
-
- /**
* @component
*/
protected VelocityComponent velocity;
@@ -170,6 +157,9 @@
FileObject [] configs = PluginUtils.resolveConfigsFromJar(jar, PluginUtils.DEFAULT_CONFIG_PATTERNS);
components.putAll(PluginUtils.processConfigs(configs, defaultDigester));
}
+ if(!webSourceDirectory.exists()) {
+ webSourceDirectory.mkdirs();
+ }
ComponentsHandler handler = findComponents(webSourceDirectory, components, PluginUtils.DEFAULT_PROCESS_INCLUDES, new String[0]);
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
ClassLoader contextClassLoader = createClassLoader();
@@ -179,6 +169,9 @@
Set <String> scripts = handler.getScripts();
if(!scripts.isEmpty()) {
+ if(!outputScriptDirectory.exists()) {
+ outputScriptDirectory.mkdirs();
+ }
File assemblyFile = new File(outputScriptDirectory, scriptPackName + ".js");
ScriptAssembler scriptAssembler = new ScriptAssembler();
mergeResources(assemblyFile, scriptAssembler, beforeScriptIncludes, afterScriptIncludes, scripts);
@@ -186,6 +179,9 @@
Set <String> styles = handler.getStyles();
if(!styles.isEmpty()) {
+ if(!outputStyleDirectory.exists()) {
+ outputStyleDirectory.mkdirs();
+ }
File assemblyFile = new File(outputStyleDirectory, stylePackName + ".xcss");
StyleAssembler styleAssembler = new StyleAssembler();
styleAssembler.setVelocityComponent(velocity);
Modified: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/utils/PluginUtils.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/utils/PluginUtils.java 2009-01-23 12:53:14 UTC (rev 12382)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/utils/PluginUtils.java 2009-01-23 13:02:28 UTC (rev 12383)
@@ -27,7 +27,6 @@
import org.apache.commons.digester.Digester;
import org.apache.commons.vfs.FileObject;
-import org.apache.commons.vfs.FileSystemException;
import org.richfaces.cdk.rd.Component;
import org.richfaces.cdk.rd.Components;
import org.richfaces.cdk.rd.JarResourceScanner;
15 years, 12 months
JBoss Rich Faces SVN: r12382 - in trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd: generator and 3 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2009-01-23 07:53:14 -0500 (Fri, 23 Jan 2009)
New Revision: 12382
Modified:
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/JarResourceScanner.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourceAssembler.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourcesGenerator.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/StyleAssembler.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java
trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/utils/PluginUtils.java
Log:
review
Modified: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/JarResourceScanner.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/JarResourceScanner.java 2009-01-23 12:46:27 UTC (rev 12381)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/JarResourceScanner.java 2009-01-23 12:53:14 UTC (rev 12382)
@@ -15,24 +15,17 @@
public class JarResourceScanner {
private FileObject baseFile;
-
+
private Set <FileObject> result = new HashSet <FileObject>();
- private String [] patterns;
+ private String [] patterns = new String[] {"**"};
+
public String[] getPatterns() {
return patterns;
}
public void setPatterns(String[] patterns) {
- if(patterns == null) {
- patterns = new String[] {"**"};
- }
-
- if(patterns.length < 1) {
- patterns = new String[] {"**"};
- }
-
this.patterns = patterns;
}
Modified: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourceAssembler.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourceAssembler.java 2009-01-23 12:46:27 UTC (rev 12381)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourceAssembler.java 2009-01-23 12:53:14 UTC (rev 12382)
@@ -1,3 +1,23 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
package org.richfaces.cdk.rd.generator;
import java.io.File;
Modified: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourcesGenerator.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourcesGenerator.java 2009-01-23 12:46:27 UTC (rev 12381)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/ResourcesGenerator.java 2009-01-23 12:53:14 UTC (rev 12382)
@@ -1,3 +1,23 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
package org.richfaces.cdk.rd.generator;
import java.io.File;
Modified: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/StyleAssembler.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/StyleAssembler.java 2009-01-23 12:46:27 UTC (rev 12381)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/generator/StyleAssembler.java 2009-01-23 12:53:14 UTC (rev 12382)
@@ -45,7 +45,7 @@
xmlBody.loadXML(resourceInputStream,true);
builder.append(xmlBody.getContent());
} catch (ParsingException e) {
- log.error("Error processing xcss: " + e.getMessage(), e);
+ log.error("Error process xcss: " + e.getMessage(), e);
}
} else {
builder.append(IOUtil.toString(resourceInputStream));
@@ -69,7 +69,7 @@
public void writeToFile(File file) {
try {
- if(builder.length() > 0) {
+ if(builder.length() > 0 && velocityComponent != null) {
VelocityContext context = new VelocityContext();
context.put("content", builder);
VelocityEngine engine = velocityComponent.getEngine();
Modified: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java 2009-01-23 12:46:27 UTC (rev 12381)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java 2009-01-23 12:53:14 UTC (rev 12382)
@@ -1,3 +1,23 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
package org.richfaces.cdk.rd.handler;
import java.util.LinkedHashSet;
Modified: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java 2009-01-23 12:46:27 UTC (rev 12381)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/ResourceDependencyMojo.java 2009-01-23 12:53:14 UTC (rev 12382)
@@ -1,6 +1,8 @@
package org.richfaces.cdk.rd.mojo;
import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -160,7 +162,7 @@
public void execute() throws MojoExecutionException, MojoFailureException {
try {
Set <Artifact> artifacts = resolveDependenciesArtifacts();
- Digester defaultDigester = getDigester();
+ Digester defaultDigester = createDigester();
Map <String, Components> components = new HashMap<String, Components>();
for (Artifact artifact : artifacts) {
@@ -208,22 +210,17 @@
styleGenerator.writeToFile();
}
- protected Set <Artifact> resolveDependenciesArtifacts() {
+ protected Set <Artifact> resolveDependenciesArtifacts() throws Exception {
ArtifactResolutionResult result = null;
- try {
- List <Dependency> dependencies = project.getDependencies();
- Set <Artifact> artifacts = MavenMetadataSource.createArtifacts(factory, dependencies, null, null, project);
- artifacts.add(project.getArtifact());
-
- result = resolver.resolveTransitively(artifacts, project.getArtifact(), Collections.EMPTY_LIST, localRepository, metadataSource);
- } catch (Exception e) {
- getLog().error(e);
- }
+ List <Dependency> dependencies = project.getDependencies();
+ Set <Artifact> artifacts = MavenMetadataSource.createArtifacts(factory, dependencies, null, null, project);
+ artifacts.add(project.getArtifact());
+ result = resolver.resolveTransitively(artifacts, project.getArtifact(), Collections.EMPTY_LIST, localRepository, metadataSource);
return result.getArtifacts();
}
- public ComponentsHandler findComponents (File webSourceDir, Map <String, Components> components, String [] includes, String [] excludes) {
+ public ComponentsHandler findComponents (File webSourceDir, Map <String, Components> components, String [] includes, String [] excludes) throws Exception {
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(webSourceDir);
@@ -236,28 +233,21 @@
ComponentsHandler handler = new ComponentsHandler();
handler.setComponents(components);
- try {
-
- SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
- saxParserFactory.setNamespaceAware(true);
- SAXParser saxParser = saxParserFactory.newSAXParser();
+ SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
+ saxParserFactory.setNamespaceAware(true);
+ SAXParser saxParser = saxParserFactory.newSAXParser();
- for(String processFile : collectedFiles) {
- File file = new File(webSourceDir,processFile);
- if(file.exists()) {
- getLog().info("process file: " + file.getName());
- try {
- saxParser.parse(file, handler);
- } catch (Exception e) {
- getLog().error("Error process file: " + file.getAbsolutePath() + "\n" + e.getMessage(), e);
- }
- }
- }
-
- } catch (Exception e) {
- getLog().error(e);
- }
-
+ for(String processFile : collectedFiles) {
+ File file = new File(webSourceDir,processFile);
+ if(file.exists()) {
+ getLog().info("process file: " + file.getName());
+ try {
+ saxParser.parse(file, handler);
+ } catch (Exception e) {
+ getLog().error("Error process file: " + file.getAbsolutePath() + "\n" + e.getMessage(), e);
+ }
+ }
+ }
return handler;
}
@@ -284,46 +274,48 @@
return jarFileObjects;
}
- public Digester getDigester() {
+ public Digester createDigester() {
// default digester for *.component-dependencies.xml
return PluginUtils.createDefaultDigester();
}
- protected ClassLoader createClassLoader() {
+ protected ClassLoader createClassLoader() throws Exception {
ClassLoader classLoader = null;
- try {
- Set <Artifact> artifacts = resolveDependenciesArtifacts();
-
- //create a new classloading space
- ClassWorld world = new ClassWorld();
+ Set <Artifact> artifacts = resolveDependenciesArtifacts();
- //use the existing ContextClassLoader in a realm of the classloading space
- ClassRealm realm = world.newRealm("org.richfaces.cdk", Thread.currentThread().getContextClassLoader());
-
- //create another realm for the app jars
- ClassRealm childRealm = realm.createChildRealm("jar");
- for(Artifact jar : artifacts ) {
+ //create a new classloading space
+ ClassWorld world = new ClassWorld();
+
+ //use the existing ContextClassLoader in a realm of the classloading space
+ ClassRealm realm = world.newRealm("org.richfaces.cdk", Thread.currentThread().getContextClassLoader());
+ //create another realm for the app jars
+ ClassRealm childRealm = realm.createChildRealm("jar");
+
+ for(Artifact jar : artifacts ) {
+ try {
childRealm.addConstituent(jar.getFile().toURL());
+ } catch (MalformedURLException e) {
+ getLog().error("Artifact url " + jar.getFile() + " is invalid");
}
- // add project classes, scripts etc ...
- List compileClasspathElements = project.getCompileClasspathElements();
- for (Object path: compileClasspathElements) {
- try {
- childRealm.addConstituent(new File((String)path).toURI().toURL());
- } catch (Exception e) {
- getLog().error(e);
- }
+ }
+
+ // add project classes, scripts etc ...
+ List compileClasspathElements = project.getCompileClasspathElements();
+ for (Object path: compileClasspathElements) {
+ try {
+ URL url = new File((String)path).toURI().toURL();
+ childRealm.addConstituent(url);
+ }catch (MalformedURLException e) {
+ getLog().error("Artifact url " + path + " is invalid");
}
- //make the child realm the ContextClassLoader
- classLoader = childRealm.getClassLoader();
-
- } catch (Exception e) {
- getLog().error(e);
- }
+ }
+
+ //make the child realm the ContextClassLoader
+ classLoader = childRealm.getClassLoader();
return classLoader;
}
}
Modified: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/utils/PluginUtils.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/utils/PluginUtils.java 2009-01-23 12:46:27 UTC (rev 12381)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/utils/PluginUtils.java 2009-01-23 12:53:14 UTC (rev 12382)
@@ -1,14 +1,37 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
package org.richfaces.cdk.rd.utils;
+import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.digester.Digester;
import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemException;
import org.richfaces.cdk.rd.Component;
import org.richfaces.cdk.rd.Components;
import org.richfaces.cdk.rd.JarResourceScanner;
+import org.xml.sax.SAXException;
public class PluginUtils {
@@ -17,33 +40,27 @@
public static String [] DEFAULT_PROCESS_INCLUDES = new String [] {"**/*.xhtml"};
- public static FileObject [] resolveConfigsFromJar(FileObject jarFileObject, String [] patterns) throws Exception {
+ public static FileObject [] resolveConfigsFromJar(FileObject jarFileObject, String [] patterns) throws IOException{
FileObject [] result = new FileObject[0];
JarResourceScanner jarScanner = new JarResourceScanner();
jarScanner.setBaseFile(jarFileObject);
jarScanner.setPatterns(patterns);
jarScanner.doScan();
result = (FileObject [])jarScanner.getResult().toArray(new FileObject[jarScanner.getResult().size()]);
-
return result;
}
- public static Map <String,Components> processConfigs(FileObject [] configs, Digester digester) throws Exception{
-
+ public static Map <String,Components> processConfigs(FileObject [] configs, Digester digester) throws SAXException, IOException {
Map <String, Components>collector = new HashMap <String, Components>();
for (FileObject config: configs) {
- InputStream configInputStream = null;
+ InputStream configInputStream = config.getContent().getInputStream();
try {
- configInputStream = config.getContent().getInputStream();
- Components components = (Components)digester.parse(configInputStream);
+ Components components = (Components)digester.parse(configInputStream);
collector.put(components.getNamespace(), components);
} finally {
- if(configInputStream != null) {
- configInputStream.close();
- }
- }
+ configInputStream.close();
+ }
}
-
return collector;
}
15 years, 12 months
JBoss Rich Faces SVN: r12381 - trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng.
by richfaces-svn-commits@lists.jboss.org
Author: andrei_exadel
Date: 2009-01-23 07:46:27 -0500 (Fri, 23 Jan 2009)
New Revision: 12381
Modified:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/DropDownMenuTest.java
Log:
Drop Down menu test
Modified: trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/DropDownMenuTest.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/DropDownMenuTest.java 2009-01-23 12:45:58 UTC (rev 12380)
+++ trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/DropDownMenuTest.java 2009-01-23 12:46:27 UTC (rev 12381)
@@ -20,6 +20,9 @@
*/
package org.richfaces.testng;
+import java.util.HashMap;
+import java.util.Map;
+
import org.ajax4jsf.autotest.bean.AutoTestBean;
import org.ajax4jsf.template.Template;
import org.richfaces.AutoTester;
@@ -33,6 +36,12 @@
static final String INIT_IMMEDIATE_METHOD = "#{ddmenuBean.initImmediateTest}";
static final String IMMEDIATE_WITH_EXTERNAL_VALIDATION_URL = "/pages/dropDownMenu/testImmediateWithExternalValidation.xhtml";
+
+ static final Map<String, String> params = new HashMap<String, String>();
+
+ static {
+ params.put("parameter1", "value1");
+ }
@Test
public void testDropDownMenuComponent(Template template) {
@@ -83,6 +92,22 @@
autoTester.testAjaxSingleWithInternalValidationFailed();
}
+
+ @Test
+ public void testAjaxSingleWithProcessExternalValidationFailed(Template template) {
+ AutoTester autoTester = getAutoTester(this);
+ autoTester.renderPage(template, RESET_METHOD);
+
+ autoTester.testAjaxSingleWithProcesExternalValidation(true);
+ }
+
+ @Test
+ public void testNestedParams(Template template) {
+ AutoTester autoTester = getAutoTester(this);
+ autoTester.renderPage(template, RESET_METHOD);
+
+ autoTester.testRequestParameters(params);
+ }
public String getTestUrl() {
15 years, 12 months
JBoss Rich Faces SVN: r12380 - in trunk/test-applications/seleniumTest/richfaces/src: main/webapp/pages/dropDownMenu and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: andrei_exadel
Date: 2009-01-23 07:45:58 -0500 (Fri, 23 Jan 2009)
New Revision: 12380
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/bean/AutoTestBean.java
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dropDownMenu/dropDownMenuAutoTest.xhtml
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/AutoTester.java
Log:
RF-5814, RF-5811
Modified: trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/bean/AutoTestBean.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/bean/AutoTestBean.java 2009-01-23 10:04:27 UTC (rev 12379)
+++ trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/bean/AutoTestBean.java 2009-01-23 12:45:58 UTC (rev 12380)
@@ -45,7 +45,7 @@
public static final String INPUT_TEXT = "Text";
public static final String STATUS_ID = "_auto_status";
-
+
public static final String UPDATE_MODEL_STATUS = "UpdateModel";
public static final String PROCESS_INPUT_UPDATE_MODEL = "ProcessInputUpdateModel";
@@ -487,7 +487,7 @@
}
public String getProcess() {
- return "_auto_process_input";
+ return (processSet) ? "_auto_process_input" : "_auto_input";
}
}
Modified: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dropDownMenu/dropDownMenuAutoTest.xhtml
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dropDownMenu/dropDownMenuAutoTest.xhtml 2009-01-23 10:04:27 UTC (rev 12379)
+++ trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dropDownMenu/dropDownMenuAutoTest.xhtml 2009-01-23 12:45:58 UTC (rev 12380)
@@ -17,11 +17,13 @@
immediate="#{autoTestBean.immediate}"
ajaxSingle="#{autoTestBean.ajaxSingle}"
value="New"
+ process="#{autoTestBean.process}"
action="#{ddmenuBean.doNew}"
- actionListener="#{autoTestBean.actionListener}">
+ actionListener="#{autoTestBean.actionListener}"
+ oncomplete="#{autoTestBean.oncomplete}">
<h:inputText id="inputRequired" value="#{ddmenuBean.input}" style="display: none" required="true"></h:inputText>
+ <f:param name="parameter1" value="value1" />
</rich:menuItem>
- <f:param name="parameter1" value="value1" />
</rich:dropDownMenu>
</ui:define>
</ui:composition>
Modified: trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/AutoTester.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/AutoTester.java 2009-01-23 10:04:27 UTC (rev 12379)
+++ trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/AutoTester.java 2009-01-23 12:45:58 UTC (rev 12380)
@@ -149,6 +149,21 @@
}
+ public void testAjaxSingleWithProcesExternalValidation(boolean checkListener) {
+ reset();
+ setupControl(TestSetupEntry.ajaxSingle, Boolean.TRUE);
+ clickLoad();
+
+ setExtrenalValidationFailed();
+ base.sendAjax();
+
+ if (checkListener) {
+ checkActionListener(false);
+ }
+ checkUpdateModel(false);
+
+ }
+
public void testAjaxSingle(boolean checkListener) {
reset();
setupControl(TestSetupEntry.ajaxSingle, Boolean.TRUE);
15 years, 12 months
JBoss Rich Faces SVN: r12379 - trunk/ui/tabPanel/src/main/java/org/richfaces/component.
by richfaces-svn-commits@lists.jboss.org
Author: dsvyatobatsko
Date: 2009-01-23 05:04:27 -0500 (Fri, 23 Jan 2009)
New Revision: 12379
Modified:
trunk/ui/tabPanel/src/main/java/org/richfaces/component/UITabPanel.java
Log:
https://jira.jboss.org/jira/browse/RF-5850
Modified: trunk/ui/tabPanel/src/main/java/org/richfaces/component/UITabPanel.java
===================================================================
--- trunk/ui/tabPanel/src/main/java/org/richfaces/component/UITabPanel.java 2009-01-23 09:42:59 UTC (rev 12378)
+++ trunk/ui/tabPanel/src/main/java/org/richfaces/component/UITabPanel.java 2009-01-23 10:04:27 UTC (rev 12379)
@@ -270,8 +270,6 @@
if(isImmediate()){
event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
- }else{
- event.setPhaseId(PhaseId.INVOKE_APPLICATION);
}
}
15 years, 12 months