Author: amarkhel
Date: 2009-01-23 08:27:29 -0500 (Fri, 23 Jan 2009)
New Revision: 12387
Removed:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandler.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandlerInterceptor.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/RealworldException.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/AvatarUpload.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileLoader.java
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandlerBean.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileManager.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileUploadBean.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileWrapper.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/ImageLoader.java
Log:
Deleted:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandler.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandler.java 2009-01-23
13:23:32 UTC (rev 12386)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandler.java 2009-01-23
13:27:29 UTC (rev 12387)
@@ -1,13 +0,0 @@
-package org.richfaces.realworld.error;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import org.jboss.seam.annotations.intercept.Interceptors;
-
-(a)Target({ElementType.TYPE ,ElementType.METHOD })
-(a)Retention(RetentionPolicy.RUNTIME)
-(a)Interceptors(ErrorHandlerInterceptor.class)
-public @interface ErrorHandler {}
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandlerBean.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandlerBean.java 2009-01-23
13:23:32 UTC (rev 12386)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandlerBean.java 2009-01-23
13:27:29 UTC (rev 12387)
@@ -1,3 +1,23 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
package org.richfaces.realworld.error;
import java.util.ArrayList;
@@ -11,13 +31,15 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Observer;
import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Startup;
@Name("errorHandlerBean")
@Scope(ScopeType.EVENT)
@AutoCreate
public class ErrorHandlerBean {
+ private static final String ERROR_ID = "mainform:error";
+ private static final String CLEAR_ERROR_EVENT = "clearErrorEvent";
+ private static final String ADD_ERROR_EVENT = "addErrorEvent";
private List<Exception> errors = new ArrayList<Exception>();
public List<Exception> getErrors() {
@@ -32,16 +54,16 @@
return errors.size() > 0 ;
}
- @Observer("clearErrorEvent")
+ @Observer(CLEAR_ERROR_EVENT)
public void clearEvents(){
errors.clear();
}
- @Observer("addErrorEvent")
+ @Observer(ADD_ERROR_EVENT)
public void addToErrors(Exception e){
FacesContext context = FacesContext.getCurrentInstance();
AjaxContext ac = AjaxContext.getCurrentInstance(context);
- ac.addRenderedArea("mainform:error");
+ ac.addRenderedArea(ERROR_ID);
errors.add(e);
}
}
Deleted:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandlerInterceptor.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandlerInterceptor.java 2009-01-23
13:23:32 UTC (rev 12386)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/ErrorHandlerInterceptor.java 2009-01-23
13:27:29 UTC (rev 12387)
@@ -1,18 +0,0 @@
-package org.richfaces.realworld.error;
-
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.intercept.AroundInvoke;
-import org.jboss.seam.annotations.intercept.Interceptor;
-import org.jboss.seam.core.BijectionInterceptor;
-import org.jboss.seam.core.Events;
-import org.jboss.seam.intercept.InvocationContext;
-
-@Name("interceptor")
-public class ErrorHandlerInterceptor {
-
- @AroundInvoke
- public Object process(InvocationContext invocation) throws Exception {
- Events.instance().raiseEvent("clearErrorEvent");
- return invocation.proceed();
- }
-}
Deleted:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/RealworldException.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/RealworldException.java 2009-01-23
13:23:32 UTC (rev 12386)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/error/RealworldException.java 2009-01-23
13:27:29 UTC (rev 12387)
@@ -1,21 +0,0 @@
-package org.richfaces.realworld.error;
-
-import javax.ejb.ApplicationException;
-
-@ApplicationException
-public class RealworldException extends Exception{
-
- private static final long serialVersionUID = -5514996140663854304L;
-
- public RealworldException(String message) {
- super(message);
- }
-
- public RealworldException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public RealworldException(Throwable cause) {
- super(cause);
- }
-}
Deleted:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/AvatarUpload.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/AvatarUpload.java 2009-01-23
13:23:32 UTC (rev 12386)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/AvatarUpload.java 2009-01-23
13:27:29 UTC (rev 12387)
@@ -1,64 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.richfaces.realworld.fileupload;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.Serializable;
-
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.richfaces.event.UploadEvent;
-import org.richfaces.model.UploadItem;
-import org.richfaces.realworld.domain.Image;
-
-@Name("avatarUpload")
-(a)Scope(ScopeType.CONVERSATION)
-public class AvatarUpload implements Serializable{
-
- private static final long serialVersionUID = -3653686566159143678L;
-
- private FileItem avatarItem;
-
- public void avatarListener(UploadEvent event){
- UploadItem item = event.getUploadItem();
- FileItem file = new FileItem();
- file.setLength(item.getData().length);
- Image image = new Image();
- image.setName(item.getFileName());
- file.setImage(image);
- file.setData(item.getData());
- this.setAvatarItem(file);
- }
-
- public synchronized void paintAvatar(OutputStream stream, Object object) throws
IOException {
- stream.write(this.getAvatarItem().getData());
- }
-
- public FileItem getAvatarItem() {
- return avatarItem;
- }
-
- public void setAvatarItem(FileItem avatarItem) {
- this.avatarItem = avatarItem;
- }
-}
Deleted:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileLoader.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileLoader.java 2009-01-23
13:23:32 UTC (rev 12386)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileLoader.java 2009-01-23
13:27:29 UTC (rev 12387)
@@ -1,40 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.richfaces.realworld.fileupload;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-
-@Name("fileLoader")
-(a)Scope(ScopeType.CONVERSATION)
-public class FileLoader {
-
- @In
- FileWrapper fileWrapper;
- public synchronized void paint(OutputStream stream, Object object) throws IOException {
- stream.write(fileWrapper.getFiles().get((Integer)object).getData());
- }
-}
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileManager.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileManager.java 2009-01-23
13:23:32 UTC (rev 12386)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileManager.java 2009-01-23
13:27:29 UTC (rev 12387)
@@ -54,6 +54,10 @@
this.uploadRoot = uploadRoot;
}
+ public String getAvatarFriendsPath(String path, String avatarPath){
+ return getUploadRoot() + path + getFileSeparator() + "avatars" +
getFileSeparator() + avatarPath;
+ }
+
public FileManager(){
FacesContext fc = FacesContext.getCurrentInstance();
this.setUploadRoot(fc.getExternalContext().getInitParameter(UPLOAD_ROOT));
@@ -106,35 +110,6 @@
writeFileTodisk(data, fileName, 0, 0, "" );
writeFileTodisk(data, fileName, 50, 50, "_mini" );
writeFileTodisk(data, fileName, 600, 400, "_medium" );
- //FileOutputStream b = new FileOutputStream(getUploadRoot() + fileName);
- //b.write(data);
- //b.close();
- /*InputStream inputStream = new ByteArrayInputStream(data);
- BufferedImage bsrc = ImageIO.read(inputStream);
- inputStream = new ByteArrayInputStream(data);
- bsrc = ImageIO.read(inputStream);
- ImageIO.write(bsrc, "JPG", new File(getUploadRoot() + fileName));
- int width = 50;
- int height = 50;
- BufferedImage bdest = new BufferedImage(width, height,
- BufferedImage.TYPE_INT_RGB);
- Graphics2D g = bdest.createGraphics();
- AffineTransform at = AffineTransform.getScaleInstance((double) width
- / bsrc.getWidth(), (double) height / bsrc.getHeight());
- g.drawRenderedImage(bsrc, at);
- String dest = getUploadRoot() + transformPath(fileName, "_mini");
- ImageIO.write(bdest, "JPG", new File(dest));
- width = 600;
- height = 400;
- bdest = new BufferedImage(width, height,
- BufferedImage.TYPE_INT_RGB);
- g = bdest.createGraphics();
- at = AffineTransform.getScaleInstance((double) width
- / bsrc.getWidth(), (double) height / bsrc.getHeight());
- g.drawRenderedImage(bsrc, at);
- dest = getUploadRoot() + transformPath(fileName, "_medium");
- ImageIO.write(bdest, "JPG", new File(dest));
- inputStream.close();*/
}
private void writeFileTodisk(byte[] data, String fileName, int width, int height, String
format) throws IOException{
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileUploadBean.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileUploadBean.java 2009-01-23
13:23:32 UTC (rev 12386)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileUploadBean.java 2009-01-23
13:27:29 UTC (rev 12387)
@@ -29,17 +29,22 @@
import java.util.Date;
import java.util.List;
+import javax.faces.model.SelectItem;
+
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Observer;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.core.Events;
import org.richfaces.event.UploadEvent;
import org.richfaces.model.UploadItem;
import org.richfaces.realworld.domain.Image;
+import org.richfaces.realworld.domain.MetaTag;
+import org.richfaces.realworld.domain.Rank;
import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.util.SelectionHelper;
+import org.richfaces.realworld.ui.ConversationState;
import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.imaging.jpeg.JpegProcessingException;
@@ -51,133 +56,222 @@
/**
* @author $Autor$
- *
+ *
*/
@Name("fileUploadBean")
@Scope(ScopeType.CONVERSATION)
+public class FileUploadBean implements Serializable {
-public class FileUploadBean implements Serializable{
-
- @In("#{messages['samplename']}") private String SAMPLE_NAME;
+ private static final int MULTY_MODE_FILE_QUANTITY = 100;
- @In("#{messages['sampledesc']}") private String SAMPLE_DESCRIPTION;
+ private static final int SINGLE_MODE_FILE_QUANTITY = 1;
+ private static final String MULTY = "multy";
+
+ private static final String SINGLE = "single";
+
+ private static final String SLASH = "/";
+
+ @In("#{messages['samplename']}")
+ private String SAMPLE_NAME;
+
+ @In("#{messages['sampledesc']}")
+ private String SAMPLE_DESCRIPTION;
+
private static final String ADD_IMAGE_EVENT = "addImage";
private static final long serialVersionUID = 4969087557225414955L;
@In
private User user;
-
- @In(create=true) @Out
+
+ private int fileQuantity = 1;
+
+ private boolean fileUploadRendered;
+
+ @In(create = true)
+ @Out
FileWrapper fileWrapper;
-
- @In(create=true)
+
+ @In(create = true)
private FileManager fileManager;
-
- @In @Out
- private SelectionHelper selectionHelper;
- public synchronized void listener(UploadEvent event) throws Exception{
- UploadItem item = event.getUploadItem();
- FileItem file = new FileItem();
- file.setLength(item.getData().length);
- file.setData(item.getData());
- file.setSelected(false);
- Image image = new Image();
- image.setUploaded(new Date());
- image.setDescription(SAMPLE_DESCRIPTION);
- image.setName(SAMPLE_NAME);
- image.setSize(file.getLength() / 1024);
- image.setPath(user.getLogin() + "/" +
selectionHelper.getSelectedAlbum().getName() + "/" + item.getFileName());
- image.setAlbumName(selectionHelper.getSelectedAlbum().getName());
- image.setAlbum(selectionHelper.getSelectedAlbum());
- try {
+ private String selectedMode;
+
+ @In
+ @Out
+ private ConversationState conversationState;
+
+ public synchronized void listener(UploadEvent event) throws Exception {
+ UploadItem item = event.getUploadItem();
+ FileItem file = new FileItem();
+ file.setLength(item.getData().length);
+ file.setData(item.getData());
+ file.setSelected(false);
+ Image image = new Image();
+ image.setUploaded(new Date());
+ image.setDescription(SAMPLE_DESCRIPTION);
+ image.setName(SAMPLE_NAME);
+ image.setSize(file.getLength() / 1024);
+ String albumPath = conversationState.getSelectedAlbum()
+ .getAlbumPathFromParents(conversationState.getSelectedAlbum(),
+ new ArrayList<String>(), SLASH)
+ + conversationState.getSelectedAlbum().getName() + SLASH;
+ image.setPath(user.getLogin() + SLASH + albumPath + item.getFileName());
+ image.setAlbumName(conversationState.getSelectedAlbum().getName());
+ image.setAlbum(conversationState.getSelectedAlbum());
+ Rank rank = new Rank();
+ rank.setHits(0L);
+ rank.setTotal(0L);
+ image.setRank(rank);
+ List<MetaTag> tags = new ArrayList<MetaTag>();
+ image.setTags(tags);
+ image.setMeta(new ArrayList<MetaTag>(tags));
+
+ try {
InputStream in = new ByteArrayInputStream(file.getData());
Metadata metadata = JpegMetadataReader.readMetadata(in);
- Directory exifDirectory = metadata.getDirectory(ExifDirectory.class);
+ Directory exifDirectory = metadata
+ .getDirectory(ExifDirectory.class);
Directory jpgDirectory = metadata.getDirectory(JpegDirectory.class);
-
- if(exifDirectory.containsTag(ExifDirectory.TAG_MODEL)){
- String cameraModel = exifDirectory.getString(ExifDirectory.TAG_MODEL);
+
+ if (exifDirectory.containsTag(ExifDirectory.TAG_MODEL)) {
+ String cameraModel = exifDirectory
+ .getString(ExifDirectory.TAG_MODEL);
image.setCameraModel(cameraModel);
}
- if(exifDirectory.containsTag(ExifDirectory.TAG_EXIF_IMAGE_WIDTH) &&
exifDirectory.containsTag(ExifDirectory.TAG_EXIF_IMAGE_HEIGHT)){
- int width = exifDirectory.getInt(ExifDirectory.TAG_EXIF_IMAGE_WIDTH);
+ if (exifDirectory.containsTag(ExifDirectory.TAG_EXIF_IMAGE_WIDTH)
+ && exifDirectory
+ .containsTag(ExifDirectory.TAG_EXIF_IMAGE_HEIGHT)) {
+ int width = exifDirectory
+ .getInt(ExifDirectory.TAG_EXIF_IMAGE_WIDTH);
image.setWidth(width);
- int height = exifDirectory.getInt(ExifDirectory.TAG_EXIF_IMAGE_HEIGHT);
+ int height = exifDirectory
+ .getInt(ExifDirectory.TAG_EXIF_IMAGE_HEIGHT);
image.setHeight(height);
- }else{
- if(jpgDirectory.containsTag(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT)){
- int width = jpgDirectory.getInt(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
+ } else {
+ if (jpgDirectory
+ .containsTag(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT)) {
+ int width = jpgDirectory
+ .getInt(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
image.setWidth(width);
- int height = jpgDirectory.getInt(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
+ int height = jpgDirectory
+ .getInt(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
image.setHeight(height);
}
}
- if(exifDirectory.containsTag(ExifDirectory.TAG_DATETIME_ORIGINAL)){
- Date time = exifDirectory.getDate(ExifDirectory.TAG_DATETIME_ORIGINAL);
+ if (exifDirectory.containsTag(ExifDirectory.TAG_DATETIME_ORIGINAL)) {
+ Date time = exifDirectory
+ .getDate(ExifDirectory.TAG_DATETIME_ORIGINAL);
image.setCreated(time);
}
- }
- catch (JpegProcessingException e1) {
+ } catch (JpegProcessingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
- } catch (MetadataException e) {
+ } catch (MetadataException me) {
// TODO Auto-generated catch block
- e.printStackTrace();
+ me.printStackTrace();
}
file.setImage(image);
- fileWrapper.getFiles().add(file);
+ fileWrapper.getFiles().add(file);
}
-
+
+ @Observer("fileUploadClear")
public void clearUploadData() {
fileWrapper.getFiles().clear();
}
-
+
public void clearSelectedData() {
- for(int i = 0; i < fileWrapper.getFiles().size(); i++){
- if(fileWrapper.getFiles().get(i).isSelected()){
+ for (int i = 0; i < fileWrapper.getFiles().size(); i++) {
+ if (fileWrapper.getFiles().get(i).isSelected()) {
fileWrapper.getFiles().remove(i);
}
}
}
-
+
public void storeSelectedData() {
List<FileItem> temp = new ArrayList<FileItem>();
- for(FileItem file:fileWrapper.getFiles()){
- if(file.isSelected()){
- //Save file to disk
- String fileName = fileManager.transformToServerPath(file.getImage().getPath());
+ for (FileItem file : fileWrapper.getFiles()) {
+ if (file.isSelected()) {
+ // Save file to disk
+ String fileName = fileManager.transformToServerPath(file
+ .getImage().getPath());
try {
- fileManager.addImage(fileName , file.getData());
+ fileManager.addImage(fileName, file.getData());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Events.instance().raiseEvent(ADD_IMAGE_EVENT, file.getImage());
- }else{
+ } else {
temp.add(file);
}
}
fileWrapper.getFiles().clear();
fileWrapper.getFiles().addAll(temp);
}
-
+
public void storeAll() {
- for(FileItem file:fileWrapper.getFiles()){
- //Save file to disk
- String fileName = fileManager.transformToServerPath(file.getImage().getPath());
+ for (FileItem file : fileWrapper.getFiles()) {
+ // Save file to disk
+ String fileName = fileManager.transformToServerPath(file.getImage()
+ .getPath());
try {
- fileManager.addImage(fileName , file.getData());
+ fileManager.addImage(fileName, file.getData());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
- //Update domain model
+ // Update domain model
Events.instance().raiseEvent(ADD_IMAGE_EVENT, file.getImage());
}
fileWrapper.getFiles().clear();
}
-
+
+ public boolean isFileUploadRendered() {
+ return fileUploadRendered;
+ }
+
+ public void setFileUploadRendered(boolean fileUploadRendered) {
+ this.fileUploadRendered = fileUploadRendered;
+ }
+
+ @Observer("showFileUpload")
+ public void showFileUpload(boolean result) {
+ this.setFileUploadRendered(result);
+ clearUploadData();
+ }
+
+ public void changeMode() {
+ if (this.getSelectedMode().equals(SINGLE)) {
+ this.setFileQuantity(SINGLE_MODE_FILE_QUANTITY);
+ } else if (this.getSelectedMode().equals(MULTY)) {
+ this.setFileQuantity(MULTY_MODE_FILE_QUANTITY);
+ }
+ }
+
+ public int getFileQuantity() {
+ return fileQuantity;
+ }
+
+ public void setFileQuantity(int fileQuantity) {
+ this.fileQuantity = fileQuantity;
+ }
+
+ public List<SelectItem> getItems() {
+ List<SelectItem> list = new ArrayList<SelectItem>(2);
+ list.add(new SelectItem(SINGLE, SINGLE));
+ list.add(new SelectItem(MULTY, MULTY));
+ return list;
+ }
+
+ public String getSelectedMode() {
+ return selectedMode;
+ }
+
+ @Observer("changeMode")
+ public void setSelectedMode(String selectedMode) {
+ this.selectedMode = selectedMode;
+ }
+
}
\ No newline at end of file
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileWrapper.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileWrapper.java 2009-01-23
13:23:32 UTC (rev 12386)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/FileWrapper.java 2009-01-23
13:27:29 UTC (rev 12387)
@@ -32,12 +32,7 @@
private ArrayList<FileItem> files = new ArrayList<FileItem>();
public int getSize() {
- if (getFiles().size()>0){
- return getFiles().size();
- }else
- {
- return 0;
- }
+ return getFiles().size();
}
public ArrayList<FileItem> getFiles() {
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/ImageLoader.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/ImageLoader.java 2009-01-23
13:23:32 UTC (rev 12386)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/fileupload/ImageLoader.java 2009-01-23
13:27:29 UTC (rev 12387)
@@ -36,14 +36,11 @@
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
-import org.richfaces.realworld.domain.User;
@Name("imageLoader")
@Scope(ScopeType.CONVERSATION)
public class ImageLoader implements Serializable{
- private static final String DELIMITER = ":";
-
private static final String JPEG = "jpeg";
private static final long serialVersionUID = -1572789608594870285L;
@@ -51,6 +48,16 @@
@In(create=true)
FileManager fileManager;
+ @In(create=true)
+ FileWrapper fileWrapper;
+ public synchronized void paintImageFromByteArray(OutputStream stream, Object object)
throws IOException {
+ stream.write(fileWrapper.getFiles().get(((Long)object).intValue()).getData());
+ }
+
+ public synchronized void paintImageFromByteArray2(OutputStream stream, Object object)
throws IOException {
+ stream.write(fileWrapper.getFiles().get(((Integer)object)).getData());
+ }
+
public synchronized void paintSearchImage(OutputStream stream, Object object) throws
IOException {
File image =
fileManager.getImage(fileManager.transformToServerPath(object.toString()));
InputStream paintData = null;
@@ -94,7 +101,7 @@
stream.write(data);
}
- public synchronized void paint(OutputStream out, Object data) throws IOException{
+ public synchronized void paintImage(OutputStream out, Object data) throws IOException{
if (null == data) {
return;
}
@@ -119,86 +126,4 @@
}
}
}
-
- public synchronized void paintGalleryImage(OutputStream out, Object data) throws
IOException{
- if (null == data) {
- return;
- }
- String fileName = fileManager.getFileSeparator() + "galleries" +
fileManager.getFileSeparator() + fileManager.transformToServerPath(data.toString());
- File imageResource = fileManager.getImage(fileName);
- if (imageResource != null) {
- FileInputStream fileInputStream = new FileInputStream(imageResource);
- BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
- InputStream paintData = bufferedInputStream;
- if (null == paintData) {
- // throw new Exception("");
- // TODO
- }
- try{
- BufferedImage images = ImageIO.read(paintData);
- ImageIO.write(images, JPEG, out);
- }catch(Exception e){
-
- }finally{
- fileInputStream.close();
- bufferedInputStream.close();
- paintData.close();
- }
- }
- }
-
- public synchronized void paintAvatar(OutputStream out, Object data) throws IOException{
- if (null == data) {
- return;
- }
- User user = (User)data;
- File imageResource = fileManager.getImage(user.getLogin() +
fileManager.getFileSeparator() + "avatars" + fileManager.getFileSeparator() +
user.getAvatarPath());
- if (imageResource != null) {
- FileInputStream fileInputStream = new FileInputStream(imageResource);
- BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
- InputStream paintData = bufferedInputStream;
- if (null == paintData) {
- // throw new Exception("");
- // TODO
- }
- try{
- BufferedImage image = ImageIO.read(paintData);
- ImageIO.write(image, JPEG, out);
- }catch(Exception e){
-
- }finally{
- fileInputStream.close();
- bufferedInputStream.close();
- paintData.close();
- }
- }
- }
-
- public synchronized void paintFriendAvatar(OutputStream out, Object data) throws
IOException{
- if (null == data) {
- return;
- }
- String temp = data.toString();
- String[] array = temp.split(DELIMITER);
- File imageResource = fileManager.getImage(array[0] + fileManager.getFileSeparator() +
"avatars" + fileManager.getFileSeparator() + array[1]);
- if (imageResource != null) {
- FileInputStream fileInputStream = new FileInputStream(imageResource);
- BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
- InputStream paintData = bufferedInputStream;
- if (null == paintData) {
- // throw new Exception("");
- // TODO
- }
- try{
- BufferedImage image = ImageIO.read(paintData);
- ImageIO.write(image, JPEG, out);
- }catch(Exception e){
-
- }finally{
- fileInputStream.close();
- bufferedInputStream.close();
- paintData.close();
- }
- }
- }
}