Author: amarkhel
Date: 2009-03-11 10:24:18 -0400 (Wed, 11 Mar 2009)
New Revision: 12922
Added:
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/RegistrationManager.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/FileUploadBean.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/FileManagerTest.java
Removed:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/FileManager.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/FileManagerTest.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/FileUploadBean.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/test2.java
trunk/test-applications/realworld2/web/src/main/webapp/includes/news/
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/FileItem.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/ImageLoader.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/listener/CopyImagesStuff.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/AlbumManager.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Authenticator.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ShelfManager.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/TagList.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/UserPrefsHelper.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/DirectLinkHelper.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/test.java
trunk/test-applications/realworld2/web/src/main/webapp/includes/contextMenu/CMForShelf.xhtml
trunk/test-applications/realworld2/web/src/main/webapp/includes/fileUpload/fileUploader.xhtml
trunk/test-applications/realworld2/web/src/main/webapp/includes/fileUpload/multyMode.xhtml
trunk/test-applications/realworld2/web/src/main/webapp/includes/index/login.xhtml
trunk/test-applications/realworld2/web/src/main/webapp/includes/register/regInfo.xhtml
trunk/test-applications/realworld2/web/src/main/webapp/includes/userPrefs/userPrefs.xhtml
trunk/test-applications/realworld2/web/src/main/webapp/layout/menu.xhtml
Log:
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/FileItem.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/FileItem.java 2009-03-11
13:49:58 UTC (rev 12921)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/FileItem.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -79,5 +79,4 @@
public void setFile(File file) {
this.file = file;
}
-
-}
+}
\ No newline at end of file
Deleted:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/FileManager.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/FileManager.java 2009-03-11
13:49:58 UTC (rev 12921)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/FileManager.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -1,367 +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.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.Transparency;
-import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.List;
-
-import javax.faces.context.FacesContext;
-import javax.imageio.ImageIO;
-import javax.imageio.ImageReader;
-import javax.imageio.ImageWriter;
-import javax.imageio.stream.ImageInputStream;
-
-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")
-(a)Scope(ScopeType.CONVERSATION)
-public class FileManager {
-
- private static final String _SMALL160 = "_small160";
- private static final String _SMALL120 = "_small120";
- private static final String _SMALL80 = "_small80";
- private static final String _MEDIUM = "_medium";
- private static final String _MINI = "_mini";
-
- private File uploadRoot;
- private String uploadRootPath;
-
- public File getUploadRoot() {
- return uploadRoot;
- }
-
- public void setUploadRoot(String uploadRootPath) throws IOException {
- if (uploadRootPath != null) {
- this.uploadRoot = new File(uploadRootPath);
- this.uploadRootPath = this.uploadRoot.getCanonicalPath()
- + File.separator;
- } else {
- this.uploadRoot = null;
- this.uploadRootPath = null;
- }
- }
-
- public FileManager() throws IOException {
- FacesContext fc = FacesContext.getCurrentInstance();
- if (fc != null) {
- // TODO nick - ask Andrei if we can throw exception here
- this.setUploadRoot(fc.getExternalContext().getInitParameter(
- Constants.UPLOAD_ROOT));
- }
- }
-
- private File getFileByPath(String path) {
- if (this.uploadRoot != null) {
- File result = new File(this.uploadRoot, path);
-
- try {
- String resultCanonicalPath = result.getCanonicalPath();
- if (!resultCanonicalPath.startsWith(this.uploadRootPath)) {
- // TODO log error
- result = null;
- }
-
- return result;
- } catch (IOException e) {
- // TODO: handle exception
- result = null;
- }
-
- return result;
- }
-
- return null;
- }
-
- public boolean isDirectoryPresent(String directory) {
- File file = getFileByPath(directory);
- return file.exists() && file.isDirectory();
- }
-
- public void deleteDirectory(String... directories) {
- String directory = new String();
- for (String chunk : directories) {
- directory += chunk + File.separator;
- }
- File file = getFileByPath(directory);
- if (file.exists()) {
- for (String f : file.list()) {
- File temp = new File(file, f);
- temp.delete();
- }
- file.delete();
- }
- }
-
- public boolean renameDirectory(String directoryOld, String directoryNew) {
- File fileOld = getFileByPath(directoryOld);
- File fileNew = getFileByPath(directoryNew);
-
- createDirectoryIfNotExist(directoryNew);
- if (fileNew.exists()) {
- if (fileNew.isDirectory()) {
- return false;
- } else {
- fileNew.delete();
- }
- }
- fileOld.renameTo(fileNew);
- return true;
- }
-
- public void addDirectory(String... directories) {
- String directory = new String();
- for (String chunk : directories) {
- directory += chunk;
- }
- File file = getFileByPath(directory);
- file.mkdirs();
- }
-
- public boolean addImage(String fileName, String tempFilePath) {
- createDirectoryIfNotExist(fileName);
- writeFile(fileName, tempFilePath, _SMALL80, 80, true);
- writeFile(fileName, tempFilePath, _SMALL120, 120, true);
- writeFile(fileName, tempFilePath, _SMALL160, 160, true);
- writeFile(fileName, tempFilePath, _MINI, 150, true);
- writeFile(fileName, tempFilePath, _MEDIUM, 600, true);
- return true;
- }
-
- public static BufferedImage bitmapToImage(String data, String format) throws IOException
{
- InputStream inb = new FileInputStream(data);
- ImageReader rdr = (ImageReader)
ImageIO.getImageReadersByFormatName(format).next();
- ImageInputStream imageInput = ImageIO.createImageInputStream(inb);
- rdr.setInput(imageInput);
- BufferedImage image = rdr.read(0);
- inb.close();
- return image;
- }
-
- public static void imageToBitmap(BufferedImage image, String data, String format)
throws IOException {
- OutputStream inb = new FileOutputStream(data);
- ImageWriter wrt = (ImageWriter)
ImageIO.getImageWritersByFormatName(format).next();
- ImageInputStream imageInput = ImageIO.createImageOutputStream(inb);
- wrt.setOutput(imageInput);
- wrt.write(image);
- inb.close();
- }
-
- /**
- * Convenience method that returns a scaled instance of the
- * provided {@code BufferedImage}.
- *
- * @param img the original image to be scaled
- * @param targetWidth the desired width of the scaled instance,
- * in pixels
- * @param targetHeight the desired height of the scaled instance,
- * in pixels
- * @param hint one of the rendering hints that corresponds to
- * {@code RenderingHints.KEY_INTERPOLATION} (e.g.
- * {@code RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR},
- * {@code RenderingHints.VALUE_INTERPOLATION_BILINEAR},
- * {@code RenderingHints.VALUE_INTERPOLATION_BICUBIC})
- * @param higherQuality if true, this method will use a multi-step
- * scaling technique that provides higher quality than the usual
- * one-step technique (only useful in downscaling cases, where
- * {@code targetWidth} or {@code targetHeight} is
- * smaller than the original dimensions, and generally only when
- * the {@code BILINEAR} hint is specified)
- * @return a scaled version of the original {@code BufferedImage}
- */
- public static BufferedImage getScaledInstance(BufferedImage img,
- int targetWidth,
- int targetHeight,
- Object hint,
- boolean higherQuality)
- {
- int type = (img.getTransparency() == Transparency.OPAQUE) ?
- BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
- BufferedImage ret = (BufferedImage)img;
- int w, h;
- if (higherQuality) {
- // Use multi-step technique: start with original size, then
- // scale down in multiple passes with drawImage()
- // until the target size is reached
- w = img.getWidth();
- h = img.getHeight();
- } else {
- // Use one-step technique: scale directly from original
- // size to target size with a single drawImage() call
- w = targetWidth;
- h = targetHeight;
- }
-
- do {
- if (higherQuality && w > targetWidth) {
- w /= 2;
- if (w < targetWidth) {
- w = targetWidth;
- }
- }
-
- if (higherQuality && h > targetHeight) {
- h /= 2;
- if (h < targetHeight) {
- h = targetHeight;
- }
- }
-
- BufferedImage tmp = new BufferedImage(w, h, type);
- Graphics2D g2 = tmp.createGraphics();
- g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint);
- g2.drawImage(ret, 0, 0, w, h, null);
- g2.dispose();
-
- ret = tmp;
- } while (w != targetWidth || h != targetHeight);
-
- return ret;
- }
-
- public void writeFile(String newFileName, String fileName,String pattern, int size,
boolean includeUploadRoot) {
- BufferedImage bsrc =null;
- try {
- bsrc = bitmapToImage(fileName, "JPG");
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- int i = bsrc.getWidth() > bsrc.getHeight()? bsrc.getWidth(): bsrc.getHeight();
- double d = (double) size
- / i;
- Double yy = ((Double)d*bsrc.getWidth());
- int width = yy.intValue();
- yy = ((Double)d*bsrc.getHeight());
- int height= yy.intValue();
- BufferedImage bdest = getScaledInstance(bsrc, width, height,
RenderingHints.VALUE_INTERPOLATION_BICUBIC, true);
- String dest = includeUploadRoot? this.uploadRootPath + transformPath(newFileName,
pattern) : transformPath(newFileName, pattern);
- try {
- imageToBitmap(bdest, dest, "JPG");
- } catch (IOException ex) {
- // TODO Auto-generated catch block
- ex.printStackTrace();
- }
- }
-
- public String transformPath(String target, String substitute) {
- String begin = target.substring(0, target.lastIndexOf(Constants.DOT));
- String end = target.substring(target.lastIndexOf(Constants.DOT));
- return begin + substitute + end;
- }
-
- public String transformFileUploadPath(String target, String substitute) {
- String begin = target.substring(0, target.lastIndexOf(Constants.DOT));
- String end = target.substring(target.lastIndexOf(Constants.DOT));
- return begin + substitute + end ;
- }
-
- public void deleteImage(String fileName) {
- deleteImage(getFileByPath(fileName));
- deleteImage(getFileByPath(transformPath(fileName, _MINI)));
- deleteImage(getFileByPath(transformPath(fileName, _MEDIUM)));
- deleteImage(getFileByPath(transformPath(fileName, _SMALL80)));
- deleteImage(getFileByPath(transformPath(fileName, _SMALL120)));
- deleteImage(getFileByPath(transformPath(fileName, _SMALL160)));
- }
-
- private void deleteImage(File file) {
- if (file.exists()) {
- file.delete();
- }
- }
-
- public String getPathOfImage(String path) {
- int i = path.lastIndexOf(Constants.SLASH);
- return path.substring(i);
- }
-
- public void renameImage(String fileNameOld, String fileNameNew) {
- createDirectoryIfNotExist(fileNameNew);
- renameImage(getFileByPath(fileNameNew), getFileByPath(fileNameOld));
-
- renameImage(getFileByPath(transformPath(fileNameNew, _MINI)),
- getFileByPath(transformPath(fileNameOld, _MINI)));
-
- renameImage(getFileByPath(transformPath(fileNameNew, _MEDIUM)),
- getFileByPath(transformPath(fileNameOld, _MEDIUM)));
-
- renameImage(getFileByPath(transformPath(fileNameNew, _SMALL80)),
- getFileByPath(transformPath(fileNameOld, _SMALL80)));
-
- renameImage(getFileByPath(transformPath(fileNameNew, _SMALL120)),
- getFileByPath(transformPath(fileNameOld, _SMALL120)));
-
- renameImage(getFileByPath(transformPath(fileNameNew, _SMALL160)),
- getFileByPath(transformPath(fileNameOld, _SMALL160)));
- }
-
- private void renameImage(File fileNew, File fileOld) {
- if (fileNew.exists()) {
- fileNew.delete();
- }
- fileOld.renameTo(fileNew);
- }
-
- private void createDirectoryIfNotExist(String fileNameNew) {
- int lastIndexOf = fileNameNew.lastIndexOf("/");
- if (lastIndexOf > 0) {
- String directory = fileNameNew.substring(0, lastIndexOf);
- File file = getFileByPath(directory);
- if (!file.exists()) {
- file.mkdirs();
- }
- }
- }
-
- public boolean isImagePresent(String fileName) {
- return getFileByPath(fileName) != null && getFileByPath(fileName).exists()
&& !getFileByPath(fileName).isDirectory();
- }
-
- public File getImage(String fileName) {
- if (isImagePresent(fileName)) {
- return getFileByPath(fileName);
- }
- return null;
- }
-
- public File getDirectImage(String fileName) {
- return new File(fileName);
- }
-
- public void deleteDirectories(List<String> directoriesToDelete) {
- for (String directory : directoriesToDelete) {
- deleteDirectory(directory);
- }
- }
-}
Deleted:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/FileManagerTest.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/FileManagerTest.java 2009-03-11
13:49:58 UTC (rev 12921)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/FileManagerTest.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -1,135 +0,0 @@
-package org.richfaces.realworld.fileupload;
-
-import java.io.IOException;
-
-import junit.framework.TestCase;
-
-public class FileManagerTest extends TestCase {
-
- protected void setUp() throws Exception {
- fileManager=new FileManager();
- fileManager.setUploadRoot("C:/Upload/");
- }
-
- protected void tearDown() throws Exception {
- }
-
-private byte[] image = new byte[40];
- private FileManager fileManager;
- public void testIsDirectoryPresent() {
- fileManager.addDirectory("amarkhel");
- assertEquals(fileManager.isDirectoryPresent("amarkhel"), true);
- assertEquals(fileManager.isDirectoryPresent("amarkhel2"), false);
- fileManager.deleteDirectory("amarkhel");
- }
-
- public void testDeleteDirectory() {
- fileManager.addDirectory("amarkhel");
- assertEquals(fileManager.isDirectoryPresent("amarkhel"), true);
- fileManager.deleteDirectory("amarkhel");
- assertEquals(fileManager.isDirectoryPresent("amarkhel"), false);
- }
-
- public void testRenameDirectory() throws Exception {
- fileManager.addDirectory("amarkhel");
- assertEquals(fileManager.isDirectoryPresent("amarkhel"), true);
- fileManager.renameDirectory("amarkhel", "amarkhel2");
- assertEquals(fileManager.isDirectoryPresent("amarkhel"), false);
- assertEquals(fileManager.isDirectoryPresent("amarkhel2"), true);
- fileManager.deleteDirectory("amarkhel2");
- }
-
- public void testRenameDirectory2(){
- fileManager.addDirectory("amarkhel");
- fileManager.addDirectory("amarkhel2");
- assertEquals(fileManager.isDirectoryPresent("amarkhel"), true);
- try {
- fileManager.renameDirectory("amarkhel", "amarkhel2");
- } catch (Exception e) {
- assertTrue(true);
- }
-
- assertEquals(fileManager.isDirectoryPresent("amarkhel"), true);
- assertEquals(fileManager.isDirectoryPresent("amarkhel2"), true);
- fileManager.deleteDirectory("amarkhel");
- fileManager.deleteDirectory("amarkhel2");
- }
-
- public void testRenameDirectory3() throws Exception {
- fileManager.addDirectory("a"+System.getProperty("file.separator")+"amarkhel");
- assertEquals(fileManager.isDirectoryPresent("a"+System.getProperty("file.separator")+"amarkhel"),
true);
- fileManager.renameDirectory("a"+System.getProperty("file.separator")+"amarkhel",
"b"+System.getProperty("file.separator")+"amarkhel");
- assertEquals(fileManager.isDirectoryPresent("a"+System.getProperty("file.separator")+"amarkhel"),
false);
- assertEquals(fileManager.isDirectoryPresent("b"+System.getProperty("file.separator")+"amarkhel"),
true);
- fileManager.deleteDirectory("b"+System.getProperty("file.separator")+"amarkhel");
- }
-
- public void testRenameDirectory4() throws Exception {
- fileManager.addDirectory("a"+System.getProperty("file.separator")+"a"+System.getProperty("file.separator")+"amarkhel");
- assertEquals(fileManager.isDirectoryPresent("a"+System.getProperty("file.separator")+"a"+System.getProperty("file.separator")+"amarkhel"),
true);
- fileManager.renameDirectory("a"+System.getProperty("file.separator")+"a"+System.getProperty("file.separator")+"amarkhel",
"b"+System.getProperty("file.separator")+"b"+System.getProperty("file.separator")+"amarkhel");
- assertEquals(fileManager.isDirectoryPresent("a"+System.getProperty("file.separator")+"a"+System.getProperty("file.separator")+"amarkhel"),
false);
- assertEquals(fileManager.isDirectoryPresent("b"+System.getProperty("file.separator")+"b"+System.getProperty("file.separator")+"amarkhel"),
true);
- fileManager.deleteDirectory("b"+System.getProperty("file.separator")+"b"+System.getProperty("file.separator")+"amarkhel");
- }
-
- public void testAddDirectory() {
- assertEquals(fileManager.isDirectoryPresent("amarkhel"), false);
- fileManager.addDirectory("amarkhel");
- assertEquals(fileManager.isDirectoryPresent("amarkhel"), true);
- fileManager.deleteDirectory("amarkhel");
- }
-
- public void testAddDirectory2() {
- assertEquals(fileManager.isDirectoryPresent("a"+System.getProperty("file.separator")+"amarkhel"),
false);
- fileManager.addDirectory("a"+System.getProperty("file.separator")+"amarkhel");
- assertEquals(fileManager.isDirectoryPresent("a"+System.getProperty("file.separator")+"amarkhel"),
true);
- fileManager.deleteDirectory("a"+System.getProperty("file.separator")+"amarkhel");
- }
-
- /*public void testAddImage() throws IOException {
- assertEquals(fileManager.isImagePresent("amarkhel.gif"), false);
- fileManager.addImage("amarkhel.gif", image);
- assertEquals(fileManager.isImagePresent("amarkhel.gif"), true);
- fileManager.deleteImage("amarkhel.gif");
- }
-
- public void testDeleteImage() throws IOException {
- fileManager.addImage("amarkhel.gif", image);
- assertEquals(fileManager.isImagePresent("amarkhel.gif"), true);
- fileManager.deleteImage("amarkhel.gif");
- assertEquals(fileManager.isImagePresent("amarkhel.gif"), false);
- }
-
- public void testRenameImage() throws IOException {
- fileManager.addImage("amarkhel.gif", image);
- assertEquals(fileManager.isImagePresent("amarkhel.gif"), true);
- fileManager.renameImage("amarkhel.gif", "amarkhel2.gif");
- assertEquals(fileManager.isImagePresent("amarkhel.gif"), false);
- assertEquals(fileManager.isImagePresent("amarkhel2.gif"), true);
- fileManager.deleteImage("amarkhel2.gif");
- }
-
- public void testRenameImage2() throws IOException {
- fileManager.addImage("a"+System.getProperty("file.separator")+"amarkhel.gif",
image);
- assertEquals(fileManager.isImagePresent("a"+System.getProperty("file.separator")+"amarkhel.gif"),
true);
- fileManager.renameImage("a"+System.getProperty("file.separator")+"amarkhel.gif",
"b"+System.getProperty("file.separator")+"amarkhel2.gif");
- assertEquals(fileManager.isImagePresent("a"+System.getProperty("file.separator")+"amarkhel.gif"),
false);
- assertEquals(fileManager.isImagePresent("b"+System.getProperty("file.separator")+"amarkhel2.gif"),
true);
- fileManager.deleteImage("b"+System.getProperty("file.separator")+"amarkhel2.gif");
- fileManager.deleteDirectory("b");
- fileManager.deleteDirectory("a");
- }
-
- public void testIsImagePresent() throws IOException {
- fileManager.addImage("amarkhel.gif", image);
- assertEquals(fileManager.isImagePresent("amarkhel.gif"), true);
- assertEquals(fileManager.isImagePresent("amarkhel3.gif"), false);
- fileManager.deleteImage("amarkhel.gif");
- fileManager.addImage("am"+System.getProperty("file.separator")+"amarkhel.gif",
image);
- assertEquals(fileManager.isImagePresent("am"+System.getProperty("file.separator")+"amarkhel.gif"),
true);
- fileManager.deleteImage("am"+System.getProperty("file.separator")+"amarkhel.gif");
- fileManager.deleteDirectory("am");
- }*/
-
-}
Deleted:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/FileUploadBean.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/FileUploadBean.java 2009-03-11
13:49:58 UTC (rev 12921)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/FileUploadBean.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -1,230 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.realworld.fileupload;
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.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.manager.NavigationEnum;
-import org.richfaces.realworld.service.Constants;
-
-import com.drew.imaging.jpeg.JpegMetadataReader;
-import com.drew.imaging.jpeg.JpegProcessingException;
-import com.drew.metadata.Directory;
-import com.drew.metadata.Metadata;
-import com.drew.metadata.MetadataException;
-import com.drew.metadata.exif.ExifDirectory;
-import com.drew.metadata.jpeg.JpegDirectory;
-
-/**
- * @author $Autor$
- *
- */
-@Name("fileUploadBean")
-(a)Scope(ScopeType.CONVERSATION)
-public class FileUploadBean implements Serializable {
-
- @In("#{messages['file_processing_error']}")
- private String FILE_PROCESSING_ERROR;
- @In("#{messages['file_saving_error']}")
- private String FILE_SAVE_ERROR;
- @In(create = true) @Out
- FileWrapper fileWrapper;
-
- @Out(required=false) FileItem file1;
- @Out(required=false) FileItem file2;
- @Out(required=false) FileItem file3;
-
- @In(create = true)
- private FileManager fileManager;
-
- @In("#{messages['samplename']}")
- private String SAMPLE_NAME;
-
- @In("#{messages['sampledesc']}")
- private String SAMPLE_DESCRIPTION;
-
- private static final long serialVersionUID = 4969087557225414955L;
-
- private boolean fileUploadRendered;
-
- public synchronized void listener(UploadEvent event) throws Exception {
- UploadItem item = event.getUploadItem();
- FileItem file = new FileItem();
- file.setLength(item.getFileSize());
- file.setFile(item.getFile());
- file.setSelected(false);
- file.setName(event.getUploadItem().getFileName());
- Image image = constructImage(item, file);
- fileManager.writeFile(file.getFile().getPath(), file.getFile().getPath(),
"_mini", 100, false);
- try {
- extractMetadata(file, image);
- } catch (JpegProcessingException e1) {
- Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new
Exception(FILE_PROCESSING_ERROR));
- return;
- } catch (MetadataException me) {
- Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new
Exception(FILE_PROCESSING_ERROR));
- return;
- }
- file.setImage(image);
- fileWrapper.getFiles().add(file);
- file1 = fileWrapper.getFiles().get(fileWrapper.getFiles().size()-1);
- if(fileWrapper.getFiles().size()-2 >=0){
- file2 = fileWrapper.getFiles().get(fileWrapper.getFiles().size()-2);
- }
- if(fileWrapper.getFiles().size()-3 >=0){
- file3 = fileWrapper.getFiles().get(fileWrapper.getFiles().size()-3);
- }
- }
-
- @Observer(Constants.FILE_UPLOAD_CLEAR_EVENT)
- public void clearUploadData() {
- fileWrapper.getFiles().clear();
- }
-
- public void clearSelectedData() {
- 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 = file.getFile().getPath();
- if(!fileManager.addImage(file.getName(), fileName)){
- Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new
Exception(FILE_SAVE_ERROR));
- }
- // Update domain model
- Events.instance().raiseEvent(Constants.ADD_IMAGE_EVENT, file.getImage());
- } 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 = file.getFile()
- .getPath();
- if(!fileManager.addImage(file.getName(), fileName)){
- Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new
Exception(FILE_SAVE_ERROR));
- }
- // Update domain model
- Events.instance().raiseEvent(Constants.ADD_IMAGE_EVENT, file.getImage());
- }
- fileWrapper.getFiles().clear();
- Events.instance().raiseEvent(Constants.UPDATE_MAIN_AREA_EVENT,NavigationEnum.IMAGE_PREVIEW);
- }
-
- public boolean isFileUploadRendered() {
- return fileUploadRendered;
- }
-
- public void setFileUploadRendered(boolean fileUploadRendered) {
- this.fileUploadRendered = fileUploadRendered;
- }
-
- @Observer(Constants.SHOW_FILE_UPLOAD_EVENT)
- public void showFileUpload(boolean result) {
- this.setFileUploadRendered(result);
- clearUploadData();
- }
-
-
- 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());
- return image;
- }
-
- private void extractMetadata(FileItem file, Image image)
- throws JpegProcessingException, MetadataException, FileNotFoundException {
- InputStream in = new FileInputStream(file.getFile());
- 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);
- }else{
- image.setCameraModel("");
- }
- }
-}
\ No newline at end of file
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/ImageLoader.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/ImageLoader.java 2009-03-11
13:49:58 UTC (rev 12921)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/ImageLoader.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -24,7 +24,6 @@
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -37,6 +36,7 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.core.Events;
+import org.richfaces.realworld.manager.FileManager;
import org.richfaces.realworld.service.Constants;
@Name("imageLoader")
@@ -49,52 +49,7 @@
FileManager fileManager;
@In("#{messages['file_processing_error']}")
private String FILE_PROCESSING_ERROR;
- @In(create=true)
- FileWrapper fileWrapper;
- public synchronized void paintImageFromByteArray(OutputStream stream, Object data)
throws IOException {
- int index;
- if(data instanceof Integer){
- index = (Integer)data;
- }else{
- index = ((Long)data).intValue();
- }
- FileInputStream fileInputStream = new
FileInputStream(fileWrapper.getFiles().get(index).getFile());
- int read = -1;
- byte [] bytes = new byte [4096];
- while ((read = fileInputStream.read(bytes)) != -1) {
- if (read == 0) {
- break;
- }
- stream.write(bytes);
- }
- // stream.write(fileWrapper.getFiles().get(index).getData());
- }
- public synchronized void paintSearchImage(OutputStream stream, Object object)
- throws IOException {
- File image = fileManager.getImage(object.toString());
- 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);
- paintData = bufferedInputStream;
- paintData.read(data);
- } catch (FileNotFoundException e) {
- Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new
Exception(FILE_PROCESSING_ERROR));
- return;
- } finally {
- fileInputStream.close();
- bufferedInputStream.close();
- paintData.close();
- }
- }
- stream.write(data);
- }
-
public synchronized void paintImage(OutputStream out, Object data) throws IOException{
if (null == data) {
return;
@@ -122,11 +77,11 @@
}
}
- public synchronized void paintImage2(OutputStream out, Object data) throws IOException{
+ public synchronized void paintImageFromFile(OutputStream out, Object data) throws
IOException{
if (null == data) {
return;
}
- File imageResource = fileManager.getDirectImage(data.toString());
+ File imageResource = fileManager.getImageFile(data.toString());
if (imageResource != null) {
FileInputStream fileInputStream = new FileInputStream(imageResource);
BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
@@ -148,27 +103,4 @@
}
}
}
-
- public synchronized void paintImageFromFile(OutputStream out, Object data) throws
IOException{
- if (null == data || !(data instanceof File)) {
- return;
- }
- File file = (File) data;
-
- FileInputStream paintData = new FileInputStream(file);
- if (null == paintData) {
- Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new
Exception(FILE_PROCESSING_ERROR));
- return;
- }
- try {
- BufferedImage images = ImageIO.read(paintData);
- ImageIO.write(images, Constants.JPEG, out);
- } catch (Exception e) {
- Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new
Exception(FILE_PROCESSING_ERROR));
- return;
- } finally {
- paintData.close();
- }
-
- }
}
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/listener/CopyImagesStuff.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/listener/CopyImagesStuff.java 2009-03-11
13:49:58 UTC (rev 12921)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/listener/CopyImagesStuff.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -5,15 +5,10 @@
import java.io.File;
import java.io.FileNotFoundException;
-import java.net.URL;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
-import org.jboss.seam.annotations.Logger;
-import org.jboss.seam.log.Log;
-import org.jboss.seam.web.LoggingFilter;
-
/**
* @author Andrey Markavtsov
*
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/AlbumManager.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/AlbumManager.java 2009-03-11
13:49:58 UTC (rev 12921)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/AlbumManager.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -31,7 +31,6 @@
import org.richfaces.realworld.domain.Album;
import org.richfaces.realworld.domain.Shelf;
import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.fileupload.FileManager;
import org.richfaces.realworld.service.Constants;
import org.richfaces.realworld.service.IAlbumAction;
@@ -42,21 +41,10 @@
private static final long serialVersionUID = 2631634926126857691L;
private String oncomplete = ";";
+
@In(create=true, required=true)
private IAlbumAction albumAction;
- private void setOncomplete() {
- oncomplete = "$('albumModalPanel').component.hide()";
- }
-
- public String getOncomplete() {
- return oncomplete;
- }
-
- public void setOncomplete(String oncomplete) {
- this.oncomplete = oncomplete;
- }
-
@In(create=true, required=true) @Out
private Album album;
@@ -71,7 +59,6 @@
public void addAlbum(Album album){
albumAction.addAlbum(album);
addDirectory();
- //Update conversation state
model.setSelectedImage(null);
model.setSelectedAlbum(album);
Events.instance().raiseEvent("albumAdded");
@@ -102,6 +89,18 @@
Events.instance().raiseEvent("clearTree");
}
+ private void setOncomplete() {
+ oncomplete = "$('albumModalPanel').component.hide()";
+ }
+
+ public String getOncomplete() {
+ return oncomplete;
+ }
+
+ public void setOncomplete(String oncomplete) {
+ this.oncomplete = oncomplete;
+ }
+
private void deleteDirectory(String albumName) {
fileManager.deleteDirectory(user.getLogin(), albumName);
}
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Authenticator.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Authenticator.java 2009-03-11
13:49:58 UTC (rev 12921)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/Authenticator.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -36,14 +36,12 @@
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.web.RequestParameter;
import org.jboss.seam.core.Conversation;
-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.jboss.seam.web.Session;
import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.fileupload.FileManager;
import org.richfaces.realworld.service.IUserAction;
import org.richfaces.realworld.ui.PasswordHolder;
import org.richfaces.realworld.service.Constants;
@@ -54,19 +52,16 @@
{
@In(create=true) ShelfManager shelfManager;
+
@In("#{messages['invalid_login']}")
private String INVALID_LOGIN_OR_PASSWORD;
- @In("#{messages['login_success']}")
- private String LOGIN_SUCCESS;
- @In(create=true) PasswordHolder passwordHolder;
- @In("#{messages['user.exist']}") private String
USER_WITH_THIS_LOGIN_ALREADY_EXIST;
- @In("#{messages['user.confirm.error']}") private String
CONFIRM_PASSWORD_NOT_EQUALS_PASSWORD;
-
@RequestParameter protected Long startConversation;
private static final long serialVersionUID = -4585673256547342140L;
+ @In(create=true) PasswordHolder passwordHolder;
+
@Logger Log log;
@In Identity identity;
@@ -126,17 +121,6 @@
}
return false;
}
-
- @End
- public String register(User user){
- if(checkPassword(user) || checkUserExist(user)){
- return "";
- }
- user.setPasswordHash(passwordHolder.hash(user.getPassword()));
- userAction.register(user);
- facesMessages.add(LOGIN_SUCCESS);
- return "main";
- }
public String logout(){
identity.logout();
@@ -146,14 +130,6 @@
return "logout";
}
- public String goToRegister(){
- identity.logout();
- identity.unAuthenticate();
- credentials.clear();
- credentials.invalidate();
- return "register";
- }
-
public String loginAnonymous(){
credentials.setUsername(null);
credentials.setPassword(null);
@@ -189,29 +165,7 @@
private boolean wantLoginAnonymous() {
return null == credentials.getUsername() ||
credentials.getUsername().equals("");
}
-
- private boolean checkUserExist(User user) {
- if(userAction.isUserExist(user.getLogin())){
- UIComponent root = FacesContext.getCurrentInstance().getViewRoot();
- UIComponent component = root.findComponent(Constants.REGISTER_LOGIN_NAME_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));
- return true;
- }
- return false;
- }
- private boolean checkPassword(User user) {
- if(!user.getPassword().equals(user.getConfirmPassword())){
- UIComponent root = FacesContext.getCurrentInstance().getViewRoot();
- UIComponent component =
root.findComponent(Constants.REGISTER_CONFIRM_PASSWORD_ID);
- FacesContext.getCurrentInstance().addMessage(component.getClientId(FacesContext.getCurrentInstance()),
new FacesMessage(
- FacesMessage.SEVERITY_ERROR, CONFIRM_PASSWORD_NOT_EQUALS_PASSWORD ,
CONFIRM_PASSWORD_NOT_EQUALS_PASSWORD));
- return true;
- }
- return false;
- }
-
public Long getStartConversation() {
return startConversation;
}
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java 2009-03-11
13:49:58 UTC (rev 12921)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -35,7 +35,6 @@
import org.richfaces.realworld.domain.Shelf;
import org.richfaces.realworld.domain.User;
import org.richfaces.realworld.fileupload.FileItem;
-import org.richfaces.realworld.fileupload.FileManager;
import org.richfaces.realworld.service.Constants;
import org.richfaces.realworld.service.IAlbumAction;
@@ -105,7 +104,7 @@
}
private void handleUploadedImage(FileItem dragValue, Album dropValue) {
- String newPath = getNewPathOfImage2(dragValue.getName(), dropValue);
+ String newPath = generateNewPath(dragValue.getName(), dropValue);
dragValue.getImage().setPath(newPath);
dropValue.addImage(dragValue.getImage());
albumAction.flush();
@@ -122,7 +121,7 @@
return fileNameNew;
}
- private String getNewPathOfImage2(String path, Album dropValue) {
+ private String generateNewPath(String path, Album dropValue) {
String fileNameNew =
user.getLogin()+"/"+dropValue.getId()+"/"+path;
return fileNameNew;
}
Copied:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/FileManager.java
(from rev 12917,
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/FileManager.java)
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/FileManager.java
(rev 0)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/FileManager.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -0,0 +1,361 @@
+/**
+ * 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.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.Transparency;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+
+import javax.faces.context.FacesContext;
+import javax.imageio.ImageIO;
+import javax.imageio.ImageReader;
+import javax.imageio.ImageWriter;
+import javax.imageio.stream.ImageInputStream;
+
+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")
+(a)Scope(ScopeType.CONVERSATION)
+public class FileManager {
+
+ private static final String _SMALL160 = "_small160";
+ private static final String _SMALL120 = "_small120";
+ private static final String _SMALL80 = "_small80";
+ private static final String _MEDIUM = "_medium";
+ private static final String _MINI = "_mini";
+
+ private File uploadRoot;
+ private String uploadRootPath;
+
+ public File getUploadRoot() {
+ return uploadRoot;
+ }
+
+ public void setUploadRoot(String uploadRootPath) throws IOException {
+ if (uploadRootPath != null) {
+ this.uploadRoot = new File(uploadRootPath);
+ this.uploadRootPath = this.uploadRoot.getCanonicalPath()
+ + File.separator;
+ } else {
+ this.uploadRoot = null;
+ this.uploadRootPath = null;
+ }
+ }
+
+ public FileManager() throws IOException {
+ FacesContext fc = FacesContext.getCurrentInstance();
+ if (fc != null) {
+ // TODO nick - ask Andrei if we can throw exception here
+ this.setUploadRoot(fc.getExternalContext().getInitParameter(
+ Constants.UPLOAD_ROOT));
+ }
+ }
+
+ private File getFileByPath(String path) {
+ if (this.uploadRoot != null) {
+ File result = new File(this.uploadRoot, path);
+
+ try {
+ String resultCanonicalPath = result.getCanonicalPath();
+ if (!resultCanonicalPath.startsWith(this.uploadRootPath)) {
+ // TODO log error
+ result = null;
+ }
+
+ return result;
+ } catch (IOException e) {
+ // TODO: handle exception
+ result = null;
+ }
+
+ return result;
+ }
+
+ return null;
+ }
+
+ public boolean isDirectoryPresent(String directory) {
+ File file = getFileByPath(directory);
+ return file.exists() && file.isDirectory();
+ }
+
+ public void deleteDirectory(String... directories) {
+ String directory = new String();
+ for (String chunk : directories) {
+ directory += chunk + File.separator;
+ }
+ File file = getFileByPath(directory);
+ if (file.exists()) {
+ for (String f : file.list()) {
+ File temp = new File(file, f);
+ temp.delete();
+ }
+ file.delete();
+ }
+ }
+
+ public boolean renameDirectory(String directoryOld, String directoryNew) {
+ File fileOld = getFileByPath(directoryOld);
+ File fileNew = getFileByPath(directoryNew);
+
+ createDirectoryIfNotExist(directoryNew);
+ if (fileNew.exists()) {
+ if (fileNew.isDirectory()) {
+ return false;
+ } else {
+ fileNew.delete();
+ }
+ }
+ fileOld.renameTo(fileNew);
+ return true;
+ }
+
+ public void addDirectory(String... directories) {
+ String directory = new String();
+ for (String chunk : directories) {
+ directory += chunk;
+ }
+ File file = getFileByPath(directory);
+ file.mkdirs();
+ }
+
+ public boolean addImage(String fileName, String tempFilePath) {
+ createDirectoryIfNotExist(fileName);
+ writeFile(fileName, tempFilePath, _SMALL80, 80, true);
+ writeFile(fileName, tempFilePath, _SMALL120, 120, true);
+ writeFile(fileName, tempFilePath, _SMALL160, 160, true);
+ writeFile(fileName, tempFilePath, _MINI, 150, true);
+ writeFile(fileName, tempFilePath, _MEDIUM, 600, true);
+ return true;
+ }
+
+ public static BufferedImage bitmapToImage(String data, String format) throws IOException
{
+ InputStream inb = new FileInputStream(data);
+ ImageReader rdr = (ImageReader)
ImageIO.getImageReadersByFormatName(format).next();
+ ImageInputStream imageInput = ImageIO.createImageInputStream(inb);
+ rdr.setInput(imageInput);
+ BufferedImage image = rdr.read(0);
+ inb.close();
+ return image;
+ }
+
+ public static void imageToBitmap(BufferedImage image, String data, String format)
throws IOException {
+ OutputStream inb = new FileOutputStream(data);
+ ImageWriter wrt = (ImageWriter)
ImageIO.getImageWritersByFormatName(format).next();
+ ImageInputStream imageInput = ImageIO.createImageOutputStream(inb);
+ wrt.setOutput(imageInput);
+ wrt.write(image);
+ inb.close();
+ }
+
+ /**
+ * Convenience method that returns a scaled instance of the
+ * provided {@code BufferedImage}.
+ *
+ * @param img the original image to be scaled
+ * @param targetWidth the desired width of the scaled instance,
+ * in pixels
+ * @param targetHeight the desired height of the scaled instance,
+ * in pixels
+ * @param hint one of the rendering hints that corresponds to
+ * {@code RenderingHints.KEY_INTERPOLATION} (e.g.
+ * {@code RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR},
+ * {@code RenderingHints.VALUE_INTERPOLATION_BILINEAR},
+ * {@code RenderingHints.VALUE_INTERPOLATION_BICUBIC})
+ * @param higherQuality if true, this method will use a multi-step
+ * scaling technique that provides higher quality than the usual
+ * one-step technique (only useful in downscaling cases, where
+ * {@code targetWidth} or {@code targetHeight} is
+ * smaller than the original dimensions, and generally only when
+ * the {@code BILINEAR} hint is specified)
+ * @return a scaled version of the original {@code BufferedImage}
+ */
+ public static BufferedImage getScaledInstance(BufferedImage img,
+ int targetWidth,
+ int targetHeight,
+ Object hint,
+ boolean higherQuality)
+ {
+ int type = (img.getTransparency() == Transparency.OPAQUE) ?
+ BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
+ BufferedImage ret = (BufferedImage)img;
+ int w, h;
+ if (higherQuality) {
+ // Use multi-step technique: start with original size, then
+ // scale down in multiple passes with drawImage()
+ // until the target size is reached
+ w = img.getWidth();
+ h = img.getHeight();
+ } else {
+ // Use one-step technique: scale directly from original
+ // size to target size with a single drawImage() call
+ w = targetWidth;
+ h = targetHeight;
+ }
+
+ do {
+ if (higherQuality && w > targetWidth) {
+ w /= 2;
+ if (w < targetWidth) {
+ w = targetWidth;
+ }
+ }
+
+ if (higherQuality && h > targetHeight) {
+ h /= 2;
+ if (h < targetHeight) {
+ h = targetHeight;
+ }
+ }
+
+ BufferedImage tmp = new BufferedImage(w, h, type);
+ Graphics2D g2 = tmp.createGraphics();
+ g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint);
+ g2.drawImage(ret, 0, 0, w, h, null);
+ g2.dispose();
+
+ ret = tmp;
+ } while (w != targetWidth || h != targetHeight);
+
+ return ret;
+ }
+
+ public void writeFile(String newFileName, String fileName,String pattern, int size,
boolean includeUploadRoot) {
+ BufferedImage bsrc =null;
+ try {
+ bsrc = bitmapToImage(fileName, "JPG");
+ } catch (IOException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ int i = bsrc.getWidth() > bsrc.getHeight()? bsrc.getWidth(): bsrc.getHeight();
+ double d = (double) size
+ / i;
+ Double yy = ((Double)d*bsrc.getWidth());
+ int width = yy.intValue();
+ yy = ((Double)d*bsrc.getHeight());
+ int height= yy.intValue();
+ BufferedImage bdest = getScaledInstance(bsrc, width, height,
RenderingHints.VALUE_INTERPOLATION_BICUBIC, true);
+ String dest = includeUploadRoot? this.uploadRootPath + transformPath(newFileName,
pattern) : transformPath(newFileName, pattern);
+ try {
+ imageToBitmap(bdest, dest, "JPG");
+ } catch (IOException ex) {
+ // TODO Auto-generated catch block
+ ex.printStackTrace();
+ }
+ }
+
+ public String transformPath(String target, String substitute) {
+ String begin = target.substring(0, target.lastIndexOf(Constants.DOT));
+ String end = target.substring(target.lastIndexOf(Constants.DOT));
+ return begin + substitute + end;
+ }
+
+ public void deleteImage(String fileName) {
+ deleteImage(getFileByPath(fileName));
+ deleteImage(getFileByPath(transformPath(fileName, _MINI)));
+ deleteImage(getFileByPath(transformPath(fileName, _MEDIUM)));
+ deleteImage(getFileByPath(transformPath(fileName, _SMALL80)));
+ deleteImage(getFileByPath(transformPath(fileName, _SMALL120)));
+ deleteImage(getFileByPath(transformPath(fileName, _SMALL160)));
+ }
+
+ private void deleteImage(File file) {
+ if (file.exists()) {
+ file.delete();
+ }
+ }
+
+ public String getPathOfImage(String path) {
+ int i = path.lastIndexOf(Constants.SLASH);
+ return path.substring(i);
+ }
+
+ public void renameImage(String fileNameOld, String fileNameNew) {
+ createDirectoryIfNotExist(fileNameNew);
+ renameImage(getFileByPath(fileNameNew), getFileByPath(fileNameOld));
+
+ renameImage(getFileByPath(transformPath(fileNameNew, _MINI)),
+ getFileByPath(transformPath(fileNameOld, _MINI)));
+
+ renameImage(getFileByPath(transformPath(fileNameNew, _MEDIUM)),
+ getFileByPath(transformPath(fileNameOld, _MEDIUM)));
+
+ renameImage(getFileByPath(transformPath(fileNameNew, _SMALL80)),
+ getFileByPath(transformPath(fileNameOld, _SMALL80)));
+
+ renameImage(getFileByPath(transformPath(fileNameNew, _SMALL120)),
+ getFileByPath(transformPath(fileNameOld, _SMALL120)));
+
+ renameImage(getFileByPath(transformPath(fileNameNew, _SMALL160)),
+ getFileByPath(transformPath(fileNameOld, _SMALL160)));
+ }
+
+ private void renameImage(File fileNew, File fileOld) {
+ if (fileNew.exists()) {
+ fileNew.delete();
+ }
+ fileOld.renameTo(fileNew);
+ }
+
+ private void createDirectoryIfNotExist(String fileNameNew) {
+ int lastIndexOf = fileNameNew.lastIndexOf("/");
+ if (lastIndexOf > 0) {
+ String directory = fileNameNew.substring(0, lastIndexOf);
+ File file = getFileByPath(directory);
+ if (!file.exists()) {
+ file.mkdirs();
+ }
+ }
+ }
+
+ public boolean isImagePresent(String fileName) {
+ return getFileByPath(fileName) != null && getFileByPath(fileName).exists()
&& !getFileByPath(fileName).isDirectory();
+ }
+
+ public File getImage(String fileName) {
+ if (isImagePresent(fileName)) {
+ return getFileByPath(fileName);
+ }
+ return null;
+ }
+
+ public File getImageFile(String fileName) {
+ return new File(fileName);
+ }
+
+ public void deleteDirectories(List<String> directoriesToDelete) {
+ for (String directory : directoriesToDelete) {
+ deleteDirectory(directory);
+ }
+ }
+}
Added:
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
(rev 0)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/FileUploadManager.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -0,0 +1,77 @@
+package org.richfaces.realworld.manager;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Observer;
+import org.jboss.seam.annotations.Out;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.core.Events;
+import org.richfaces.realworld.fileupload.FileItem;
+import org.richfaces.realworld.fileupload.FileWrapper;
+import org.richfaces.realworld.service.Constants;
+
+@Name("fileUploadManager")
+(a)Scope(ScopeType.CONVERSATION)
+public class FileUploadManager {
+
+ @In("#{messages['file_saving_error']}")
+ private String FILE_SAVE_ERROR;
+
+ @Out(required=false) FileItem file1;
+ @Out(required=false) FileItem file2;
+ @Out(required=false) FileItem file3;
+
+ @In(create = true)
+ private FileManager fileManager;
+
+ @In(create = true) @Out
+ FileWrapper fileWrapper;
+
+ @Observer(Constants.FILE_UPLOAD_CLEAR_EVENT)
+ public void clearUploadData() {
+ fileWrapper.getFiles().clear();
+ }
+
+ public void clearSelectedData() {
+ 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 = file.getFile().getPath();
+ if(!fileManager.addImage(file.getName(), fileName)){
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new
Exception(FILE_SAVE_ERROR));
+ }
+ Events.instance().raiseEvent(Constants.ADD_IMAGE_EVENT, file.getImage());
+ } 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 = file.getFile().getPath();
+ if(!fileManager.addImage(file.getName(), fileName)){
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new
Exception(FILE_SAVE_ERROR));
+ }
+ Events.instance().raiseEvent(Constants.ADD_IMAGE_EVENT, file.getImage());
+ }
+ fileWrapper.getFiles().clear();
+ Events.instance().raiseEvent(Constants.UPDATE_MAIN_AREA_EVENT,NavigationEnum.IMAGE_PREVIEW);
+ }
+}
Property changes on:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/FileUploadManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java 2009-03-11
13:49:58 UTC (rev 12921)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -32,7 +32,6 @@
import org.richfaces.realworld.domain.Comment;
import org.richfaces.realworld.domain.Image;
import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.fileupload.FileManager;
import org.richfaces.realworld.service.Constants;
import org.richfaces.realworld.service.IImageAction;
import org.richfaces.realworld.util.DirectLinkHelper;
Added:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/RegistrationManager.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/RegistrationManager.java
(rev 0)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/RegistrationManager.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -0,0 +1,86 @@
+package org.richfaces.realworld.manager;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.End;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Logger;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+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.service.Constants;
+import org.richfaces.realworld.service.IUserAction;
+import org.richfaces.realworld.ui.PasswordHolder;
+
+@Name("registerManager")
+(a)Scope(ScopeType.CONVERSATION)
+public class RegistrationManager {
+
+ @In("#{messages['login_success']}")
+ private String LOGIN_SUCCESS;
+
+ @In("#{messages['user.exist']}") private String
USER_WITH_THIS_LOGIN_ALREADY_EXIST;
+
+ @In("#{messages['user.confirm.error']}") private String
CONFIRM_PASSWORD_NOT_EQUALS_PASSWORD;
+
+ @Logger Log log;
+
+ @In Identity identity;
+
+ @In Credentials credentials;
+
+ @In FacesMessages facesMessages;
+
+ @In(create=true) PasswordHolder passwordHolder;
+
+ @In(create = true)
+ IUserAction userAction;
+
+ @End
+ public String register(User user){
+ if(checkPassword(user) || checkUserExist(user)){
+ return "";
+ }
+ user.setPasswordHash(passwordHolder.hash(user.getPassword()));
+ userAction.register(user);
+ facesMessages.add(LOGIN_SUCCESS);
+ return "main";
+ }
+
+ public String goToRegister(){
+ identity.logout();
+ identity.unAuthenticate();
+ credentials.clear();
+ credentials.invalidate();
+ return "register";
+ }
+
+ private boolean checkUserExist(User user) {
+ if(userAction.isUserExist(user.getLogin())){
+ UIComponent root = FacesContext.getCurrentInstance().getViewRoot();
+ UIComponent component = root.findComponent(Constants.REGISTER_LOGIN_NAME_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));
+ return true;
+ }
+ return false;
+ }
+
+ private boolean checkPassword(User user) {
+ if(!user.getPassword().equals(user.getConfirmPassword())){
+ UIComponent root = FacesContext.getCurrentInstance().getViewRoot();
+ UIComponent component =
root.findComponent(Constants.REGISTER_CONFIRM_PASSWORD_ID);
+ FacesContext.getCurrentInstance().addMessage(component.getClientId(FacesContext.getCurrentInstance()),
new FacesMessage(
+ FacesMessage.SEVERITY_ERROR, CONFIRM_PASSWORD_NOT_EQUALS_PASSWORD ,
CONFIRM_PASSWORD_NOT_EQUALS_PASSWORD));
+ return true;
+ }
+ return false;
+ }
+}
Property changes on:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/RegistrationManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ShelfManager.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ShelfManager.java 2009-03-11
13:49:58 UTC (rev 12921)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/manager/ShelfManager.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -34,7 +34,6 @@
import org.richfaces.realworld.domain.Album;
import org.richfaces.realworld.domain.Shelf;
import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.fileupload.FileManager;
import org.richfaces.realworld.service.Constants;
import org.richfaces.realworld.service.IShelfAction;
@@ -49,25 +48,9 @@
@In(create=true, required=true)
private IShelfAction shelfAction;
private String oncomplete = ";";
- private void setOncomplete() {
- oncomplete = "$('shelfModalPanel').component.hide()";
- }
- public String getOncomplete() {
- return oncomplete;
- }
-
- public void initEdit(){
- shelf = new Shelf();
- }
-
- public void setOncomplete(String oncomplete) {
- this.oncomplete = oncomplete;
- }
-
- @In(create=true, required=true) @Out
- private Shelf shelf;
@In @Out Model model;
+
@In
private User user;
@@ -116,4 +99,16 @@
public void clearShelfs(){
shelfs = null;
}
+
+ private void setOncomplete() {
+ oncomplete = "$('shelfModalPanel').component.hide()";
+ }
+
+ public String getOncomplete() {
+ return oncomplete;
+ }
+
+ public void setOncomplete(String oncomplete) {
+ this.oncomplete = oncomplete;
+ }
}
Copied:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/FileUploadBean.java
(from rev 12917,
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/FileUploadBean.java)
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/FileUploadBean.java
(rev 0)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/FileUploadBean.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -0,0 +1,167 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.realworld.ui;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.Date;
+
+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.event.UploadEvent;
+import org.richfaces.model.UploadItem;
+import org.richfaces.realworld.domain.Image;
+import org.richfaces.realworld.fileupload.FileItem;
+import org.richfaces.realworld.fileupload.FileWrapper;
+import org.richfaces.realworld.manager.FileManager;
+import org.richfaces.realworld.service.Constants;
+
+import com.drew.imaging.jpeg.JpegMetadataReader;
+import com.drew.imaging.jpeg.JpegProcessingException;
+import com.drew.metadata.Directory;
+import com.drew.metadata.Metadata;
+import com.drew.metadata.MetadataException;
+import com.drew.metadata.exif.ExifDirectory;
+import com.drew.metadata.jpeg.JpegDirectory;
+
+/**
+ * @author $Autor$
+ *
+ */
+@Name("fileUploadBean")
+(a)Scope(ScopeType.CONVERSATION)
+public class FileUploadBean implements Serializable {
+
+ @In("#{messages['file_processing_error']}")
+ private String FILE_PROCESSING_ERROR;
+
+ @In(create = true) @Out
+ FileWrapper fileWrapper;
+
+ @Out(required=false) FileItem file1;
+ @Out(required=false) FileItem file2;
+ @Out(required=false) FileItem file3;
+
+ @In(create = true)
+ private FileManager fileManager;
+
+ @In("#{messages['samplename']}")
+ private String SAMPLE_NAME;
+
+ @In("#{messages['sampledesc']}")
+ private String SAMPLE_DESCRIPTION;
+
+ private static final long serialVersionUID = 4969087557225414955L;
+
+ public synchronized void listener(UploadEvent event) throws Exception {
+ UploadItem item = event.getUploadItem();
+ FileItem file = new FileItem();
+ file.setLength(item.getFileSize());
+ file.setFile(item.getFile());
+ file.setSelected(false);
+ file.setName(event.getUploadItem().getFileName());
+ Image image = constructImage(item, file);
+ fileManager.writeFile(file.getFile().getPath(), file.getFile().getPath(),
"_mini", 100, false);
+ try {
+ extractMetadata(file, image);
+ } catch (JpegProcessingException e1) {
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new
Exception(FILE_PROCESSING_ERROR));
+ return;
+ } catch (MetadataException me) {
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new
Exception(FILE_PROCESSING_ERROR));
+ return;
+ }
+ file.setImage(image);
+ fileWrapper.getFiles().add(file);
+ outJectLastThreeImages();
+ }
+
+ private void outJectLastThreeImages() {
+ file1 = fileWrapper.getFiles().get(fileWrapper.getFiles().size()-1);
+ if(fileWrapper.getFiles().size()-2 >=0){
+ file2 = fileWrapper.getFiles().get(fileWrapper.getFiles().size()-2);
+ }
+ if(fileWrapper.getFiles().size()-3 >=0){
+ file3 = fileWrapper.getFiles().get(fileWrapper.getFiles().size()-3);
+ }
+ }
+
+ 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());
+ return image;
+ }
+
+ private void extractMetadata(FileItem file, Image image)
+ throws JpegProcessingException, MetadataException, FileNotFoundException {
+ InputStream in = new FileInputStream(file.getFile());
+ 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);
+ }else{
+ image.setCameraModel("");
+ }
+ }
+}
\ No newline at end of file
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/TagList.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/TagList.java 2009-03-11
13:49:58 UTC (rev 12921)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/TagList.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -58,19 +58,4 @@
public void ImageDeleted(){
fetchTags();
}
-
- @Observer(value = "albumEdited", create = false)
- public void AlbumEdited(){
- fetchTags();
- }
-
- @Observer(value = "albumDeleted", create = false)
- public void AlbumDeleted(){
- fetchTags();
- }
-
- @Observer(value = "albumAdded", create = false)
- public void AlbumAdded(){
- fetchTags();
- }
}
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/UserPrefsHelper.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/UserPrefsHelper.java 2009-03-11
13:49:58 UTC (rev 12921)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/ui/UserPrefsHelper.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -19,7 +19,7 @@
import org.richfaces.model.UploadItem;
import org.richfaces.realworld.domain.Sex;
import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.fileupload.FileManager;
+import org.richfaces.realworld.manager.FileManager;
import org.richfaces.realworld.manager.Model;
import org.richfaces.realworld.service.Constants;
import org.richfaces.realworld.service.IUserAction;
@@ -58,8 +58,7 @@
avatarData = item.getFile();
}
- public void saveUser(){
- User user = model.getSelectedUser();
+ public void saveUser(User user){
if (avatarData != null) {
try {
BufferedImage image = fileManager.bitmapToImage(avatarData.getPath(),"JPG"
);
@@ -75,12 +74,6 @@
userAction.updateUser(user);
}
- public void registerUser() {
- if (user != null) {
- userAction.register(user);
- }
- }
-
public void cancel() {
avatarData = null;
}
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/DirectLinkHelper.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/DirectLinkHelper.java 2009-03-11
13:49:58 UTC (rev 12921)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/DirectLinkHelper.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -21,7 +21,7 @@
import org.jboss.seam.annotations.web.RequestParameter;
import org.jboss.seam.core.Events;
import org.richfaces.realworld.domain.Image;
-import org.richfaces.realworld.fileupload.FileManager;
+import org.richfaces.realworld.manager.FileManager;
import org.richfaces.realworld.service.Constants;
@Name("directLink")
Copied:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/FileManagerTest.java
(from rev 12917,
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/FileManagerTest.java)
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/FileManagerTest.java
(rev 0)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/FileManagerTest.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -0,0 +1,137 @@
+package org.richfaces.realworld.util;
+
+import java.io.IOException;
+
+import org.richfaces.realworld.manager.FileManager;
+
+import junit.framework.TestCase;
+
+public class FileManagerTest extends TestCase {
+
+ protected void setUp() throws Exception {
+ fileManager=new FileManager();
+ fileManager.setUploadRoot("C:/Upload/");
+ }
+
+ protected void tearDown() throws Exception {
+ }
+
+private byte[] image = new byte[40];
+ private FileManager fileManager;
+ public void testIsDirectoryPresent() {
+ fileManager.addDirectory("amarkhel");
+ assertEquals(fileManager.isDirectoryPresent("amarkhel"), true);
+ assertEquals(fileManager.isDirectoryPresent("amarkhel2"), false);
+ fileManager.deleteDirectory("amarkhel");
+ }
+
+ public void testDeleteDirectory() {
+ fileManager.addDirectory("amarkhel");
+ assertEquals(fileManager.isDirectoryPresent("amarkhel"), true);
+ fileManager.deleteDirectory("amarkhel");
+ assertEquals(fileManager.isDirectoryPresent("amarkhel"), false);
+ }
+
+ public void testRenameDirectory() throws Exception {
+ fileManager.addDirectory("amarkhel");
+ assertEquals(fileManager.isDirectoryPresent("amarkhel"), true);
+ fileManager.renameDirectory("amarkhel", "amarkhel2");
+ assertEquals(fileManager.isDirectoryPresent("amarkhel"), false);
+ assertEquals(fileManager.isDirectoryPresent("amarkhel2"), true);
+ fileManager.deleteDirectory("amarkhel2");
+ }
+
+ public void testRenameDirectory2(){
+ fileManager.addDirectory("amarkhel");
+ fileManager.addDirectory("amarkhel2");
+ assertEquals(fileManager.isDirectoryPresent("amarkhel"), true);
+ try {
+ fileManager.renameDirectory("amarkhel", "amarkhel2");
+ } catch (Exception e) {
+ assertTrue(true);
+ }
+
+ assertEquals(fileManager.isDirectoryPresent("amarkhel"), true);
+ assertEquals(fileManager.isDirectoryPresent("amarkhel2"), true);
+ fileManager.deleteDirectory("amarkhel");
+ fileManager.deleteDirectory("amarkhel2");
+ }
+
+ public void testRenameDirectory3() throws Exception {
+ fileManager.addDirectory("a"+System.getProperty("file.separator")+"amarkhel");
+ assertEquals(fileManager.isDirectoryPresent("a"+System.getProperty("file.separator")+"amarkhel"),
true);
+ fileManager.renameDirectory("a"+System.getProperty("file.separator")+"amarkhel",
"b"+System.getProperty("file.separator")+"amarkhel");
+ assertEquals(fileManager.isDirectoryPresent("a"+System.getProperty("file.separator")+"amarkhel"),
false);
+ assertEquals(fileManager.isDirectoryPresent("b"+System.getProperty("file.separator")+"amarkhel"),
true);
+ fileManager.deleteDirectory("b"+System.getProperty("file.separator")+"amarkhel");
+ }
+
+ public void testRenameDirectory4() throws Exception {
+ fileManager.addDirectory("a"+System.getProperty("file.separator")+"a"+System.getProperty("file.separator")+"amarkhel");
+ assertEquals(fileManager.isDirectoryPresent("a"+System.getProperty("file.separator")+"a"+System.getProperty("file.separator")+"amarkhel"),
true);
+ fileManager.renameDirectory("a"+System.getProperty("file.separator")+"a"+System.getProperty("file.separator")+"amarkhel",
"b"+System.getProperty("file.separator")+"b"+System.getProperty("file.separator")+"amarkhel");
+ assertEquals(fileManager.isDirectoryPresent("a"+System.getProperty("file.separator")+"a"+System.getProperty("file.separator")+"amarkhel"),
false);
+ assertEquals(fileManager.isDirectoryPresent("b"+System.getProperty("file.separator")+"b"+System.getProperty("file.separator")+"amarkhel"),
true);
+ fileManager.deleteDirectory("b"+System.getProperty("file.separator")+"b"+System.getProperty("file.separator")+"amarkhel");
+ }
+
+ public void testAddDirectory() {
+ assertEquals(fileManager.isDirectoryPresent("amarkhel"), false);
+ fileManager.addDirectory("amarkhel");
+ assertEquals(fileManager.isDirectoryPresent("amarkhel"), true);
+ fileManager.deleteDirectory("amarkhel");
+ }
+
+ public void testAddDirectory2() {
+ assertEquals(fileManager.isDirectoryPresent("a"+System.getProperty("file.separator")+"amarkhel"),
false);
+ fileManager.addDirectory("a"+System.getProperty("file.separator")+"amarkhel");
+ assertEquals(fileManager.isDirectoryPresent("a"+System.getProperty("file.separator")+"amarkhel"),
true);
+ fileManager.deleteDirectory("a"+System.getProperty("file.separator")+"amarkhel");
+ }
+
+ /*public void testAddImage() throws IOException {
+ assertEquals(fileManager.isImagePresent("amarkhel.gif"), false);
+ fileManager.addImage("amarkhel.gif", image);
+ assertEquals(fileManager.isImagePresent("amarkhel.gif"), true);
+ fileManager.deleteImage("amarkhel.gif");
+ }
+
+ public void testDeleteImage() throws IOException {
+ fileManager.addImage("amarkhel.gif", image);
+ assertEquals(fileManager.isImagePresent("amarkhel.gif"), true);
+ fileManager.deleteImage("amarkhel.gif");
+ assertEquals(fileManager.isImagePresent("amarkhel.gif"), false);
+ }
+
+ public void testRenameImage() throws IOException {
+ fileManager.addImage("amarkhel.gif", image);
+ assertEquals(fileManager.isImagePresent("amarkhel.gif"), true);
+ fileManager.renameImage("amarkhel.gif", "amarkhel2.gif");
+ assertEquals(fileManager.isImagePresent("amarkhel.gif"), false);
+ assertEquals(fileManager.isImagePresent("amarkhel2.gif"), true);
+ fileManager.deleteImage("amarkhel2.gif");
+ }
+
+ public void testRenameImage2() throws IOException {
+ fileManager.addImage("a"+System.getProperty("file.separator")+"amarkhel.gif",
image);
+ assertEquals(fileManager.isImagePresent("a"+System.getProperty("file.separator")+"amarkhel.gif"),
true);
+ fileManager.renameImage("a"+System.getProperty("file.separator")+"amarkhel.gif",
"b"+System.getProperty("file.separator")+"amarkhel2.gif");
+ assertEquals(fileManager.isImagePresent("a"+System.getProperty("file.separator")+"amarkhel.gif"),
false);
+ assertEquals(fileManager.isImagePresent("b"+System.getProperty("file.separator")+"amarkhel2.gif"),
true);
+ fileManager.deleteImage("b"+System.getProperty("file.separator")+"amarkhel2.gif");
+ fileManager.deleteDirectory("b");
+ fileManager.deleteDirectory("a");
+ }
+
+ public void testIsImagePresent() throws IOException {
+ fileManager.addImage("amarkhel.gif", image);
+ assertEquals(fileManager.isImagePresent("amarkhel.gif"), true);
+ assertEquals(fileManager.isImagePresent("amarkhel3.gif"), false);
+ fileManager.deleteImage("amarkhel.gif");
+ fileManager.addImage("am"+System.getProperty("file.separator")+"amarkhel.gif",
image);
+ assertEquals(fileManager.isImagePresent("am"+System.getProperty("file.separator")+"amarkhel.gif"),
true);
+ fileManager.deleteImage("am"+System.getProperty("file.separator")+"amarkhel.gif");
+ fileManager.deleteDirectory("am");
+ }*/
+
+}
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/test.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/test.java 2009-03-11
13:49:58 UTC (rev 12921)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/test.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -45,7 +45,6 @@
e1.printStackTrace();
}
int i = bsrc.getWidth() > bsrc.getHeight()? bsrc.getWidth(): bsrc.getHeight();
- int width2 = bsrc.getWidth();
double d = (double) size
/ i;
Double yy = ((Double)d*bsrc.getWidth());
Deleted:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/test2.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/test2.java 2009-03-11
13:49:58 UTC (rev 12921)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/test2.java 2009-03-11
14:24:18 UTC (rev 12922)
@@ -1,113 +0,0 @@
-package org.richfaces.realworld.util;
-
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.Transparency;
-import java.awt.image.BufferedImage;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import javax.imageio.ImageIO;
-import javax.imageio.ImageReader;
-import javax.imageio.ImageWriter;
-import javax.imageio.stream.ImageInputStream;
-public class test2 {
- public static BufferedImage bitmapToImage(String data, String format) throws IOException
{
- InputStream inb = new FileInputStream(data);
- ImageReader rdr = (ImageReader)
ImageIO.getImageReadersByFormatName(format).next();
- ImageInputStream imageInput = ImageIO.createImageInputStream(inb);
- rdr.setInput(imageInput);
- BufferedImage image = rdr.read(0);
- inb.close();
- return image;
- }
-
- public static void imageToBitmap(BufferedImage image, String data, String format)
throws IOException {
- OutputStream inb = new FileOutputStream(data);
- ImageWriter wrt = (ImageWriter)
ImageIO.getImageWritersByFormatName(format).next();
- ImageInputStream imageInput = ImageIO.createImageOutputStream(inb);
- wrt.setOutput(imageInput);
- wrt.write(image);
- inb.close();
- }
-
- /**
- * Convenience method that returns a scaled instance of the
- * provided {@code BufferedImage}.
- *
- * @param img the original image to be scaled
- * @param targetWidth the desired width of the scaled instance,
- * in pixels
- * @param targetHeight the desired height of the scaled instance,
- * in pixels
- * @param hint one of the rendering hints that corresponds to
- * {@code RenderingHints.KEY_INTERPOLATION} (e.g.
- * {@code RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR},
- * {@code RenderingHints.VALUE_INTERPOLATION_BILINEAR},
- * {@code RenderingHints.VALUE_INTERPOLATION_BICUBIC})
- * @param higherQuality if true, this method will use a multi-step
- * scaling technique that provides higher quality than the usual
- * one-step technique (only useful in downscaling cases, where
- * {@code targetWidth} or {@code targetHeight} is
- * smaller than the original dimensions, and generally only when
- * the {@code BILINEAR} hint is specified)
- * @return a scaled version of the original {@code BufferedImage}
- */
- public static BufferedImage getScaledInstance(BufferedImage img,
- int targetWidth,
- int targetHeight,
- Object hint,
- boolean higherQuality)
- {
- int type = (img.getTransparency() == Transparency.OPAQUE) ?
- BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
- BufferedImage ret = (BufferedImage)img;
- int w, h;
- if (higherQuality) {
- // Use multi-step technique: start with original size, then
- // scale down in multiple passes with drawImage()
- // until the target size is reached
- w = img.getWidth();
- h = img.getHeight();
- } else {
- // Use one-step technique: scale directly from original
- // size to target size with a single drawImage() call
- w = targetWidth;
- h = targetHeight;
- }
-
- do {
- if (higherQuality && w > targetWidth) {
- w /= 2;
- if (w < targetWidth) {
- w = targetWidth;
- }
- }
-
- if (higherQuality && h > targetHeight) {
- h /= 2;
- if (h < targetHeight) {
- h = targetHeight;
- }
- }
-
- BufferedImage tmp = new BufferedImage(w, h, type);
- Graphics2D g2 = tmp.createGraphics();
- g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint);
- g2.drawImage(ret, 0, 0, w, h, null);
- g2.dispose();
-
- ret = tmp;
- } while (w != targetWidth || h != targetHeight);
-
- return ret;
- }
- public static void main(String[] args) throws Exception {
- BufferedImage bitmapToImage =
bitmapToImage("E:\\realworldnew\\web\\src\\main\\webapp\\WEB-INF\\Upload\\amarkhel\\20\\sport
(14).jpg", "JPG");
- BufferedImage scaledInstance = getScaledInstance(bitmapToImage, 80, 60,
RenderingHints.VALUE_INTERPOLATION_BICUBIC, true);
- imageToBitmap(scaledInstance,
"E:\\realworldnew\\web\\src\\main\\webapp\\WEB-INF\\Upload\\amarkhel\\20\\sport
(14)_copy.jpg", "JPG");
- }
-}
Modified:
trunk/test-applications/realworld2/web/src/main/webapp/includes/contextMenu/CMForShelf.xhtml
===================================================================
(Binary files differ)
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/multyMode.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/test-applications/realworld2/web/src/main/webapp/includes/index/login.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/test-applications/realworld2/web/src/main/webapp/includes/register/regInfo.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/test-applications/realworld2/web/src/main/webapp/includes/userPrefs/userPrefs.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld2/web/src/main/webapp/layout/menu.xhtml
===================================================================
(Binary files differ)