Author: amarkhel
Date: 2009-04-08 13:04:31 -0400 (Wed, 08 Apr 2009)
New Revision: 13444
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/FileManager.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/FileUploadManager.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Model.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/FileWrapper.java
trunk/test-applications/realworld2/web/src/main/webapp/includes/fileUpload/fileUploader.xhtml
trunk/test-applications/realworld2/web/src/main/webapp/includes/fileUpload/uploadResult.xhtml
Log:
Enhance fileUpload
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/FileManager.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/FileManager.java 2009-04-08
16:43:26 UTC (rev 13443)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/FileManager.java 2009-04-08
17:04:31 UTC (rev 13444)
@@ -223,6 +223,9 @@
if(!writeFile(fileName, tempFilePath, Constants._MEDIUM, Constants.MEDIUM_SIZE,
true)){
return false;
}
+ if(!writeOriginalFile(fileName, tempFilePath, true)){
+ return false;
+ }
return true;
}
@@ -317,6 +320,25 @@
return ret;
}
+ public boolean writeOriginalFile(String newFileName, String fileName,
+ boolean includeUploadRoot){
+ BufferedImage bsrc = null;
+ try {
+ bsrc = bitmapToImage(fileName, Constants.JPG);
+ } catch (IOException e1) {
+ return false;
+ }
+ BufferedImage bdest = getScaledInstance(bsrc, bsrc.getWidth(), bsrc.getHeight(),
+ RenderingHints.VALUE_INTERPOLATION_BICUBIC, true);
+ String dest = includeUploadRoot ? this.uploadRootPath
+ + newFileName : newFileName;
+ try {
+ imageToBitmap(bdest, dest, Constants.JPG);
+ } catch (IOException ex) {
+ return false;
+ }
+ return true;
+ }
@Restrict("#{s:hasRole('admin')}")
public boolean writeFile(String newFileName, String fileName,
String pattern, int size, boolean includeUploadRoot) {
@@ -333,6 +355,11 @@
int width = yy.intValue();
yy = ((Double) d * bsrc.getHeight());
int height = yy.intValue();
+ //Too small picture
+ if(width > bsrc.getWidth() || height > bsrc.getHeight()){
+ width = bsrc.getWidth();
+ height = bsrc.getHeight();
+ }
BufferedImage bdest = getScaledInstance(bsrc, width, height,
RenderingHints.VALUE_INTERPOLATION_BICUBIC, true);
String dest = includeUploadRoot ? this.uploadRootPath
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/FileUploadManager.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/FileUploadManager.java 2009-04-08
16:43:26 UTC (rev 13443)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/FileUploadManager.java 2009-04-08
17:04:31 UTC (rev 13444)
@@ -74,19 +74,18 @@
try {
extractMetadata(item, image);
} catch (Exception e1) {
- Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT,
Constants.FILE_PROCESSING_ERROR);
+ addError(item, image);
return;
}
image.setAlbum(model.getSelectedAlbum());
if(model.getSelectedAlbum() == null){
- Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT,
Constants.NO_ALBUM_TO_DOWNLOAD_ERROR);
+ addError(item, image);
return;
}
String newPath = Constants.SLASH + model.getSelectedAlbum().getOwner().getLogin() +
Constants.SLASH + model.getSelectedAlbum().getId() + Constants.SLASH +item.getFileName();
image.setPath(newPath);
if(!fileManager.addImage(newPath, item.getFile().getPath())){
- Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, Constants.FILE_SAVE_ERROR);
- item.getFile().delete();
+ addError(item, image);
return;
}
fileWrapper.getFiles().add(image);
@@ -95,6 +94,11 @@
item.getFile().delete();
}
+ private void addError(UploadItem item, Image image) {
+ fileWrapper.getErrorFiles().add(image);
+ item.getFile().delete();
+ }
+
private Image constructImage(UploadItem item) {
Image image = new Image();
image.setUploaded(new Date());
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Model.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Model.java 2009-04-08
16:43:26 UTC (rev 13443)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Model.java 2009-04-08
17:04:31 UTC (rev 13444)
@@ -38,11 +38,11 @@
private List<Image> images;
public void resetModel(NavigationEnum mainArea, User selectedUser, Shelf selectedShelf,
Album selectedAlbum, Image selectedImage, List<Image> images){
- this.setMainArea(mainArea);
this.setSelectedAlbum(selectedAlbum);
this.setSelectedImage(selectedImage);
this.setSelectedShelf(selectedShelf);
this.setSelectedUser(selectedUser);
+ this.setMainArea(mainArea);
this.images = images;
}
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/FileWrapper.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/FileWrapper.java 2009-04-08
16:43:26 UTC (rev 13443)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/FileWrapper.java 2009-04-08
17:04:31 UTC (rev 13444)
@@ -39,8 +39,23 @@
private static final long serialVersionUID = -1767281809514660171L;
+ private boolean complete = false;
+
private List<Image> files = new ArrayList<Image>();
+ private List<Image> errorFiles = new ArrayList<Image>();
+
+ public String getErrorNames(){
+ StringBuilder s = new StringBuilder();
+ for(int i = 0; i < errorFiles.size(); i++){
+ Image im = errorFiles.get(i);
+ s.append(im.getName());
+ if(!(i == errorFiles.size() - 1)){
+ s.append(" ,");
+ }
+ }
+ return s.toString();
+ }
public int getSize() {
return getFiles().size();
}
@@ -61,5 +76,23 @@
@Observer(Constants.CLEAR_FILE_UPLOAD_EVENT)
public void clear(){
files.clear();
+ errorFiles.clear();
+ complete = false;
}
+
+ public boolean isComplete() {
+ return complete;
+ }
+
+ public void setComplete(boolean complete) {
+ this.complete = complete;
+ }
+
+ public List<Image> getErrorFiles() {
+ return errorFiles;
+ }
+
+ public void setErrorFiles(List<Image> errorFiles) {
+ this.errorFiles = errorFiles;
+ }
}
\ No newline at end of file
Modified:
trunk/test-applications/realworld2/web/src/main/webapp/includes/fileUpload/fileUploader.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/test-applications/realworld2/web/src/main/webapp/includes/fileUpload/uploadResult.xhtml
===================================================================
(Binary files differ)