JBoss Rich Faces SVN: r12418 - in trunk/test-applications/realworld/web/src/main/webapp: includes and 8 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: amarkhel
Date: 2009-01-26 07:44:43 -0500 (Mon, 26 Jan 2009)
New Revision: 12418
Modified:
trunk/test-applications/realworld/web/src/main/webapp/
trunk/test-applications/realworld/web/src/main/webapp/includes/contextMenu/CMForAlbum.xhtml
trunk/test-applications/realworld/web/src/main/webapp/includes/contextMenu/CMForImage.xhtml
trunk/test-applications/realworld/web/src/main/webapp/includes/contextMenu/CMForUser.xhtml
trunk/test-applications/realworld/web/src/main/webapp/includes/fileUpload.xhtml
trunk/test-applications/realworld/web/src/main/webapp/includes/fileUpload/multyMode.xhtml
trunk/test-applications/realworld/web/src/main/webapp/includes/fileUpload/singleMode.xhtml
trunk/test-applications/realworld/web/src/main/webapp/includes/image/breadCrumb.xhtml
trunk/test-applications/realworld/web/src/main/webapp/includes/image/comments.xhtml
trunk/test-applications/realworld/web/src/main/webapp/includes/image/imagePreview.xhtml
trunk/test-applications/realworld/web/src/main/webapp/includes/image/imageScroller.xhtml
trunk/test-applications/realworld/web/src/main/webapp/includes/misc/slideShowPooler.xhtml
trunk/test-applications/realworld/web/src/main/webapp/includes/panelBar/favoriteAlbums.xhtml
trunk/test-applications/realworld/web/src/main/webapp/includes/panelBar/tree.xhtml
trunk/test-applications/realworld/web/src/main/webapp/includes/panelBar/treeFriends.xhtml
trunk/test-applications/realworld/web/src/main/webapp/includes/search/searchResults.xhtml
trunk/test-applications/realworld/web/src/main/webapp/includes/userPrefs/friendTab.xhtml
trunk/test-applications/realworld/web/src/main/webapp/layout/menu.xhtml
trunk/test-applications/realworld/web/src/main/webapp/main.xhtml
Log:
Property changes on: trunk/test-applications/realworld/web/src/main/webapp
___________________________________________________________________
Name: svn:ignore
+ *.db
Modified: trunk/test-applications/realworld/web/src/main/webapp/includes/contextMenu/CMForAlbum.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld/web/src/main/webapp/includes/contextMenu/CMForImage.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld/web/src/main/webapp/includes/contextMenu/CMForUser.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld/web/src/main/webapp/includes/fileUpload/multyMode.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld/web/src/main/webapp/includes/fileUpload/singleMode.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld/web/src/main/webapp/includes/fileUpload.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld/web/src/main/webapp/includes/image/breadCrumb.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld/web/src/main/webapp/includes/image/comments.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld/web/src/main/webapp/includes/image/imagePreview.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld/web/src/main/webapp/includes/image/imageScroller.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld/web/src/main/webapp/includes/misc/slideShowPooler.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld/web/src/main/webapp/includes/panelBar/favoriteAlbums.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld/web/src/main/webapp/includes/panelBar/tree.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld/web/src/main/webapp/includes/panelBar/treeFriends.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld/web/src/main/webapp/includes/search/searchResults.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld/web/src/main/webapp/includes/userPrefs/friendTab.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld/web/src/main/webapp/layout/menu.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld/web/src/main/webapp/main.xhtml
===================================================================
(Binary files differ)
16 years, 8 months
JBoss Rich Faces SVN: r12417 - in trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld: error and 8 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: amarkhel
Date: 2009-01-26 07:37:09 -0500 (Mon, 26 Jan 2009)
New Revision: 12417
Added:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/util/
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/util/ConversationState.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/util/RenderLogic.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/ImageLoader.java
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/DnDManager.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/MessageManager.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/modalpanel/AlbumPopupHelper.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/modalpanel/LinkBuilder.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/modalpanel/test.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/servlet/WebUtil.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/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/TreeMyAlbumsItem.java
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/ui/EditorBean.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/ui/History.java
Log:
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-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandlerBean.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -31,15 +31,12 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Observer;
import org.jboss.seam.annotations.Scope;
+import org.richfaces.realworld.service.Constants;
@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() {
@@ -54,16 +51,16 @@
return errors.size() > 0 ;
}
- @Observer(CLEAR_ERROR_EVENT)
+ @Observer(Constants.CLEAR_ERROR_EVENT)
public void clearEvents(){
errors.clear();
}
- @Observer(ADD_ERROR_EVENT)
+ @Observer(Constants.ADD_ERROR_EVENT)
public void addToErrors(Exception e){
FacesContext context = FacesContext.getCurrentInstance();
AjaxContext ac = AjaxContext.getCurrentInstance(context);
- ac.addRenderedArea(ERROR_ID);
+ ac.addRenderedArea(Constants.ERROR_ID);
errors.add(e);
}
}
Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileManager.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileManager.java 2009-01-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileManager.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -37,13 +37,15 @@
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
+import org.richfaces.realworld.service.Constants;
@Name("fileManager")
@Scope(ScopeType.CONVERSATION)
public class FileManager {
- private static final String UPLOAD_ROOT = "uploadRoot";
- private static final String FILE_SEPARATOR = "file.separator";
+
+ private static final String _MEDIUM = "_medium";
+ private static final String _MINI = "_mini";
private String uploadRoot;
public String getUploadRoot() {
@@ -54,17 +56,13 @@
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));
+ this.setUploadRoot(fc.getExternalContext().getInitParameter(Constants.UPLOAD_ROOT));
}
public String getFileSeparator() {
- return System.getProperty(FILE_SEPARATOR);
+ return System.getProperty(Constants.FILE_SEPARATOR);
}
public boolean isDirectoryPresent(String directory) {
@@ -85,14 +83,14 @@
}
}
- public void renameDirectory(String directoryOld, String directoryNew){
+ public void renameDirectory(String directoryOld, String directoryNew) throws Exception{
String fullPath = getAbsolutePath(directoryOld);
File fileOld = new File(fullPath);
File fileNew = new File(getUploadRoot() + directoryNew);
createDirectoryIfNotExist(directoryNew);
if(fileNew.exists())
if( fileNew.isDirectory() ){
- //throw new Exception("exc");
+ throw new Exception(Constants.ALBUM_WITH_THIS_NAME_ALREADY_PRESENT);
}else{
fileNew.delete();
}
@@ -108,8 +106,8 @@
public void addImage(String fileName, byte[] data) throws IOException {
createDirectoryIfNotExist(fileName);
writeFileTodisk(data, fileName, 0, 0, "" );
- writeFileTodisk(data, fileName, 50, 50, "_mini" );
- writeFileTodisk(data, fileName, 600, 400, "_medium" );
+ writeFileTodisk(data, fileName, 50, 50, _MINI );
+ writeFileTodisk(data, fileName, 600, 400, _MEDIUM );
}
private void writeFileTodisk(byte[] data, String fileName, int width, int height, String format) throws IOException{
@@ -117,7 +115,7 @@
BufferedImage bsrc = ImageIO.read(inputStream);
if(width == 0){
String dest = getUploadRoot() + fileName;
- ImageIO.write(bsrc, "JPG", new File(dest));
+ ImageIO.write(bsrc, Constants.JPG, new File(dest));
return;
}
BufferedImage bdest = new BufferedImage(width, height,
@@ -131,13 +129,13 @@
g.drawRenderedImage(bsrc, at);
String dest = getUploadRoot() + transformPath(fileName, format);
- ImageIO.write(bdest, "JPG", new File(dest));
+ ImageIO.write(bdest, Constants.JPG, new File(dest));
inputStream.close();
}
public String transformPath(String target, String substitute){
- String begin = target.substring(0, target.lastIndexOf("."));
- String end = target.substring(target.lastIndexOf("."));
+ String begin = target.substring(0, target.lastIndexOf(Constants.DOT));
+ String end = target.substring(target.lastIndexOf(Constants.DOT));
return begin + substitute + end;
}
@@ -160,11 +158,11 @@
if(file.exists()){
file.delete();
}
- file = new File(transformPath(fullPath, "_mini"));
+ file = new File(transformPath(fullPath, _MINI));
if(file.exists()){
file.delete();
}
- file = new File(transformPath(fullPath, "_medium"));
+ file = new File(transformPath(fullPath, _MEDIUM));
if(file.exists()){
file.delete();
}
@@ -179,14 +177,14 @@
fileNew.delete();
}
fileOld.renameTo(fileNew);
- fileOld = new File(transformPath(fullPath, "_mini"));
- fileNew = new File(getAbsolutePath(transformPath(fileNameNew, "_mini")));
+ fileOld = new File(transformPath(fullPath, _MINI));
+ fileNew = new File(getAbsolutePath(transformPath(fileNameNew, _MINI)));
if(fileNew.exists()){
fileNew.delete();
}
fileOld.renameTo(fileNew);
- fileOld = new File(transformPath(fullPath, "_medium"));
- fileNew = new File(getAbsolutePath(transformPath(fileNameNew, "_medium")));
+ fileOld = new File(transformPath(fullPath, _MEDIUM));
+ fileNew = new File(getAbsolutePath(transformPath(fileNameNew, _MEDIUM)));
if(fileNew.exists()){
fileNew.delete();
}
@@ -222,7 +220,7 @@
}
public String transformToServerPath(String filename){
- String[] res = filename.split("/");
+ String[] res = filename.split(Constants.SLASH);
StringBuilder sb = new StringBuilder();
sb.append(res[0]);
for(int i = 1; i < res.length; i++){
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-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileUploadBean.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -30,6 +30,7 @@
import java.util.List;
import javax.faces.model.SelectItem;
+import org.richfaces.realworld.service.Constants;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
@@ -44,7 +45,7 @@
import org.richfaces.realworld.domain.MetaTag;
import org.richfaces.realworld.domain.Rank;
import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.ui.ConversationState;
+import org.richfaces.realworld.util.ConversationState;
import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.imaging.jpeg.JpegProcessingException;
@@ -62,121 +63,55 @@
@Scope(ScopeType.CONVERSATION)
public class FileUploadBean implements Serializable {
- private static final int MULTY_MODE_FILE_QUANTITY = 100;
+
- private static final int SINGLE_MODE_FILE_QUANTITY = 1;
+ @In
+ private User user;
- private static final String MULTY = "multy";
+ @In(create = true) @Out
+ FileWrapper fileWrapper;
+
+ @In @Out
+ private ConversationState conversationState;
- private static final String SINGLE = "single";
+ @In(create = true)
+ private FileManager fileManager;
- 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;
-
+ private String selectedMode;
+
private int fileQuantity = 1;
private boolean fileUploadRendered;
- @In(create = true)
- @Out
- FileWrapper fileWrapper;
-
- @In(create = true)
- private FileManager fileManager;
-
- 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));
-
+ Image image = constructImage(item, file);
try {
- InputStream in = new ByteArrayInputStream(file.getData());
- Metadata metadata = JpegMetadataReader.readMetadata(in);
- 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);
- 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);
- image.setWidth(width);
- int height = exifDirectory
- .getInt(ExifDirectory.TAG_EXIF_IMAGE_HEIGHT);
- image.setHeight(height);
- } else {
- if (jpgDirectory
- .containsTag(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT)) {
- int width = jpgDirectory
- .getInt(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
- image.setWidth(width);
- 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);
- image.setCreated(time);
- }
+ extractMetadata(file, image);
} catch (JpegProcessingException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new Exception(Constants.FILE_PROCESSING_ERROR));
+ return;
} catch (MetadataException me) {
- // TODO Auto-generated catch block
- me.printStackTrace();
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new Exception(Constants.FILE_PROCESSING_ERROR));
+ return;
}
file.setImage(image);
fileWrapper.getFiles().add(file);
}
-
- @Observer("fileUploadClear")
+
+ @Observer(Constants.FILE_UPLOAD_CLEAR_EVENT)
public void clearUploadData() {
fileWrapper.getFiles().clear();
}
@@ -194,15 +129,15 @@
for (FileItem file : fileWrapper.getFiles()) {
if (file.isSelected()) {
// Save file to disk
- String fileName = fileManager.transformToServerPath(file
- .getImage().getPath());
+ String fileName = fileManager.transformToServerPath(file.getImage().getPath());
try {
fileManager.addImage(fileName, file.getData());
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new Exception(Constants.FILE_SAVE_ERROR));
+ return;
}
- Events.instance().raiseEvent(ADD_IMAGE_EVENT, file.getImage());
+ // Update domain model
+ Events.instance().raiseEvent(Constants.ADD_IMAGE_EVENT, file.getImage());
} else {
temp.add(file);
}
@@ -219,11 +154,11 @@
try {
fileManager.addImage(fileName, file.getData());
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new Exception(Constants.FILE_SAVE_ERROR));
+ return;
}
// Update domain model
- Events.instance().raiseEvent(ADD_IMAGE_EVENT, file.getImage());
+ Events.instance().raiseEvent(Constants.ADD_IMAGE_EVENT, file.getImage());
}
fileWrapper.getFiles().clear();
}
@@ -236,17 +171,17 @@
this.fileUploadRendered = fileUploadRendered;
}
- @Observer("showFileUpload")
+ @Observer(Constants.SHOW_FILE_UPLOAD_EVENT)
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);
+ if (this.getSelectedMode().equals(Constants.SINGLE)) {
+ this.setFileQuantity(Constants.SINGLE_MODE_FILE_QUANTITY);
+ } else if (this.getSelectedMode().equals(Constants.MULTY)) {
+ this.setFileQuantity(Constants.MULTY_MODE_FILE_QUANTITY);
}
}
@@ -260,8 +195,8 @@
public List<SelectItem> getItems() {
List<SelectItem> list = new ArrayList<SelectItem>(2);
- list.add(new SelectItem(SINGLE, SINGLE));
- list.add(new SelectItem(MULTY, MULTY));
+ list.add(new SelectItem(Constants.SINGLE, Constants.SINGLE));
+ list.add(new SelectItem(Constants.MULTY, Constants.MULTY));
return list;
}
@@ -269,9 +204,80 @@
return selectedMode;
}
- @Observer("changeMode")
+ @Observer(Constants.CHANGE_MODE_FILE_UPLOAD_EVENT)
public void setSelectedMode(String selectedMode) {
this.selectedMode = selectedMode;
}
+ private Image constructImage(UploadItem item, FileItem file) {
+ Image image = new Image();
+ image.setUploaded(new Date());
+ image.setDescription(SAMPLE_DESCRIPTION);
+ image.setName(SAMPLE_NAME);
+ image.setSize(file.getLength() / Constants.KB);
+ String albumPath = conversationState.getSelectedAlbum().getAlbumPathFromParents(conversationState.getSelectedAlbum(),
+ new ArrayList<String>(), Constants.SLASH)+ conversationState.getSelectedAlbum().getName() + Constants.SLASH;
+ image.setPath(user.getLogin() + Constants.SLASH + albumPath + item.getFileName());
+ image.setAlbumName(conversationState.getSelectedAlbum().getName());
+ image.setAlbum(conversationState.getSelectedAlbum());
+ addRankToImage(image);
+ addMetaTags(image);
+ return image;
+ }
+
+ private void addMetaTags(Image image) {
+ List<MetaTag> tags = new ArrayList<MetaTag>();
+ image.setTags(tags);
+ image.setMeta(new ArrayList<MetaTag>(tags));
+ }
+
+ private void addRankToImage(Image image) {
+ Rank rank = new Rank();
+ rank.setHits(0L);
+ rank.setTotal(0L);
+ image.setRank(rank);
+ }
+
+ private void extractMetadata(FileItem file, Image image)
+ throws JpegProcessingException, MetadataException {
+ InputStream in = new ByteArrayInputStream(file.getData());
+ Metadata metadata = JpegMetadataReader.readMetadata(in);
+ Directory exifDirectory = metadata.getDirectory(ExifDirectory.class);
+ Directory jpgDirectory = metadata.getDirectory(JpegDirectory.class);
+ setupCameraModel(image, exifDirectory);
+ setupDimensions(image, exifDirectory, jpgDirectory);
+ setupCreatedDate(image, exifDirectory);
+ }
+
+ private void setupCreatedDate(Image image, Directory exifDirectory)
+ throws MetadataException {
+ if (exifDirectory.containsTag(ExifDirectory.TAG_DATETIME_ORIGINAL)) {
+ Date time = exifDirectory.getDate(ExifDirectory.TAG_DATETIME_ORIGINAL);
+ image.setCreated(time);
+ }
+ }
+
+ private void setupDimensions(Image image, Directory exifDirectory,
+ Directory jpgDirectory) throws MetadataException {
+ if (exifDirectory.containsTag(ExifDirectory.TAG_EXIF_IMAGE_WIDTH) && exifDirectory.containsTag(ExifDirectory.TAG_EXIF_IMAGE_HEIGHT)) {
+ int width = exifDirectory.getInt(ExifDirectory.TAG_EXIF_IMAGE_WIDTH);
+ image.setWidth(width);
+ int height = exifDirectory.getInt(ExifDirectory.TAG_EXIF_IMAGE_HEIGHT);
+ image.setHeight(height);
+ } else {
+ if (jpgDirectory.containsTag(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT)) {
+ int width = jpgDirectory.getInt(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
+ image.setWidth(width);
+ int height = jpgDirectory.getInt(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
+ image.setHeight(height);
+ }
+ }
+ }
+
+ private void setupCameraModel(Image image, Directory exifDirectory) {
+ if (exifDirectory.containsTag(ExifDirectory.TAG_MODEL)) {
+ String cameraModel = exifDirectory.getString(ExifDirectory.TAG_MODEL);
+ image.setCameraModel(cameraModel);
+ }
+ }
}
\ No newline at end of file
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-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/ImageLoader.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -29,6 +29,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
+import org.richfaces.realworld.service.Constants;
import javax.imageio.ImageIO;
@@ -41,8 +42,8 @@
@Scope(ScopeType.CONVERSATION)
public class ImageLoader implements Serializable{
- private static final String JPEG = "jpeg";
+
private static final long serialVersionUID = -1572789608594870285L;
@In(create=true)
@@ -50,21 +51,24 @@
@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 paintImageFromByteArray(OutputStream stream, Object data) throws IOException {
+ int index;
+ if(data instanceof Integer){
+ index = (Integer)data;
+ }else{
+ index = ((Long)data).intValue();
+ }
+ stream.write(fileWrapper.getFiles().get(index).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 {
+ public synchronized void paintSearchImage(OutputStream stream, Object object)
+ throws IOException {
File image = fileManager.getImage(fileManager.transformToServerPath(object.toString()));
- InputStream paintData = null;
- byte[] data = new byte[(int)image.length() - 1];
- FileInputStream fileInputStream = null;
- BufferedInputStream bufferedInputStream = null;
- if (image != null) {
+ InputStream paintData = null;
+ byte[] data = new byte[(int) image.length() - 1];
+ FileInputStream fileInputStream = null;
+ BufferedInputStream bufferedInputStream = null;
+ if (image != null) {
try {
fileInputStream = new FileInputStream(image);
bufferedInputStream = new BufferedInputStream(fileInputStream);
@@ -73,31 +77,12 @@
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
+ } finally {
+ fileInputStream.close();
+ bufferedInputStream.close();
+ paintData.close();
}
- catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }finally{
- try {
- fileInputStream.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- bufferedInputStream.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- paintData.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
+ }
stream.write(data);
}
@@ -105,7 +90,7 @@
if (null == data) {
return;
}
- File imageResource = fileManager.getImage(fileManager.transformToServerPath(data.toString()));;
+ File imageResource = fileManager.getImage(fileManager.transformToServerPath(data.toString()));
if (imageResource != null) {
FileInputStream fileInputStream = new FileInputStream(imageResource);
BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
@@ -114,12 +99,12 @@
// throw new Exception("");
// TODO
}
- try{
- BufferedImage images = ImageIO.read(paintData);
- ImageIO.write(images, JPEG, out);
- }catch(Exception e){
-
- }finally{
+ try {
+ BufferedImage images = ImageIO.read(paintData);
+ ImageIO.write(images, Constants.JPEG, out);
+ } catch (Exception e) {
+
+ } finally {
fileInputStream.close();
bufferedInputStream.close();
paintData.close();
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-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/AlbumManager.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -28,22 +28,21 @@
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.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;
-import org.richfaces.realworld.ui.ConversationState;
+import org.richfaces.realworld.service.Constants;
+import org.richfaces.realworld.util.ConversationState;
@Name("albumManager")
@Scope(ScopeType.CONVERSATION)
public class AlbumManager {
- private static final String SLASH = "/";
-
@In(create=true, required=true)
private IAlbumAction albumAction;
@@ -61,58 +60,66 @@
@In @Out
private ConversationState conversationState;
+ private static final String ADD_ERROR_EVENT = "addErrorEvent";
+
public void addAlbum(){
+ //Update domain model
albumAction.addAlbum(album);
- TreeNode parent = null;
- if(null == album.getParent()){
- parent = treeMyAlbumsItem;
- }else{
- parent = treeMyAlbumsItem.getParentItem(album.getParent().getName());
- }
+ //Correcting tree
+ TreeNode<Object> parent = findParentTreeNode();
TreeAlbumItem albumItem = new TreeAlbumItem(album.getId(), parent, album, treeMyAlbumsItem);
treeMyAlbumsItem.addAlbumToTree(parent, albumItem);
+ //Create directory on disk
List<String> list = new ArrayList<String>();
String albumPath = album.getAlbumPathFromParents(album, list, fileManager.getFileSeparator()) + album.getName();
fileManager.addDirectory(user.getLogin() + fileManager.getFileSeparator() + albumPath);
+ //Update conversation state
conversationState.setSelectedImage(null);
conversationState.setSelectedAlbum(albumItem.getAlbum());
}
+ private TreeNode<Object> findParentTreeNode() {
+ TreeNode<Object> parent = null;
+ if(null == album.getParent()){
+ parent = treeMyAlbumsItem;
+ }else{
+ parent = treeMyAlbumsItem.getNode(album.getParent().getName());
+ }
+ return parent;
+ }
+
public void editAlbum(Album album){
boolean nameChanged = !album.getName().equals(album.getChangedName());
if(nameChanged){
String directoryOld = user.getLogin() + fileManager.getFileSeparator() + album.getAlbumPathFromParents(album, new ArrayList<String>(),fileManager.getFileSeparator() )+album.getName();
- Album oldAlbum = ((TreeAlbumItem)treeMyAlbumsItem.getParentItem(album.getName())).getAlbum();
+ Album oldAlbum = ((TreeAlbumItem)treeMyAlbumsItem.getNode(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();
+ Events.instance().raiseEvent(ADD_ERROR_EVENT, e);
+ return;
}
- 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();
+ String albumOld = user.getLogin() + Constants.SLASH + album.getAlbumPathFromParents(album, new ArrayList<String>(),Constants.SLASH )+album.getName();
+ String albumNew = user.getLogin() + Constants.SLASH + oldAlbum.getAlbumPathFromParents(oldAlbum, new ArrayList<String>(),Constants.SLASH )+album.getChangedName();
albumAction.renameAllImagesFromAlbumAndChilds(album, albumOld, albumNew);
album.setName(album.getChangedName());
album.setChangedName(null);
-
}
albumAction.editAlbum(album);
treeMyAlbumsItem.updateChild(album);
}
public void deleteAlbum(Album album){
+ //Update domain model
String albumName = album.getName();
albumAction.deleteAlbum(album);
- TreeAlbumItem oldAlbum = (TreeAlbumItem)treeMyAlbumsItem.getParentItem(album.getName());
+ //Update tree
+ TreeAlbumItem oldAlbum = (TreeAlbumItem)treeMyAlbumsItem.getNode(album.getName());
oldAlbum.getParent().removeChild(album.getId());
+ //Delete from disk
fileManager.deleteDirectory(user.getLogin() + fileManager.getFileSeparator() + albumName);
}
-
- public void updateSelectedAlbum(){
- 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-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/Authenticator.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -36,45 +36,31 @@
import org.jboss.seam.core.Events;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.log.Log;
+import org.jboss.seam.security.Credentials;
import org.jboss.seam.security.Identity;
import org.richfaces.realworld.domain.User;
import org.richfaces.realworld.fileupload.FileManager;
import org.richfaces.realworld.navigation.NavigationEnum;
import org.richfaces.realworld.service.IUserAction;
-import org.richfaces.realworld.ui.ConversationState;
+import org.richfaces.realworld.util.ConversationState;
+import org.richfaces.realworld.service.Constants;
@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;
- private static final String REGISTER_LOGIN_NAME_ID = "register:loginName";
-
- private static final String REGISTER_CONFIRM_PASSWORD_ID = "register:confirmPassword";
-
- private static final String INDEX_OUTCOME = "index";
-
- private static final String ADMIN_ROLE = "admin";
-
- private static final String GUEST_ROLE = "guest";
-
- private static final String UPDATE_MAIN_AREA_EVENT = "updateMainArea";
-
private static final long serialVersionUID = -4585673256547342140L;
@Logger Log log;
@In Identity identity;
+
+ @In Credentials credentials;
@In FacesMessages facesMessages;
@@ -86,65 +72,69 @@
@In(create=true) @Out
private ConversationState conversationState;
-
- /* (non-Javadoc)
- * @see org.richfaces.realworld.service.IAuthenticator#authenticate()
- */
+
public boolean authenticate()
{
- if(null == identity.getUsername() || identity.getUsername().equals("")){
- identity.addRole(GUEST_ROLE);
- userAction.loginAnonymous();
- Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.SEARCH);
- return true;
- }
- try{
- User user = userAction.login(identity.getUsername(), identity.getPassword());
- if(user != null){
- identity.addRole(ADMIN_ROLE);
- if(!fileManager.isDirectoryPresent(identity.getUsername())){
- fileManager.addDirectory(identity.getUsername());
- }
- conversationState.setSelectedUser(user);
- Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
- return true;
- }
- }catch(Exception nre){
- facesMessages.add(INVALID_LOGIN_OR_PASSWORD);
- return false;
- }
- return false;
+ if (null == credentials.getUsername() || credentials.getUsername().equals("")) {
+ identity.addRole(Constants.GUEST_ROLE);
+ userAction.loginAnonymous();
+ Events.instance().raiseEvent(Constants.UPDATE_MAIN_AREA_EVENT,NavigationEnum.SEARCH);
+ return true;
+ }
+ try {
+ User user = userAction.login(credentials.getUsername(), credentials.getPassword());
+ if (user != null) {
+ identity.addRole(Constants.ADMIN_ROLE);
+ if (!fileManager.isDirectoryPresent(credentials.getUsername())) {
+ fileManager.addDirectory(credentials.getUsername());
+ }
+ conversationState.setSelectedUser(user);
+ Events.instance().raiseEvent(Constants.UPDATE_MAIN_AREA_EVENT,NavigationEnum.IMAGE_PREVIEW);
+ return true;
+ }
+ } catch (Exception nre) {
+ facesMessages.add(Constants.INVALID_LOGIN_OR_PASSWORD);
+ return false;
+ }
+ return false;
}
@End
public String register(User user){
- boolean errorHappened = false;
- if(!user.getPassword().equals(user.getConfirmPassword())){
+ if(checkPassword(user) || checkUserExist(user)){
+ return "";
+ }
+ userAction.register(user);
+ facesMessages.add(Constants.LOGIN_SUCCESS);
+ return Constants.INDEX_OUTCOME;
+ }
+
+ private boolean checkUserExist(User user) {
+ if(userAction.isUserExist(user.getLogin())){
UIComponent root = FacesContext.getCurrentInstance().getViewRoot();
- UIComponent component = root.findComponent(REGISTER_CONFIRM_PASSWORD_ID);
+ UIComponent component = root.findComponent(Constants.REGISTER_LOGIN_NAME_ID);
FacesContext.getCurrentInstance().addMessage(component.getClientId(FacesContext.getCurrentInstance()), new FacesMessage(
- FacesMessage.SEVERITY_ERROR, CONFIRM_PASSWORD_NOT_EQUALS_PASSWORD , CONFIRM_PASSWORD_NOT_EQUALS_PASSWORD));
- errorHappened = true;
+ FacesMessage.SEVERITY_ERROR, USER_WITH_THIS_LOGIN_ALREADY_EXIST , USER_WITH_THIS_LOGIN_ALREADY_EXIST));
+ return true;
}
- if(userAction.isUserExist(user.getLogin())){
+ return false;
+ }
+
+ private boolean checkPassword(User user) {
+ if(!user.getPassword().equals(user.getConfirmPassword())){
UIComponent root = FacesContext.getCurrentInstance().getViewRoot();
- UIComponent component = root.findComponent(REGISTER_LOGIN_NAME_ID);
+ UIComponent component = root.findComponent(Constants.REGISTER_CONFIRM_PASSWORD_ID);
FacesContext.getCurrentInstance().addMessage(component.getClientId(FacesContext.getCurrentInstance()), new FacesMessage(
- FacesMessage.SEVERITY_ERROR, USER_WITH_THIS_LOGIN_ALREADY_EXIST , USER_WITH_THIS_LOGIN_ALREADY_EXIST));
- errorHappened = true;
+ FacesMessage.SEVERITY_ERROR, CONFIRM_PASSWORD_NOT_EQUALS_PASSWORD , CONFIRM_PASSWORD_NOT_EQUALS_PASSWORD));
+ return true;
}
- if(errorHappened){
- return "";
- }
- userAction.register(user);
- facesMessages.add(LOGIN_SUCCESS);
- return INDEX_OUTCOME;
- }
+ return false;
+ }
public String loginAnonymous(){
- identity.setUsername(null);
- identity.setPassword(null);
+ credentials.setUsername(null);
+ credentials.setPassword(null);
this.authenticate();
- return MAIN_OUTCOME;
+ return Constants.MAIN_OUTCOME;
}
}
Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java 2009-01-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -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.manager;
import java.util.ArrayList;
@@ -4,6 +24,7 @@
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
+import org.richfaces.realworld.service.Constants;
import org.ajax4jsf.context.AjaxContext;
import org.jboss.seam.annotations.In;
@@ -25,12 +46,6 @@
@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;
@@ -57,37 +72,51 @@
private void handleRoot(Album dragValue) {
TreeAlbumItem itemParent = null;
if(!dragValue.getOwner().equals(user)){
- Events.instance().raiseEvent(ADD_ERROR_EVENT, new Exception(WRONG_DND));
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new Exception(Constants.WRONG_DND));
return;
}
if(dragValue.getParent() != null ){
- itemParent = treeMyAlbumsItem.getAlbumByName(dragValue.getParent().getName());
+ itemParent = (TreeAlbumItem)treeMyAlbumsItem.getNode(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());
+ try{
+ fileManager.renameDirectory(directoryOld, directoryNew);
+ } catch (Exception e) {
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, e);
+ return;
+ }
+ String albumOld = user.getLogin() + Constants.SLASH + dragValue.getAlbumPathFromParents(dragValue, new ArrayList<String>(), Constants.SLASH );
+ String albumNew = user.getLogin() + Constants.SLASH;
+ TreeAlbumItem item = (TreeAlbumItem)treeMyAlbumsItem.getNode(dragValue.getName());
itemParent.removeChild(item.getId());
treeMyAlbumsItem.addChild(item.getId(), item);
- fileManager.renameDirectory(directoryOld, directoryNew);
albumAction.renameAllImagesFromAlbumAndChilds(dragValue, albumOld, albumNew);
-
+ addTreeToRerender();
}
+ private void addTreeToRerender() {
+ try {
+ FacesContext fc = FacesContext.getCurrentInstance();
+ AjaxContext ac = AjaxContext.getCurrentInstance();
+ UIComponent destTree = fc.getViewRoot().findComponent(Constants.TREE_ID);
+ ac.addComponentToAjaxRender(destTree);
+ } catch (Exception e) {
+ System.err.print(e.getMessage());
+ }
+ }
+
private void handleAlbum(Album dragValue, Album dropValue) {
- TreeNode itemParent = null;
+ TreeNode<Object> itemParent = null;
if(!dragValue.getOwner().equals(user)){
- Events.instance().raiseEvent(ADD_ERROR_EVENT, new Exception(WRONG_DND));
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new Exception(Constants.WRONG_DND));
return;
}
if(dragValue.getParent() != null ){
- itemParent = treeMyAlbumsItem.getAlbumByName(dragValue.getParent().getName());
+ itemParent = treeMyAlbumsItem.getNode(dragValue.getParent().getName());
if(dragValue.getParent().equals(dropValue)){
return;
}
@@ -96,23 +125,21 @@
}
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);
+ String albumOld = user.getLogin() + Constants.SLASH + dragValue.getAlbumPathFromParents(dragValue, new ArrayList<String>(), Constants.SLASH );
+ String albumNew = user.getLogin() + Constants.SLASH + dropValue.getAlbumPathFromParents(dropValue, new ArrayList<String>(), Constants.SLASH);
dropValue.addChildAlbum(dragValue);
- TreeAlbumItem itemParentNew = treeMyAlbumsItem.getAlbumByName(dropValue.getName());
- TreeAlbumItem item = treeMyAlbumsItem.getAlbumByName(dragValue.getName());
+ TreeAlbumItem itemParentNew = (TreeAlbumItem)treeMyAlbumsItem.getNode(dropValue.getName());
+ TreeAlbumItem item = (TreeAlbumItem)treeMyAlbumsItem.getNode(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);
+ try{
+ fileManager.renameDirectory(directoryOld, directoryNew);
} catch (Exception e) {
- //System.err.print(e.getMessage());
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, e);
+ return;
}
+ albumAction.renameAllImagesFromAlbumAndChilds(dragValue, albumOld, albumNew);
+ addTreeToRerender();
}
private void handleImage(Image dragValue, Album dropValue) {
@@ -120,10 +147,10 @@
return;
}
String fileNameOld = fileManager.transformToServerPath(dragValue.getPath());
- int lastIndexOf = dragValue.getPath().lastIndexOf(SLASH);
+ int lastIndexOf = dragValue.getPath().lastIndexOf(Constants.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;
+ String newPath = user.getLogin() + Constants.SLASH + dropValue.getAlbumPathFromParents(dropValue, new ArrayList<String>(), Constants.SLASH) + prevPathEnd;
dragValue.setPath(newPath);
dropValue.addImage(dragValue);
fileManager.renameImage(fileNameOld, fileNameNew);
Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java 2009-01-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -40,21 +40,16 @@
import org.richfaces.realworld.tree.TreeAlbumItem;
import org.richfaces.realworld.tree.TreeMyAlbumsItem;
import org.richfaces.realworld.ui.RatingBinder;
-import org.richfaces.realworld.ui.ConversationState;
+import org.richfaces.realworld.util.ConversationState;
+import org.richfaces.realworld.service.Constants;
@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;
@@ -76,17 +71,16 @@
}
public void editImage(Image image){
- TreeAlbumItem parent = treeMyAlbumsItem.getAlbumByName(image.getAlbum().getName());
+ TreeAlbumItem parent = (TreeAlbumItem)treeMyAlbumsItem.getNode(image.getAlbum().getName());
boolean parentChanged = !parent.getAlbum().getName().equals(image.getAlbumName());
-
if(parentChanged){
- TreeAlbumItem albumItem = treeMyAlbumsItem.getAlbumByName(image.getAlbumName());
+ TreeAlbumItem albumItem = (TreeAlbumItem)treeMyAlbumsItem.getNode(image.getAlbumName());
String fileNameOld = fileManager.transformToServerPath(image.getPath());
- int lastIndexOf = image.getPath().lastIndexOf("/");
+ int lastIndexOf = image.getPath().lastIndexOf(Constants.SLASH);
String prevPathEnd = image.getPath().substring(lastIndexOf);
- Album dropValue = treeMyAlbumsItem.getAlbumByName(image.getAlbumName()).getAlbum();
+ Album dropValue = ((TreeAlbumItem)treeMyAlbumsItem.getNode(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;
+ String newPath = user.getLogin() + Constants.SLASH + albumItem.getAlbum().getAlbumPathFromParents(albumItem.getAlbum(), new ArrayList<String>(), Constants.SLASH) + prevPathEnd;
image.setPath(newPath);
fileManager.renameImage(fileNameOld, fileNameNew);
conversationState.setSelectedImage(image);
@@ -95,25 +89,17 @@
imageAction.editImage(image, parentChanged);
}
- @Observer("addImage")
+ @Observer(Constants.ADD_IMAGE_EVENT)
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 = treeMyAlbumsItem.getAlbumByName(image.getAlbumName());
+ TreeAlbumItem albumItem = (TreeAlbumItem)treeMyAlbumsItem.getNode(image.getAlbumName());
conversationState.setSelectedAlbum(albumItem.getAlbum());
- Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
+ Events.instance().raiseEvent(Constants.UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
}
public void editComment(Comment comment) {
imageAction.editComment(comment);
}
-
- public void addComment(Comment comment) {
- imageAction.addComment(comment);
- }
public void addAutoComment(Image image) {
Comment comment = new Comment();
@@ -124,7 +110,17 @@
imageAction.addComment(comment);
}
+ public void addComment(Image image, String message){
+ Comment comment= new Comment();
+ comment.setAuthor(user);
+ comment.setImage(image);
+ comment.setDate(new Date());
+ comment.setMessage(message);
+ imageAction.addComment(comment);
+ Events.instance().raiseEvent(Constants.CLEAR_EDITOR_EVENT, "");
+ }
+
public void vote(Image image){
- imageAction.vote(image, (Long)Long.valueOf(ratingBinder.getInputSlider().getValue().toString()));
+ imageAction.vote(image, Long.valueOf(ratingBinder.getInputSlider().getValue().toString()));
}
}
Modified: 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 2009-01-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/MessageManager.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -23,8 +23,6 @@
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;
@@ -35,8 +33,8 @@
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;
+import org.richfaces.realworld.service.Constants;
@Name("messageManager")
@Scope(ScopeType.CONVERSATION)
@@ -44,8 +42,6 @@
private static final long serialVersionUID = 2561824019376412988L;
- private static final String UPDATE_MAIN_AREA_EVENT = "updateMainArea";
-
@In
private User user;
@@ -65,7 +61,7 @@
}
public void showHistory(User u){
- Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.READ_MESSAGES);
+ Events.instance().raiseEvent(Constants.UPDATE_MAIN_AREA_EVENT, NavigationEnum.READ_MESSAGES);
history.setSelected(true);
history.setHistoryUser(u);
}
@@ -83,7 +79,7 @@
}else{
this.messageForSend = new Message();
this.messageForSend.setAuthor(user);
- if(theme.startsWith("Re:")){
+ if(theme.startsWith(Constants.RE)){
this.messageForSend.setTheme(theme + this.message.getTheme());
}else{
this.messageForSend.setTheme(theme);
@@ -92,7 +88,7 @@
this.messageForSend.setMessage(content);
this.messageForSend.setFriendshipRequest(isFrRequest);
}
- Events.instance().raiseEvent("updateMainArea", NavigationEnum.READ_MESSAGES);
+ Events.instance().raiseEvent(Constants.UPDATE_MAIN_AREA_EVENT, NavigationEnum.READ_MESSAGES);
}
public void initMessage(){
Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/UserManager.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/UserManager.java 2009-01-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/UserManager.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -23,56 +23,34 @@
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.navigation.NavigationEnum;
-import org.richfaces.realworld.service.IMessageAction;
import org.richfaces.realworld.service.IUserAction;
import org.richfaces.realworld.tree.TreeFriendItem;
import org.richfaces.realworld.tree.TreeFriendsItem;
-import org.richfaces.realworld.ui.History;
-import org.richfaces.realworld.ui.ConversationState;
+import org.richfaces.realworld.service.Constants;
@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;
@In("#{messages['removedfromfriendsby']}") private String YOU_ARE_WERE_REMOVED_FROM_FRIENDS_MESSAGE;
- 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;
@@ -81,32 +59,12 @@
@In(create=true, required=true)
private IUserAction userAction;
-
- @In(create=true) @Out
- private ConversationState conversationState;
public List<String> availableUserLogins(Object suggest){
List<String> suggestions = userAction.getUsers((String)suggest);
return suggestions;
}
-
- public void showUserProfile(){
- conversationState.setSelectedUser(user);
- conversationState.setSecondSelectedUser(null);
- Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.USER_PREFS);
- }
- public void showUserProfile(User user){
- conversationState.setSelectedUser(user);
- conversationState.setSecondSelectedUser(null);
- Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.USER_PREFS);
- }
-
- 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());
@@ -118,7 +76,7 @@
message.setReaded(false);
message.setMessage(YOU_ARE_WERE_REMOVED_FROM_FRIENDS_MESSAGE+ user.getLogin());
message.setTheme(REMOVED_FROM_FRIENDS_MESSAGE_THEME);
- Events.instance().raiseEvent(SEND_MESSAGE, message);
+ Events.instance().raiseEvent(Constants.SEND_MESSAGE_EVENT, message);
}
public void addToFriends(User friend){
@@ -128,29 +86,24 @@
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());
- message.setOwner(friend);
- message.setFriendshipRequest(false);
- message.setReaded(false);
- message.setMessage(ADDED_TO_FRIENDS_MESSAGE+ user.getLogin());
- message.setTheme(ADDED_TO_FRIENDS_MESSAGE_THEME);
- Events.instance().raiseEvent(SEND_MESSAGE, message);
+ sendAcquireMessage(friend);
}
}else{
- Events.instance().raiseEvent(ADD_ERROR_EVENT, new Exception(FRIEND_ERROR_MESSAGE));
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new Exception(Constants.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, "");
+
+ private void sendAcquireMessage(User friend) {
+ Message message = new Message();
+ message.setAuthor(user);
+ message.setDate(new Date());
+ message.setOwner(friend);
+ message.setFriendshipRequest(false);
+ message.setReaded(false);
+ message.setMessage(ADDED_TO_FRIENDS_MESSAGE+ user.getLogin());
+ message.setTheme(ADDED_TO_FRIENDS_MESSAGE_THEME);
+ Events.instance().raiseEvent(Constants.SEND_MESSAGE_EVENT, message);
}
public void addToFavoriteAlbums(Album album){
@@ -169,73 +122,12 @@
userAction.removeFromFavoriteImages(user, 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);
- conversationState.setSelectedAlbum(image.getAlbum());
- conversationState.setSelectedImage(image);
- setDataScrollerIndex(image.getAlbum().getIndex(image));
- conversationState.setSelectedUser(image.getAlbum().getOwner());
- }
-
- public void showUser(User u){
- Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
- conversationState.setSelectedAlbum(null);
- conversationState.setSelectedImage(null);
- conversationState.setSelectedUser(u);
- }
-
- 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);
+ int i = path.lastIndexOf(Constants.SLASH);
return path.substring(i);
}
}
Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/modalpanel/AlbumPopupHelper.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/modalpanel/AlbumPopupHelper.java 2009-01-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/modalpanel/AlbumPopupHelper.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -60,7 +60,6 @@
this.album = new Album();
this.parent = null;
}
-
}
public void initAlbumData( String actionName, String caption, Album album, Album parent){
Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/modalpanel/LinkBuilder.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/modalpanel/LinkBuilder.java 2009-01-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/modalpanel/LinkBuilder.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -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.modalpanel;
import java.io.Serializable;
@@ -13,67 +33,60 @@
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
+import org.richfaces.realworld.service.Constants;
@Name("linkBuilder")
@Scope(ScopeType.CONVERSATION)
public class LinkBuilder implements Serializable{
private static final long serialVersionUID = 2561824019376412988L;
- private static final String MINI_FORMAT = "_mini";
- private static final String MEDIUM_FORMAT = "_medium";
@In("#{messages['small']}") private String SMALL;
@In("#{messages['medium']}") private String MEDIUM;
@In("#{messages['full']}") private String FULL;
private Long scaleChoice = 1L;
- private String generatedLink;
- private String currentFormat = URL;
+ private String currentFormat = Constants.URL;
private String path;
- private static String URL = "URL";
- private static String HTML = "HTML";
- private static String FORUM = "Forum";
- private static String HTML_PATTERN = "<a href='%s'><img src='%s' border='0'></a>";
- private static String FORUM_PATTERN = "[URL=%s][IMG]%s[/IMG][/URL]";
public String getGeneratedLink() {
-
- ServletRequest servletRequest = ((ServletRequest)(FacesContext.getCurrentInstance().getExternalContext().getRequest()));
- ServletContext s = (ServletContext)(FacesContext.getCurrentInstance().getExternalContext().getContext());
- String protocol = servletRequest.getProtocol().equals("HTTP/1.1") || servletRequest.getProtocol().equals("HTTP/1.0") ? "http://" : "https://" ;
- String servletPath = protocol + servletRequest.getLocalAddr() + ":" + servletRequest.getLocalPort() + s.getContextPath();
+ String serverPath = getServerPath();
String link = null;
String tempPath = null;
if(getScaleChoice() == 3L){
- tempPath = MINI_FORMAT;
+ tempPath = Constants.MINI_FORMAT;
}else if(getScaleChoice() == 2L){
- tempPath = MEDIUM_FORMAT;
+ tempPath = Constants.MEDIUM_FORMAT;
}else if(getScaleChoice() == 1L){
tempPath="";
}
if(null == path){
return "";
}
- if(getCurrentFormat().equals(URL)){
- link = servletPath + "/picture/" + transformPath(path, tempPath);
+ if(getCurrentFormat().equals(Constants.URL)){
+ link = serverPath + Constants.PICTURE_FOLDER_PATH + transformPath(path, tempPath);
}else
- if(getCurrentFormat().equals(HTML)){
- link = String.format(HTML_PATTERN, servletPath, servletPath+ "/pictures/" + transformPath(path, tempPath));
+ if(getCurrentFormat().equals(Constants.HTML)){
+ link = String.format(Constants.HTML_PATTERN, serverPath, serverPath + Constants.PICTURE_FOLDER_PATH + transformPath(path, tempPath));
}else
- if(getCurrentFormat().equals(FORUM)){
- link = String.format(FORUM_PATTERN, servletPath, servletPath+ "/pictures/" + transformPath(path, tempPath));
+ if(getCurrentFormat().equals(Constants.FORUM)){
+ link = String.format(Constants.FORUM_PATTERN, serverPath, serverPath + Constants.PICTURE_FOLDER_PATH + transformPath(path, tempPath));
}
return link;
}
+
+ private String getServerPath() {
+ ServletRequest servletRequest = ((ServletRequest)(FacesContext.getCurrentInstance().getExternalContext().getRequest()));
+ ServletContext s = (ServletContext)(FacesContext.getCurrentInstance().getExternalContext().getContext());
+ String protocol = servletRequest.getProtocol().equals(Constants.HTTP_1_1) || servletRequest.getProtocol().equals(Constants.HTTP_1_0) ? Constants.HTTP : Constants.HTTPS ;
+ String servletPath = protocol + servletRequest.getLocalAddr() + ":" + servletRequest.getLocalPort() + s.getContextPath();
+ return servletPath;
+ }
private String transformPath(String target, String substitute){
- String begin = target.substring(0, target.lastIndexOf("."));
- String end = target.substring(target.lastIndexOf("."));
+ String begin = target.substring(0, target.lastIndexOf(Constants.DOT));
+ String end = target.substring(target.lastIndexOf(Constants.DOT));
return begin + substitute + end;
}
- public void setGeneratedLink(String generatedLink) {
- this.generatedLink = generatedLink;
- }
-
public List<SelectItem> getItems() {
List<SelectItem> list = new ArrayList<SelectItem>(4);
list.add(new SelectItem(Long.valueOf(1L), FULL));
Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/modalpanel/test.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/modalpanel/test.java 2009-01-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/modalpanel/test.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -3,15 +3,10 @@
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
-import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
@@ -26,76 +21,10 @@
* @throws IOException
*/
public static void main(String[] args) throws IOException {
- //String directory ="C:\\Documents and Settings\\Administrator\\Desktop\\Fun";
- //writeFiles(directory, "_mini", 100, 100);
- //transform();
- //String oldDirectory = "E:\\richfaces\\test-applications\\realworld\\Upload\\amarkhel\\Cars\\Child2";
- //String newDirectory = "E:\\richfaces\\test-applications\\realworld\\Upload\\amarkhel\\Cars\\Child1\\Child2";
- //renameDirectory(oldDirectory, newDirectory);
-
- //Album a = init();
- //renameAllImagesFromAlbumAndChilds(a, "Album", "Albums/Album");
- String s1 = "amarkhel+qwe";
- String s2 = "amarkhel-qwe+rich";
- String s3 = "amarkhel";
- String s4 = "";
- String s5 = "+amarkhel";
- String s6 = "a+b";
- String s7 = "as+we+dfg-ret-df+deee-dff+ffgh";
- ArrayList<String> a = new ArrayList<String>();
- ArrayList<String> b = new ArrayList<String>();
-
- //parse(s1, a, b);
- a.clear();
- b.clear();
- //parse(s2, a, b);
- a.clear();
- b.clear();
- //parse(s3, a, b);
- a.clear();
- b.clear();
- //parse(s4, a, b);
- a.clear();
- b.clear();
- //parse(s5, a, b);
- a.clear();
- b.clear();
- //parse(s6, a, b);
- a.clear();
- b.clear();
- //parse(s7, a, b);
- a.clear();
- b.clear();
+ String directory ="C:\\Documents and Settings\\Administrator\\Desktop\\Fun";
+ writeFiles(directory, "_mini", 100, 100);
}
- private static Album init() {
- Album a = new Album();
- a.setName("Album");
- Album a1 = new Album();
- a1.setName("Album1");
- Album a2 = new Album();
- a2.setName("Album2");
- Album a3 = new Album();
- a3.setName("Album3");
- Image i = new Image();
- i.setPath("user/amarkhel/Album/i.jpg");
- Image i1 = new Image();
- i1.setPath("user/amarkhel/Album/Album1/i1.jpg");
- Image i2 = new Image();
- i2.setPath("user/amarkhel/Album/Album1/Album2/i2.jpg");
- Image i3 = new Image();
- i3.setPath("user/amarkhel/Album/Album3/i3.jpg");
-
- a.addImage(i);
- a1.addImage(i1);
- a2.addImage(i2);
- a3.addImage(i3);
- a1.addChildAlbum(a2);
- a.addChildAlbum(a1);
- a.addChildAlbum(a3);
- return a;
- }
-
public static void renameAllImagesFromAlbumAndChilds(Album album, String replace,
String forReplace) {
for(Image image: album.getImages()){
@@ -103,7 +32,6 @@
image.setPath(image.getPath().replaceAll(replace, forReplace));
System.out.println(image.getPath());
}
-
for(Album a:album.getChildAlbums()){
String replace2 = replace + "/" + a.getName();
String forReplace2 = forReplace + "/" + a.getName();
@@ -156,78 +84,7 @@
return begin + substitute + end;
}
- 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){
- System.out.println("Error");
- return false;
- }
- if(str.lastIndexOf('+')==-1 && str.lastIndexOf('-')==-1){
- adds.add(str);
- return false;
- }
- 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 {
- System.out.println("Error");
- 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 {
- System.out.println("Error");
- 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));
- }
- adds.remove(0);
- return true;
- }
-
- private static void transform() throws IOException{
+ /*private static void transform() throws IOException{
File temp = new File("E:\\richfaces\\test-applications\\realworld\\Upload\\galleries\\Nature\\1.jpg");
BufferedImage bsrc =null;
bsrc = ImageIO.read(temp);
@@ -242,5 +99,5 @@
AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
bsrc = op.filter(bsrc, null);
ImageIO.write(bsrc, "JPG", temp);
- }
+ }*/
}
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-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/servlet/PictureServlet.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -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.servlet;
import java.io.BufferedInputStream;
@@ -6,10 +26,8 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-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;
@@ -18,74 +36,38 @@
import org.richfaces.realworld.domain.Image;
import org.richfaces.realworld.domain.User;
import org.richfaces.realworld.fileupload.FileManager;
+import org.richfaces.realworld.service.Constants;
public class PictureServlet extends javax.servlet.http.HttpServlet {
+
public static final long serialVersionUID = 596009789004L;
- 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));
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ String fileName = WebUtil.getFileName(request.getPathInfo());
+ if(!isAccessGranted(request, response, request.getPathInfo())){
+ sendToErrorPage(request, response);
+ return;
}
- 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;
- }
+ byte[] data = getImageData(request, response, fileName);
+ if(data == null){
+ sendToErrorPage(request, response);
+ return;
}
+ response.setContentType(Constants.IMAGE_JPG);
+ response.setContentLength((int) data.length - 1);
+ response.getOutputStream().write(data);
+ response.getOutputStream().flush();
+ response.getOutputStream().close();
+ }
+
+ private byte[] getImageData(HttpServletRequest request,
+ HttpServletResponse response, String fileName) throws IOException {
if (fileName == null) {
- String contextPath = request.getContextPath();
- response.sendRedirect(contextPath + "/error.seam");
- return;
+ return null;
}
- ServletContext context = getServletContext();
- //FileHelper helper = new FileHelper(context.getInitParameter(UPLOAD_ROOT));
+ FileManager fileManager = (FileManager)Component.getInstance(Constants.FILE_MANAGER, true);
File file = fileManager.getImage(fileName);
- /*try {
- Metadata metadata = JpegMetadataReader.readMetadata(file);
- Directory exifDirectory = metadata.getDirectory(ExifDirectory.class);
- if(exifDirectory.containsTag(ExifDirectory.TAG_MODEL)){
- String cameraModel = exifDirectory.getString(ExifDirectory.TAG_MODEL);
- System.out.println(cameraModel);
- }
- if(exifDirectory.containsTag(ExifDirectory.TAG_EXIF_IMAGE_WIDTH)){
- int width = exifDirectory.getInt(ExifDirectory.TAG_EXIF_IMAGE_WIDTH);
- System.out.println(width);
- }
- if(exifDirectory.containsTag(ExifDirectory.TAG_EXIF_IMAGE_HEIGHT)){
- int height = exifDirectory.getInt(ExifDirectory.TAG_EXIF_IMAGE_HEIGHT);
- System.out.println(height);
- }
- if(exifDirectory.containsTag(ExifDirectory.TAG_DATETIME_ORIGINAL)){
- Date time = exifDirectory.getDate(ExifDirectory.TAG_DATETIME_ORIGINAL);
- System.out.println(time);
- }
- }
- catch (JpegProcessingException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (MetadataException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }*/
InputStream paintData = null;
byte[] data = new byte[(int) file.length() - 1];
FileInputStream fileInputStream = null;
@@ -97,36 +79,57 @@
paintData = bufferedInputStream;
paintData.read(data);
} catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ return null;
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ return null;
} finally {
try {
fileInputStream.close();
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ return null;
}
try {
bufferedInputStream.close();
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ return null;
}
try {
paintData.close();
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ return null;
}
}
}
- response.setContentType("image/jpg");
- response.setContentLength((int) data.length - 1);
- response.getOutputStream().write(data);
- response.getOutputStream().flush();
- response.getOutputStream().close();
+ return data;
}
+
+ private boolean isAccessGranted(HttpServletRequest request,
+ HttpServletResponse response, String pathInfo) throws IOException {
+ String userId = request.getParameter(Constants.USER_ID);
+ EntityManager em = (EntityManager)Component.getInstance(Constants.ENTITY_MANAGER, 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(Constants.PATH_PARAMETER, 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{
+ return false;
+ }
+ }else{
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private void sendToErrorPage(HttpServletRequest request,
+ HttpServletResponse response) throws IOException {
+ String contextPath = request.getContextPath();
+ response.sendRedirect(contextPath + Constants.ERROR_PAGE);
+ return;
+ }
}
Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/servlet/WebUtil.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/servlet/WebUtil.java 2009-01-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/servlet/WebUtil.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -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.servlet;
public class WebUtil {
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-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/slideshow/SlideshowBean.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -27,16 +27,12 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
-import org.richfaces.realworld.tree.TreeManager;
+import org.richfaces.realworld.service.Constants;
@Name("slideshow")
@Scope(ScopeType.CONVERSATION)
public class SlideshowBean implements Serializable{
- private static final int INITIAL_DELAY = 10000;
-
- private static final int DELAY = 1000;
-
private static final long serialVersionUID = 7801877176558409702L;
@In(required=false) @Out(required=false)
@@ -44,7 +40,7 @@
private boolean active;
- private int interval = INITIAL_DELAY;
+ private int interval = Constants.INITIAL_DELAY;
public int getInterval() {
return interval;
@@ -71,6 +67,6 @@
}
public void updateInterval(){
- this.setInterval((int)(DELAY * Long.valueOf(slideshowHelper.getInputSlider().getValue().toString())));
+ this.setInterval((int)(Constants.DELAY * Long.valueOf(slideshowHelper.getInputSlider().getValue().toString())));
}
}
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-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeAlbumItem.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -28,27 +28,21 @@
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;
+import org.richfaces.realworld.service.Constants;
-public class TreeAlbumItem implements TreeNode {
+public class TreeAlbumItem implements TreeNode<Object> {
- private static final String ALBUM_NODE_TYPE = "album";
TreeMyAlbumsItem treeMyAlbumsItem;
private static final long serialVersionUID = 6514596192023597908L;
private long id;
- private Map<Object, TreeNode> childs = new LinkedHashMap<Object, TreeNode>();
+ private Map<Object, TreeNode<Object>> childs = new LinkedHashMap<Object, TreeNode<Object>>();
private Album album;
- TreeNode parent;
+ TreeNode<Object> parent;
- public TreeAlbumItem(long id, TreeNode parent, Album album, TreeMyAlbumsItem treeMyAlbumsItem) {
+ public TreeAlbumItem(long id, TreeNode<Object> parent, Album album, TreeMyAlbumsItem treeMyAlbumsItem) {
this.id = id;
this.parent = parent;
this.album = album;
@@ -64,20 +58,20 @@
alb.setParent(this);
}
- public void addChild(Object identifier, TreeNode child) {
+ public void addChild(Object identifier, TreeNode<Object> child) {
childs.put(identifier, child);
}
- public TreeNode getChild(Object id) {
- return (TreeNode) childs.get(id);
+ public TreeNode<Object> getChild(Object id) {
+ return (TreeNode<Object>) childs.get(id);
}
- public Iterator<Map.Entry<Object, TreeNode>> getChildren() {
+ public Iterator<Map.Entry<Object, TreeNode<Object>>> getChildren() {
return childs.entrySet().iterator();
}
- public List<TreeNode> getAlbums() {
- List<TreeNode> childCollection = new ArrayList<TreeNode>();
+ public List<TreeNode<Object>> getAlbums() {
+ List<TreeNode<Object>> childCollection = new ArrayList<TreeNode<Object>>();
childCollection.addAll(childs.values());
return childCollection;
}
@@ -86,7 +80,7 @@
return this;
}
- public TreeNode getParent() {
+ public TreeNode<Object> getParent() {
return parent;
}
@@ -101,7 +95,7 @@
public void setData(Object data) {
}
- public void setParent(TreeNode parent) {
+ public void setParent(TreeNode<Object> parent) {
this.parent = parent;
}
@@ -121,7 +115,7 @@
}
public String getType() {
- return ALBUM_NODE_TYPE;
+ return Constants.ALBUM_NODE_TYPE;
}
public String toString(){
@@ -129,13 +123,13 @@
}
public boolean containAlbum(Album selectedAlbum) {
- for(TreeNode item : this.childs.values()){
+ for(TreeNode<Object> 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()){
+ for(TreeNode<Object> a : node.getAlbums()){
TreeAlbumItem temp = (TreeAlbumItem)a;
return temp.containAlbum(selectedAlbum);
}
@@ -146,7 +140,7 @@
public List<SelectItem> getArrayOfChildsAlbumsNames() {
List<SelectItem> items = new ArrayList<SelectItem>();
- for(TreeNode item: this.getAlbums()){
+ for(TreeNode<Object> item: this.getAlbums()){
TreeAlbumItem a = (TreeAlbumItem)item;
String pathFromParents = a.getAlbum().getAlbumPathFromParents(a.getAlbum(), new ArrayList<String>(), "/");
SelectItem e = new SelectItem(pathFromParents);
@@ -157,7 +151,7 @@
}
public void getArrayOfChildsAlbumsNames(List<SelectItem> list) {
- for(TreeNode item: this.getAlbums()){
+ for(TreeNode<Object> item: this.getAlbums()){
TreeAlbumItem a = (TreeAlbumItem)item;
String pathFromParents = this.getAlbum().getAlbumPathFromParents(this.getAlbum(), new ArrayList<String>(), "/");
SelectItem e = new SelectItem(pathFromParents);
Modified: 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 2009-01-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendItem.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -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.tree;
import java.util.HashMap;
@@ -5,38 +25,34 @@
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;
+import org.richfaces.realworld.service.Constants;
@Name("treeFriendAlbum")
@Scope(ScopeType.CONVERSATION)
-public class TreeFriendItem implements TreeNode{
+public class TreeFriendItem implements TreeNode<Object>{
- private static final String TYPE = "treeFriendAlbum";
-
private long id;
private User friend;
- public TreeFriendItem(long id, TreeNode parent, User friend){
+ public TreeFriendItem(long id, TreeNode<Object> parent, User friend){
this.id = id;
this.parent = parent;
this.friend = friend;
}
public UserManager getUserManager() {
- return (UserManager) Contexts.getConversationContext().get("userManager");
+ return (UserManager) Contexts.getConversationContext().get(Constants.USER_MANAGER);
}
- private TreeNode parent;
+ private TreeNode<Object> parent;
private static final long serialVersionUID = -3530085227471752526L;
@@ -49,13 +65,13 @@
return this.albums;
}
- public void addChild(Object identifier, TreeNode child) {
+ public void addChild(Object identifier, TreeNode<Object> child) {
getAlbums().put((Long)identifier, (TreeAlbumItem)child);
child.setParent(this);
}
- public TreeNode getChild(Object id) {
- return (TreeNode) albums.get(id);
+ public TreeNode<Object> getChild(Object id) {
+ return (TreeNode<Object>) albums.get(id);
}
public Iterator getChildren() {
@@ -66,7 +82,7 @@
return this;
}
- public TreeNode getParent() {
+ public TreeNode<Object> getParent() {
return parent;
}
@@ -82,12 +98,12 @@
this.friend = (User)data;
}
- public void setParent(TreeNode parent) {
+ public void setParent(TreeNode<Object> parent) {
this.parent = parent;
}
public String getType() {
- return TYPE;
+ return Constants.TREE_FRIEND_ALBUM_TYPE;
}
private void initData() {
Modified: 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 2009-01-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendRootItem.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -20,44 +20,36 @@
*/
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;
+import org.richfaces.realworld.service.Constants;
@Name("treeFriendRoot")
@Scope(ScopeType.CONVERSATION)
-public class TreeFriendRootItem implements TreeNode {
+public class TreeFriendRootItem implements TreeNode<Object> {
@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;
+ private Map<Long, TreeNode<Object>> childs;
- public void addChild(Object identifier, TreeNode child) {
+ public void addChild(Object identifier, TreeNode<Object> child) {
getChilds().put((Long)identifier, child);
child.setParent(this);
}
- public TreeNode getChild(Object id) {
+ public TreeNode<Object> getChild(Object id) {
return getChilds().get(id);
}
@@ -69,7 +61,7 @@
return this;
}
- public TreeNode getParent() {
+ public TreeNode<Object> getParent() {
return null;
}
@@ -84,14 +76,14 @@
public void setData(Object data) {
}
- public void setParent(TreeNode parent) {
+ public void setParent(TreeNode<Object> parent) {
}
public String getType() {
- return TREE_ROOT_NODE_TYPE;
+ return Constants.TREE_FRIEND_ROOT_NODE_TYPE;
}
- public Map<Long, TreeNode> getChilds() {
+ public Map<Long, TreeNode<Object>> getChilds() {
if (this.childs==null) {
initialise();
}
@@ -99,16 +91,13 @@
}
private void initialise() {
- childs = new HashMap<Long, TreeNode>();
- //TreeMyAlbumsItem item = new TreeMyAlbumsItem(1L, this);
- //childs.put(item.getId(), item);
+ childs = new HashMap<Long, TreeNode<Object>>();
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) {
+ public void setChilds(Map<Long, TreeNode<Object>> childs) {
this.childs = childs;
}
}
Modified: 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 2009-01-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendsItem.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -1,115 +1,125 @@
+/**
+ * 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;
+import org.richfaces.realworld.service.Constants;
+
@Name("treeFriendsAlbums")
@Scope(ScopeType.CONVERSATION)
-public class TreeFriendsItem implements TreeNode{
-
- private static final String TYPE = "treeFriendsAlbums";
+public class TreeFriendsItem implements TreeNode<Object> {
- 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;
+ private long id;
- 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 TreeFriendsItem(long id, TreeNode<Object> parent) {
+ this.id = id;
+ this.parent = parent;
+ }
- public TreeNode getChild(Object id) {
- return (TreeNode) friends.get(id);
- }
+ private TreeNode<Object> parent;
- public Iterator getChildren() {
- return getFriends().entrySet().iterator();
- }
+ private static final long serialVersionUID = -3530085227471752526L;
- public Object getData() {
- return this;
- }
+ private Map<Long, TreeFriendItem> friends = null;
- public TreeNode getParent() {
- return parent;
+ public Map<Long, TreeFriendItem> getFriends() {
+ if (this.friends == null) {
+ initData();
}
+ return this.friends;
+ }
- public boolean isLeaf() {
- return getFriends().isEmpty();
- }
+ public void addAlbumToTree(TreeFriendItem friend) {
+ addChild(friend.getId(), friend);
+ }
- public void removeChild(Object id) {
- friends.remove(id);
- }
+ public void addChild(Object identifier, TreeNode<Object> child) {
+ getFriends().put((Long) identifier, (TreeFriendItem) child);
+ child.setParent(this);
+ }
- public void setData(Object data) {
- }
+ public TreeNode<Object> getChild(Object id) {
+ return (TreeNode<Object>) friends.get(id);
+ }
- public void setParent(TreeNode parent) {
- this.parent = parent;
- }
+ public Iterator getChildren() {
+ return getFriends().entrySet().iterator();
+ }
- public String getType() {
- return TYPE;
+ public Object getData() {
+ return this;
+ }
+
+ public TreeNode<Object> 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<Object> parent) {
+ this.parent = parent;
+ }
+
+ public String getType() {
+ return Constants.TREE_FRIEND_TYPE;
+ }
+
+ private void initData() {
+ friends = new HashMap<Long, TreeFriendItem>();
+ if (null == getUser().getFriends()) {
+ return;
}
-
- 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);
- }
+ for (User u : getUser().getFriends()) {
+ TreeFriendItem item = new TreeFriendItem(u.getId(), this, u);
+ friends.put(item.getId(), item);
}
+ }
- public long getId() {
- return id;
- }
+ public long getId() {
+ return id;
+ }
- public void setId(long id) {
- this.id = id;
- }
+ public void setId(long id) {
+ this.id = id;
+ }
- public User getUser() {
- return (User) Contexts.getConversationContext().get("user");
- }
+ public User getUser() {
+ return (User) Contexts.getConversationContext().get(Constants.USER);
+ }
}
Modified: 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 2009-01-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeMyAlbumsItem.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -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.tree;
/**
@@ -28,7 +48,6 @@
import java.util.Map;
import javax.faces.model.SelectItem;
-import javax.persistence.EntityManager;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
@@ -39,28 +58,24 @@
import org.richfaces.realworld.domain.Album;
import org.richfaces.realworld.domain.User;
import org.richfaces.realworld.manager.UserManager;
+import org.richfaces.realworld.service.Constants;
@Name("treeMyAlbumsItem")
@Scope(ScopeType.CONVERSATION)
-public class TreeMyAlbumsItem implements TreeNode {
-
- private static final String TYPE = "treeMyAlbums";
+public class TreeMyAlbumsItem implements TreeNode<Object> {
+
+
private long id;
-
- UserManager userManager;
-
- public TreeMyAlbumsItem(){
-
- }
- public TreeMyAlbumsItem(long id, TreeNode parent){
+
+ public TreeMyAlbumsItem(long id, TreeNode<Object> parent){
this.id = id;
this.parent = parent;
}
private List<SelectItem> availableAlbums;
- private TreeNode parent;
+ private TreeNode<Object> parent;
private static final long serialVersionUID = -3530085227471752526L;
@@ -73,17 +88,17 @@
return this.albums;
}
- public void addAlbumToTree(TreeNode parent, TreeAlbumItem album) {
+ public void addAlbumToTree(TreeNode<Object> parent, TreeAlbumItem album) {
parent.addChild(album.getId(), album);
}
- public void addChild(Object identifier, TreeNode child) {
+ public void addChild(Object identifier, TreeNode<Object> child) {
getAlbums().put((Long)identifier, (TreeAlbumItem)child);
child.setParent(this);
}
- public TreeNode getChild(Object id) {
- return (TreeNode) albums.get(id);
+ public TreeNode<Object> getChild(Object id) {
+ return (TreeNode<Object>) albums.get(id);
}
public Iterator getChildren() {
@@ -94,7 +109,7 @@
return this;
}
- public TreeNode getParent() {
+ public TreeNode<Object> getParent() {
return parent;
}
@@ -109,12 +124,12 @@
public void setData(Object data) {
}
- public void setParent(TreeNode parent) {
+ public void setParent(TreeNode<Object> parent) {
this.parent = parent;
}
public String getType() {
- return TYPE;
+ return Constants.TREE_MY_ALBUMS_TYPE;
}
private void initData() {
@@ -126,7 +141,7 @@
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()+"/"));
+ availableAlbums.add(new SelectItem(album.getName() + Constants.SLASH));
addAlbumToTree(this, albumNode);
}
}
@@ -144,13 +159,8 @@
}
return null;
}
-
- public TreeAlbumItem getAlbumByName(String albumName) {
- Object album = getParentItem(albumName);
- return album != null ? (TreeAlbumItem)album : null;
- }
- public TreeNode getParentItem(String albumName){
+ public TreeNode<Object> getNode(String albumName){
for(Map.Entry<Long, TreeAlbumItem> entry : getAlbums().entrySet()){
if(entry.getValue().getAlbum().getName().equals(albumName)){
return entry.getValue();
@@ -158,7 +168,7 @@
if(entry.getValue() instanceof TreeAlbumItem){
TreeAlbumItem value = (TreeAlbumItem)entry.getValue();
if(value.getAlbums().size() >0){
- TreeNode parentItem = getParentItem(value, albumName);
+ TreeNode<Object> parentItem = getNode(value, albumName);
if(parentItem != null){
return parentItem;
}
@@ -169,13 +179,13 @@
return null;
}
- public TreeNode getParentItem(TreeAlbumItem item, String albumName){
- for(TreeNode entry : item.getAlbums()){
+ public TreeNode<Object> getNode(TreeAlbumItem item, String albumName){
+ for(TreeNode<Object> entry : item.getAlbums()){
if(((TreeAlbumItem)entry).getAlbum().getName().equals(albumName)){
return (TreeAlbumItem)entry;
}else{
if(((TreeAlbumItem)entry).getAlbums().size() >0){
- getParentItem((TreeAlbumItem)entry, albumName);
+ getNode((TreeAlbumItem)entry, albumName);
}
}
}
@@ -185,7 +195,7 @@
public List<SelectItem> getAvailableAlbums() {
List<SelectItem> availableAlbums = new ArrayList<SelectItem>();
for(TreeAlbumItem item :this.getAlbums().values()){
- SelectItem e = new SelectItem(item.getAlbum().getName() + "/");
+ SelectItem e = new SelectItem(item.getAlbum().getName() + Constants.SLASH);
availableAlbums.add(e);
List<SelectItem> availableChildAlbums = item.getArrayOfChildsAlbumsNames();
availableAlbums.addAll(availableChildAlbums);
@@ -202,7 +212,7 @@
}
public User getUser() {
- return (User) Contexts.getConversationContext().get("user");
+ return (User) Contexts.getConversationContext().get(Constants.USER);
}
public String getAlbumPathFromParents(Album album2, List<String> list, String delimiter) {
@@ -225,7 +235,7 @@
if(userManager2 != null){
return userManager2;
}
- else return (UserManager)Component.getInstance("userManager", true);
+ else return (UserManager)Component.getInstance(Constants.USER_MANAGER, true);
}
}
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-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeRootItem.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -20,44 +20,36 @@
*/
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;
+import org.richfaces.realworld.service.Constants;
@Name("treeRoot")
@Scope(ScopeType.CONVERSATION)
-public class TreeRootItem implements TreeNode {
+public class TreeRootItem implements TreeNode<Object> {
@In(create=true, required=true)
IUserAction userAction;
- private static final String TREE_ROOT_NODE_TYPE = "treeRoot";
-
private static final long serialVersionUID = -3530085227471752526L;
- private Map<Long, TreeNode> childs;
+ private Map<Long, TreeNode<Object>> childs;
- public void addChild(Object identifier, TreeNode child) {
+ public void addChild(Object identifier, TreeNode<Object> child) {
getChilds().put((Long)identifier, child);
child.setParent(this);
}
- public TreeNode getChild(Object id) {
+ public TreeNode<Object> getChild(Object id) {
return getChilds().get(id);
}
@@ -69,7 +61,7 @@
return this;
}
- public TreeNode getParent() {
+ public TreeNode<Object> getParent() {
return null;
}
@@ -84,14 +76,14 @@
public void setData(Object data) {
}
- public void setParent(TreeNode parent) {
+ public void setParent(TreeNode<Object> parent) {
}
public String getType() {
- return TREE_ROOT_NODE_TYPE;
+ return Constants.TREE_ROOT_NODE_TYPE;
}
- public Map<Long, TreeNode> getChilds() {
+ public Map<Long, TreeNode<Object>> getChilds() {
if (this.childs==null) {
initialise();
}
@@ -99,13 +91,13 @@
}
private void initialise() {
- childs = new HashMap<Long, TreeNode>();
+ childs = new HashMap<Long, TreeNode<Object>>();
TreeMyAlbumsItem item = new TreeMyAlbumsItem(1L, this);
childs.put(item.getId(), item);
- Contexts.getConversationContext().set("treeMyAlbumsItem", item);
+ Contexts.getConversationContext().set(Constants.TREE_MY_ALBUMS_ITEM, item);
}
- public void setChilds(Map<Long, TreeNode> childs) {
+ public void setChilds(Map<Long, TreeNode<Object>> childs) {
this.childs = childs;
}
}
Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/ui/EditorBean.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/ui/EditorBean.java 2009-01-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/ui/EditorBean.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -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.ui;
import org.jboss.seam.annotations.Name;
Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/ui/History.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/ui/History.java 2009-01-26 11:02:00 UTC (rev 12416)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/ui/History.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -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.ui;
import java.util.List;
Added: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/util/ConversationState.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/util/ConversationState.java (rev 0)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/util/ConversationState.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -0,0 +1,355 @@
+/**
+ * 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.util;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+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.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.navigation.NavigationEnum;
+import org.richfaces.realworld.tree.TreeAlbumItem;
+import org.richfaces.realworld.tree.TreeFriendItem;
+import org.richfaces.realworld.tree.TreeFriendsItem;
+import org.richfaces.realworld.tree.TreeMyAlbumsItem;
+import org.richfaces.realworld.service.Constants;
+
+@Name("conversationState")
+(a)Scope(ScopeType.CONVERSATION)
+@Synchronized(timeout=200000)
+public class ConversationState implements Serializable{
+
+ private static final long serialVersionUID = 5656562187249324512L;
+
+ private Integer selectedImageIndex = 1;
+
+ private Image selectedImage;
+
+ private Album selectedAlbum;
+
+ private User selectedUser;
+
+ private User secondSelectedUser;
+
+ private NavigationEnum mainArea;
+
+ @In private User user;
+ @In(required=false) private TreeMyAlbumsItem treeMyAlbumsItem;
+
+ public Integer getSelectedImageIndex() {
+ return selectedImageIndex;
+ }
+
+ public NavigationEnum getMainArea() {
+ return mainArea;
+ }
+
+ @Observer(Constants.UPDATE_MAIN_AREA_EVENT)
+ public void setMainArea(NavigationEnum mainArea) {
+ this.mainArea = mainArea;
+ if(mainArea.equals(NavigationEnum.FILE_UPLOAD)){
+ Events.instance().raiseEvent(Constants.SHOW_FILE_UPLOAD_EVENT, true);
+ }
+ }
+
+ public void setSelectedImageIndex(Integer selectedImageIndex) {
+ this.selectedImageIndex = selectedImageIndex;
+ }
+
+ public Image getSelectedImage() {
+ return selectedImage;
+ }
+
+ public void setSelectedImage(Image selectedImage) {
+ this.selectedImage = selectedImage;
+ }
+
+ public Album getSelectedAlbum() {
+ return selectedAlbum;
+ }
+
+ public void setSelectedAlbum(Album selectedAlbum) {
+ this.selectedAlbum = selectedAlbum;
+ }
+
+ public String getSelectedAlbumName() {
+ if(null == selectedAlbum){
+ return "";
+ }
+ return selectedAlbum.getAlbumPathFromParents(selectedAlbum, new ArrayList<String>(), Constants.SLASH);
+ }
+
+ public void setSelectedAlbumName(String selectedAlbumName) {
+ selectedAlbumName = selectedAlbumName.substring(0, selectedAlbumName.length() -1);
+ int lastIndexOf = selectedAlbumName.lastIndexOf(Constants.SLASH);
+ String prevPathEnd = selectedAlbumName.substring(lastIndexOf+1);
+ this.selectedAlbum = ((TreeAlbumItem)treeMyAlbumsItem.getNode(prevPathEnd)).getAlbum();
+ }
+
+ public void showUserProfile(User user){
+ setSelectedUser(user);
+ setSecondSelectedUser(null);
+ Events.instance().raiseEvent(Constants.UPDATE_MAIN_AREA_EVENT, NavigationEnum.USER_PREFS);
+ }
+
+ public void showSecondUserProfile(User user){
+ setSecondSelectedUser(user);
+ Events.instance().raiseEvent(Constants.UPDATE_MAIN_AREA_EVENT, NavigationEnum.USER_PREFS);
+ }
+
+ public void showImage(Image image){
+ if(!image.getAlbum().isShared() && !image.getAlbum().getOwner().equals(user) && !user.getFriends().contains(image.getAlbum().getOwner())){
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new Exception(Constants.HAVENT_ACCESS));
+ return;
+ }
+ Events.instance().raiseEvent(Constants.UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
+ setSelectedAlbum(image.getAlbum());
+ setSelectedImage(image);
+ setDataScrollerIndex(image.getAlbum().getIndex(image));
+ setSelectedUser(image.getAlbum().getOwner());
+ }
+
+ public void showUser(User u){
+ Events.instance().raiseEvent(Constants.UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
+ setSelectedAlbum(null);
+ setSelectedImage(null);
+ setSelectedUser(u);
+ }
+
+ private void setDataScrollerIndex(int index) {
+ UIComponent component = FacesContext.getCurrentInstance().getViewRoot();
+ UIDatascroller scroller = (UIDatascroller)component.findComponent(Constants.DATASCROLLER_ID);
+ Map<String, Object> attributes = scroller.getDataTable().getAttributes();
+ attributes.put(UIDatascroller.SCROLLER_STATE_ATTRIBUTE, index+1);
+ setSelectedImageIndex(index+1);
+ }
+
+ public void showAlbum(Album album){
+ if(!album.isShared() && !album.getOwner().equals(user) && !user.getFriends().contains(album.getOwner())){
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new Exception(Constants.HAVENT_ACCESS));
+ return;
+ }
+ Events.instance().raiseEvent(Constants.UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
+ setSelectedAlbum(album);
+ setSelectedUser(album.getOwner());
+ }
+
+ public void selectMyAlbums(){
+ setSelectedAlbum(null);
+ setSelectedImage(null);
+ setSelectedUser(user);
+ }
+
+ public void selectMyFriends(){
+ setSelectedAlbum(null);
+ setSelectedImage(null);
+ setSelectedUser(null);
+ }
+
+ public void selectUser(User u){
+ setSelectedAlbum(null);
+ setSelectedImage(null);
+ setSelectedUser(u);
+ }
+
+ public void selectAlbum(Album a){
+ setSelectedAlbum(a);
+ setSelectedImage(null);
+ setSelectedUser(a.getOwner());
+ }
+
+ public void showFileUpload(TreeAlbumItem item, boolean singleMode){
+ String i;
+ if(singleMode){
+ i=Constants.SINGLE;
+ }else{
+ i=Constants.MULTY;
+ }
+ Events.instance().raiseEvent(Constants.CHANGE_MODE_FILE_UPLOAD_EVENT, i);
+ Events.instance().raiseEvent(Constants.FILE_UPLOAD_CLEAR_EVENT);
+ setSelectedAlbum(item.getAlbum());
+ this.setMainArea(NavigationEnum.FILE_UPLOAD);
+ }
+
+ public void showFileUpload(Album item, boolean singleMode){
+ String i;
+ if(singleMode){
+ i=Constants.SINGLE;
+ }else{
+ i=Constants.MULTY;
+ }
+ Events.instance().raiseEvent(Constants.CHANGE_MODE_FILE_UPLOAD_EVENT, i);
+ Events.instance().raiseEvent(Constants.FILE_UPLOAD_CLEAR_EVENT);
+ setSelectedAlbum(item);
+ this.setMainArea(NavigationEnum.FILE_UPLOAD);
+ }
+
+ public void scrollerListener(DataScrollerEvent event) {
+ List<Image> images = getSelectedAlbum().getImages();
+ if (event.getNewScrolVal().equals(Constants.PREVIOUS)) {
+ for(int index = 0 ; index < images.size(); index++){
+ if(images.get(index) ==getSelectedImage()){
+ setSelectedImage(images.get(index - 1));
+ setSelectedImageIndex(index);
+ }
+ }
+ } else if (event.getNewScrolVal().equals(Constants.LAST)) {
+ setSelectedImage(images.get(images.size() - 1));
+ setSelectedImageIndex(images.size());
+ } else if (event.getNewScrolVal().equals(Constants.NEXT)) {
+ for(int index = 0 ; index < images.size(); index++){
+ if(images.get(index) == getSelectedImage()){
+ setSelectedImage(images.get(index + 1));
+ setSelectedImageIndex(index + 2);
+ return;
+ }
+ }
+ } else if (event.getNewScrolVal().equals(Constants.FIRST)) {
+ setSelectedImage(images.get(0));
+ setSelectedImageIndex(1);
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public Boolean adviseNodeSelected(UITree tree) {
+ TreeRowKey<Object> treeRowKey = (TreeRowKey<Object>) tree.getRowKey();
+ TreeNode<Object> treeNode = (TreeNode<Object>) tree.getRowData(treeRowKey);
+ if (treeNode instanceof TreeAlbumItem) {
+ TreeAlbumItem currentNode = (TreeAlbumItem) treeNode;
+ boolean selected = currentNode.getAlbum() == getSelectedAlbum() || currentNode.containAlbum(getSelectedAlbum());
+ return selected;
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Boolean adviseNodeOpened(UITree tree) {
+ TreeRowKey<Object> treeRowKey = (TreeRowKey<Object>) tree.getRowKey();
+ TreeNode<Object> treeNode = (TreeNode<Object>) tree.getRowData(treeRowKey);
+ if (treeNode instanceof TreeAlbumItem) {
+ TreeAlbumItem currentNode = (TreeAlbumItem) treeNode;
+ boolean selected = currentNode.getAlbum() == getSelectedAlbum() || currentNode.containAlbum(getSelectedAlbum());
+ return selected;
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void processSelection(NodeSelectedEvent event) {
+ Events.instance().raiseEvent(Constants.UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
+ HtmlTree tree = (HtmlTree) event.getComponent();
+ TreeNode<Object> currentNode = (TreeNode<Object>)tree.getModelTreeNode(tree.getRowKey());
+ if(currentNode instanceof TreeAlbumItem){
+ TreeAlbumItem node = (TreeAlbumItem)currentNode;
+ Album album = node.getAlbum();
+ setSelectedAlbum(album);
+ }else if(currentNode instanceof TreeMyAlbumsItem){
+ setSelectedAlbum(null);
+ }
+ setSelectedUser(user);
+ setSelectedImage(null);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void processSelectionFriends(NodeSelectedEvent event) {
+ Events.instance().raiseEvent(Constants.UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
+ HtmlTree tree = (HtmlTree) event.getComponent();
+ TreeNode<Object> currentNode = (TreeNode<Object>)tree.getModelTreeNode(tree.getRowKey());
+ if(currentNode instanceof TreeAlbumItem){
+ TreeAlbumItem node = (TreeAlbumItem)currentNode;
+ setSelectedUser(((TreeAlbumItem)currentNode).getAlbum().getOwner());
+ Album album = node.getAlbum();
+ setSelectedAlbum(album);
+ }else if(currentNode instanceof TreeFriendsItem){
+ setSelectedUser(null);
+ setSelectedAlbum(null);
+ }else if(currentNode instanceof TreeFriendItem){
+ setSelectedUser(((TreeFriendItem)currentNode).getFriend());
+ setSelectedAlbum(null);
+ }
+ setSelectedImage(null);
+ }
+
+ public void incrementSlideshowIndex() {
+ int index = getSelectedAlbum().getIndex(getSelectedImage());
+ if(getSelectedAlbum().getImages().size() == index +1){
+ index = -1;
+ }
+ setSelectedImage(getSelectedAlbum().getImages().get(index +1));
+ UIComponent component = FacesContext.getCurrentInstance().getViewRoot();
+ UIDatascroller scroller = (UIDatascroller)component.findComponent(Constants.DATASCROLLER_ID);
+ Map<String, Object> attributes = scroller.getDataTable().getAttributes();
+ attributes.put(UIDatascroller.SCROLLER_STATE_ATTRIBUTE, index+2);
+ setSelectedImageIndex(index+2);
+ }
+
+ public SelectItem[] getAvailableIndexOfImages(){
+ SelectItem[] group = new SelectItem[getSelectedAlbum().getImages().size()];
+ for(int i = 0; i < getSelectedAlbum().getImages().size(); i++){
+ group[i] = new SelectItem(i+1);
+ }
+ return group;
+ }
+
+ public void updateSelectedItems(Image image){
+ setSelectedImage(image);
+ Integer index = getSelectedAlbum().getIndex(getSelectedImage());
+ setDataScrollerIndex(index);
+ }
+
+ public User getSelectedUser() {
+ return selectedUser;
+ }
+
+ public void setSelectedUser(User selectedUser) {
+ this.selectedUser = selectedUser;
+ }
+
+ public User getSecondSelectedUser() {
+ return secondSelectedUser;
+ }
+
+ public void setSecondSelectedUser(User secondSelectedUser) {
+ this.secondSelectedUser = secondSelectedUser;
+ }
+}
Property changes on: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/util/ConversationState.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/util/RenderLogic.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/util/RenderLogic.java (rev 0)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/util/RenderLogic.java 2009-01-26 12:37:09 UTC (rev 12417)
@@ -0,0 +1,128 @@
+/**
+ * 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.util;
+
+import java.io.Serializable;
+
+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.jboss.seam.security.Identity;
+import org.richfaces.realworld.domain.Album;
+import org.richfaces.realworld.domain.Image;
+import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.service.Constants;
+
+@Name("renderLogic")
+(a)Scope(ScopeType.CONVERSATION)
+public class RenderLogic implements Serializable{
+
+ @In User user;
+ @In Identity identity;
+ @In ConversationState conversationState;
+
+ private static final long serialVersionUID = 5656562187249324512L;
+
+ public boolean shouldRenderFriendFolders(){
+ return conversationState.getSelectedUser() == null;
+ }
+
+ public boolean shouldRenderFolders(){
+ return conversationState.getSelectedUser()!=null && conversationState.getSelectedImage() == null;
+ }
+
+ public boolean shouldRenderImage(){
+ return conversationState.getSelectedUser()!=null && conversationState.getSelectedAlbum()!=null && conversationState.getSelectedImage() != null;
+ }
+
+ public boolean shouldRenderImageList(){
+ return conversationState.getSelectedUser()!=null && conversationState.getSelectedAlbum()!=null;
+ }
+
+ public boolean isCurrentUserProfileSelected(){
+ return user.equals(conversationState.getSelectedUser());
+ }
+
+ public boolean isSecondUserProfileSelected(){
+ return conversationState.getSecondSelectedUser() != null;
+ }
+
+ public boolean isUserAlbumSelected(){
+ return conversationState.getSelectedAlbum() != null && conversationState.getSelectedAlbum().getOwner().equals(user);
+ }
+
+ public boolean isUserGuest(){
+ return identity.hasRole(Constants.GUEST_ROLE);
+ }
+
+ public boolean shouldRenderFileUpload(){
+ return conversationState.getSelectedAlbum()!=null && conversationState.getSelectedAlbum().getOwner().equals(user);
+ }
+
+ public boolean isUserSelected(){
+ return user.equals(conversationState.getSelectedUser());
+ }
+
+ public boolean isFriendSelected(){
+ return conversationState.getSelectedUser() == null || isUserFriend();
+ }
+
+ public boolean isNotFriendSelected(){
+ return !isUserSelected() && !isUserFriend();
+ }
+
+ public boolean isUserFriend(){
+ return user.getFriends() != null && user.getFriends().contains(conversationState.getSelectedUser());
+ }
+
+ public boolean isUserFriend(User u){
+ return user.getFriends() != null && user.getFriends().contains(u);
+ }
+
+ public boolean isAlbumSelected(){
+ return conversationState.getSelectedAlbum() != null;
+ }
+
+ public boolean isImageSelected(){
+ return conversationState.getSelectedImage() != null;
+ }
+
+ public boolean isAccessToAlbumGranted(Album album){
+ return album.getOwner().equals(user) || album.isShared() || isUserFriend(album.getOwner());
+ }
+
+ public boolean isUserAlbum(Album album){
+ if(album == null){
+ return false;
+ }
+ return album.getOwner().equals(user);
+ }
+
+ public boolean isFavoriteAlbum(Album album){
+ return user.getFavoriteAlbums().contains(album);
+ }
+
+ public boolean isFavoriteImage(Image image){
+ return user.getFavoriteImages().contains(image);
+ }
+
+}
Property changes on: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/util/RenderLogic.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
16 years, 8 months
JBoss Rich Faces SVN: r12416 - trunk/test-applications/jsp/src/main/webapp/ScrollableDataTable.
by richfaces-svn-commits@lists.jboss.org
Author: tkuprevich
Date: 2009-01-26 06:02:00 -0500 (Mon, 26 Jan 2009)
New Revision: 12416
Modified:
trunk/test-applications/jsp/src/main/webapp/ScrollableDataTable/ScrollableDataTable.jsp
trunk/test-applications/jsp/src/main/webapp/ScrollableDataTable/ScrollableDataTableProperty.jsp
Log:
Modified: trunk/test-applications/jsp/src/main/webapp/ScrollableDataTable/ScrollableDataTable.jsp
===================================================================
--- trunk/test-applications/jsp/src/main/webapp/ScrollableDataTable/ScrollableDataTable.jsp 2009-01-26 11:01:33 UTC (rev 12415)
+++ trunk/test-applications/jsp/src/main/webapp/ScrollableDataTable/ScrollableDataTable.jsp 2009-01-26 11:02:00 UTC (rev 12416)
@@ -1,4 +1,4 @@
-<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
+bind<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
Modified: trunk/test-applications/jsp/src/main/webapp/ScrollableDataTable/ScrollableDataTableProperty.jsp
===================================================================
--- trunk/test-applications/jsp/src/main/webapp/ScrollableDataTable/ScrollableDataTableProperty.jsp 2009-01-26 11:01:33 UTC (rev 12415)
+++ trunk/test-applications/jsp/src/main/webapp/ScrollableDataTable/ScrollableDataTableProperty.jsp 2009-01-26 11:02:00 UTC (rev 12416)
@@ -38,6 +38,9 @@
onchange="submit();">
</h:inputText>
+ <h:outputLabel value="Binding:" for="checkBind"></h:outputLabel>
+ <a4j:commandButton value="Check" id="checkBind" actionListener="#{scrollableDT.checkBinding}"></a4j:commandButton>:
+
<h:outputText value="limitToList"></h:outputText>
<h:selectBooleanCheckbox value="#{scrollableDT.limitToList}"
onchange="submit();">
16 years, 8 months
JBoss Rich Faces SVN: r12415 - trunk/test-applications/jsp/src/main/java/scrollableDataTable.
by richfaces-svn-commits@lists.jboss.org
Author: tkuprevich
Date: 2009-01-26 06:01:33 -0500 (Mon, 26 Jan 2009)
New Revision: 12415
Modified:
trunk/test-applications/jsp/src/main/java/scrollableDataTable/ScrollableDataTable.java
Log:
Modified: trunk/test-applications/jsp/src/main/java/scrollableDataTable/ScrollableDataTable.java
===================================================================
--- trunk/test-applications/jsp/src/main/java/scrollableDataTable/ScrollableDataTable.java 2009-01-23 23:44:08 UTC (rev 12414)
+++ trunk/test-applications/jsp/src/main/java/scrollableDataTable/ScrollableDataTable.java 2009-01-26 11:01:33 UTC (rev 12415)
@@ -4,6 +4,9 @@
import java.util.GregorianCalendar;
import java.util.Iterator;
+import javax.faces.context.FacesContext;
+import javax.faces.event.ActionEvent;
+
import org.ajax4jsf.model.DataComponentState;
import org.richfaces.component.html.HtmlScrollableDataTable;
import org.richfaces.model.selection.SimpleSelection;
@@ -40,6 +43,15 @@
private GregorianCalendar date;
private HtmlScrollableDataTable htmlScrollableDataTable = null;
+ public void checkBinding(ActionEvent e){
+ String id = htmlScrollableDataTable.getId();
+ if("sdt".equals(id)){
+ System.out.println("Binding works for SDT");
+ } else {
+ System.out.println("Binding doesn't work for SDT");
+ }
+ }
+
public void addHtmlScrollableDataTable() {
ComponentInfo info = ComponentInfo.getInstance();
info.addField(htmlScrollableDataTable);
16 years, 8 months
JBoss Rich Faces SVN: r12414 - in trunk/ui/core/src/test: resources/org/ajax4jsf/component and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2009-01-23 18:44:08 -0500 (Fri, 23 Jan 2009)
New Revision: 12414
Modified:
trunk/ui/core/src/test/java/org/ajax4jsf/component/AbstractQueueComponentTest.java
trunk/ui/core/src/test/java/org/ajax4jsf/component/ImplicitQueuesTest.java
trunk/ui/core/src/test/java/org/ajax4jsf/component/QueueScriptedTest.java
trunk/ui/core/src/test/java/org/ajax4jsf/component/QueueSizeTest.java
trunk/ui/core/src/test/resources/org/ajax4jsf/component/queue-scripted.xhtml
trunk/ui/core/src/test/resources/org/ajax4jsf/component/queue-size.xhtml
Log:
https://jira.jboss.org/jira/browse/RF-5788
Modified: trunk/ui/core/src/test/java/org/ajax4jsf/component/AbstractQueueComponentTest.java
===================================================================
--- trunk/ui/core/src/test/java/org/ajax4jsf/component/AbstractQueueComponentTest.java 2009-01-23 23:42:05 UTC (rev 12413)
+++ trunk/ui/core/src/test/java/org/ajax4jsf/component/AbstractQueueComponentTest.java 2009-01-23 23:44:08 UTC (rev 12414)
@@ -46,7 +46,6 @@
import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.UserResourceRenderer2;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.ajax4jsf.resource.InternetResource;
import org.ajax4jsf.resource.InternetResourceBuilder;
import org.ajax4jsf.resource.ResourceNotFoundException;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
Modified: trunk/ui/core/src/test/java/org/ajax4jsf/component/ImplicitQueuesTest.java
===================================================================
--- trunk/ui/core/src/test/java/org/ajax4jsf/component/ImplicitQueuesTest.java 2009-01-23 23:42:05 UTC (rev 12413)
+++ trunk/ui/core/src/test/java/org/ajax4jsf/component/ImplicitQueuesTest.java 2009-01-23 23:44:08 UTC (rev 12414)
@@ -83,24 +83,33 @@
clickOnTime(0, "form:buttonIgnoreDupResponces");
clickOnTime(500, "form:buttonIgnoreDupResponces");
- clickOnTime(750, "form:buttonIgnoreDupResponces");
executeTimer();
TestsResult result = getTestsResult();
List<RequestData> dataList = result.getDataList();
- assertEquals(3, dataList.size());
+
+ //RF-5788
+ //assertEquals(3, dataList.size());
+ assertEquals(2, dataList.size());
//request time set to 5000 in .xhtml file
checkRequestData(dataList.get(0), "form:buttonIgnoreDupResponces", 0, 5000, false);
- checkRequestData(dataList.get(1), "form:buttonIgnoreDupResponces", 500, 5500, false);
- checkRequestData(dataList.get(2), "form:buttonIgnoreDupResponces", 750, 5750, false);
+ checkRequestData(dataList.get(1), "form:buttonIgnoreDupResponces", 5000, 10000, false);
+
+ //RF-5788
+ //checkRequestData(dataList.get(2), "form:buttonIgnoreDupResponces", 750, 5750, false);
- assertEquals(5750d, result.getCurrentTime());
+ //RF-5788
+ //assertEquals(5750d, result.getCurrentTime());
+ assertEquals(10000d, result.getCurrentTime());
Double requestsCompletedCounter = (Double) executeJavaScript("counter");
assertEquals(1d, requestsCompletedCounter);
Double requestsCompletionTime = (Double) executeJavaScript("time");
- assertEquals(5750d, requestsCompletionTime);
+
+ //RF-5788
+ //assertEquals(5750d, requestsCompletionTime);
+ assertEquals(10000d, requestsCompletionTime);
}
}
Modified: trunk/ui/core/src/test/java/org/ajax4jsf/component/QueueScriptedTest.java
===================================================================
--- trunk/ui/core/src/test/java/org/ajax4jsf/component/QueueScriptedTest.java 2009-01-23 23:42:05 UTC (rev 12413)
+++ trunk/ui/core/src/test/java/org/ajax4jsf/component/QueueScriptedTest.java 2009-01-23 23:44:08 UTC (rev 12414)
@@ -114,8 +114,8 @@
ajax(0, "a", parametersBuilder.similarityGroupingId("a"));
ajax(500, "b", parametersBuilder.similarityGroupingId("a"));
- ajax(2000, "c", parametersBuilder.similarityGroupingId("a"));
- ajax(2500, "d", parametersBuilder.similarityGroupingId("a").ignoreDupResponses(false));
+ ajax(2500, "c", parametersBuilder.similarityGroupingId("a"));
+ ajax(3000, "d", parametersBuilder.similarityGroupingId("a").ignoreDupResponses(false));
TestsResult result = getTestsResult();
List<RequestData> dataList = result.getDataList();
@@ -123,18 +123,18 @@
assertEquals(4, dataList.size());
checkRequestData(dataList.get(0), "a", 0, 1000, false);
- checkRequestData(dataList.get(1), "b", 500, 1500, false);
+ checkRequestData(dataList.get(1), "b", 1000, 2000, false);
- checkRequestData(dataList.get(2), "c", 2000, 3000, false);
- checkRequestData(dataList.get(3), "d", 3000, 4000, false);
+ checkRequestData(dataList.get(2), "c", 2500, 3500, false);
+ checkRequestData(dataList.get(3), "d", 3500, 4500, false);
NativeArray array = (NativeArray) executeJavaScript("queueIgnoreDupResponsesTest");
long length = array.getLength();
assertEquals(3, length);
- assertEquals("b:1500", (String) array.get(0, array));
- assertEquals("c:3000", (String) array.get(1, array));
- assertEquals("d:4000", (String) array.get(2, array));
+ assertEquals("b:2000", (String) array.get(0, array));
+ assertEquals("c:3500", (String) array.get(1, array));
+ assertEquals("d:4500", (String) array.get(2, array));
}
public void testIgnoreDupResponsesDefault() throws Exception {
@@ -154,9 +154,26 @@
checkRequestData(dataList.get(0), "a", 0, 500, false);
checkRequestData(dataList.get(1), "b", 500, 1000, false);
- checkRequestData(dataList.get(2), "c", 750, 1250, false);
+ checkRequestData(dataList.get(2), "c", 1000, 1500, false);
}
+ public void testIgnoreDupResponsesTimeout() throws Exception {
+ renderView(VIEW_NAME);
+
+ ParametersBuilder parametersBuilder = createAjaxParameters().
+ eventsQueue("queueTimeout").ignoreDupResponses(true).requestDelay(0).requestTime(1000);
+
+ ajax(0, "a", parametersBuilder.timeout(500));
+ ajax(100, "b", parametersBuilder);
+
+ TestsResult result = getTestsResult();
+ List<RequestData> dataList = result.getDataList();
+
+ assertEquals(2, dataList.size());
+ checkRequestData(dataList.get(0), "a", 0, 500, true);
+ checkRequestData(dataList.get(1), "b", 500, 1500, false);
+ }
+
public void testSimpleAjax() throws Exception {
renderView(VIEW_NAME);
@@ -210,4 +227,31 @@
assertEquals(80d, result.getCurrentTime());
}
+
+ public void testStatusIgnoreDupResponses() throws Exception {
+ renderView(VIEW_NAME);
+
+ ParametersBuilder parameters = createAjaxParameters().requestDelay(0).eventsQueue("queueIgnoreDupResponses");
+
+ ajax(0, "a", parameters);
+ ajax(100, "b", parameters);
+
+ TestsResult result = getTestsResult();
+ List<RequestData> dataList = result.getDataList();
+ assertEquals(2, dataList.size());
+
+ checkRequestData(dataList.get(0), "a", 0, DEFAULT_REQUEST_TIME, false);
+ checkRequestData(dataList.get(1), "b", DEFAULT_REQUEST_TIME, 2 * DEFAULT_REQUEST_TIME, false);
+
+ NativeArray array = (NativeArray) executeJavaScript("window.statusData");
+ assertEquals(2, array.getLength());
+
+ NativeArray nestedArray = (NativeArray) array.get(0, array);
+ assertEquals(Double.valueOf(0), nestedArray.get(0, nestedArray));
+ assertEquals(Double.valueOf(DEFAULT_REQUEST_TIME), nestedArray.get(1, nestedArray));
+
+ nestedArray = (NativeArray) array.get(1, array);
+ assertEquals(Double.valueOf(DEFAULT_REQUEST_TIME), nestedArray.get(0, nestedArray));
+ assertEquals(Double.valueOf(2 * DEFAULT_REQUEST_TIME), nestedArray.get(1, nestedArray));
+ }
}
Modified: trunk/ui/core/src/test/java/org/ajax4jsf/component/QueueSizeTest.java
===================================================================
--- trunk/ui/core/src/test/java/org/ajax4jsf/component/QueueSizeTest.java 2009-01-23 23:42:05 UTC (rev 12413)
+++ trunk/ui/core/src/test/java/org/ajax4jsf/component/QueueSizeTest.java 2009-01-23 23:44:08 UTC (rev 12414)
@@ -398,4 +398,25 @@
Double secondEventTime = (Double) secondHandlerData.get("_time", secondHandlerData);
assertEquals(3d, secondEventTime);
}
+
+ public void testSingleSizedQueueIgnoreDupResponses() throws Exception {
+ renderView("/queue-size.xhtml");
+
+ ParametersBuilder parametersBuilder = createAjaxParameters().eventsQueue("singleSizedDefaultQueue").
+ requestDelay(0);
+
+ ajax(0, "a", parametersBuilder);
+ ajax(500, "b", parametersBuilder);
+
+ TestsResult result = getTestsResult();
+ List<RequestData> list = result.getDataList();
+ assertEquals(1, list.size());
+
+ checkRequestData(list.get(0), "a", 0, DEFAULT_REQUEST_TIME, false);
+
+ NativeArray handlersData = (NativeArray) executeJavaScript("defaultSingleSizedQueueResults");
+ assertEquals(1, handlersData.getLength());
+
+ assertEquals("a", handlersData.get(0, handlersData));
+ }
}
Modified: trunk/ui/core/src/test/resources/org/ajax4jsf/component/queue-scripted.xhtml
===================================================================
--- trunk/ui/core/src/test/resources/org/ajax4jsf/component/queue-scripted.xhtml 2009-01-23 23:42:05 UTC (rev 12413)
+++ trunk/ui/core/src/test/resources/org/ajax4jsf/component/queue-scripted.xhtml 2009-01-23 23:44:08 UTC (rev 12414)
@@ -11,6 +11,9 @@
<f:view>
<a4j:status startText="...running..." stopText="stopped" startStyle="color: green" />
+ <a4j:status id="queueStatus" forceId="true" onstart="window.startStatusTime = Timer.currentTime;"
+ onstop="statusData.push([window.startStatusTime, Timer.currentTime]); window.startStatusTime = undefined;" />
+
<a4j:queue name="queueDefaults" />
<a4j:queue name="queueRequestDelay" requestDelay="15" />
@@ -18,13 +21,15 @@
<a4j:queue name="queueTimeout" timeout="5000" />
<script type="text/javascript">
- window.queueIgnoreDupResponsesTest = new Array();
+ //LOG.LEVEL = LOG.ALL;
+ window.queueIgnoreDupResponsesTest = new Array();
+ window.statusData = new Array();
</script>
- <a4j:queue name="queueIgnoreDupResponses" ignoreDupResponses="true" oncomplete="queueIgnoreDupResponsesTest.push(data + ':' + Timer.currentTime)" />
+ <a4j:queue status="queueStatus" name="queueIgnoreDupResponses" ignoreDupResponses="true" oncomplete="queueIgnoreDupResponsesTest.push(data + ':' + Timer.currentTime)" />
<a4j:queue name="testQueue" />
-
+
</f:view>
</body>
</html>
Modified: trunk/ui/core/src/test/resources/org/ajax4jsf/component/queue-size.xhtml
===================================================================
--- trunk/ui/core/src/test/resources/org/ajax4jsf/component/queue-size.xhtml 2009-01-23 23:42:05 UTC (rev 12413)
+++ trunk/ui/core/src/test/resources/org/ajax4jsf/component/queue-size.xhtml 2009-01-23 23:44:08 UTC (rev 12414)
@@ -38,6 +38,8 @@
defaultExceededQueueResults.push({queue: queue, query: query, options: options, event: event, _time: Timer.currentTime});
}
+
+ defaultSingleSizedQueueResults = new Array();
</script>
<a4j:queue onsizeexceeded="addEventData(this, query, options, event)" size="2" name="defaultExceededQueue" />
@@ -47,6 +49,8 @@
<a4j:commandButton id="button2" eventsQueue="defaultExceededQueue" value="button" />
<a4j:commandButton id="button3" eventsQueue="defaultExceededQueue" value="button" />
</h:form>
+
+ <a4j:queue name="singleSizedDefaultQueue" size="1" ignoreDupResponses="true" oncomplete="defaultSingleSizedQueueResults.push(data)" />
</f:view>
</body>
</html>
16 years, 8 months
JBoss Rich Faces SVN: r12413 - trunk/framework/impl/src/main/javascript/ajaxjsf.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2009-01-23 18:42:05 -0500 (Fri, 23 Jan 2009)
New Revision: 12413
Modified:
trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
trunk/framework/impl/src/main/javascript/ajaxjsf/queue.js
Log:
https://jira.jboss.org/jira/browse/RF-5788
Modified: trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
===================================================================
--- trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js 2009-01-23 19:42:25 UTC (rev 12412)
+++ trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js 2009-01-23 23:42:05 UTC (rev 12413)
@@ -54,10 +54,25 @@
this._request.onreadystatechange = function(){
if(window.document.documentElement != _this._documentElement){
LOG.warn("Page for current request have been unloaded - abort processing" );
- _this.abort();
+
+ if(!_this._status_stopped) {
+ //end status early
+ A4J.AJAX.status(_this.containerId, _this.options.status, false);
+ _this._status_stopped = true;
+ }
+
+ _this.abort();
+
return;
};
+
if(_this._aborted){
+ if (_this._request.readyState == 4) {
+ //this will be true just once for request - no need to track state of status
+ A4J.AJAX.status(_this.containerId, _this.options.status, false);
+ A4J.AJAX.popQueue(_this);
+ }
+
return;
};
LOG.debug("Reqest state : "+_this._request.readyState );
@@ -147,24 +162,14 @@
},
abort: function(){
- if(!this._aborted){
- A4J.AJAX.status(this.containerId,this.options.status,false);
- if(typeof(A4J.AJAX.onAbort) == "function"){
- A4J.AJAX.onAbort(this);
- }
- }
- this._aborted=true;
- if(this._request){
- try{
-// this._request.abort();
- if(this._timeoutID){
- window.clearTimeout(this._timeoutID);
- }
- } catch (e){
- LOG.warn("Exception for abort current request "+e.Message);
+ if(!this._aborted){
+ if(typeof(A4J.AJAX.onAbort) == "function"){
+ A4J.AJAX.onAbort(this);
}
}
+ this._aborted=true;
},
+
getResponseText : function(){
try {
return this._request.responseText;
@@ -1187,11 +1192,15 @@
}, 0)
}
- if (request.shouldNotifyQueue && request.queue) {
- request.queue.pop();
- }
+ A4J.AJAX.popQueue(request);
};
+A4J.AJAX.popQueue = function(request) {
+ if (request.shouldNotifyQueue && request.queue) {
+ request.queue.pop();
+ }
+};
+
A4J.AJAX.getCursorPos = function(inp){
if(inp.selectionEnd != null)
Modified: trunk/framework/impl/src/main/javascript/ajaxjsf/queue.js
===================================================================
--- trunk/framework/impl/src/main/javascript/ajaxjsf/queue.js 2009-01-23 19:42:25 UTC (rev 12412)
+++ trunk/framework/impl/src/main/javascript/ajaxjsf/queue.js 2009-01-23 23:42:05 UTC (rev 12413)
@@ -65,13 +65,16 @@
},
abort: function() {
- if (this.request) {
+ if (this.request && !this.aborted) {
//tell request not to notify queue after its processing finished
//request.queue = undefined
//is not ok for this case because user might want to obtain queue in any event handler
- this.request.shouldNotifyQueue = false;
+
+ //RF-5788
+ this.aborted = true;
+ //this.request.shouldNotifyQueue = false;
this.request.abort();
- this.request = undefined;
+ //this.request = undefined;
}
},
@@ -180,6 +183,10 @@
return this.queueOptions.size;
},
+ isFull: function() {
+ return this.getSize() == this.getMaximumSize();
+ },
+
getSizeExceededBehavior: function() {
var policy = this.queueOptions.sizeExceededBehavior;
if (!policy) {
@@ -224,14 +231,21 @@
if (last.request) {
LOG.debug("Request has already beeen sent to server");
if (entry.isIgnoreDupResponses()) {
- LOG.debug("Duplicate responses ignore requested, queue will abort current request");
+ LOG.debug("Duplicate responses ignore requested");
- last.abort();
+ if (!this.isFull()) {
+ last.abort();
+
+ LOG.debug("Response for the current request will be ignored");
+
+ /* Change for - RF-5788 - wait current request to complete even if ignore duplicate is true
+ //remove last (that is actually first) from queue - will be safer to do that in LinkedList
+ this.dequeue();
+ */
+ } else {
+ LOG.debug("Queue is full, cannot set to ignore response for the current request");
+ }
- LOG.debug("Current request in queue '" + this.name + "' has been aborted");
-
- //remove last (that is actually first) from queue - will be safer to do that in LinkedList
- this.dequeue();
}
} else {
LOG.debug("Combine similar requests and reset timer");
@@ -253,7 +267,7 @@
}
if (!handled) {
- if (this.queueOptions.size == this.items.length) {
+ if (this.isFull()) {
LOG.debug("Queue '" + this.name + "' is currently full")
var b = this.getSizeExceededBehavior();
16 years, 8 months
JBoss Rich Faces SVN: r12412 - in trunk/test-applications/seleniumTest/richfaces/src: main/webapp/pages/treeNodesAdaptor and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: konstantin.mishin
Date: 2009-01-23 14:42:25 -0500 (Fri, 23 Jan 2009)
New Revision: 12412
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/tree/TreeNodesAdaptorTestBean.java
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/treeNodesAdaptor/recursiveTreeNodesAdaptor.xhtml
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/treeNodesAdaptor/treeNodesAdaptorBase.xhtml
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/AbstractTreeNodesAdaptorTest.java
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/RecursiveTreeNodesAdaptorTest.java
Log:
RF-5579
Modified: trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/tree/TreeNodesAdaptorTestBean.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/tree/TreeNodesAdaptorTestBean.java 2009-01-23 17:43:39 UTC (rev 12411)
+++ trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/tree/TreeNodesAdaptorTestBean.java 2009-01-23 19:42:25 UTC (rev 12412)
@@ -50,6 +50,7 @@
private String trace;
private Boolean ajaxSingle;
private Boolean includedNode;
+ private Boolean includedRoot;
public TreeNodesAdaptorTestBean() {
init();
@@ -71,6 +72,7 @@
trace = "";
ajaxSingle = false;
includedNode = true;
+ includedRoot = true;
}
public void submit(ActionEvent event) {
@@ -108,4 +110,12 @@
public Boolean getIncludedNode() {
return includedNode;
}
+
+ public void setIncludedRoot(Boolean includedRoot) {
+ this.includedRoot = includedRoot;
+ }
+
+ public Boolean getIncludedRoot() {
+ return includedRoot;
+ }
}
Modified: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/treeNodesAdaptor/recursiveTreeNodesAdaptor.xhtml
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/treeNodesAdaptor/recursiveTreeNodesAdaptor.xhtml 2009-01-23 17:43:39 UTC (rev 12411)
+++ trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/treeNodesAdaptor/recursiveTreeNodesAdaptor.xhtml 2009-01-23 19:42:25 UTC (rev 12412)
@@ -8,7 +8,7 @@
<ui:composition template="treeNodesAdaptorBase.xhtml">
<ui:define name="treeNodesAdaptor">
- <rich:recursiveTreeNodesAdaptor roots="#{treeNodesAdaptor.nodes}" var="node" nodes="#{node.children}" includedNode="#{treeNodesAdaptor.includedNode}">
+ <rich:recursiveTreeNodesAdaptor roots="#{treeNodesAdaptor.nodes}" var="node" nodes="#{node.children}" includedNode="#{treeNodesAdaptor.includedNode}" includedRoot="#{treeNodesAdaptor.includedRoot}">
<rich:treeNode ajaxSingle="#{treeNodesAdaptor.ajaxSingle}">
<h:inputText value="#{node.id}"></h:inputText>
<h:commandButton id="submit" value="submit" actionListener="#{treeNodesAdaptor.submit}"></h:commandButton>
Modified: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/treeNodesAdaptor/treeNodesAdaptorBase.xhtml
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/treeNodesAdaptor/treeNodesAdaptorBase.xhtml 2009-01-23 17:43:39 UTC (rev 12411)
+++ trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/treeNodesAdaptor/treeNodesAdaptorBase.xhtml 2009-01-23 19:42:25 UTC (rev 12412)
@@ -17,6 +17,10 @@
<h:selectBooleanCheckbox id="includedNode" value="#{treeNodesAdaptor.includedNode}">
<a4j:support event="onchange" reRender="tree"/>
</h:selectBooleanCheckbox>
+ <h:outputText value="includedRoot" />
+ <h:selectBooleanCheckbox id="includedRoot" value="#{treeNodesAdaptor.includedRoot}">
+ <a4j:support event="onchange" reRender="tree"/>
+ </h:selectBooleanCheckbox>
</h:form>
<h:form id="mainForm">
<rich:tree id="tree">
Modified: trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/AbstractTreeNodesAdaptorTest.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/AbstractTreeNodesAdaptorTest.java 2009-01-23 17:43:39 UTC (rev 12411)
+++ trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/AbstractTreeNodesAdaptorTest.java 2009-01-23 19:42:25 UTC (rev 12412)
@@ -32,17 +32,21 @@
public abstract class AbstractTreeNodesAdaptorTest extends SeleniumTestBase {
- private List<Node> nodes;
+ protected List<Node> nodes;
- private String ajaxSingle;
+ protected String attrForm;
+ private String ajaxSingle;
+
private String includedNode;
- private String tree;
+ protected String tree;
private String outputText;
+
private String dataTable;
- private void init(Template template) {
+
+ protected void init(Template template) {
renderPage(null, template, "#{treeNodesAdaptor.init}");
nodes = new ArrayList<Node>(3);
for (int i = 1; i <= 3; i++) {
@@ -56,13 +60,13 @@
}
}
}
- String attrForm = getParentId() + "attrForm";
- ajaxSingle = attrForm + ":ajaxSingle";
- includedNode = attrForm + ":includedNode";
- String mainForm = getParentId() + "mainForm";
- tree = mainForm + ":tree";
- outputText = getParentId() + "outputText";
- dataTable = getParentId() + "dataTable";
+ attrForm = getParentId() + "attrForm";
+ ajaxSingle = attrForm + ":ajaxSingle";
+ includedNode = attrForm + ":includedNode";
+ String mainForm = getParentId() + "mainForm";
+ tree = mainForm + ":tree";
+ outputText = getParentId() + "outputText";
+ dataTable = getParentId() + "dataTable";
}
/**
Modified: trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/RecursiveTreeNodesAdaptorTest.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/RecursiveTreeNodesAdaptorTest.java 2009-01-23 17:43:39 UTC (rev 12411)
+++ trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/RecursiveTreeNodesAdaptorTest.java 2009-01-23 19:42:25 UTC (rev 12412)
@@ -20,11 +20,36 @@
*/
package org.richfaces.testng;
+import org.ajax4jsf.template.Template;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
public class RecursiveTreeNodesAdaptorTest extends AbstractTreeNodesAdaptorTest {
+ private String includedRoot;
+
@Override
+ protected void init(Template template) {
+ super.init(template);
+ includedRoot = attrForm + ":includedRoot";
+ }
+ /**
+ * includedRoot expression is handled properly
+ */
+ @Test
+ public void testIncludedRoot(Template template) {
+ init(template);
+ String xpath = "id('"+ tree + "')/div";
+ clickAjaxCommandAndWait("xpath=" + xpath + "/table[2]/tbody/tr/td[1]/div/a");
+ String childrenXpath = "id('"+ tree + "')/div/table";
+ Assert.assertEquals(selenium.getXpathCount(childrenXpath), nodes.size());
+ clickAjaxCommandAndWait(includedRoot);
+ Assert.assertEquals(selenium.getXpathCount(childrenXpath), 0);
+ }
+
+ @Override
public String getTestUrl() {
return "pages/treeNodesAdaptor/recursiveTreeNodesAdaptor.xhtml";
}
16 years, 8 months
JBoss Rich Faces SVN: r12411 - in trunk/test-applications/seleniumTest/richfaces/src: test/java/org/richfaces/testng and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: dsvyatobatsko
Date: 2009-01-23 12:43:39 -0500 (Fri, 23 Jan 2009)
New Revision: 12411
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/panelMenuItem/styleAndClasseStandardHTMLAttributesTest.xhtml
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/PanelMenuItemTest.java
Log:
https://jira.jboss.org/jira/browse/RF-5793
Modified: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/panelMenuItem/styleAndClasseStandardHTMLAttributesTest.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/PanelMenuItemTest.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/PanelMenuItemTest.java 2009-01-23 16:51:30 UTC (rev 12410)
+++ trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/PanelMenuItemTest.java 2009-01-23 17:43:39 UTC (rev 12411)
@@ -7,6 +7,7 @@
import org.richfaces.AutoTester;
import org.richfaces.SeleniumEvent;
import org.richfaces.SeleniumTestBase;
+import org.testng.Assert;
import org.testng.annotations.Test;
public class PanelMenuItemTest extends SeleniumTestBase {
@@ -73,12 +74,9 @@
writeStatus("Check standard HTML attributes are output to client");
String parentId = getParentId();
- String isDisabledId = parentId + CONTROL_FORM_ID + "isDisabled";
- String disablingControlId = parentId + CONTROL_FORM_ID + "disable";
String menuItemId = "icon" + parentId + FORM_ID + "item";
- check(isDisabledId, false);
- clickCommandAndWait(disablingControlId);
+ disable(false);
writeStatus("Check standart HTML attributes");
assertEvents(menuItemId, SeleniumEvent.STANDARD_HTML_EVENTS);
@@ -91,13 +89,10 @@
writeStatus("Check styles and classes are output to client");
String parentId = getParentId();
- String isDisabledId = parentId + CONTROL_FORM_ID + "isDisabled";
- String disablingControlId = parentId + CONTROL_FORM_ID + "disable";
String itemId = parentId + FORM_ID + "item";
writeStatus("Check enabled component at first");
- check(isDisabledId, false);
- clickCommandAndWait(disablingControlId);
+ disable(false);
String styleElementId = "tablehide" + parentId + FORM_ID + "item";
assertStyleAttribute(styleElementId, "font-size: 16px", "Style attribute was not output to client");
@@ -115,14 +110,27 @@
assertClassNames(iconTdXpath, new String[] { "icon-class" }, "iconClass attribute was not output to client", false);
writeStatus("Check disabled component");
- check(isDisabledId, true);
- clickCommandAndWait(disablingControlId);
+ disable(true);
writeStatus("Check disabledClass/disabledStyle attributes");
assertStyleAttribute(styleElementId, "font-size: 13px", "disabledStyle attribute was not output to client");
assertClassNames(styleElementId, new String[] { "disabled-class" }, "disabledStyle attribute was not output to client", true);
}
+ @Test
+ public void testIconsAttributesApply(Template template) {
+ renderPage(LOOK_AND_FEEL_TEST_URL, template, null);
+
+ writeStatus("Check icons attributes apply: are output to client and images are accessible");
+
+ disable(false);
+
+ String itemId = getParentId() + FORM_ID + "item";
+ String iconImgXpath = "//*[@id='" + itemId + "']/table/tbody/tr/td[1]/img";
+ Assert.assertTrue(isPresent(iconImgXpath), "Icon is not rendered");
+ testIcon(iconImgXpath, "Chevron");
+ }
+
@Override
public void sendAjax() {
clickAjaxCommandAndWait("icon" + getAutoTester(this).getClientId("") + "item");
@@ -138,8 +146,29 @@
return null;
}
- private void check(String id, boolean isChecked) {
- runScript("document.getElementById('" + id + "').checked=" + isChecked);
+ private boolean disable(boolean isDisabled) {
+ String parentId = getParentId();
+ String isDisabledId = parentId + CONTROL_FORM_ID + "isDisabled";
+ String disablingControlId = parentId + CONTROL_FORM_ID + "disable";
+ boolean prevValue = Boolean.parseBoolean(runScript("document.getElementById('" + isDisabledId + "').checked"));
+ if (prevValue != isDisabled) {
+ runScript("document.getElementById('" + isDisabledId + "').checked=" + isDisabled);
+ clickCommandAndWait(disablingControlId);
+ }
+ return prevValue;
}
+ /**
+ * Test an icon.
+ *
+ * @param location location of image representing icon to be tested
+ * @param iconName substring that icon uri has to contain
+ */
+ private void testIcon(String location, String iconSubstring) {
+ String iconSrc = selenium.getAttribute(location + "/@src");
+ if (null == iconSrc || !iconSrc.matches(".*" + iconSubstring + ".*")) {
+ Assert.fail("It looks as if the icon is not proper. Uri of icon is being tested must contain ["
+ + iconSubstring + "]");
+ }
+ }
}
16 years, 8 months
JBoss Rich Faces SVN: r12410 - in trunk/test-applications/realworld/web/src/main/webapp/img: ajax and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: amarkhel
Date: 2009-01-23 11:51:30 -0500 (Fri, 23 Jan 2009)
New Revision: 12410
Added:
trunk/test-applications/realworld/web/src/main/webapp/img/ajax/
trunk/test-applications/realworld/web/src/main/webapp/img/ajax/Thumbs.db
trunk/test-applications/realworld/web/src/main/webapp/img/ajax/ajax_process.gif
trunk/test-applications/realworld/web/src/main/webapp/img/ajax/error.gif
trunk/test-applications/realworld/web/src/main/webapp/img/ajax/passed.gif
Log:
Added items remotely
E:\richfaces\test-applications\realworld\web\src\main\webapp\img\icons
E:\richfaces\test-applications\realworld\web\src\main\webapp\img\modal
E:\richfaces\test-applications\realworld\web\src\main\webapp\img\tree
E:\richfaces\test-applications\realworld\web\src\main\webapp\img\ajax
Added: trunk/test-applications/realworld/web/src/main/webapp/img/ajax/Thumbs.db
===================================================================
(Binary files differ)
Property changes on: trunk/test-applications/realworld/web/src/main/webapp/img/ajax/Thumbs.db
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/test-applications/realworld/web/src/main/webapp/img/ajax/ajax_process.gif
===================================================================
(Binary files differ)
Property changes on: trunk/test-applications/realworld/web/src/main/webapp/img/ajax/ajax_process.gif
___________________________________________________________________
Name: svn:mime-type
+ image/gif
Added: trunk/test-applications/realworld/web/src/main/webapp/img/ajax/error.gif
===================================================================
(Binary files differ)
Property changes on: trunk/test-applications/realworld/web/src/main/webapp/img/ajax/error.gif
___________________________________________________________________
Name: svn:mime-type
+ image/gif
Added: trunk/test-applications/realworld/web/src/main/webapp/img/ajax/passed.gif
===================================================================
(Binary files differ)
Property changes on: trunk/test-applications/realworld/web/src/main/webapp/img/ajax/passed.gif
___________________________________________________________________
Name: svn:mime-type
+ image/gif
16 years, 8 months
JBoss Rich Faces SVN: r12409 - in trunk/test-applications/realworld/web/src/main/webapp/img: tree and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: amarkhel
Date: 2009-01-23 11:51:24 -0500 (Fri, 23 Jan 2009)
New Revision: 12409
Added:
trunk/test-applications/realworld/web/src/main/webapp/img/tree/
trunk/test-applications/realworld/web/src/main/webapp/img/tree/Thumbs.db
trunk/test-applications/realworld/web/src/main/webapp/img/tree/disc.gif
trunk/test-applications/realworld/web/src/main/webapp/img/tree/dnd/
trunk/test-applications/realworld/web/src/main/webapp/img/tree/dnd/Thumbs.db
trunk/test-applications/realworld/web/src/main/webapp/img/tree/dnd/favorites.gif
trunk/test-applications/realworld/web/src/main/webapp/img/tree/dnd/image.gif
trunk/test-applications/realworld/web/src/main/webapp/img/tree/dnd/trash.gif
trunk/test-applications/realworld/web/src/main/webapp/img/tree/dnd/trash_full.gif
trunk/test-applications/realworld/web/src/main/webapp/img/tree/singer.gif
trunk/test-applications/realworld/web/src/main/webapp/img/tree/song.gif
Log:
Added items remotely
E:\richfaces\test-applications\realworld\web\src\main\webapp\img\icons
E:\richfaces\test-applications\realworld\web\src\main\webapp\img\modal
E:\richfaces\test-applications\realworld\web\src\main\webapp\img\tree
E:\richfaces\test-applications\realworld\web\src\main\webapp\img\ajax
Added: trunk/test-applications/realworld/web/src/main/webapp/img/tree/Thumbs.db
===================================================================
(Binary files differ)
Property changes on: trunk/test-applications/realworld/web/src/main/webapp/img/tree/Thumbs.db
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/test-applications/realworld/web/src/main/webapp/img/tree/disc.gif
===================================================================
(Binary files differ)
Property changes on: trunk/test-applications/realworld/web/src/main/webapp/img/tree/disc.gif
___________________________________________________________________
Name: svn:mime-type
+ image/gif
Added: trunk/test-applications/realworld/web/src/main/webapp/img/tree/dnd/Thumbs.db
===================================================================
(Binary files differ)
Property changes on: trunk/test-applications/realworld/web/src/main/webapp/img/tree/dnd/Thumbs.db
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/test-applications/realworld/web/src/main/webapp/img/tree/dnd/favorites.gif
===================================================================
(Binary files differ)
Property changes on: trunk/test-applications/realworld/web/src/main/webapp/img/tree/dnd/favorites.gif
___________________________________________________________________
Name: svn:mime-type
+ image/gif
Added: trunk/test-applications/realworld/web/src/main/webapp/img/tree/dnd/image.gif
===================================================================
(Binary files differ)
Property changes on: trunk/test-applications/realworld/web/src/main/webapp/img/tree/dnd/image.gif
___________________________________________________________________
Name: svn:mime-type
+ image/gif
Added: trunk/test-applications/realworld/web/src/main/webapp/img/tree/dnd/trash.gif
===================================================================
(Binary files differ)
Property changes on: trunk/test-applications/realworld/web/src/main/webapp/img/tree/dnd/trash.gif
___________________________________________________________________
Name: svn:mime-type
+ image/gif
Added: trunk/test-applications/realworld/web/src/main/webapp/img/tree/dnd/trash_full.gif
===================================================================
(Binary files differ)
Property changes on: trunk/test-applications/realworld/web/src/main/webapp/img/tree/dnd/trash_full.gif
___________________________________________________________________
Name: svn:mime-type
+ image/gif
Added: trunk/test-applications/realworld/web/src/main/webapp/img/tree/singer.gif
===================================================================
(Binary files differ)
Property changes on: trunk/test-applications/realworld/web/src/main/webapp/img/tree/singer.gif
___________________________________________________________________
Name: svn:mime-type
+ image/gif
Added: trunk/test-applications/realworld/web/src/main/webapp/img/tree/song.gif
===================================================================
(Binary files differ)
Property changes on: trunk/test-applications/realworld/web/src/main/webapp/img/tree/song.gif
___________________________________________________________________
Name: svn:mime-type
+ image/gif
16 years, 8 months